Stable ordering when generating StructMeta code #1
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.
Currently, when user specifies
derive(StructMeta)
, this crategenerates a branch of code for each of the attributes.
These attributes however have so far been stored inside a
HashMap
which means the ordering of the branches is more or less random. This
has no real impact on the runtime: the order of the branches doesn't
change the semantics of the code. It does matter however for compile
time:
rustc
will calculate a different crate hash (effectively a sortof ABI signature) if code is re-ordered.
This means that any time we recompile code with
derive(StructMeta)
somewhere, we're breaking the ABI even if there were no changes at all
to any code. Basically, we're throwing a die at compile time as to what
order the code will be laid out in.
This is very bad for reproducability and plays very poorly with any sort
of binary caching.
I initially thought that the reproducability issue was coming from
rustc
itself but the more I was debugging, I made my way back to thiscrate.
You can see the original rustc issue for context
here.
I think this change should be basically invisible to anyone that's been
using the crate so far.