Skip to content

fix 1239 - #1962

Merged
ehartford merged 3 commits into
fix-1356from
fix-1239
Oct 2, 2026
Merged

ehartford merged 3 commits into
fix-1356from
fix-1239

Conversation

@ehartford

@ehartford ehartford commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1239. Spec: README v7.4 / D71 — a positional collection has no get; xs[i] is the one spelling. On main v.get(0) on Vec compiled (arrays/slices already refused). Sema now refuses it naming xs[i]; the c-facade renderer and derive(SoA) emitters updated; tools/migrate_vec_get.w (Lexer-based, from check logs) rewrote 876 sites in 233 files to a fixpoint. Two compile_errors fixtures pin the diagnostic.

Also fixes a pre-existing miscompile it exposed (473b029): a block tail let t = f(); t[id].x lowered drop(t) before the element read (lldb + --dump-mir); MirLower now materializes the read first; behav_tail_element_read_before_drop.w panics on main, passes now. The pinned seed still carries that bug, so the seed-built stage1 miscompiles one function until the next seed bump; stage2/release are correct.

examples/ecs changed .get(i) → [i]: a spec-required spelling (D71), per the 2026-09-22 ruling that examples track the spec. Gate green, drop-audit 254/0 on the stack top. Battery with the next batch.

Eric Hartford added 3 commits October 2, 2026 10:28
…1239)

Spec (README v7.4, D71): "a positional collection has no `get`, `xs[i]` is
the one spelling (§ Element access, D27)". Arrays and slices already had no
`get`; `Vec[T].get(i)` still typed as the element view, so one meaning had
two spellings.

Sema (SemaCheck.check_method_call_parts): `Vec.get` is an error naming the
spelling — "Vec has no 'get': element access is spelled 'xs[i]' (§ Element
access, D71)" — and still types as `&T` so checking continues past it.

Emitters that synthesized the old spelling move to the index node: the
`c facade` renderer's retained-free loop (FacadeRender.w) and the
`@[derive(SoA)]` row rebuild (ComptimeTransform.ct_build_index).

tools/migrate_vec_get.w rewrites the sites the compiler reports: it reads
`with check` logs, takes each diagnostic's location and caret span, matches
the call's parentheses with the Lexer (bytes inside an f-string
interpolation), and applies the byte edits in one pass; stale sites (a stage
binary's embedded std predating a rewrite) and synthesized sources are
skipped and named. 876 sites in 233 files across src/, lib/std, build/,
tools/, examples/ and test/ were rewritten with it, to a fixpoint: the
stage1 built from this tree (`src/main build :dev` rc=0) checks
`src/main.w` clean, and the pinned seed checks the migrated tree (`src/main
check src/main.w` ok).

Fixtures: the two `Vec.get` bad-index compile-error tests now pin the D71
diagnostic; behav_pipeline_methods' `v |> get(0)` is `v[0]`.
… the block drops reads before the scope-exit drop

`fn arity(id: i32) -> i32: let t = table(); t[id].arity` lowered as
`drop(_2) @ scope-exit; _0 = copy _2[_4].f` — the tail was left a lazy
place operand (bare place tails stay lazy for view returns), the block's
pop_scope_inline emitted the Vec's drop, and the consumer's assignment
read the element from the freed Vec: "panic: index out of bounds" from
the cleared length. Pre-existing on main (the minimal repro panics with
the installed compiler); the D71 migration exposed it in
MathBuiltins.math_fn_arity, where `t.get(id).arity` — a call, so
materialized — became `t[id].arity`, and every program calling a math
builtin then crashed the compiler (sema-order-check, examples-tests and
benchmarks-check in the gate).

Root cause (lldb: with_panic_ref <- math_fn_arity MathBuiltins.w:82 <-
Sema.check_intrinsic_call; `--dump-mir` of the repro shows the order):
lower_block_mode materializes only the explicit `move owned.field` tail
(materialize_tail_field_move). Fix: materialize_tail_read_of_dropped_local
copies a lazy OK_COPY projected-place tail into a temp before
pop_scope_inline when the place's base local is in the closing scope's
drop list and the read is not a reference or pointer (a view-typed tail
stays lazy for its `&`-typed destination; Sema refuses one that outlives
its origin). The repro's MIR is now `_5 = copy _2[_4].f; drop(_2); _0 =
copy _5`.

test/behavior/behav_tail_element_read_before_drop.w pins it (panics on
main, passes under the stage1 built from this tree). Note: the pinned
seed still carries the bug, so the seed-built stage1's own
math_fn_arity is miscompiled until the next seed bump; stage2 and the
release binary are built by stage1's fixed lowering and are correct.
The spec change (README v7.4, D71) updates the example in the same change:
storage.w and world.w read `entries.get(i)` on a Vec; the ecs sources
are a multi-module project whose modules the per-file corpus check could
not resolve, so examples-tests reported them. Rewritten with
tools/migrate_vec_get.w from the release binary's own diagnostics.
@ehartford

Copy link
Copy Markdown
Contributor Author

Note: this PR was merged from the stack UI into its base branch fix-1356, not main — a middle-of-stack merge. The commits are carried by #1968 (the same three, rebased) in stack #1969; nothing reached main from here.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Positional collections have two spellings for one meaning: xs[i] and xs.get(i); keep [i]

1 participant