Skip to content

Make manifest serialization deterministic#4562

Merged
bors merged 1 commit intorust-lang:masterfrom
SimonSapin:btree-manifest
Oct 2, 2017
Merged

Make manifest serialization deterministic#4562
bors merged 1 commit intorust-lang:masterfrom
SimonSapin:btree-manifest

Conversation

@SimonSapin
Copy link
Contributor

Fixes #4326

cargo package (and so cargo publish) parses a crate’s Cargo.toml, makes some modifications, and re-serializes it. Because the TomlManifest struct uses HashMap with its default RandomState hasher, the maps’ iteration order changed on every run.

As a result, when using cargo vendor, updating a dependency would generate a diff larger than necessary, with non-significant order-changes obscuring significant changes.

This replaces some uses of HashMap with BTreeMap, whose iteration order is deterministic (based on Ord).

Fixes rust-lang#4326

`cargo package` (and so `cargo publish`) parses a crate’s `Cargo.toml`,
makes some modifications, and re-serializes it.
Because the `TomlManifest` struct uses `HashMap`
with its default `RandomState` hasher,
the maps’ iteration order changed on every run.

As a result, when using `cargo vendor`,
updating a dependency would generate a diff larger than necessary,
with non-significant order-changes obscuring significant changes.

This replaces some uses of `HashMap` with `BTreeMap`,
whose iteration order is deterministic (based on `Ord`).
@rust-highfive
Copy link

r? @matklad

(rust_highfive has picked a reviewer for you, use r? to override)

@matklad
Copy link
Contributor

matklad commented Oct 2, 2017

Perhaps we should use OrderedMap here in some cases, to preserve the order of the original Cargo.toml?

@SimonSapin
Copy link
Contributor Author

I personally don’t care much about preserving the original order, as long as it doesn’t change on every update.

"checksum crypto-hash 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "34903878eec1694faf53cae8473a088df333181de421d4d3d48061d6559fe602"
"checksum curl 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7034c534a1d7d22f7971d6088aa9d281d219ef724026c3428092500f41ae9c2c"
"checksum curl-sys 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "4bee31aa3a079d5f3ff9579ea4dcfb1b1a17a40886f5f467436d383e78134b55"
"checksum custom_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "ef8ae57c4978a2acd8b869ce6b9ca1dfe817bff704c220209fdef2c0b75a01b9"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, where do these lockfile changes come from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They’re unrelated, and happen when I compile master unmodified. @alexcrichton said (in person) that it’s likely that someone forgot to include that change when they changed Cargo’s Cargo.toml in a previous PR, and that including that in this PR was fine. I can remove it if you prefer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or split it into a separate commit in the same PR.

@matklad
Copy link
Contributor

matklad commented Oct 2, 2017

@bors r+

Thanks @SimonSapin !

@bors
Copy link
Contributor

bors commented Oct 2, 2017

📌 Commit f38c53f has been approved by matklad

@bors
Copy link
Contributor

bors commented Oct 2, 2017

⌛ Testing commit f38c53f with merge d7e3b7f...

bors added a commit that referenced this pull request Oct 2, 2017
Make manifest serialization deterministic

Fixes #4326

`cargo package` (and so `cargo publish`) parses a crate’s `Cargo.toml`, makes some modifications, and re-serializes it. Because the `TomlManifest` struct uses `HashMap` with its default `RandomState` hasher, the maps’ iteration order changed on every run.

As a result, when using `cargo vendor`, updating a dependency would generate a diff larger than necessary, with non-significant order-changes obscuring significant changes.

This replaces some uses of `HashMap` with `BTreeMap`, whose iteration order is deterministic (based on `Ord`).
@bors
Copy link
Contributor

bors commented Oct 2, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: matklad
Pushing d7e3b7f to master...

@bors bors merged commit f38c53f into rust-lang:master Oct 2, 2017
@bors bors mentioned this pull request Oct 2, 2017
@ehuss ehuss added this to the 1.22.0 milestone Feb 6, 2022
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.

Manifest re-serialization in 'cargo package' is non-deterministic

5 participants