Skip to content

Commit 29954af

Browse files
authored
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
2 parents c1d1f7a + 64df9e3 commit 29954af

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

compiler/rustc_codegen_ssa/src/mir/operand.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,15 @@ pub enum OperandValue<V> {
4545
Immediate(V),
4646
/// A pair of immediate LLVM values. Used by wide pointers too.
4747
///
48-
/// An `OperandValue` *must* be this variant for any type for which
48+
/// # Invariants
49+
/// - For `Pair(a, b)`, `a` is always at offset 0, but may have `FieldIdx(1..)`
50+
/// - `b` is not at offset 0, because `V` is not a 1ZST type.
51+
/// - `a` and `b` will have a different FieldIdx, but otherwise `b`'s may be lower
52+
/// or they may not be adjacent, due to arbitrary numbers of 1ZST fields that
53+
/// will not affect the shape of the data which determines if `Pair` will be used.
54+
/// - An `OperandValue` *must* be this variant for any type for which
4955
/// [`LayoutTypeCodegenMethods::is_backend_scalar_pair`] returns `true`.
50-
/// The backend values in this variant must be the *immediate* backend types,
56+
/// - The backend values in this variant must be the *immediate* backend types,
5157
/// as returned by [`LayoutTypeCodegenMethods::scalar_pair_element_backend_type`]
5258
/// with `immediate: true`.
5359
Pair(V, V),

0 commit comments

Comments
 (0)