Skip to content

Commit bda6b97

Browse files
committed
Use smallvec crate in pubgrub
1 parent 0974ddb commit bda6b97

File tree

7 files changed

+18
-248
lines changed

7 files changed

+18
-248
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@ keywords = ["dependency", "pubgrub", "semver", "solver", "version"]
2020
categories = ["algorithms"]
2121
include = ["Cargo.toml", "LICENSE", "README.md", "src/**", "tests/**", "examples/**", "benches/**"]
2222

23-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
24-
2523
[dependencies]
2624
indexmap = "2.6.0"
2725
# for debug logs in tests
2826
log = "0.4.22"
2927
priority-queue = "2.1.1"
3028
rustc-hash = ">=1.0.0, <3.0.0"
3129
serde = { version = "1.0", features = ["derive"], optional = true }
30+
smallvec = { version = "1.13.2", features = ["union"] }
3231
thiserror = "2.0"
3332
version-ranges = { version = "0.1.0", path = "version-ranges" }
3433

src/internal/core.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
66
use std::sync::Arc;
77

8+
use smallvec::SmallVec;
9+
810
use crate::{
911
internal::{
1012
Arena, DecisionLevel, IncompDpId, Incompatibility, PartialSolution, Relation,
11-
SatisfierSearch, SmallVec,
13+
SatisfierSearch,
1214
},
1315
DependencyProvider, DerivationTree, Map, PackageArena, PackageId, Set, Term, VersionIndex,
1416
VersionSet,
@@ -26,7 +28,7 @@ pub(crate) struct State<DP: DependencyProvider> {
2628
/// All incompatibilities expressing dependencies,
2729
/// with common dependents merged.
2830
#[allow(clippy::type_complexity)]
29-
merged_dependencies: Map<(PackageId, PackageId), SmallVec<IncompDpId<DP>>>,
31+
merged_dependencies: Map<(PackageId, PackageId), SmallVec<[IncompDpId<DP>; 4]>>,
3032

3133
/// Partial solution.
3234
/// TODO: remove pub.
@@ -38,7 +40,7 @@ pub(crate) struct State<DP: DependencyProvider> {
3840
/// This is a stack of work to be done in `unit_propagation`.
3941
/// It can definitely be a local variable to that method, but
4042
/// this way we can reuse the same allocation for better performance.
41-
unit_propagation_buffer: SmallVec<PackageId>,
43+
unit_propagation_buffer: Vec<PackageId>,
4244
}
4345

4446
impl<DP: DependencyProvider> State<DP> {
@@ -57,7 +59,7 @@ impl<DP: DependencyProvider> State<DP> {
5759
incompatibilities,
5860
partial_solution: PartialSolution::empty(),
5961
incompatibility_store,
60-
unit_propagation_buffer: SmallVec::Empty,
62+
unit_propagation_buffer: Vec::new(),
6163
merged_dependencies: Map::default(),
6264
}
6365
}
@@ -254,7 +256,7 @@ impl<DP: DependencyProvider> State<DP> {
254256
if let Some((pid1, pid2)) = self.incompatibility_store[id].as_dependency() {
255257
// If we are a dependency, there's a good chance we can be merged with a previous dependency
256258
let deps_lookup = self.merged_dependencies.entry((pid1, pid2)).or_default();
257-
if let Some((past, merged)) = deps_lookup.as_mut_slice().iter_mut().find_map(|past| {
259+
if let Some((past, merged)) = deps_lookup.iter_mut().find_map(|past| {
258260
self.incompatibility_store[id]
259261
.merge_dependents(&self.incompatibility_store[*past])
260262
.map(|m| (past, m))

src/internal/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ mod core;
77
mod incompatibility;
88
mod partial_solution;
99
mod small_map;
10-
mod small_vec;
1110

1211
pub(crate) use arena::{Arena, Id};
1312
pub(crate) use core::State;
1413
pub(crate) use incompatibility::{IncompDpId, IncompId, Incompatibility, Relation};
1514
pub(crate) use partial_solution::{DecisionLevel, PartialSolution, SatisfierSearch};
1615
pub(crate) use small_map::SmallMap;
17-
pub(crate) use small_vec::SmallVec;

src/internal/partial_solution.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ use std::hash::BuildHasherDefault;
77

88
use priority_queue::PriorityQueue;
99
use rustc_hash::FxHasher;
10+
use smallvec::{smallvec, SmallVec};
1011

1112
use crate::Map;
1213
use crate::{
13-
internal::{Arena, IncompDpId, IncompId, Incompatibility, Relation, SmallMap, SmallVec},
14+
internal::{Arena, IncompDpId, IncompId, Incompatibility, Relation, SmallMap},
1415
DependencyProvider, FxIndexMap, PackageArena, PackageId, SelectedDependencies, Term,
1516
VersionIndex, VersionSet,
1617
};
@@ -97,7 +98,7 @@ impl<'a, DP: DependencyProvider> Display for PartialSolutionDisplay<'a, DP> {
9798
struct PackageAssignments<M: Eq + Clone + Debug + Display> {
9899
smallest_decision_level: DecisionLevel,
99100
highest_decision_level: DecisionLevel,
100-
dated_derivations: SmallVec<DatedDerivation<M>>,
101+
dated_derivations: SmallVec<[DatedDerivation<M>; 1]>,
101102
assignments_intersection: AssignmentsIntersection,
102103
}
103104

@@ -298,7 +299,7 @@ impl<DP: DependencyProvider> PartialSolution<DP> {
298299
v.insert(PackageAssignments {
299300
smallest_decision_level: self.current_decision_level,
300301
highest_decision_level: self.current_decision_level,
301-
dated_derivations: SmallVec::One([dated_derivation]),
302+
dated_derivations: smallvec![dated_derivation],
302303
assignments_intersection: AssignmentsIntersection::derivations(term),
303304
});
304305
}
@@ -599,14 +600,15 @@ impl<M: Eq + Clone + Debug + Display> PackageAssignments<M> {
599600
start_term: Term,
600601
package_store: &PackageArena<DP::P>,
601602
) -> (Option<IncompId<M>>, u32, DecisionLevel) {
602-
let empty = Term::empty();
603603
// Indicate if we found a satisfier in the list of derivations, otherwise it will be the decision.
604604
let idx = self
605605
.dated_derivations
606-
.as_slice()
607606
.partition_point(|dd| !dd.accumulated_intersection.is_disjoint(start_term));
608607
if let Some(dd) = self.dated_derivations.get(idx) {
609-
debug_assert_eq!(dd.accumulated_intersection.intersection(start_term), empty);
608+
debug_assert_eq!(
609+
dd.accumulated_intersection.intersection(start_term),
610+
Term::empty(),
611+
);
610612
return (Some(dd.cause), dd.global_index, dd.decision_level);
611613
}
612614
// If it wasn't found in the derivations, it must be the decision which is last (if called in the right context).

src/internal/small_vec.rs

Lines changed: 0 additions & 232 deletions
This file was deleted.

version-ranges/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ impl<V: Ord> Ranges<V> {
305305
/// See [`Ranges`] for the invariants checked.
306306
fn check_invariants(self) -> Self {
307307
if cfg!(debug_assertions) {
308-
for p in self.segments.as_slice().windows(2) {
308+
for p in self.segments.windows(2) {
309309
assert!(end_before_start_with_gap(&p[0].1, &p[1].0));
310310
}
311311
for (s, e) in self.segments.iter() {

0 commit comments

Comments
 (0)