-
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
Make reprs use a structured representation instead of a slice #39595
Conversation
26f340d
to
272a3e5
Compare
src/librustc/ty/mod.rs
Outdated
@@ -1818,6 +1847,14 @@ impl<'tcx> TyS<'tcx> { | |||
} | |||
} | |||
} | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extraneous empty line.
src/librustc/ty/mod.rs
Outdated
@@ -1818,6 +1847,14 @@ impl<'tcx> TyS<'tcx> { | |||
} | |||
} | |||
} | |||
|
|||
|
|||
pub fn get_repr(&self) -> Option<&ReprOptions> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only used in encoder.rs
, could it be a helper method there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it could. But my thought is that things like future lints are going to want it as well.
src/librustc_metadata/encoder.rs
Outdated
@@ -401,8 +401,12 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { | |||
} | |||
} | |||
|
|||
let repr_options = *self.tcx.item_type(adt_def_id).get_repr().expect( | |||
&format!("{:?} is not an ADT", def_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not the best to have this allocating here. If you make an encoding-specific helper method you can just use bug!
in cases other than TyAdt
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll factor those out.
I've moved all of this to a helper method in |
…utes. This effectively deprecates lookup_repr_hints.
272a3e5
to
541aa8a
Compare
Unless we want me to try to kill more if someone wants to suggest a large crate with a lot of tests that I can build really quickly to see if metadata is actually working, that's not necessarily a bad idea. |
@bors r+ |
📋 Looks like this PR is still in progress, ignoring approval |
@bors r+ |
📌 Commit c3b64cf has been approved by |
Make reprs use a structured representation instead of a slice This is needed for `-z reorder-fields`. The old design uses a slice taken from HIR, plus a cache that lazily parses. The new design stores it directly in the `AdtDef` as a `ReprOptions`. We're doing this now because we need to be able to add reprs that don't necessarily exist in HIR for `-z reorder-fields`, but it needs to happen anyway. `lookup_repr_hints` should be mostly deprecated. I want to remove it from `layout` before closing this, unless people think that should be a separate PR. The `[WIP]` is because of this. The problem with closing this as-is is that the code here isn't actually testable until some parts of the compiler start using it. r? @eddyb
This is needed for
-z reorder-fields
. The old design uses a slice taken from HIR, plus a cache that lazily parses. The new design stores it directly in theAdtDef
as aReprOptions
. We're doing this now because we need to be able to add reprs that don't necessarily exist in HIR for-z reorder-fields
, but it needs to happen anyway.lookup_repr_hints
should be mostly deprecated. I want to remove it fromlayout
before closing this, unless people think that should be a separate PR. The[WIP]
is because of this. The problem with closing this as-is is that the code here isn't actually testable until some parts of the compiler start using it.r? @eddyb