-
Notifications
You must be signed in to change notification settings - Fork 13.4k
compiler: Document the offset invariant of OperandValue::Pair
#142044
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
compiler: Document the offset invariant of OperandValue::Pair
#142044
Conversation
Some changes occurred in compiler/rustc_codegen_ssa |
@@ -45,9 +45,11 @@ pub enum OperandValue<V> { | |||
Immediate(V), | |||
/// A pair of immediate LLVM values. Used by wide pointers too. | |||
/// | |||
/// An `OperandValue` *must* be this variant for any type for which | |||
/// # Invariants | |||
/// - for `Pair(a, b)`, `a` is always offset 0 but **may** be `FieldIdx::ONE` |
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.
not entirely sure if this is more of a "by definition" thing or if it requires manually enforcing it. not entirely sure if anyone knows.
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.
You might consider elaborating in a later paragraph.
For example, if you discuss struct Foo((), u8, (), u32, ());
, today that's a ScalarPair
where the Pair(a, b)
has a
as FieldIdx(3)
and b
as FieldIdx(1)
.
(We shouldn't be using LLVM struct types to do this any more, but I think originally it had to be that way so that if you loaded the pair type from memory they'd go into the correct fields. Now it's just that that's the definition of what a ScalarPair layout even means, I think.)
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.
Hm.
Is b
guaranteed to not be at offset 0, then?
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.
better, worse, incorrect?
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.
Is
b
guaranteed to not be at offset 0, then?
Yes. Neither of the immediates can be a unit -- we don't bother making backend immediate values for a nothing-unit. So both scalars have non-zero size (which you can also see by inspection of https://doc.rust-lang.org/nightly/nightly-rustc/rustc_abi/enum.Scalar.html ) and thus they necessarily have two different offsets.
fc26e4e
to
64df9e3
Compare
Thanks! This looks good to me. @bors r+ rollup |
…ue-pair, r=scottmcm compiler: Document the offset invariant of `OperandValue::Pair` A subtle invariant of `OperandValue::Pair` that came up during review and was found to be undocumented. Visible in code like this: https://github.com/rust-lang/rust/blob/4b27a04cc8ed4da10a546a871e23e665d03f7a79/compiler/rustc_codegen_ssa/src/mir/operand.rs#L376-L392
Rollup of 11 pull requests Successful merges: - #125087 (Optimize `Seek::stream_len` impl for `File`) - #141982 (`tests/ui`: A New Order [5/N]) - #142012 (Replace some `Option<Span>` with `Span` and use DUMMY_SP instead of None) - #142044 (compiler: Document the offset invariant of `OperandValue::Pair`) - #142047 (Ensure stack in two places that affect s390x) - #142058 (Clean `rustc_attr_parsing/src/lib.rs` documentation) - #142067 (canon_abi: make to_erased_extern_abi just a detail in formatting) - #142072 (doc: Fix inverted meaning in E0783.md) - #142084 (add myself to rotation) - #142091 (Fix AIX build) - #142092 (rustdoc: Support middle::ty associated const equality predicates again) Failed merges: - #142042 (Make E0621 missing lifetime suggestion verbose) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 11 pull requests Successful merges: - #125087 (Optimize `Seek::stream_len` impl for `File`) - #141982 (`tests/ui`: A New Order [5/N]) - #142012 (Replace some `Option<Span>` with `Span` and use DUMMY_SP instead of None) - #142044 (compiler: Document the offset invariant of `OperandValue::Pair`) - #142047 (Ensure stack in two places that affect s390x) - #142058 (Clean `rustc_attr_parsing/src/lib.rs` documentation) - #142067 (canon_abi: make to_erased_extern_abi just a detail in formatting) - #142072 (doc: Fix inverted meaning in E0783.md) - #142084 (add myself to rotation) - #142091 (Fix AIX build) - #142092 (rustdoc: Support middle::ty associated const equality predicates again) Failed merges: - #142042 (Make E0621 missing lifetime suggestion verbose) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 11 pull requests Successful merges: - #125087 (Optimize `Seek::stream_len` impl for `File`) - #141982 (`tests/ui`: A New Order [5/N]) - #142012 (Replace some `Option<Span>` with `Span` and use DUMMY_SP instead of None) - #142044 (compiler: Document the offset invariant of `OperandValue::Pair`) - #142047 (Ensure stack in two places that affect s390x) - #142058 (Clean `rustc_attr_parsing/src/lib.rs` documentation) - #142067 (canon_abi: make to_erased_extern_abi just a detail in formatting) - #142072 (doc: Fix inverted meaning in E0783.md) - #142084 (add myself to rotation) - #142091 (Fix AIX build) - #142092 (rustdoc: Support middle::ty associated const equality predicates again) Failed merges: - #142042 (Make E0621 missing lifetime suggestion verbose) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #142044 - workingjubilee:document-operandvalue-pair, r=scottmcm compiler: Document the offset invariant of `OperandValue::Pair` A subtle invariant of `OperandValue::Pair` that came up during review and was found to be undocumented. Visible in code like this: https://github.com/rust-lang/rust/blob/4b27a04cc8ed4da10a546a871e23e665d03f7a79/compiler/rustc_codegen_ssa/src/mir/operand.rs#L376-L392
A subtle invariant of
OperandValue::Pair
that came up during review and was found to be undocumented.Visible in code like this:
rust/compiler/rustc_codegen_ssa/src/mir/operand.rs
Lines 376 to 392 in 4b27a04
r? @scottmcm