fix(ir): single-assign field store delegates to fieldLvaluePtr, completing the lvalue consolidation [F0.10]
Migrate lowerAssignment's `.field_access` target onto the shared
`fieldLvaluePtr` resolver, deleting its duplicated union / promoted /
tuple / vector / struct walk. All three lvalue field-store sites —
single-assign, address-of (lowerExprAsPtr), and multi-assign
(lowerMultiAssign) — now resolve through the one resolver, removing the
issue-0083 two-resolver divergence.
Fold vector-lane resolution into `fieldLvaluePtr` (reusing
vectorLaneIndex) so the single resolver covers struct fields, union
direct fields, promoted anonymous-struct union members, tuple elements,
and vector lanes — null only on a genuine miss, which every caller turns
into the read path's `emitFieldError` diagnostic.
`fieldLvaluePtr` now types every field GEP `*field_ty` (the convention
the single-assign path always used), not the bare field value type:
emitStore unwraps one pointer level to find the stored value's type.
The earlier lowerExprAsPtr / lowerMultiAssign walks typed the GEP with
the bare field type, so a field whose own type is a pointer-to-aggregate
(`*Pair`, a two-pointer struct) made emitStore unwrap to the aggregate
and coerceArg's closure auto-promotion store a 16-byte `{ptr,null}`
struct over the 8-byte slot, clobbering the neighbouring field.
Consolidating onto the one `*field_ty` resolver preserves single-assign
and fixes that pre-existing multi-assign / address-of clobber.
The types.zig `.unresolved` tripwire is untouched; no `.s64` / `.void` /
`.unresolved` default remains.
Regression: examples/0167-types-ptr-to-aggregate-field-store.sx (a
`*Pair` field stored via all three lvalue sites leaves the neighbour
intact) + a lowering unit test asserting the `*field_ty` GEP convention.
This commit is contained in:
42
examples/0167-types-ptr-to-aggregate-field-store.sx
Normal file
42
examples/0167-types-ptr-to-aggregate-field-store.sx
Normal file
@@ -0,0 +1,42 @@
|
||||
// Storing a struct field whose own type is a pointer to a two-pointer struct
|
||||
// (`*Pair` — the shape `coerceArg` would closure-auto-promote into `{ptr,null}`)
|
||||
// must store an 8-byte pointer, never a 16-byte struct that overruns the slot
|
||||
// and clobbers the neighbouring field. The shared field-lvalue resolver types
|
||||
// the GEP as `*field_ty`, so `emitStore` unwraps exactly one pointer level to
|
||||
// the field's own type (`*Pair`, an opaque pointer) instead of the pointee
|
||||
// aggregate (`Pair`).
|
||||
//
|
||||
// Regression (issue 0094, attempt-3 consolidation): the shared `fieldLvaluePtr`
|
||||
// resolver used to type struct/tuple GEPs with the bare field value type, so a
|
||||
// `*Pair` field stored via the multi-assign / address-of paths promoted the
|
||||
// pointer to a 16-byte struct and clobbered the next field (`sentinel` read 0).
|
||||
// The single-assign path already used the `*field_ty` convention; folding all
|
||||
// three lvalue sites onto the one resolver applies it uniformly.
|
||||
|
||||
#import "modules/std.sx";
|
||||
|
||||
Pair :: struct { a: *s64; b: *s64; }
|
||||
Holder :: struct { pr: *Pair; sentinel: s64; }
|
||||
|
||||
main :: () {
|
||||
x : s64 = 7;
|
||||
y : s64 = 9;
|
||||
pair : Pair = .{ a = @x, b = @y };
|
||||
other : Pair = .{ a = @y, b = @x };
|
||||
|
||||
h : Holder = .{ pr = @pair, sentinel = 99 };
|
||||
|
||||
// single-assign: store a *Pair into h.pr; sentinel must stay 99.
|
||||
h.pr = @other;
|
||||
print("single: a={} b={} sentinel={}\n", h.pr.a.*, h.pr.b.*, h.sentinel);
|
||||
|
||||
// multi-assign: store into h.pr alongside a plain local; sentinel untouched.
|
||||
dummy : s64 = 0;
|
||||
h.pr, dummy = @pair, 1;
|
||||
print("multi: a={} b={} sentinel={}\n", h.pr.a.*, h.pr.b.*, h.sentinel);
|
||||
|
||||
// address-of the *Pair field, store through it; sentinel untouched.
|
||||
ppr := @h.pr;
|
||||
ppr.* = @other;
|
||||
print("addr: a={} b={} sentinel={}\n", h.pr.a.*, h.pr.b.*, h.sentinel);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
0
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
single: a=9 b=7 sentinel=99
|
||||
multi: a=7 b=9 sentinel=99
|
||||
addr: a=9 b=7 sentinel=99
|
||||
Reference in New Issue
Block a user