-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Unify Rvalue::Aggregate
paths in cg_ssa
#124999
Conversation
debug_assert!( | ||
val.is_expected_variant_for_type(self.cx, layout), | ||
"Made wrong variant {val:?} for type {layout:?}", | ||
); |
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.
Added this to help make the ICE clearer in debug, since otherwise it hit this less-helpful one:
_ => bug!("not immediate: {:?}", self), |
let ty = rvalue.ty(self.mir, self.cx.tcx()); | ||
let ty = self.monomorphize(ty); | ||
let layout = self.cx.layout_of(ty); | ||
|
||
let field_indices = if let mir::AggregateKind::RawPtr(..) = **kind { | ||
// `index_by_increasing_offset` gives an empty iterator for primitives |
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.
what happens if we instead modify Index_by_increasing_offset
to also return the fields of a raw ptr? I would expect that we'd want to consistently treat raw pointers as (actual_ptr, metadata) pairs during codegen
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.
Hmm, I haven't audited the other 6 places this is used. I know that when I implemented AggregateKind::RawPtr
originally I tried doing it via the non-OperandValue
path, but that tried to project into a pointer which also didn't have the fields and thus ICEd. Maybe it'd make sense to have fat pointers at least have the two fields, if they don't? I'm not sure.
One thing about this code specifically, though, is that RawPtr
always takes two "field" arguments, because from_raw_parts
wants from_raw_parts(thin, ())
to work for thin pointers too. And I have to assume that we don't want thin pointers to have a unit metadata field in the Layout
? So the debug assertion about the field lengths matching couldn't be done any more, though maybe that's fine and we can instead trust the MIR validator for it instead...
I think my preference here would be to leave this as-is, because even if changing index_by_increasing_offset
(and possibly pointer layouts in general) is the right way forward, I think it should be its own PR.
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.
Well, a quick scan through the other uses of index_by_increasing_offset
suggests that it's almost entirely for Aggregate
s, and thus we can probably tweak it directly. I've pushed a commit with that; let's see what CI thinks about it. It definitely makes the change in cg_ssa
nicer, so here's hoping.
EDIT: Looks like it's happy!
☔ The latest upstream changes (presumably #124153) made this pull request unmergeable. Please resolve the merge conflicts. |
nice to see that my review comment ended up being actually useful 😊 this is now involved enough for me to not be comfortable approving this myself 😅 while I think this is correct r? compiler |
@bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (6be7b0c): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Bootstrap: 677.638s -> 675.291s (-0.35%) |
In #123840 and #123886 I added two different codepaths for
Rvalue::Aggregate
incg_ssa
.This merges them into one, since raw pointers are also immediates that can be built from the immediates of their "fields".