Skip to content

fix: iterate all entries of a sparse Mapping - #319

Open
RaphaelFakhri wants to merge 1 commit into
prefix-dev:mainfrom
RaphaelFakhri:fix/mapping-iter-sparse
Open

RaphaelFakhri wants to merge 1 commit into
prefix-dev:mainfrom
RaphaelFakhri:fix/mapping-iter-sparse

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

MappingIter stops once its offset reaches Mapping::len, the number of stored values. When the ids in a Mapping are not contiguous from zero, or a value was removed with unset, the iterator ends before it reaches the highest id and silently skips entries.

DependencySnapshot::from_provider hits this when the snapshot covers only some of the provider's packages. It iterates packages to apply the provider's candidate order, so packages with high NameIds keep order: 0 for every solvable. Solving against the snapshot then picks candidates in insertion order instead of the provider's preferred order, which can produce a different solution than the original provider.

Changes

  • MappingIter now iterates up to the highest inserted id (Mapping::max) instead of Mapping::len.
  • test_iter_sparse in src/utils/mapping.rs covers sparse ids and unset.
  • test_snapshot_subset_of_packages_keeps_candidate_order snapshots only b from a provider that also has a. Before the fix the snapshot solves to b=1; with the fix it solves to b=3, matching the original provider's highest-version-first order.

Testing

cargo test --lib mapping
cargo test --test solver test_snapshot_subset
cargo test --workspace --all-features
cargo fmt --all -- --check
cargo clippy --workspace --all-targets --all-features -- -D warnings

Fixes #318

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MappingIter skips entries when Mapping ids are sparse, so DependencySnapshot leaves candidates unsorted

1 participant