-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Encode VariantIdx
so we can decode ADT variants in the right order
#111494
Conversation
I think you could put |
r=me, preferably with a test #111494 (comment). |
68c97c4
to
ff54c80
Compare
Took a lot of work, but I found a test that actually reproduced the issue. It was surprisingly hard (and really order-dependent) to load the wrong ADT from the crate metadata... @bors r=petrochenkov |
Rollup of 6 pull requests Successful merges: - rust-lang#110454 (Require impl Trait in associated types to appear in method signatures) - rust-lang#111096 (Add support for `cfg(overflow_checks)`) - rust-lang#111451 (Note user-facing types of coercion failure) - rust-lang#111469 (Fix data race in llvm source code coverage) - rust-lang#111494 (Encode `VariantIdx` so we can decode ADT variants in the right order) - rust-lang#111499 (asm: loongarch64: Drop efiapi) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
[beta] backport - debuginfo: split method declaration and definition rust-lang#111167 - Encode VariantIdx so we can decode ADT variants in the right order rust-lang#111494 - Simplify find_width_of_character_at_span. rust-lang#111560 r? cuviper
…trieb Add extra debug assertions for equality for Adt/Variant/FieldDef Would've made it easier to both catch and test rust-lang#111494. Maybe not worth it, since it does mean that the compiler is doing extra work when debug-assertions are enabled, but also that's what debug assertions are for :^) This is a revival of rust-lang#111523 because I think I pushed an empty branch and bors got a bit too excited it closed the PR.
As far as I can tell, we don't guarantee anything about the ordering of
DefId
s and module children...The code that motivated this PR (#111483) looks something like:
The specific macro (
protocol
) doesn't really matter, but as far as I can tell (from calls tobuild_reduced_graph
), the presence of that#[protocol(..)]
helper attribute causes the def-id of theDisconnect
enum variant to be collected after its siblings, and it shows up after the other variants inmodule_children
.When we decode the variants for
Data
in a child crate (an example test, in this case), this means that theDisconnect
variant is moved to the end of the variants list, and all of the other variants now have incorrect relative discriminant data, causing the ICE.This PR fixes this by sorting manually by variant index after they are decoded. I guess there are alternative ways of fixing this, such as not reusing
module_children_non_reexports
to encode the order-sensitive ADT variants, or to do some sorting inrustc_resolve
... but none of those seemed particularly satisfying either.I really struggled to create a reproduction here -- it required at least 3 crates, one of which is a proc macro, and then some code to actually compute discriminants in the child crate... Needless to say, I failed to repro this in a test, but I can confirm that it fixes the regression in #111483.Test exists now.r? @petrochenkov but feel free to reassign.
Again, sorry for no test, but I hope the explanation at least suggests why a fix like this is likely necessary.Feedback is welcome.