Skip to content

Commit 8458661

Browse files
committed
reuse vars where publicly_exports implies can_see
1 parent a7676eb commit 8458661

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

tests/testsuite/support/resolver.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ fn sat_at_most_one(solver: &mut impl varisat::ExtendFormula, vars: &[varisat::Va
223223
/// as compared to the real resolver.
224224
///
225225
/// For the subset of functionality that are currently made by `registry_strategy` this will,
226-
/// find a valid resolution if one exists.
226+
/// find a valid resolution if one exists. The big thing that the real resolver does,
227+
/// that this one does not do is work with features and optional dependencies.
227228
///
228229
/// The SAT library dose not optimize for the newer version,
229230
/// so the selected packages may not match the real resolver.
@@ -346,14 +347,12 @@ impl SatResolve {
346347
// if a `dep` is public then `p` `publicly_exports` all the things that the selected version `publicly_exports`
347348
for &p in topological_order.iter() {
348349
if let Some(deps) = version_selected_for.get(&p) {
350+
let mut p_exports = publicly_exports.remove(&p.as_activations_key()).unwrap();
349351
for (_, versions) in deps.iter().filter(|(d, _)| d.is_public()) {
350352
for (ver, sel) in versions {
351-
for (&export_pid, &export_var) in publicly_exports[ver].clone().iter() {
352-
let our_var = publicly_exports
353-
.entry(p.as_activations_key())
354-
.or_default()
355-
.entry(export_pid)
356-
.or_insert_with(|| cnf.new_var());
353+
for (&export_pid, &export_var) in publicly_exports[ver].iter() {
354+
let our_var =
355+
p_exports.entry(export_pid).or_insert_with(|| cnf.new_var());
357356
cnf.add_clause(&[
358357
sel.negative(),
359358
export_var.negative(),
@@ -362,23 +361,22 @@ impl SatResolve {
362361
}
363362
}
364363
}
364+
publicly_exports.insert(p.as_activations_key(), p_exports);
365365
}
366366
}
367367

368368
// we already ensure there is only one version for each `activations_key` so we can think of
369369
// `can_see` as being in terms of a set of `activations_key`s
370-
let mut can_see: HashMap<_, HashMap<_, varisat::Var>> = HashMap::new();
370+
// and if `p` `publicly_exports` `export` then it `can_see` `export`
371+
let mut can_see: HashMap<_, HashMap<_, varisat::Var>> = publicly_exports.clone();
371372

372373
// if `p` has a `dep` that selected `ver` then it `can_see` all the things that the selected version `publicly_exports`
373374
for (&p, deps) in version_selected_for.iter() {
374-
for (_, versions) in deps {
375+
let p_can_see = can_see.entry(p.as_activations_key()).or_default();
376+
for (_, versions) in deps.iter().filter(|(d, _)| !d.is_public()) {
375377
for (&ver, sel) in versions {
376378
for (&export_pid, &export_var) in publicly_exports[&ver].iter() {
377-
let our_var = can_see
378-
.entry(p.as_activations_key())
379-
.or_default()
380-
.entry(export_pid)
381-
.or_insert_with(|| cnf.new_var());
379+
let our_var = p_can_see.entry(export_pid).or_insert_with(|| cnf.new_var());
382380
cnf.add_clause(&[
383381
sel.negative(),
384382
export_var.negative(),

0 commit comments

Comments
 (0)