Repository navigation
Three trees T6x-a1: the statement stack owns statement handles - #346
Conversation
Why:
Phase T6x of the three trees removes the J rows the lowering stores
and passes. Its first row (T6x-a1) puts the statement stack itself on
the interface: the stack owns the statements of its runs as handles
of the implementation, so a statement built through the interface is
pushed as it is, not turned into a row first.
Representation modified (StatementStack):
Before:
struct StatementStack { slots: Vec<Option<Slot>>, held: Vec<NodeId>, .. }
enum Slot { Statement(NodeId), Held(Span), Dead(u32) }
push(NodeId), fill(slot, NodeId), fill_held(slot, &[NodeId])
take_list(&mut Bir, Span) -> ListId
drop_empty_blocks(&mut Bir, Span) // View match, Bir::release
After:
struct StatementStack<B: JsStmt> { slots: Vec<Option<Slot<B::S>>>, held: Vec<Option<B::S>>, .. }
enum Slot<S> { Statement(S), Held(Span), Dead(u32) }
push(B::S), fill(slot, B::S), fill_held(slot, impl IntoIterator<Item = B::S>)
take_list(&mut B, &mut Pools, Span) -> B::L // JsStmt::list over the moved run
drop_empty_blocks(&mut B, &mut Pools, Span) // is_empty_block, release_stmt
`hold_run` and `take_list` move each statement out of its slot (a hold
inside a run entry by entry). The reads keep their results as rows
(`first`, `first_single_slot`, `only`, `last`, `statements`,
`statements_rev`) and read a statement in place through one private
`peek`, which T6x-a3 deletes. `close` keeps its signature (T6x-b), so
`take_list` gives it `B::list_id` of the list.
Added, each with its cost in its doc comment: `statement_refs` (the
statements of a run read in place; O(slots + held statements));
`take_run` (private: the statements of a run moved out; same cost);
`slot_len` (O(1)) and `slot_row` (O(1), through `peek`) in place of
`slot`; `peek` (O(1)); `Default` written out (O(1)). In `cond.rs` the
implementation of `norm::IfLists` moves from the stack to `StackLists`,
the stack and the implementation (16 bytes), with the same six bodies;
T6x-a3 deletes it.
Callers wrap at the call: a push or fill of `B::stmt_node(x)` gives `x`;
of a row, `B::stmt_from_node(row)`; a `take_list` whose result went into
`B::list_from` loses both wraps, one that is stored or passed on as a
`ListId` is `B::list_id(..)`. `args.rs::declares_pure` takes `&B::S` and
reads the runs of the arguments with `statement_refs`. Where a caller
pushed a handle and then noted it as an empty block, the row it notes is
`JsStmt::stmt_id` of the handle, read before the push (on rows the row),
so no `stmt_node`/`stmt_from_node` pair is left: `cond.rs` `place`,
`block_statement` and the guard of an `if` without an else.
Generated JavaScript does not change; the default build does not run
this code.
Tests: `--lib bir::lower` 568 passed, `--lib bir::j` 58 passed, none
ignored. The tests of the stack and of its callers changed only to
compile (`StatementStack::<Rows>`, `Rows::stmt_from_node` around a pushed
row, `take_list` with an implementation); no expected value changed; the
two size assertions keep 96 and 12.
Co-authored-by: Jaap Frolich <jfrolich@gmail.com>
Session: https://os.submodule.nl/session/bks-6e0f5c7f-c4b3-74aa-868a-9195e58e2297
Signed-off-by: Jaap Frolich <jfrolich@gmail.com>
Internal release note for the statement stack of the backend lowering on statement handles (three trees, T6x-a1). Co-authored-by: Jaap Frolich <jfrolich@gmail.com> Session: https://os.submodule.nl/session/bks-6e0f5c7f-c4b3-74aa-868a-9195e58e2297 Signed-off-by: Jaap Frolich <jfrolich@gmail.com>
|
First-pass checklist review at 36d7b91 (a checklist for the final reviewer, not an approval). First-pass review (checklist, not an approval): Setup: 1. Scope — PASS (one task end-state line is not met; see 18)
Not done, by the body's own account: the five 2. Default path — PASSEvery changed function belongs to 3. Engineering standard — PASS, with notes on (b)Greps over the added lines of
4. Tests and oracles — PASSThe diff does not touch 5. New scripts and fixtures — PASS (none added)6. Privacy — PASS
7. Changelog — PASS
8. Numbers — PASSEach figure in the body comes with its command and pasted output: the test result lines, the cost-docs line, the CI Instruction count table, the check-mode table with its command, and the count_lowering_ids totals. One exception: the allocation counts 86/103/86/156 are stated without output. unit.rs is not in the diff, and CI ran all four 9. Focused tests — not run (host review)CI 10. Where I would look hardest
11. Files and signatures — PASS
The cond.rs lines are the 12. out.rs, function by function — PASS (two minor note gaps, both copied from trunk)
13.
|
|
Coordinator review, final, at 36d7b91 (the author did not write this review). The first-pass checklist (comment 6962399373) was read whole; I read Verdict: accepted. Slice T6x-a1 is what its task describes: the statement stack owns statement handles, every caller hands it one, and nothing that is built, or the order it is built in, changes. What I checked myself
Rulings
On record
|
Slice T6x-a1 of the backend rewrite (
compiler-rust/docs/THREE_TREES.md11.4, "T6x-a: the statement stack, after the probe"). The lowering's statement stack owns the statement handles of the interface (JsStmt::S) instead of J rows.What changes
out.rs:StatementStack<B: JsStmt>. The slots holdSlot<B::S>, andheldisVec<Option<B::S>>, where a statement moved out leavesNone.Defaultis written out.push,fillandfill_heldtake handles.hold_runmoves each statement; a hold inside the run is moved entry by entry.take_list(js, a, span) -> B::Lcounts the run and callsJsStmt::listover the statements moved out of their slots (privatetake_run). It then kills the run and callsclose(a, B::list_id(list)).closeis unchanged until T6x-b.drop_empty_blocks(js, a, span)usesis_empty_blockandrelease_stmt.first,first_single_slot,only,last,statementsandstatements_revstill return rows. They read a statement in place through one privatepeek, which T6x-a3 deletes.statement_refs(span)reads the statements of a run in place.mod.rs: the field isstatements: StatementStack<B>. The three pushes of the realisation and the push ofcompletewrap their row. The two lists that go tofinishareB::list_id(..).cond.rs:impl norm::IfLists for StatementStackbecomes an implementation forStackLists(the stack and the implementation, 16 bytes), with the same six bodies. T6x-a3 deletes it.B::stmt_node(x)givesx; a row givesB::stmt_from_node(row). Atake_listwhose result went intoB::list_fromloses both wraps; a stored or passed-on list isB::list_id(..).args.rs::declares_puretakes&B::S(private, one file) and reads the arguments' runs withstatement_refs.Decision not given by the task
cond.rshas three sites:place,block_statement, and the guard of anifwithout an else. Each pushes or fills a handle and then notes it as an empty block, andnote_empty_blockstill takes aNodeId. A plain wrap there would put astmt_node/stmt_from_nodepair on one value. Instead,placekeeps its row argument. The other two take the noted id fromJsStmt::stmt_idbefore the push; on rows that is the row. The interface documentsstmt_idas the key of this table, and T6x-a3 changes the table's key type to it.Gates
cargo test --manifest-path compiler-rust/Cargo.toml --lib bir::lower:cargo test --manifest-path compiler-rust/Cargo.toml --lib bir::j:The four allocation counts in
unit.rsstay 86, 103, 86, 156, and everysize_ofkeeps its number (StatementStack<Rows>96,Option<Slot<rows::S>>12).cargo check --all-targetsandcargo clippy --all-targets -- -D warnings: no output.RUSTDOCFLAGS="-D warnings" cargo doc --locked --manifest-path compiler-rust/Cargo.toml --all-features --no-deps: no warning.python3 scripts/check_lowering_cost_docs.py --base origin/ocaml-to-rust-rewrite:CI
Backend bridge coverage: every*_differencesis 0, and "Backend coverage ratchet passed".CI
Instruction count:Check mode, run locally on two release builds of
rewatch(base =origin/ocaml-to-rust-rewrite61f7f41). Both sides used the same checkout, which--sequentialallows; the two commits differ only incompiler-rust:python3 scripts/compare_build_instructions.py --base base-rescript CHECKOUT --head head-rescript CHECKOUT --sequentialgit statuswas clean afterwards.python3 ../scripts/count_lowering_ids.py | grep '^| total', first line, beside the probe's:Why the counts differ (36 fewer transition calls):
B::list_id(take_list(..))whose list then went straight intoB::list_from. Here both wraps go: 14 fewerlist_fromand 16 fewerlist_id, two of those 16 being theB::list_idpairs ofif_statement.stmt_from_node+ 3stmt_node.End state
The
B::stmt_node/B::stmt_from_nodesearch finds the three calls, all inpeek, on two lines.rg -n '(push|fill)\(B::stmt_node\(' src/bir/lowerfinds no call of the stack. Five lines push onto otherVecs of rows that later slices own:args.rs:88,args.rs:124:Evaluation::statements(T6x-a2)tail.rs:65:tail_assignments(T6x-a2)expr.rs:310:scratchofhold_effect, a hold filled by a sink (T6x-a2)ffi_args.rs:305: the actions of a string switch (T6x-a4)Tests edited, only to compile
out.rs:use crate::bir::j::rows::Rows,StatementStack::<Rows>::default(),Rows::stmt_from_node(..)around pushed and filled rows and inside the expectedSlot::Statement(..),take_list(&mut Rows::default(), &mut bir, ..), and the type argument of the two size assertions. This includesthe_actions_of_ten_thousand_switches_leave_only_the_slots_of_their_runs.args.rs: one push wrapped. Only one test of the file calls the stack in a way that stops compiling; the other reads it with calls whose signature is unchanged.cond.rs: the four pushes of theHandhelper wrapped.oracle_tests.rs: one push and onetake_list.No expected value changed.
Started by Jaap Frolich in this Assistant session