-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Update InterpCx::project_field
to take FieldIdx
#142103
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
base: master
Are you sure you want to change the base?
Conversation
Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 Some changes occurred in compiler/rustc_codegen_ssa Some changes occurred to the CTFE machinery Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt The Miri subtree was changed cc @rust-lang/miri |
This comment has been minimized.
This comment has been minimized.
As suggested by Ralf in 142005.
74c269e
to
8bce225
Compare
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 PR highlights several situations where we can do improvements, but let's land this on its own and investigate from_usize
and as_usize
calls later
@@ -288,7 +295,7 @@ impl<'a, Ty> TyAndLayout<'a, Ty> { | |||
// More than one non-1-ZST field. | |||
return None; | |||
} | |||
found = Some((field_idx, field)); | |||
found = Some((FieldIdx::from_usize(field_idx), field)); |
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.
it may be worth adding an iter
and an iter_enumerated
method to FieldsShape
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, most of the layout-related usize
s in ABI are sketchy. I've tried pulling on the tendrils before, but usually ended up giving up because of just how far that goes and -- as I mentioned in the other PR -- that the ones related to arrays sometimes need more than FieldIdx
, and figuring out which those are can be hard.
(Conveniently this one was obvious because a over-4-billion-length array clearly can't have exactly one non-ZST.)
@bors r+ rollup |
impl FieldIdx { | ||
/// The second field. | ||
/// | ||
/// For use alongside [`FieldIdx::ZERO`], particularly with scalar pairs. |
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.
Why is this not defined near FieldIdx::ZERO
?
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.
Because all rustc_newtype_index! types get a ZERO
; it's not something special for FieldIdx
.
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.
@@ -60,7 +60,7 @@ pub(crate) fn try_destructure_mir_constant_for_user_output<'tcx>( | |||
|
|||
let fields_iter = (0..field_count) | |||
.map(|i| { | |||
let field_op = ecx.project_field(&down, i).discard_err()?; | |||
let field_op = ecx.project_field(&down, FieldIdx::from_usize(i)).discard_err()?; |
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 could also use a typed field iterator
@@ -40,7 +40,7 @@ fn branches<'tcx>( | |||
} | |||
|
|||
for i in 0..field_count { | |||
let field = ecx.project_field(&place, i).unwrap(); | |||
let field = ecx.project_field(&place, FieldIdx::from_usize(i)).unwrap(); |
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.
And more here
(probably not worth pointing them all out)
// Computing the layout does normalization, so we get a normalized type out of this | ||
// even if the field type is non-normalized (possible e.g. via associated types). | ||
let field_layout = base.layout().field(self, field); | ||
let field_layout = base.layout().field(self, field.as_usize()); |
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.
Why does field
not take FieldIdx
...?
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.
It's https://doc.rust-lang.org/nightly/nightly-rustc/rustc_abi/struct.TyAndLayout.html#method.field, I think. And that's like I mentioned in #142005 (comment) something that takes usize
today, because it works on arrays https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_middle/ty/layout.rs.html#795-998.
Co-authored-by: Ralf Jung <[email protected]>
@bors r=oli-obk |
Yeah those should be separate methods for fields and array elements.
Is this entire project tracked somewhere? (Also re: field iterators)
|
I think "project" overstates at least how I've been handling this. I had rust-lang/compiler-team#606 to add There's never been a tracking issue for it, or a list of all the things that should happen, or anything. Just a bunch of "spots I saw in passing" PRs. |
…-obk Update `InterpCx::project_field` to take `FieldIdx` As suggested by Ralf in rust-lang#142005 (comment)
Rollup of 11 pull requests Successful merges: - #140418 (Reexport types from `c_size_t` in `std`) - #141471 (unsafe keyword docs: emphasize that an unsafe fn in a trait does not get to choose its safety contract) - #141603 (Reduce `ast::ptr::P` to a typedef of `Box`) - #142043 (Verbose suggestion to make param `const`) - #142086 (duduplicate more AST visitor methods) - #142103 (Update `InterpCx::project_field` to take `FieldIdx`) - #142105 (remove extraneous text) - #142112 (fix typo) - #142113 (Reduce confusion of some drop order tests) - #142114 (Compute number of digits instead of relying on constant value for u128 display code) - #142118 (rustc_lexer: typo fix + small cleanups) r? `@ghost` `@rustbot` modify labels: rollup
As suggested by Ralf in #142005 (comment)