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:
@@ -14,20 +14,34 @@
|
||||
> assignment, address-of, and multi-target assignment — route field resolution
|
||||
> through one shared helper, `fieldLvaluePtr(obj_ptr, obj_ty, field)`, which
|
||||
> resolves struct fields, union/tagged-union direct fields, promoted
|
||||
> anonymous-struct union members, and tuple elements, and returns `null` (no
|
||||
> field 0 / `.unresolved` default) when nothing matches. Each caller emits the
|
||||
> read path's field-not-found diagnostic (`emitFieldError`) on a `null` result:
|
||||
> 1. `lowerAssignment` `.field_access` target — `found`-flag bail on the struct
|
||||
> loop, with union direct + promoted handled before it.
|
||||
> anonymous-struct union members, tuple elements, and vector lanes (reusing
|
||||
> `vectorLaneIndex`), and returns `null` (no field 0 / `.unresolved` /`.s64`
|
||||
> default) when nothing matches. Each caller emits the read path's
|
||||
> field-not-found diagnostic (`emitFieldError`) on a `null` result:
|
||||
> 1. `lowerAssignment` `.field_access` target — delegates to `fieldLvaluePtr`;
|
||||
> its own duplicated union / promoted / tuple / vector / struct walk is
|
||||
> deleted (issue-0083 two-resolver divergence removed).
|
||||
> 2. `lowerExprAsPtr` `.field_access` — delegates to `fieldLvaluePtr`, so the
|
||||
> address-of path now resolves promoted union members (`@v.x`) — not only
|
||||
> direct union fields — and a genuine miss errors. The `.s64` sentinel is gone.
|
||||
> address-of path resolves promoted union members (`@v.x`) — not only direct
|
||||
> union fields — and a genuine miss errors. The `.s64` sentinel is gone.
|
||||
> 3. `lowerMultiAssign` `.field_access` target — replaced its struct-only loop
|
||||
> (which defaulted `field_idx 0` / `field_ty .unresolved` on a miss, silently
|
||||
> storing into field 0 — `p.q, y = 2, 3` printed `x=2 y=3`) with the shared
|
||||
> `fieldLvaluePtr`; a missing field now errors, and a valid promoted-union /
|
||||
> tuple member at a non-zero offset stores into its own slot, not field 0.
|
||||
>
|
||||
> `fieldLvaluePtr` types every GEP `*field_ty` (a pointer to the field), the
|
||||
> convention the single-assign path always used: `emitStore` reads the
|
||||
> store-target pointer's IR type and unwraps exactly one `.pointer` level to
|
||||
> find the stored value's type. The earlier `lowerExprAsPtr` / `lowerMultiAssign`
|
||||
> walks typed the GEP with the *bare* field value 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 all three sites onto the one `*field_ty` resolver
|
||||
> preserves single-assign and fixes that pre-existing multi-assign / address-of
|
||||
> clobber.
|
||||
>
|
||||
> All sites reuse `emitFieldError` (the exact facility the read path
|
||||
> `lowerFieldAccessOnType` uses), so the read and write paths reject identically.
|
||||
> The `src/backend/llvm/types.zig` tripwire is untouched — the fix is to never
|
||||
@@ -38,8 +52,10 @@
|
||||
> exit 1), `examples/0165-types-nested-struct-field-assign.sx` (positive — nested
|
||||
> struct field write + address-of a matched field), `examples/0166-types-union-promoted-member-lvalue.sx`
|
||||
> (positive — promoted union member written and address-of'd, including a non-zero
|
||||
> offset member), and two lowering unit tests in `src/ir/lower.test.zig`
|
||||
> (single- and multi-assign missing-field field-not-found).
|
||||
> offset member), `examples/0167-types-ptr-to-aggregate-field-store.sx` (positive —
|
||||
> a `*Pair` field stored via all three lvalue sites leaves the neighbour intact),
|
||||
> and three lowering unit tests in `src/ir/lower.test.zig` (single- and
|
||||
> multi-assign missing-field field-not-found, plus the `*field_ty` GEP convention).
|
||||
|
||||
## Symptom
|
||||
Assigning to a nonexistent struct field (`p.q = ...`) panics during LLVM emission instead of reporting a source diagnostic.
|
||||
|
||||
Reference in New Issue
Block a user