Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changes/three-trees-t6-design-14.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- Three trees T6 design turn 14: the lowering interface can own a statement taken out of a list, put a changed list
back and read the source location of a node (`JsStmt::own`, `set_body_adopting`, `set_literal_body_adopting`,
`Js::location`; the first three on rows and on the builder, with a pair each for the two setters), and THREE_TREES.md
records the build of slice T6u (the seal: the flatten rules in the naming replay's walk) and its prompt.
723 changes: 723 additions & 0 deletions compiler-rust/docs/THREE_TREES.md

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions compiler-rust/src/bir/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,53 @@ impl Bir {
self.parents[node.index()] = None;
}

/// The entries of the pool list of the block `block` that have no
/// parent become its statements, and the block's facts are computed
/// again: what a block needs after its row was written over a list
/// that holds statements made or detached since the list was taken
/// (`JsStmt::set_body_adopting` on rows). An entry that has a parent
/// is the block's own already (a debug build checks it). Returns the
/// number of statements adopted.
///
/// Precondition: the arena holds no weighted switch (a debug build
/// checks it). Every use weight is then 1, so a statement adopted
/// into any slot keeps the counts its uses were taken with, and
/// nothing is recounted and no weight is stored. It holds wherever
/// the lowering's interface is used: only a `Switch` of level L is
/// weighted (`is_weighted_switch`), the lowering reads those from its
/// source arena and writes statements of level J into an arena of
/// its own, and a JavaScript program imported into rows has none. A
/// caller in an arena that can hold one needs [`Self::replace`],
/// which recounts and stores the slot's weight.
///
/// Precondition, not checked here (`validate` reports it): a variable
/// an adopted statement uses is not carried across a function or a
/// loop by the adoption. No capture flag is computed, as
/// [`Self::replace`] computes it for a tree it attaches: the
/// statements the flatten rules make are made of the parts of a
/// statement of the same list.
///
/// One read per entry and one store per statement adopted. Then
/// `repair`: the block's facts from its statements, and its owners'
/// while a fact changes. Allocates nothing.
pub(crate) fn adopt_block_list(&mut self, block: NodeId) -> u32 {
debug_assert_eq!(self.weighted_switches, 0, "a statement list adopted in an arena with a weighted switch");
let list = self.node(block).block_list_id().expect("a statement list of a statement is a block");
let mut adopted = 0;
for i in 0..self.lists.get(list).len() {
let child = self.lists.get(list)[i];
match self.parents[child.index()] {
None => {
self.parents[child.index()] = Some(block);
adopted += 1;
}
Some(owner) => debug_assert_eq!(owner, block, "a statement put back into a list it was not taken from"),
}
}
self.repair(block);
adopted
}

/// The use weight of a slot: 1, doubled for each switch default above it
/// that today's counts visit twice.
pub fn weight_of(&mut self, node: NodeId) -> u32 {
Expand Down
6 changes: 6 additions & 0 deletions compiler-rust/src/bir/j/rows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,12 @@ impl Js for Rows {
fn located(&self, a: &Pools, r: NodeId) -> bool {
a.node(r).flags().contains(NodeFlags::JS_LOC_PRESENT)
}
fn location(&self, a: &Pools, r: NodeId) -> Option<LamLoc> {
if !a.node(r).flags().contains(NodeFlags::JS_LOC_PRESENT) {
return None;
}
a.cold(r).map(|cold| cold.loc)
}
fn runs_no_code(&self, a: &Pools, r: NodeId) -> bool {
facts::runs_no_code(a, r)
}
Expand Down
23 changes: 23 additions & 0 deletions compiler-rust/src/bir/j/rows_stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
//! | `below` | T6r | a walk on `Rows::work`, above what it holds, of the children of the statement that are no statements and of everything below them: a `JFun` is given by its header and not entered, a `Var` of a variable with `VarFlags::JS_GLOBAL` is given and, when `visit` says so, `Bir::qualify_global`ed; every other node has its children pushed, the last first; every node is read, whatever `want` is |
//! | `reserve_below` | T6r | `Rows::work` gets room for one entry per node of the arena above what it holds: at most one allocation |
//! | `declarations` | T6r | a walk on `Rows::work`, above what it holds, of the entries of the pool list and of the `statements` of every `SBlock` among them, to any depth: an `SDecl` or an `SRest` is given to `visit`, an `SBlock` has its entries pushed, the last first (an entry whose parent is not the block, a hole, is not); every other statement is read and left |
//! | `own` | T6u | `Bir::detach` of the row when it has a parent: the link to its block is cut and its use weight pinned; nothing for a row without a parent; no step |
//! | `set_body_adopting` | T6u | the block that is list `index` written again over the pool list given, as `set_body`; then `Bir::adopt_block_list`: each entry without a parent gets the block as its parent (its uses recounted when it carries another weight than the block's slot), and the block is `repair`ed; one step and one per entry adopted |
//! | `set_literal_body_adopting` | T6u | the same for the `SBlock` that is the `body` of the `JFun` of the header |
//! | `effect_free` | T6q | the read `export.rs::has_toplevel_effect` made of a statement that is not a declaration row: a work stack (`Rows::work`) of the node's children for a compound statement, the `STRICT` flag of the value of `SExp` and `SReturn` and of every expression below a compound statement, `false` at `SThrow`, `SDebugger`, a jump, `SDecl`, `SRest`, `SForOf`, `SForAwaitOf`; one step per node read |
//! | `release_stmt` | T6n | `Bir::release`; one step per node it frees |
//! | `if_blocks` | T6n | `Bir::new_node(View::SIf { condition, then_, else_: Some(else_) }, 0)` over the two blocks; one step |
Expand Down Expand Up @@ -556,6 +559,26 @@ impl JsStmt for Rows {
self.work = work;
read
}
#[inline]
fn own(&mut self, a: &mut Pools, s: &mut S) {
// The statement keeps the use counts it was built with wherever
// it goes back: every weight is 1 without a weighted switch, and
// an arena of level J has none (`Bir::adopt_block_list`).
debug_assert_eq!(a.weighted_switches, 0, "a statement owned in an arena with a weighted switch");
if a.parents[s.0.index()].is_some() {
a.detach(s.0);
}
}
fn set_body_adopting(&mut self, a: &mut Pools, s: &mut S, index: u32, body: ListId) {
let block = Self::body_block(a, s, index);
Self::write_block(a, block, body);
self.steps += 1 + u64::from(a.adopt_block_list(block));
}
fn set_literal_body_adopting(&mut self, a: &mut Pools, header: FuncId, body: ListId) {
let block = Self::literal_block(a, header);
Self::write_block(a, block, body);
self.steps += 1 + u64::from(a.adopt_block_list(block));
}
fn effect_free(&mut self, a: &Pools, s: &S) -> bool {
let mut work = std::mem::take(&mut self.work);
debug_assert!(work.is_empty());
Expand Down
Loading
Loading