Skip to content

Two fixes for migrating STC: an index in an assignment target, and ternaries as if expressions - #2285

Merged
ehartford merged 3 commits into
corpus-pinsfrom
stc-phase3
Oct 9, 2026
Merged

ehartford merged 3 commits into
corpus-pinsfrom
stc-phase3

Conversation

@ehartford

@ehartford ehartford commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Groundwork for STC (stdlib sourcing plan, Phase 3).

  • An index is a value inside an assignment target: check_runtime_index_operand checks the index in value context, and the diagnostic names the type. Test: behav_if_index_in_assignment_target.w.
  • The migrator lowers a ternary that needs no statement to an if expression. Hoisting every ternary into a temp made STC's vec constructors untranslatable (malloc((size_t)(1 ? n : -1)) inside an initializer list). Under D112 nothing re-promotes; the drift report shows pcre2 21, zlib 15, c-algorithms 1 and tommyds 3 modules would change, and the migrator gate passes on all four fresh migrations.
  • A 0 arm of a pointer ternary is cast to the ternary's type, as NULL already was. Otherwise it became a bare null, which has no type (an if arm never takes the other arm's type), and the c_facade_children fixture stopped compiling. The migrate-core check gains the case; it fails before the fix.

Eric Hartford added 3 commits October 8, 2026 20:12
check_runtime_index_operand checked the index with no expected type, so an
`if` in the index of an assignment target was typed as a statement (Unit):
`xs[if c: 1 else: 2] = v` was refused, on main too. The migrator emits
exactly that for C's `tree[cond ? a : b].freq++` once a pure ternary is an
if expression (zlib deflate/trees). The index is checked in value context.
The diagnostic now names the type it found.
C's ?: evaluates one arm, as With's if expression does. The value lowering
hoisted every ternary into a temp and an if statement, so a pure context
(an initializer-list element, a call's argument inside one) refused it:
STC's `Self out = {_i_new_n(T, n), 0, n}` expands to
`malloc((size_t)(1 ? n : -1))` there, and every vec constructor was
untranslatable. A ternary whose condition and arms need no statement is
now the expression; hoisting stays for arms that need statements.
c-migrator-core-tests gains the case.

Per D112 no corpus re-promotes for this: corpus-migrator-gate migrates
each afresh and runs its upstream tests (pcre2's regenerated output, for
one, shrinks by ~3,100 lines of hoisted temps).
…n is spelled with its type

`give ? s->owner : 0` became `if give != 0: s.owner else: null`, and
`null` has no type of its own (an if arm never takes the other arm's), so
the c_facade_children fixture stopped compiling. The null arm is now cast
to the ternary's type, as C's NULL already was. The migrate-core check
gains the case.
@ehartford
ehartford added this pull request to stack #2287 October 9, 2026 04:33
@ehartford ehartford changed the title stc phase3 Two fixes for migrating STC: an index in an assignment target, and ternaries as if expressions Oct 9, 2026
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery GREEN on f329092 (stack top: #2280, #2284, #2285, #2286), with run tools/battery.w: gate rc=0 (605 s), uat rc=0 (97 s), battery-checks rc=0 (1213 s), fixpoint and the drop and move audits included.

The first battery, on 859e562, was red. It found three defects the fixed-array default had hidden, plus a red main, all fixed in f329092 and f57ba3c:

@ehartford
ehartford marked this pull request as ready for review October 9, 2026 05:41
@ehartford
ehartford merged commit a9fa74f into main Oct 9, 2026
@ehartford
ehartford deleted the stc-phase3 branch October 9, 2026 05:42
ehartford added a commit that referenced this pull request Oct 9, 2026
* tools/rename_vec_to_list.w: D118 step (c) identifier rename and string-literal report (#2296)

* seed.lock: nightly-20261009-local-1-2638c97adaf8, the first seeds that accept List (D118 step a)

darwin-aarch64, linux-x86_64 and windows-x86_64 cut from main 2638c97,
each built on its own host to a stage2 == stage3 fixpoint over all 16
units. The aarch64 platforms keep their .version pins (#2305).

* corpora: re-promote pcre2, zlib, c_algorithms and tommyds (D112)

The renamed migrator is a new pin. The regenerated modules also carry the
migrator changes merged since the last promotion (#2285: a pure ternary is
an if expression), which no promotion had taken in.

* D118 step (c)+(d): the growable sequence is List; Vec names no type (#2296)

A Lexer-driven rename of identifier tokens (tools/rename_vec_to_list.w:
a word part exactly vec/Vec/VEC, incl. member names after a dot; with_*
runtime symbols are pinned by the seed and keep their names) and a pass
over string literals and comments (capitalized Vec words; Rust's Vec<T>,
Vector, Vec2 kept). The step-(a) alias is gone; 'Vec' is an error naming
List in type and value position. vec-name joins the ceremony census at
zero. StdGeneric's List variant is spelled Sequence while the step-(a)
seed drives the build (its alias misses member names after a dot, #2305).
The ABI hash is re-recorded: TypeLayout.w's diff is the rename only.

* build/seed.w: own the pin-block asset name until the seed copies interior views (#2307)

seed-driver read a freed buffer: `pending_asset = line.slice(..).trim()`
stores a view into the temporary slice as a str, and the D111 seed lowers
that as copy+retain, a no-op for an interior pointer. .to_owned() copies;
it comes out with the step-(d) seed that carries the #2307 fix.

* D118 step (c): the rename's misses the battery found (#2296)

benchmarks/ and tests/ were outside the first file list; identifiers in
f-string holes are inside string tokens, so the identifier pass skipped
them (`{vec.len()}`, `{vec_closed}`, `{local_vec()}`, checked against
every renamed name); the module std.collections.sorted_vec is the file
sorted_list.w.

* sorted_list.w: drop three redundant explicit Unit returns the file rename re-presented for review

---------

Co-authored-by: Eric Hartford <[email protected]>
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.

1 participant