Use BTreeMap for deterministic Into impl order (fixes #48)#49
Open
pchikku wants to merge 1 commit into
Open
Conversation
The Into derive iterated TypeAttribute.types (a HashMap) to emit one impl block per target. HashMap iteration order is randomized per process, so the generated impls came out in a different order each compile, changing the consuming crate's metadata hash (SVH) build-to-build (rust-lang/rust#89904 class). HashType already implements Ord, so switching types to BTreeMap makes the order deterministic with no other change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #48.
The
Intoderive emits oneimpl Into<…>block per entry ofTypeAttribute.types, which is astd::collections::HashMap.HashMapiteration order is randomized per process (getrandom seed), so the generatedimplblocks come out in a different order on every compile, which changes the consuming crate's metadata hash (SVH). Under content-addressed build systems with a shared cache this causes the same input to produce different artifacts, and mixing a fresh build with a cached dependency fails witherror[E0463]: can't find crate(the proc-macro variant of rust-lang/rust#89904).HashTypealready implementsOrd, so this PR switchesTypeAttribute.typesfromHashMaptoBTreeMap— deterministic iteration order, no other change.Verified: a struct with several
Intotargets, built three times with a clean rebuild each, produced three different.rmetahashes before this change and three identical hashes after.