Skip to main content

lower_value

Function lower_value 

Source
pub fn lower_value(
    cx: &StageCx<'_>,
    inputs: &LoweringInputs<'_>,
    value: &Arc<NodeTree<Flm>>,
) -> Result<LoweringOutcome, CatchUpError>
Expand description

Lowers a synthesized value for one backend: brings it up to date, then runs the rounds over it exactly as lower_tree runs them over a document tree.

A synthesized value is a small tree that a stage builds while a run is under way, held outside the document’s trees (see synthesized values). This function does for a whole value what a rule’s Lowerer::splice does for a value inside the node it lowers; a backend’s pieces stage lowers each piece with it.

The value is brought up to date by value catch-up (StageCx::resolve_value): the plan’s rewrites run over it, then the per-tree stages the calling stage depends on, and what they compute goes into a catch-up store of the value’s own. Every table read a rule makes at an address of the value reads that catch-up store first, so a per-tree table holds the value’s own entries, and every table that no re-entered stage writes (the document-scope tables: anchors, counters, the label index) is the document’s, unchanged. A reference inside a value therefore resolves to the document’s labels. Content of the document that a rule inside the value lowers through Lowerer::lower_region is read at the document’s addresses, in the run’s store, never in the value’s catch-up store.

The diagnostics the catch-up raised come first in the outcome, then the lowering’s own, as a splice records them. A value whose lowering fails comes back with LoweringOutcome::lowered set to None and an Error diagnostic, as a tree does.

cx is the calling stage’s context. The catch-up runs again the per-tree stages that stage depends on, so a stage calling this function must declare the needs of the rules it lowers with (rules_needs). Call it on a worker thread, as lower_tree.

§Errors

Returns the CatchUpError when the value could not be brought up to date: a rewrite refused it, it nests too deeply, or a re-entered stage produced a fact about the document as a whole (a labeled reference point, for example), which a synthesized value may not state. Nothing was lowered then; the caller records the error’s diagnostic, when it has one.

§Panics

Panics if inputs.selected was built against a registry other than inputs.registry, so that a selected rule’s index is out of range for that registry’s rule list. The lowering stage and the pieces stage always pass a matching pair; only inputs assembled by hand from two registries can reach this.

A rewrite or a re-entered stage that panics propagates out of this call, as it does out of StageCx::resolve_value.