Skip to main content

kernel/
plan.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4// Copyright (c) 2026 2youg1 and the sprawling contributors
5
6//! The plan as a tree: what the nodes are, what each one is worth, what
7//! may be started now, and the two ways a held node is put down.
8//! The part `crates/kernel/spec/Plan.lean` specifies this module.
9//!
10//! `crate::spine` owns the document — how a row is written and read.
11//! This module owns the structure that document describes, and the two
12//! are separate because the grammar of a line and the arithmetic of a
13//! plan fail in different ways: a mistyped row is repaired by editing
14//! it, while a cycle in the dependencies is repaired by rethinking the
15//! work.
16//!
17//! **Weight is conserved because [`crate::share`] is the only way to
18//! hold any.** A node's share is divided out of its parent's when the
19//! tree is built, so the total is 1 whatever the plan turns into and no
20//! version number is needed for the denominator. What grows when a
21//! branch is split is the number of leaves, not the total; that is why
22//! the interface shows both — a percentage says how much is done and a
23//! leaf count says how much was found.
24//!
25//! **Progress is counted on leaves only.** A branch has no work of its
26//! own: its children are its work, and counting both would count the
27//! same effort twice. A branch that says `Done` while a child does not
28//! is refused where the tree is built, so the status column of a branch
29//! is a summary a reader can trust rather than a second opinion.
30
31use std::collections::BTreeMap;
32
33use crate::node_id::NodeId;
34
35mod blocking;
36mod node;
37mod share;
38mod tree;
39
40pub use node::{Held, PlanExit, PlanNode, StopCause};
41
42#[derive(Debug, Clone, PartialEq, Eq)]
43pub struct PlanTree {
44    pub(crate) nodes: BTreeMap<NodeId, PlanNode>,
45}