Encode VariantIdx so we can decode ADT variants in the right order#111494
Merged
bors merged 1 commit intorust-lang:masterfrom May 13, 2023
Merged
Encode VariantIdx so we can decode ADT variants in the right order#111494bors merged 1 commit intorust-lang:masterfrom
VariantIdx so we can decode ADT variants in the right order#111494bors merged 1 commit intorust-lang:masterfrom
Conversation
Contributor
I think you could put |
Contributor
|
r=me, preferably with a test #111494 (comment). |
68c97c4 to
ff54c80
Compare
Contributor
Author
|
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 |
Collaborator
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
May 13, 2023
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
Contributor
Merged
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
May 20, 2023
[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
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
May 22, 2023
…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.
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.
As far as I can tell, we don't guarantee anything about the ordering of
DefIds 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 theDisconnectenum variant to be collected after its siblings, and it shows up after the other variants inmodule_children.When we decode the variants for
Datain a child crate (an example test, in this case), this means that theDisconnectvariant 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_reexportsto 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.