Skip to content

D120 merge-gate measurement against the pre-CoW compiler: the last-use view-edge regression (1.093 → 1.032), corpus A/B tool, parser hang - #2448

Merged
ehartford merged 7 commits into
mainfrom
d120-take-sema
Oct 18, 2026
Merged

ehartford merged 7 commits into
mainfrom
d120-take-sema

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Follow-up to D120 stages 1–6 (#2304): the merge-gate measurement the plan owes, taken against the pre-CoW compiler, and the regression it found.

Each stage's A/B had been taken against the main before it, so the ratios compounded unseen. Against the last pre-CoW compiler (6069361, release built under the pinned seed), check src/main.w measured 1.088–1.104 (median 1.093), a counted regression; the corpus suites had never been measured.

Cause, at the line. WITH_PROFILE=1 put the whole delta in mir.lower (+3.4 s of 4 s). WITH_TRACE_COW_COPIES=4096 reported 239,743 list copies over 4 KB in one self-check, every backtrace through stage 4's own cow_transfer_stmt/cow_transfer_term: the dataflow's state vector was a retained copy at every statement. with analyze src/main.w cow named the sites; a 24-line repro and a new per-verdict trace in the last-use pass (WITH_TRACE_COW=1 → [cow-last-use] … kept, view _3 live after) showed last_use_build_view_edges drawing a view edge for an integer copied out of the list (out[l] = state[l]), which made out a "view" of state and kept the handoff a retain.

  • MirSuspendCheck: a view edge needs an operand whose own type can carry a view. Pin: behav_d120_element_copy_is_not_a_view (buffer address stable across handoffs; fails on main).
  • rt_core: rt_value_is_zero (the drop guard for sizes other than 8/16) reads a word at a time (64 → 590 ms of a self-check once structs of values dropped through it).
  • MirLower: the uniqueness dataflow's arrays are block-count × candidate-count, not × local-count (the allocator's large-range bookkeeping, +0.6 s).
  • ComptimeEval: the evaluator takes the Sema out of the pointer (stated ownership; main already makes 0 large copies there since stage 4).
  • Parser: match o: { Some(x) => x, None => 0 } spun forever in the struct-pattern field loop (found while writing the tooling; pre-existing, hangs the pre-D120 compiler too). Fixture err_parse_brace_after_match_colon_terminates.
  • tools/corpus_ab.w: the corpus-suite half of the gate (pcre2 RunTest -8 0-29 over the pinned 10.47 reference; a 16 MB minigzip round trip).
  • docs: the measurement in the decision's status text and the plan header.

Measurement (three interleaved rounds each, baseline = pre-CoW 6069361):

workload before this PR after
self-host check src/main.w 1.1038, 1.0965, 1.0882 (median 1.093) 0.9899, 1.0316, 1.0480 (median 1.032)
pcre2 suite (baseline tree's corpus source, both compilers) not measured 0.9741, 0.9242, 0.9910 (median 0.966)
zlib minigzip 16 MB round trip not measured 1.0001, 0.9917, 0.9917 (median 0.992)

What remains of the 3%: the uniqueness check at mutation sites the proof does not cover (with_vec_is_unique, ~0.9 s of 45 s) and the proof's own dataflow (~0.4 s). The ruling's "what would reopen it" is a cost over 2% that is not removable; those two are the next targets and are Eric's call.

Gate green (d120-take-sema-gate3.log), :deep-debug-tool-tests, :debug-alloc-tests, :drop-audit green, census diff clean. Battery: pending.

Eric Hartford added 7 commits October 18, 2026 04:42
…of re-reading the token forever

`match o: { Some(x) => x, None => 0 }` opens a struct pattern after the
colon, and `(` is not a field name; expect_ident reported it and consumed
nothing, and the field loop asked again, forever. The loop now leaves on
a failed name and the diagnostic comes out (the inline form is
`match o { ... }`). Fixture: err_parse_brace_after_match_colon_terminates.
…w, so the list's last-use handoff is taken (D120 §2.3)

The last-use pass drew a view edge for every unheld copy, including an
integer read out of a list (`out[l] = state[l]`), which made `out` a
"view" of `state` and kept every later handoff of `state` a retained
copy. In the compiler that was its own stage 4 dataflow: the state vector
was copied at every statement, 239,743 copies over 4 KB in one
`check src/main.w` (WITH_TRACE_COW_COPIES=4096; every backtrace through
cow_transfer_stmt/cow_transfer_term), all of the 3.4 s mir.lower delta in
the 9.3% self-host regression against the pre-D120 compiler. An edge now
needs an operand whose own type can carry a view.

WITH_TRACE_COW=1 now also prints the pass's verdict per held site
([cow-last-use] ... taken / kept, <why>), which is what located this.

Pin: behav_d120_element_copy_is_not_a_view (the buffer address stays the
same across the handoffs; fails on main).
… of reading a second holder

The four entry points read `*sema_ptr` into a local and handed it to the
evaluator while the pointer still held the original: under D120 two
holders of every table. comptime_take_sema reads, blanks the pointer's
Sema, and returns the one holder; comptime_eval_finish writes the
evaluator's Sema back as before. (At stage 3 this was 1,908 copies over
64 KB per self-check; stage 4's last-use take already removes them on
main, so this is the stated ownership, not a measured saving.)
…suites (D120's second merge gate)

Builds lib/std/re/pcre2test.w or lib/std/zl/minigzip.w with each
compiler once, then times the suite alone, interleaved A B A B, with
ab_bench's report (median, ratio, spread; a regression counts only when
every round exceeds 1.05). pcre2 runs upstream RunTest -8 0-29 as the
pcre2-test lane does; zlib round-trips a 16 MB text through minigzip
(the lane's 14-byte round trip times process start, not zlib).
rt_value_is_zero, the guard codegen emits on a value's drop when its size
is not 8 or 16, compared one byte at a time. With structs of values
dropping through it (D120 stage 3) it was 0.5 s of a self-check
(sample: 64 ms before D120, 590 ms after). Now a word at a time, then
the tail bytes, as rt_memcmp reads.
…date), not per (block, local)

cow_compute_unique_dataflow sized unique_in/unique_out at block-count x
local-count words per body and initialized every entry; in the compiler's
big bodies that is megabytes per body, which showed as the allocator's
large-range bookkeeping (rt_range_store, rt_record_large_range,
rt_forget_large_range, +0.6 s of a self-check against the pre-D120
compiler). The arrays are now block-count x candidate-count, indexed by
candidate, in the driver and both consumers (the hoist and the elision);
the per-statement state vector stays per local.
… its cause

Status text only (the decision record's "Status of the work" and the
plan's header): the per-stage A/Bs compounded unseen to 1.093 on the
self-host; after the last-use view-edge fix 1.032, pcre2 0.966, zlib
0.992, three interleaved rounds each.
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery and measurement (1e087af)

  • Battery: GREEN, battery rc=0 wall=229s on 1e087af04 (a first run went red on raylib_spiral only: with get c.raylib timed out downloading the GitHub tarball, exit 124; the scenario passes alone, 10 steps, and the full battery passed on re-run; a second earlier run caught behav_1944_comptime_snapshot_memory at the 32 MB limit, which found InternPool and AstPool are Copy handles over raw allocations that nothing frees: every init leaks (the LSP leaks 1 MB per reparse) #2449 and was fixed in the comptime commit before this battery).
  • Self-host A/B vs pre-CoW 6069361: 0.9899 / 1.0316 / 1.0480, median 1.032 (was 1.1038 / 1.0965 / 1.0882, median 1.093, on main 3d73b98).
  • pcre2 RunTest -8 0-29 (baseline tree's corpus source, both compilers): 0.9741 / 0.9242 / 0.9910, median 0.966.
  • zlib minigzip 16 MB round trip: 1.0001 / 0.9917 / 0.9917, median 0.992.
  • Gate, :deep-debug-tool-tests, :debug-alloc-tests, :drop-audit green; ceremony census unchanged.

@ehartford
ehartford marked this pull request as ready for review October 18, 2026 13:14
@ehartford
ehartford merged commit a82424d into main Oct 18, 2026
@ehartford
ehartford deleted the d120-take-sema branch October 18, 2026 13:14
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