Skip to content

Tuples and multi-field enum payloads at TypeLayout's alignment (#1964); Unit tuple elements (#1994); vector-holding aggregates refuse == (#1995); typed tuple vs literal compare (#1996); generic method call args read at the caller's slot (#2009) - #1999

Merged
ehartford merged 5 commits into
mainfrom
wave-tuple
Oct 3, 2026

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Fixes #1964, conforming to with-abi.md §2 as written ("Tuples lay out as structs of their elements"; structs place each field at the next offset aligned to its own alignment). Before: (i8,Al32) 96/32 model vs 72/8 emitted; (i8,V8) 48/16 vs 64/32 on AArch64; multi-field payload F.A(k: i8, v: V8) wrote 64 bytes into a 48-byte area and read back 4 0 0. TypeLayout.type_layout_tuple_elem_offset is the one placement rule; Codegen.tuple_type_from_layout builds bodies from it (plain struct when LLVM already matches, else a padded named struct); tuple_elem_index is the one accessor; check_tuple_layout verifies size/align/offsets (BUG + had_error). The new check caught the model sizing Sender/Receiver/VecRange at 0 bytes — fixed. Stack slots get the model's alignment. Tests behav_1964_tuple_over_aligned_element.w and behav_1964_enum_payload_over_aligned_fields.w red→green; 285 tuple/enum/channel/iterator/map/layout tests ok on stage1; gate, deep-debug-tool-tests, drop-audit 254/0, fixpoint green. ABI hash re-recorded; still v13. The v13 history sentence awaits Eric's blessing. Filed #1994, #1995, #1996 (pre-existing on the base).

Eric Hartford added 5 commits October 2, 2026 22:55
… accessor for their elements; check_tuple_layout proves it (#1964)

A tuple's LLVM body was the literal struct of its element types, so an
element whose model alignment differs from its LLVM body's landed at
LLVM's offset: `(i8, Al)` with an `@[align(32)]` record (§16.4, packed
LLVM body, align 1) was 72/8 against the model's 96/32, and
`(i8, Vector[8, f32])` on AArch64 64/32 against 48/16 (§4.3d). Nothing
compared them, so `comptime T.size()`, union members, channel slots and
map tuples over such a tuple were mis-sized silently. A multi-field enum
payload is the same literal struct: `F.A(k: i8, v: V8)` wrote a 64-byte
payload into the model's 48-byte area and read `4 0 0` back.

- TypeLayout: type_layout_tuple_elem_offset is the one tuple placement
  rule (the size rule reads it); the offsets are preregistered with the
  struct field offsets and audited at the MIR boundary. Generic
  instances find their template by the recorded template, not the
  visible name, and the compiler-built `Sender`/`Receiver` ({i64}) and
  `VecRange`/`VecIterRef` ({i64 x 3}) are modeled; both were sized 0,
  which the new check reported.
- Codegen: tuple_type_from_layout builds a tuple from the model's
  offsets/size/align: the literal when it already measures that, else a
  named body with [n x i8] padding (packed when an element's LLVM
  alignment does not divide its offset), its alignment in
  struct_declared_align. tuple_elem_index is the one source -> LLVM
  index map, read by get_llvm_field_index and the tuple_elem_* accessors
  every tuple and payload access goes through (drop, compare, zip,
  enumerate, unzip, partition, split_at, collect-to-map, chan, slot
  maps, get_disjoint, enum payload construct/read/drop).
  check_tuple_layout proves size, alignment and every element offset
  against the model: BUG + had_error on a mismatch. A stack slot of a
  type with a declared alignment above LLVM's is given it.
- behav_layout_model_matches_llvm: 7 tuple MISMATCH rows on the base
  (fix-1438) stage1, all ok after. behav_1964_tuple_over_aligned_element
  and behav_1964_enum_payload_over_aligned_fields construct, project,
  destructure, pass, return, compare, match, drop and iterate such values.
- ABI hash re-recorded (TypeLayout.w).
…; two tuples compare only at one type; no DEBUG print in MIR validation (#1996)

`u == (1, 2)` with `u: (i8, i64)` typed the literal `(i32, i32)`: the
§4.2.1 rule-3 peer typing that gives `x == 1` its `1` stopped at bare
literals (SemaCheck.check_binary's comparison branch checked an
aggregate operand in value context). Sema then accepted the pair through
builtin_arg_type_compatible, and MirCore's validator refused it after
printing `DEBUG cmp fail: ...` to the user.

- check_binary: a tuple or array literal beside a non-literal operand is
  checked with that operand's type as its expected type
  (comparison_operand_is_aggregate_literal).
- Two tuple operands must be one type; `(i8, i64) == (i32, i32)` is a
  Sema error naming both, not invalid MIR (Sema was the tool that stayed
  silent).
- MirCore: the stray `DEBUG cmp fail:` eprint is gone; its type facts are
  in the validation failure message.
- behav_1996_tuple_literal_compare (failed on the #1964 release binary
  with the MIR error) and err_1996_tuple_compare_mismatch.
…1995)

§4.3d: "`== != < <= > >=` are lane-wise and yield a `Mask`"; §11.7:
"`Eq.eq(self: &Self, other: &Self) -> bool` backs `==` and `!=`". A
vector has no one-`bool` equality, so a tuple, array or record holding
one has no structural equality to derive, and §4.3d refuses to pick
"all lanes" for a mask (`m == n`). Sema accepted `(i8, f32x8) == ...`
and Codegen.compare_value_eq recursed into the element and emitted
`icmp eq <8 x float>` (invalid LLVM).

- SemaVector.aggregate_held_vector finds a vector/mask held by value in a
  tuple, array, record or generic record, at any depth.
- check_binary refuses `==`/`!=` on such an aggregate (a view compares
  what it observes, so `&T` is looked through), naming the held type and
  the spelling `(a == b).all()`. A type with its own `eq` is unaffected.
- err_1995_tuple_eq_holds_vector and err_1995_struct_eq_holds_vector
  (the second through an array field); both reached codegen on the #1964
  release binary.
…ike any field (#1994)

with-abi.md §1 gives Unit zero size in a layout, so `(Unit, i32)` is 4
bytes with both elements at offset 0. Codegen lowered the element to the
`void` a Unit value type maps to and put it in the tuple body, and LLVM
aborted the compile in DataLayout::getTypeSizeInBits (SIGTRAP, rc 133).
Past that, MirLower.lower_field_access (MirLower.w:5924) refused any
field of type Unit (`t.0`) as unsupported, and the function signature's
tuple (resolve_type) carried Unit as the `i32` value carrier, so a
returned `(Unit, i32)` was `{i32, i32}` against the body's type.

- Codegen.tuple_member_types: a void element is the empty struct `{}` —
  at its offset, occupying nothing — in tuple_type_from_layout and
  tuple_type_from_elems; resolve_type's tuple path maps a Unit element
  to that member, not to the carrier.
- coerce_value_to_type: the one Unit value crosses between a `{}` member
  and the `i32` carrier without bits to convert.
- lower_field_access refuses only an untyped field, not a Unit one.
- behav_1994_tuple_holds_unit: construct, project, destructure, return,
  Vec and Option of `(Unit, i32)` / `(i64, Unit)`, model and LLVM size;
  debug allocator clean (also `(Unit, str, Unit)`).
…tart, never an `in` node's d1 (#2009)

The ephemeral-argument gate in Sema.check_generic_method_call
(SemaCheck.w:25435) took the argument as
`get_extra(get_data1(node) + i)`. That is a call's argument list only
when `node` is the call. check_membership_operator passes the `in` node
(and the `|>` lowering passes the pipe node), whose d1 is the lhs node
id, with the operand's slot in `extra_start`. A view operand (`k: &i32`,
ephemeral) on a generic owner's `contains` reached the branch on the
release-equivalent stage2 compiler and checked an unrelated node: lldb at
25437 read eg_arg=9815 for lhs node 9698 (`in` node 9700). On a seed-built
stage1 the same read ran past the extras (spec_ss11_7_btree_contains).

- The argument is `get_extra(extra_start + i)`, the slot every caller
  passes; a resolved (reordered) list is read only for an NK_CALL node.
  After: lldb on stage1 reads eg_arg=578962, the lhs of `in` node 578964.
- behav_2009_membership_view_operand: a view on either side of `in` over
  a generic owner, and the same `contains` called directly.
@ehartford ehartford changed the title Tuples and multi-field enum payloads place elements at TypeLayout's alignment; check_tuple_layout verifies (#1964); Sender/Receiver/VecRange modeled Tuples and multi-field enum payloads at TypeLayout's alignment (#1964); Unit tuple elements (#1994); vector-holding aggregates refuse == (#1995); typed tuple vs literal compare (#1996); generic method call args read at the caller's slot (#2009) Oct 3, 2026
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery GREEN on 857b5a4 (seed-driven, with run tools/battery.w, on main 0c10fd6): gate rc=0 wall=547s, battery-checks rc=0 wall=541s — fixpoint, drop and move audits, every corpus. Merged by the coordinator per Eric's standing direction. The v13 history sentence for tuples still awaits Eric's blessing (code conforms to §2 as written).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant