-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Metadata from incremental isn't the same as non-incremental #47066
Comments
@alexcrichton who helped look into #46846 |
Aha now this one's fascinating! Using the same script from #46846 I get:
So the metadata is changing! (cc @michaelwoerister, minimal test case) Interestingly I can only reproduce this nondeterminism though on the first incremental rebuild. That is:
@johnklai1 is this what you're seeing as well? Or is the md5 of libserde_derive.dylib constantly changing? Or only after the first build? I originally thought this was related to incremental compilation, but once I set I was having trouble narrowing down what's going on here. I took a diff of the Now I wasn't quite sure what was going on here so I tried to reduce it. Turns out ...
This is where things started to get real crazy. With the help of goblin (took me forever to realize to use that) I hunted this down to...
Turns out with debuginfo on OSX somehow the timestamp of the object file is going into the final output. That's why this isn't showing up in incremental compilation because the timestamp isn't changing (we're reusing the object file). That is, however, why this is showing up with random empty files! I... dunno what to do about this latter one. I suppose rustc could always set the mtime to all input object files to something deterministic though? |
Looking at the open source code available for It looks like lld also unconditionally gets the mtime without an option to reset it... Our only recourse on the latter issue here may be to just always reset the mtime to a known value. That wouldn't help anyone linking in C code but it could hopefully help pure-Rust projects at least? |
I've also minimized the "first time incremental metadata changes" to https://gist.github.com/alexcrichton/80c976db507a7f56a16a1f15b25293e4 I believe. |
Wow, awesome investigation @alexcrichton !
Yeah, this appears to be what I am seeing as well. If I run I'm taking a look at Windows too and will report back with my findings. |
I've extracted the OSX issue to #47086, retitled this issue to focus on the incremental problem, and updated the OP to have the current test case I've been using. @johnklai1 ok cool thanks for confirming. Windows will for sure be affected by this specific issue (incremental compilation with a warm and cold cache causes different outputs b/c the metadata object file is changing). Whether or not Windows suffers from an issue like #47086 though I'm not sure, and would for sure be good to investigate :) @michaelwoerister I did some more debugging in why the metadata is changing. I'm not super familiar with metadata and such and I found it difficult to debug, but I'm relatively certain that what's happening here is that a I believe that the closure in the test case has the MIR make its way into the metadata (not sure why but hey). I think that the encoded MIR for this closure is what's different in the metadata (again though, I find it difficult to say this with certainty). What I believe, though, is that with a cold cache (no incremental directory) a span is generated with the encoding I noticed that there's a pretty tricky implementation for spans being decoded, and I wonder if that's involved here perhaps? Do you know if the set of |
I think this problem arises due to our handling of invalid spans: Invalid spans (e.g. with This should be easily fixable by also adjusting invalid spans at serialization time for crate metadata. Thanks for debugging into this, @alexcrichton! |
It's strange that spans with rust/src/libsyntax_pos/span_encoding.rs Lines 39 to 42 in b893439
You have to work with SpanData exclusively without ever going through Span to get spans with lo > hi , but this never happens in rustc as far as I can see.
|
From what I can tell, these invalid spans originate mostly (or even exclusively) from macro expansion. Another case of invalid span is when |
Oh wait, looks like decoder doesn't work with spans, but with raw byte positions from codemap |
…tadata-encoding, r=alexcrichton Map invalid Spans to DUMMY_SP during crate metadata encoding. This mirrors what we do for stabilizing the incr. comp. cache and is necessary for reproducible builds. For the incr. comp. cache, we *have* to do this because the encoding there cannot represent broken Spans. Metadata encoding has to be in sync with that as not to get unexpected interactions when compiling incrementally. This should help with fixing issue #47066. r? @alexcrichton
The latest nightly should contain the fix from #47177. |
Looks to be so, thanks @michaelwoerister! |
Updated report
Looks like metadata generated from a cold cache of incremental compilation ends up being byte-for-byte different than metadata generated from a warm cache of incremental compilation. This can be seen with this script: https://gist.github.com/alexcrichton/80c976db507a7f56a16a1f15b25293e4
Original report
It looks like #46846 may not be fully resolved.
After updating to a recent nightly I can no longer reproduce the non-determinism on Linux, but I am still seeing it on OS X:
serde commit:
rustc version:
xcode version:
The text was updated successfully, but these errors were encountered: