Repository navigation
Three trees T6x-a3: the stack's reads give references, and conditionals place and return handles - #349
Conversation
…ls place and return handles The statement stack (out.rs) reads by reference: `first`, `last`, `only`, `first_single_slot` give `&B::S`; `first_slot` and `last_slot` give the slot; `at`, `head`, `head_mut` read a slot in place. `take(slot)` moves the statement of a slot out and leaves the slot `Dead(1)` (one write). `take_run` becomes `pub(super)`, `take_run_rev` gives the statements last first. The empty-block table is keyed by `JsStmt::stmt_id` (`empties: Vec<(u32, u32)>`), read by the three callers before the push or fill; `drop_empty_blocks` compares `js.stmt_id`. Deleted: `peek`, `clear`, `statements_rev`, `slot_row` and the production `statements`; a `#[cfg(test)]` `statements` on `StatementStack<Rows>` serves the tests that release a run row by row. The stack implements `Runs<B>` (`Run = Span`), and `cond.rs::if_in_place` calls `JsStmt::if_head` over it. The adapter `StackLists` and its `norm::IfLists` implementation are deleted with `peek`; they cannot outlive it, so both land in this commit. cond.rs: `place(u32, B::S)`, `if_statement(..) -> B::S`, `unnest(..) -> Option<u32>`, `single_assignment(..) -> Option<u32>`, `assignment_statement(..) -> B::S`, `merge_tail_guard -> B::S`, `single_return -> bool`; `terminal` is deleted (written out where it was called). Callers in exit.rs, loops.rs, switch.rs, untagged.rs and variant.rs lose their wraps; location.rs reads the first slot once; export.rs::build_rows keys rows by `stmt_id`; mod.rs::append_outputs releases the dropped run with `take_run`. Private helpers added in out.rs: `slot_ref` (O(1)) and `last_at` (one step per trailing hole or dead slot), which `last` and `last_slot` share. Tests edited so that they compile: the `Hand` helper passes `statement.0` to `note_empty_block`; `if_statement_is_simplify_if_for_every_rule` pushes the statement `if_statement` now gives without the `stmt_from_node` wrap. No expected value changed. Signed-off-by: Jaap Frolich <jfrolich@gmail.com> Co-authored-by: Jaap Frolich <jfrolich@gmail.com> Session: https://os.submodule.nl/session/bks-95248a7a-965c-7675-8050-84109b97ebb4
Signed-off-by: Jaap Frolich <jfrolich@gmail.com> Co-authored-by: Jaap Frolich <jfrolich@gmail.com> Session: https://os.submodule.nl/session/bks-95248a7a-965c-7675-8050-84109b97ebb4
|
First-pass checklist review at 6509509 (a checklist for the final reviewer, not an approval). First-pass review (checklist, not an approval): Setup: 1. ScopeCommit 1 of the task, item by item:
The body names nothing as not done. Work the task did not name: the private helpers 2. Default pathNone of the changed functions runs in an ordinary build. All of them are in 3. Engineering standardGrep over the 287 added lines above the tests:
UNCLEAR (only (b): the changed 4. Tests and oraclesThe diff stat touches no expected file, ratchet or script. The only changes below 5. New scripts and fixturesNone added. PASS 6. Privacy
7. Changelog
8. Numbers in the body
PASS 9. Focused testsNot run (host review: no cargo). From the CI 10. Where I would look hardest
11. Files and signatures
Every file is one the task names as "Yours". Changed Two more signature changes are not on
The five, beside the task:
Also 12. out.rs, the stack, function by function (base lines 1–FreeId, branch lines 1–570; both read whole)
Two nits in the cost notes, not in the task's list:
Neither omission is a scan. PASS (with the two nits) 13. The reads and
|
| Function | Deleted StackLists body |
New impl | Same? |
|---|---|---|---|
trim |
self.stack.drop_empty_blocks(self.js, b, span) |
self.drop_empty_blocks(js, a, run) |
yes |
empty |
EMPTY (= Span { start: 0, len: 0 }) |
Span::default(), and Span derives Default (out.rs:18), so {0, 0} |
yes |
last |
self.stack.last(span) |
StatementStack::last(self, run) |
yes |
only |
self.stack.only(span).map(|(_, s)| s) |
the same | yes |
release |
for statement in self.stack.statements(span) { b.release(statement); } self.stack.kill(span); |
for statement in self.take_run(run) { js.release_stmt(a, statement); } self.kill(run); |
Same statements in the same forward order (holds in order), then kill. release_stmt on rows is steps += a.release(s.0) (rows_stmt.rs:357-359): the same nodes released, plus a step count (10.2). |
take |
B::list_id(self.stack.take_list(self.js, b, span)) |
self.take_list(js, a, run) |
yes, the same list |
if_in_place is quoted in pr.diff, cond.rs:444-456. The new body is the task's text verbatim. When if_head returns None, the else branch calls self.if_statement(B::node(condition), yes, no) with the test as if_head left it, and it places at head in both branches, as before.
Rows::if_head (rows_stmt.rs:385-397, unchanged) does steps += 1 and one norm::simplify_if_head through RunLists. On None, if_statement → js.if_ runs js3_simplify_if over pool lists, exactly as the old if_statement did on this path. No second simplification was added. PASS
17. cond.rs readers
-
single_return:- Old:
only?, thenReturn?, thenvalue_of?, thenSome((stmt, NodeId(js.id(value)))). - New:
onlyelsefalse, thenkind == Return && value_of.is_some().
The same predicate.
Rows::idisr.0with no step (rows.rs:220). The callers changed.is_some()/.is_none()tobool. SAME. - Old:
-
unnest:only?; if not a block, it returns the slot; otherwise it doestake(slot)(old:clear(slot)) andunblock, pushing. The same statements in the same order. SAME, except the held-slot panic (10.1). -
effect_output:- Old:
unnest,take_value(row),clear,trim. - New:
unnest,at(slot)for the kind,take(slot),take_value,trim.
The same nodes. The statement is read twice (
onlyinunnest, thenat), but that follows from the task'sunnest -> Option<u32>. SAME. - Old:
-
merge_assignments(cond.rs:577-591): bothsingle_assignments run first, as before. Old:take_value(then_ row),keep_operand,take_value(else_ row),keep_operand,kill. New:take(then_),take_value,keep_operand,take(else_),take_value,keep_operand,kill. SAME. -
merge_tail_guard: the guard comes fromfirst_single_slot, the kind and branch checks are unchanged, thenmerge.filter(last_slot(run) != Some(slot))andtake(slot)where the old code calledclear(slot). The guard's slot hasslot_len == 1.last_atreturns the last slot withlen != 0and its last index, solast_slot == guard slotholds exactly when the last statement is the guard, which is the old row comparison. That still holds when the guard's slot is a hold of one, but thentakepanics (10.1). SAME, except that case. -
effect_conditional: written out asself.statements.last(yes).is_some_and(|last| matches!(stmt_kind(last), Return | Throw | Break | Continue)). The deletedterminalmatchedReturn | Throw | Break | Continue, so it is the same predicate arm by arm.last(yes)is still read beforesingle_return(no); the kind read is now eager and pure. SAME. -
returns_after_effects(cond.rs:817-841):statement_refs(run).peekable()stops whenpeek().is_none(), before theExpcheck, at the position where the old code hitstatement == last.stepscounts the same, anddrop(statements)comes beforeself.statements.scanned += steps. SAME. -
fold_return_tail:take_run_revfolds last first, asstatements_revdid, and the caller kills both runs (cond.rs:728). SAME. -
release_run:take_runforward withrelease_stmt, thenkill, in the same order as the oldstatementsloop. SAME.
PASS (apart from 10.1)
18. Callers of the five functions
Per-function counts from git show <branch>:<file> | grep -n "self.<fn>(":
| Function | Call sites | Count | Task |
|---|---|---|---|
place |
switch:1109, untagged:800, 819, variant:484 | 1/2/1 | ✓ |
if_statement |
exit:422, loops:153, switch:1103, untagged:818, variant:480 | 1 each | ✓ |
unnest |
exit:573, switch:897, untagged:625, 787, 821, 1124, variant:491 | 1/1/4/1 | ✓ |
single_assignment |
switch:883 | 1 | ✓ |
assignment_statement |
switch:1101 | 1 | ✓ |
Wraps removed:
- exit.rs:423:
push(B::stmt_from_node(statement))→push(statement). - loops.rs:156: the same, with
guard. - variant.rs:480, 484:
B::stmt_from_node(self.if_statement(..))→self.if_statement(..), andplace(plan.head, B::stmt_node(statement))→place(plan.head, statement). - switch.rs:1106-1109: the line
let statement = B::stmt_from_node(statement);is removed, andplace(plan.head, B::stmt_node(statement))→place(plan.head, statement). - untagged.rs:818-819 needed no edit.
The two callers that read a result:
-
untagged.rs
Op::Block(792-799):- Old:
if let Some((_, statement)) = only { self.statements.kill(run); statement } else { …B::stmt_node(self.js.explicit_block(..)) }. - New:
if let Some(slot) = only { let statement = self.statements.take(slot); self.statements.kill(run); statement } else { …self.js.explicit_block(..) }.
The same statement, then the kill.
- Old:
-
switch.rs declaration fold (882-889):
- Old:
take_value(B::stmt_from_node(statement)),keep_operand,kill(candidate). - New:
take(slot),take_value,keep_operand,kill(candidate).
The same nodes in the same order.
- Old:
The other sites:
- location.rs:
first_slot, thenstmt_located(head(slot)), thenlocate_stmt(head_mut(slot));scannedread once. - export.rs:350:
for stmt in self.statements.statement_refs(run).map(|s| NodeId(self.js.stmt_id(&self.arena, s))), which is the task's line. - mod.rs:772:
for statement in self.statements.take_run(second.stmts) { self.js.release_stmt(&mut self.arena, statement); }, which is the task's line.appendthen truncates tofirst.stmts.end()(out.rs:472), so the holes it leaves go away. - exit.rs: the
firstread. - untagged.rs:843:
stmt_kind(&self.arena, s)on thelastread.
PASS
19. Transition calls
-
git grep -n -E 'B::stmt_node\(|B::stmt_from_node\(' <branch> -- compiler-rust/src/bir/lower/out.rs: empty. -
In cond.rs above
mod tests, two lines:cond.rs:356: B::stmt_node(self.js.explicit_block(&mut self.arena, list)), in#[cfg(test)] fn empty_block.cond.rs:421: B::stmt_node(statement), in#[cfg(test)] fn raw_if.
-
git grep -n -E 'IfLists|simplify_if_head' <branch> -- compiler-rust/src/bir/lower:close.rs:27: a///comment, the line the task names.js_stmt.rs:314: the doc comment ofJsStmt::if_head. The file is unchanged by this PR, and the line was already present on trunk.oracle_tests.rs:1044(test function name) and:1048(comment): a#[cfg(test)]module (mod.rs:33-34), present on trunk too.
No line is code.
-
git grep -n -E 'fn (peek|clear|statements_rev|terminal|only_row|last_row)\b' <branch> -- …out.rs …cond.rs: empty (exit 1). -
No
stmt_from_node(stmt_node(..))pair in the added lines. The grep over+lines finds nostmt_from_nodeabove the tests at all.
PASS
20. Tests
Every changed line below a mod tests:
+ use crate::bir::j::norm; (cond.rs:983, moved in)
- self.state.statements.note_empty_block(slot, statement);
+ self.state.statements.note_empty_block(slot, statement.0); (Hand helper)
- hand.state.statements.push(<…Rows as …JsStmt>::stmt_from_node(statement));
+ hand.state.statements.push(statement); (if_statement_is_simplify_if_for_every_rule)
That is all. raw_if is a #[cfg(test)] helper above mod tests, already covered in 11. No expected value changed, no assertion or test was deleted, and no #[ignore] was added.
git diff $D | grep -n '^[-+].*\.statements(' gives five hits, all deletions in production code:
- 48:
StackLists::release - 88:
release_run - 422:
returns_after_effects - 514:
export.rs::build_rows - 560:
mod.rs::append_outputs
statements.statements( is counted 27 times on trunk and 23 on the branch, in 19 files (git grep -c/-l), so the 23 test calls are untouched. PASS
21. Counts as failure
The grep in 3 over the added lines above the tests is empty for every listed pattern (allow(, unsafe, MaybeUninit, Clone, Copy, Default, HashMap, HashSet, Box::new, format!, View::, Op::, plain::, bir.view(, bir.release(, norm::). Span::default() is lower-case and is a Default use on Span, not a bound on B::S/B::L.
From the task's own list:
- A read that returns an id where a reference serves: none.
export.rsmaps to an id becausebuild_rows' work list isNodeId, and that is the task's line. - A statement read twice:
effect_output(onlyinsideunnest, thenat), which the task'sunnest -> Option<u32>makes necessary. location.rs reads once. stmt_idused to find a statement again: none.- A copy of a J-S3 rule in cond.rs: none, since
if_in_placecallsif_head. - An action list touched (
switch_output_nodes,ActionState::cached): none; the diff does not touch those names.
PASS
22. Numbers
gh pr checks 349 -R jfrolich/rescript-rust: all 23 checks pass. They are Backend bridge coverage, Derived code check, Playground wasm check, Signature equality, Snapshot equivalence, base, build, build-system-tests, build-system-tests (macOS), compare, compiler-tests, compiler-warnings, head, ocaml, oxc parity (gentype/js/stdlib) and parity (analysis/diagnostics/gentype/javascript/stdlib), plus script-tests. Runs 44196403073 and 44196403068 are both at head 65095095a9.
Instruction count (job 134443348235):
| base | 4,135,005,023 | 4,135.0, 4,136.4, 4,135.4, 4,137.7, 4,136.0 | 788 |
| head | 4,134,577,182 | 4,136.2, 4,135.9, 4,134.6, 4,134.9, 4,136.9 | 788 |
| change | -427,841 (-0.010%) | | |
compiler-tests (job 134438918846):
grep -c -E 'test bir::lower::.* \.\.\. ok'gives 567.grep -c -E 'test bir::j::.* \.\.\. ok'gives 58.- No ignored test under either.
Backend bridge coverage (job 134440572654): every decision_count/decision_site/decision_status/finish/free/name_differences is 0 in all three reports.
The body's check-mode table, as written:
$ scripts/compare_build_instructions.py --base rescript-base base --head rescript-head head --runs 5 --sequential --allow-increase
| base | 4,141,363,994 | 4,141.7, 4,141.4, 4,141.9, 4,144.4, 4,143.5 | 788 |
| head | 4,141,191,483 | 4,141.2, 4,142.7, 4,141.7, 4,143.4, 4,143.2 | 788 |
| change | -172,511 (-0.004%) | | |
Both sides show five runs. It is the default backend; see 2.
count_lowering_ids totals: the body shows 517 on the branch and 556 on trunk, and I reproduced both (see 8).
Allocation counts: 86, 103, 86 and 156 still asserted at unit.rs:118-130, and they pass in CI. Cost-note line: cost docs: production functions=548; changed/new=50; missing/generic=0; removed=0 (CI script-tests, the same as the body).
Rows::if_head's extra step (and release_stmt's, 10.2): no test of the lowering reads Js::steps() across an if_in_place. git grep -n -E 'js\.steps\(\)|\.js\.steps' <branch> -- compiler-rust/src/bir/lower compiler-rust/src/bir/j is empty. The steps() readers in bir/lower are js_tests.rs and js_stmt_tests.rs (on Rows directly; the if_head tests at js_stmt_tests.rs:1364/1459 run over a test Runs, not the stack) plus unrelated counters (names, untagged grouping, export coercion). The cond.rs step tests read pushed/copied/scanned, not Js::steps. PASS
…slot of one it is only and first_single_slot give any slot that holds exactly one statement, a hold of one included. Before this slice their callers cleared the slot, which worked for either kind; take and at accepted a statement slot alone and would stop the compiler on a hold of one. Both accept it now, with a test. The cost notes of Runs::trim and Runs::take name the drain and the close they left out. Co-authored-by: Jaap Frolich <jfrolich@gmail.com> Session: https://os.submodule.nl/session/os-01a1c9fa-0c5d-7912-a93b-3e7f38e53547 Signed-off-by: open-session-submodule[bot] <341020755+open-session-submodule[bot]@users.noreply.github.com>
|
Coordinator review, final, at d6010b1 (the author did not write this review). The first-pass checklist (comment 6964191018) was read whole; I read the stack of Verdict: accepted with one reviewer commit. Slice T6x-a3 is its task: the stack's reads give references, a statement is moved out with The reviewer commit (d6010b1)
What else I checked
Accepted as the builder decided
On record
|
Slice T6x-a3 of the backend rewrite (
compiler-rust/docs/THREE_TREES.md11.4, "T6x-a: the statement stack, after the probe"). The statement stack's reads now give references to statement handles. Five functions ofcond.rsthat place or return statements now take and give handles.if_in_placecallsJsStmt::if_headover the stack, which implementsRuns<B>. The default build does not run this code, and the generated JavaScript does not change.What changed
out.rs, the stackfirst,last,onlyandfirst_single_slotgive&B::S.first_slotandlast_slotgive the slot.at,headandhead_mutread a slot in place.take(slot)moves a statement out and leaves the slotDead(1). It is one write.take_runbecomespub(super).take_run_revis new beside it.Vec<(u32, u32)>, keyed byJsStmt::stmt_id.drop_empty_blockscomparesjs.stmt_id. Both cost notes now include the O(E) shift of the vector's tail.impl Runs<B> for StatementStack<B>withRun = Span.peek,clear,statements_rev,slot_rowand the productionstatements.#[cfg(test)]statementsonStatementStack<Rows>, for the 23 tests that release a run row by row. Those tests are not edited.slot_ref(O(1)) andlast_at(one step per trailing hole or dead slot), whichlastandlast_slotshare.cond.rsplace(u32, B::S)if_statement(..) -> B::Sunnest(..) -> Option<u32>single_assignment(..) -> Option<u32>assignment_statement(..) -> B::Smerge_tail_guard -> B::Ssingle_return -> boolterminalis deleted, and its test is written out ineffect_conditional.StackListsand itsnorm::IfListsimplementation are deleted.use crate::bir::j::norm;moves intomod tests.stmt_idbefore the fill or push.Callers
exit.rs,loops.rs,switch.rs,untagged.rsandvariant.rslose their wraps.switch.rsanduntagged.rstake the statement withtake(slot).location.rsusesfirst_slot, thenheadandhead_mut.export.rs::build_rowsreadsstmt_idby reference.mod.rs::append_outputsreleases the dropped run withtake_runandrelease_stmt.Tests edited, only so that they compile; no expected value changed
Handhelper incond.rspassesstatement.0tonote_empty_block, as the task says.if_statement_is_simplify_if_for_every_rulepushes the statementif_statementnow returns. Itsstmt_from_nodewrap had to go because the function changed signature.Decision not set by the task: in
merge_tail_guard,last_slot(run)is read only when the guard qualifies. Trunk's&&chain reads it at the same point, soscannedis unchanged.Gates
The tests pin the four allocation counts of
unit.rsand everysize_ofassertion, and all of them pass unchanged.cargo check --all-targetsandcargo clippy --all-targets -- -D warningsprint no warning.RUSTDOCFLAGS="-D warnings" cargo doc --locked --manifest-path compiler-rust/Cargo.toml --all-features --no-deps: no warning, exit 0.CI
Backend bridge coverage: every*_differencesfield is 0. These are decision count, decision site, decision status, finish, free and name, in all three reports.CI
Instruction count: base 4,135,005,023, head 4,134,577,182, −0.010%.Check mode, run on Linux under cachegrind against
tests/tests. Both sides are fat-LTO release builds: the base at 109b2bd and the head at this branch. The head checkout uses the base'stests/testsandtests/dependencies, as CI does.git statuswas clean afterwards.Transition-call totals (
python3 ../scripts/count_lowering_ids.py | grep '^| total'from compiler-rust):Trunk, after T6x-a2, had 556 transition calls; this branch has 517. Compared with the probe there are 5 fewer
stmt_from_nodeand 5 fewerstmt_node. The probe still wrapped the statement at several sites where this slice passes handles:placeinif_in_place, andsingle_assignment, which kept a value this task drops. The line count is 23 higher than the probe's, from the cost notes.End state
rg -n 'fn (peek|clear|statements_rev|terminal|only_row|last_row)\b' src/bir/lower/out.rs src/bir/lower/cond.rs: empty.rg -n 'IfLists|simplify_if_head' src/bir/lowershows four lines. One is the comment inclose.rs:27. The other three are the doc comment ofjs_stmt.rs::if_head(js_stmt.rs:314, which namesnorm::simplify_if_headas the body ofif_head) and two test lines oforacle_tests.rs(1044, 1048). None of them is code.rg -n 'B::stmt_node\(|B::stmt_from_node\(' src/bir/lower/out.rs: empty. Incond.rsabovemod teststhere are two lines, 356 and 421, in the#[cfg(test)]helpersempty_blockandraw_if.rg -n 'note_empty_block' compiler-rust/src/bir/lowerabove the tests shows the definition (out.rs:348) and three calls (cond.rs:348, 473, 700). Each call passes au32id.Started by Jaap Frolich in this Assistant session