Skip to main content

Plan

Struct Plan 

Source
pub struct Plan { /* private fields */ }
Expand description

A plan: the list of stages that satisfies a plan request, in dependency order and grouped in batches.

A plan is a pure value of the registry and the request, with nothing of any document in it; one plan therefore serves every document rendered the same way. Build one with Plan::for_workflow from the name of a registered workflow, or with Plan::build from a PlanRequest; then run it over a document with Run::new, which takes it in an Arc. The module documentation describes what a plan holds and how it is checked.

Besides the order of the stages, a plan exposes the record of how it was built: Plan::warnings for the preferences it could not honor and the output nothing checks, Plan::excluded and Plan::commit_order for the provider choices, Plan::selections for the lowering rules, and Plan::render for all of it as stable text.

§Examples

use flm_core::core::plan::{Overrides, Plan};
use flm_core::core::registry::{PackageEntry, RegistryBuilder, RegistryInputs};
use flm_core::stdlib::{self, StdlibConfig};

let mut builder = RegistryBuilder::new();
builder.use_package(stdlib::add_features(PackageEntry::new("std"), StdlibConfig::new()));
builder.use_package(flm_core::math_passthrough::package());
let registry = builder.build(&RegistryInputs::new())?;

let plan = Plan::for_workflow(&registry, "text", &Overrides::none())?;

// The rewrite stages run first, then the other stages, in order.
assert!(!plan.rewrite_names().is_empty());
assert!(plan.active_backends().iter().any(|name| name.as_str() == "text"));

Implementations§

Source§

impl Plan

Source

pub fn build( registry: &Arc<FlmRegistry>, request: &PlanRequest, ) -> Result<Plan, PlanError>

Builds the plan that satisfies request against registry.

The module documentation describes the steps and every check. The plan keeps the registry (an Arc clone) and a copy of request.

§Errors

Returns a PlanError for a name in request that the registry does not declare, a contradiction between what the stages declare, a choice that cannot be made, or a backend taking part in the plan that cannot render every element a document may contain. The variant holds the names of the entities involved.

§Panics

Building a plan asks every registered stage what it needs (Stage::needs or RewriteStage::needs); a panic in that method propagates out of this call.

Source

pub fn for_workflow( registry: &Arc<FlmRegistry>, name: &str, overrides: &Overrides, ) -> Result<Plan, PlanError>

Builds the plan of the registered workflow name, with overrides applied.

This is the usual way to get a plan. A workflow (WorkflowDef) is a named set of demands together with the choices that go with them, held in the registry as a complete plan request, and a caller changes only what it needs to through Overrides. This method turns the workflow into a PlanRequest with workflow_request, which documents exactly how, and builds that request with Plan::build.

§Errors

Returns PlanError::UnknownWorkflow when no workflow named name is registered, PlanError::UnknownOutput when the workflow lists an output that is not registered, and any error Plan::build returns.

§Panics

As Plan::build: a panic in a registered stage’s Stage::needs or RewriteStage::needs propagates out of this call.

Source

pub fn registry(&self) -> &Arc<FlmRegistry> ⓘ

The registry the plan was built against. Every stage, capability, table and rule number the plan holds is a number of this registry.

Source

pub fn request(&self) -> &PlanRequest

The plan request the plan was built from; for a plan built with Plan::for_workflow, the request the workflow was turned into, with the overrides applied.

Source

pub fn demands(&self) -> &BTreeSet<CapName>

Every demanded capability, with collections replaced by their members, in name order.

Source

pub fn key(&self) -> PlanKey

The number that identifies the plan by everything it was built from: see PlanKey.

Source

pub fn manifest(&self, idx: StageIdx) -> Option<&StagePlan>

The record the plan keeps about the stage idx, or None when idx is not a stage number of this plan’s registry.

Every registered stage has a record, whether or not it will run; Plan::is_scheduled says whether it will.

Source

pub fn manifests(&self) -> &BTreeMap<StageIdx, StagePlan>

The records the plan keeps about every registered stage, in registration order.

Source

pub fn rewrites(&self) -> &[StageIdx]

The rewrite stages that will run, in the order they run.

Source

pub fn rewrite_names(&self) -> Vec<StageName>

The names of the rewrite stages that will run, in the order they run.

Source

pub fn order(&self) -> &[StageIdx]

The stages that will run after the rewrite stages, in the order they run.

Source

pub fn stage_names(&self) -> Vec<StageName>

The names of the stages that will run after the rewrite stages, in the order they run.

Source

pub fn is_scheduled(&self, idx: StageIdx) -> bool

Whether the stage idx will run, as a rewrite stage or as a later stage.

Source

pub fn scheduled_names(&self) -> Vec<StageName>

The names of every stage that will run, rewrite stages included, in name order.

Source

pub fn batches(&self) -> &[Range<usize>]

The batches the runner executes, as ranges of positions in Plan::order.

No stage of a batch depends on another stage of the same batch, so the stages of a batch may run at the same time. See the module documentation.

Source

pub fn batch_names(&self) -> Vec<Vec<StageName>>

The batches, each as the names of its stages in order.

Source

pub fn first_io_batch(&self) -> Option<usize>

The index of the first batch that holds a stage with effect Effect::Io (a stage that acts outside the run’s computed data, for example by writing the output), or None when the plan schedules no such stage.

A run that has recorded an error diagnostic stops before this batch, unless the caller sets RunOptions::continue_with_errors.

Source

pub fn selections(&self) -> &BTreeMap<BackendName, SelectedRules>

The lowering rules chosen for every registered backend whose rules could be chosen, whether or not that backend takes part in this plan.

Source

pub fn selection(&self, backend: &str) -> Option<&SelectedRules>

The lowering rules chosen for backend, or None when backend is not registered or its rules could not be chosen (which makes the plan build fail only when that backend takes part).

Source

pub fn active_backends(&self) -> &BTreeSet<BackendName>

The backends that take part in this plan, in name order: those whose lowering stage is scheduled.

Source

pub fn needed_names(&self) -> Vec<CapName>

The names of every capability the plan needs, in name order: the demanded capabilities, together with every capability the scheduled stages require.

Source

pub fn externals(&self) -> &BTreeSet<TableId>

The external tables of this plan. An external table is a table that no stage of the run writes: the caller installs its value when the run is constructed (Externals).

Source

pub fn external_names(&self) -> Vec<CapName>

The names of the external tables of this plan, in the registry’s table order.

Source

pub fn warnings(&self) -> &[PlanWarning]

The warnings of this plan (PlanWarning): first, for each backend that takes part, in backend name order, its lowering rule preferences that could not be honored, then its unchecked outputs in feature name order; then the stage preferences that could not be honored.

Source

pub fn excluded(&self) -> &[Excluded]

The stages that provider selection ruled out (Excluded), sorted by the name of the stage ruled out, then by the name of the stage that ruled it out.

Source

pub fn commit_order(&self) -> Vec<StageName>

The names of the scheduled stages in the order in which provider selection chose them, which is not the order in which they run. It shows how the plan was built.

Source

pub fn predecessors(&self, idx: StageIdx) -> Option<&BTreeSet<StageIdx>>

The scheduled stages that the stage idx depends on directly, or None when idx is not scheduled.

The dependencies come from the stage’s requirements, its reads, its ordering edges and the registry’s ordering declarations. A rewrite stage’s dependencies are rewrite stages only, and a later stage’s dependencies are later stages only.

Source

pub fn per_tree_closure(&self, idx: StageIdx) -> Vec<StageIdx>

The stages that run once per tree and that the stage idx depends on, directly or through other stages, in the order they run; idx itself is not among them, and neither is any stage with effect Effect::Io.

Value catch-up runs these stages over a synthesized value, so that the stage that renders the value finds the same kinds of computed data it would find for a tree of the document. A synthesized value is a small tree that a stage builds while a run is under way, held outside the document’s trees (synthesized values).

Source

pub fn render(&self) -> String

The plan as five lines of text: its rewrite stages, its order, the order in which provider selection chose the stages, the stages that were ruled out, and the external tables.

The format is fixed and lists stage, capability and table names only, so a report can print it and a test can compare the text of two plans, for example to check that a plan does not depend on the order in which the features registered.

Trait Implementations§

Source§

impl Debug for Plan

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Plan

§

impl !UnwindSafe for Plan

§

impl Forget for Plan

§

impl Freeze for Plan
where *const ArcInner<FlmRegistry> is !null: Freeze, PhantomData<ArcInner<FlmRegistry>>: Freeze, *const u8 is !null: Freeze, PhantomData<CapName>: Freeze, PhantomData<StageName>: Freeze, *const LeafNode<BackendName, LoweringSelection> is !null: Freeze, PhantomData<(Owned, LeafOrInternal)>: Freeze, PhantomData<Box<(BackendName, LoweringSelection)>>: Freeze, *const LeafNode<BackendName, Vec<ElementName>> is !null: Freeze, PhantomData<Box<(BackendName, Vec<ElementName>)>>: Freeze, *const LeafNode<OptionKey, OptionValue> is !null: Freeze, PhantomData<Box<(OptionKey, OptionValue)>>: Freeze, *const ArcInner<str> is !null: Freeze, PhantomData<ArcInner<str>>: Freeze, *const LeafNode<CapName, SetValZST> is !null: Freeze, PhantomData<Box<(CapName, SetValZST)>>: Freeze, *const LeafNode<StageIdx, StagePlan> is !null: Freeze, PhantomData<Box<(StageIdx, StagePlan)>>: Freeze, PhantomData<StageIdx>: Freeze, PhantomData<Range<usize>>: Freeze, *const LeafNode<BackendName, SelectedRules> is !null: Freeze, PhantomData<Box<(BackendName, SelectedRules)>>: Freeze, *const LeafNode<BackendName, SetValZST> is !null: Freeze, PhantomData<Box<(BackendName, SetValZST)>>: Freeze, *const LeafNode<CapId, SetValZST> is !null: Freeze, PhantomData<Box<(CapId, SetValZST)>>: Freeze, *const LeafNode<TableId, SetValZST> is !null: Freeze, PhantomData<Box<(TableId, SetValZST)>>: Freeze, PhantomData<PlanWarning>: Freeze, PhantomData<Excluded>: Freeze, *const LeafNode<StageIdx, BTreeSet<StageIdx>> is !null: Freeze, PhantomData<Box<(StageIdx, BTreeSet<StageIdx>)>>: Freeze,

§

impl Move for Plan

§

impl Send for Plan
where Arc<FlmRegistry>: Send, RawVecInner: Send, Arc<str>: Send, NodeRef<Owned, BackendName, LoweringSelection, LeafOrInternal>: Send, BoxRaw<(BackendName, LoweringSelection)>: Send, NodeRef<Owned, BackendName, Vec<ElementName>, LeafOrInternal>: Send, BoxRaw<(BackendName, Vec<ElementName>)>: Send, NodeRef<Owned, OptionKey, OptionValue, LeafOrInternal>: Send, BoxRaw<(OptionKey, OptionValue)>: Send, NodeRef<Owned, CapName, SetValZST, LeafOrInternal>: Send, BoxRaw<(CapName, SetValZST)>: Send, NodeRef<Owned, StageIdx, StagePlan, LeafOrInternal>: Send, BoxRaw<(StageIdx, StagePlan)>: Send, NodeRef<Owned, BackendName, SelectedRules, LeafOrInternal>: Send, BoxRaw<(BackendName, SelectedRules)>: Send, NodeRef<Owned, BackendName, SetValZST, LeafOrInternal>: Send, BoxRaw<(BackendName, SetValZST)>: Send, NodeRef<Owned, CapId, SetValZST, LeafOrInternal>: Send, BoxRaw<(CapId, SetValZST)>: Send, NodeRef<Owned, TableId, SetValZST, LeafOrInternal>: Send, BoxRaw<(TableId, SetValZST)>: Send, NodeRef<Owned, StageIdx, BTreeSet<StageIdx>, LeafOrInternal>: Send, BoxRaw<(StageIdx, BTreeSet<StageIdx>)>: Send,

§

impl Sync for Plan
where Arc<FlmRegistry>: Sync, RawVecInner: Sync, Arc<str>: Sync, NodeRef<Owned, BackendName, LoweringSelection, LeafOrInternal>: Sync, BoxRaw<(BackendName, LoweringSelection)>: Sync, NodeRef<Owned, BackendName, Vec<ElementName>, LeafOrInternal>: Sync, BoxRaw<(BackendName, Vec<ElementName>)>: Sync, NodeRef<Owned, OptionKey, OptionValue, LeafOrInternal>: Sync, BoxRaw<(OptionKey, OptionValue)>: Sync, NodeRef<Owned, CapName, SetValZST, LeafOrInternal>: Sync, BoxRaw<(CapName, SetValZST)>: Sync, NodeRef<Owned, StageIdx, StagePlan, LeafOrInternal>: Sync, BoxRaw<(StageIdx, StagePlan)>: Sync, NodeRef<Owned, BackendName, SelectedRules, LeafOrInternal>: Sync, BoxRaw<(BackendName, SelectedRules)>: Sync, NodeRef<Owned, BackendName, SetValZST, LeafOrInternal>: Sync, BoxRaw<(BackendName, SetValZST)>: Sync, NodeRef<Owned, CapId, SetValZST, LeafOrInternal>: Sync, BoxRaw<(CapId, SetValZST)>: Sync, NodeRef<Owned, TableId, SetValZST, LeafOrInternal>: Sync, BoxRaw<(TableId, SetValZST)>: Sync, NodeRef<Owned, StageIdx, BTreeSet<StageIdx>, LeafOrInternal>: Sync, BoxRaw<(StageIdx, BTreeSet<StageIdx>)>: Sync,

§

impl Unpin for Plan
where Arc<FlmRegistry>: Unpin, *const u8 is !null: Unpin, Arc<str>: Unpin, *const LeafNode<BackendName, LoweringSelection> is !null: Unpin, Box<(BackendName, LoweringSelection)>: Unpin, *const LeafNode<BackendName, Vec<ElementName>> is !null: Unpin, Box<(BackendName, Vec<ElementName>)>: Unpin, *const LeafNode<OptionKey, OptionValue> is !null: Unpin, Box<(OptionKey, OptionValue)>: Unpin, *const LeafNode<CapName, SetValZST> is !null: Unpin, Box<(CapName, SetValZST)>: Unpin, *const LeafNode<StageIdx, StagePlan> is !null: Unpin, Box<(StageIdx, StagePlan)>: Unpin, *const LeafNode<BackendName, SelectedRules> is !null: Unpin, Box<(BackendName, SelectedRules)>: Unpin, *const LeafNode<BackendName, SetValZST> is !null: Unpin, Box<(BackendName, SetValZST)>: Unpin, *const LeafNode<CapId, SetValZST> is !null: Unpin, Box<(CapId, SetValZST)>: Unpin, *const LeafNode<TableId, SetValZST> is !null: Unpin, Box<(TableId, SetValZST)>: Unpin, *const LeafNode<StageIdx, BTreeSet<StageIdx>> is !null: Unpin, Box<(StageIdx, BTreeSet<StageIdx>)>: Unpin,

§

impl UnsafeUnpin for Plan
where *const ArcInner<FlmRegistry> is !null: UnsafeUnpin, PhantomData<ArcInner<FlmRegistry>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<CapName>: UnsafeUnpin, PhantomData<StageName>: UnsafeUnpin, *const LeafNode<BackendName, LoweringSelection> is !null: UnsafeUnpin, PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin, PhantomData<Box<(BackendName, LoweringSelection)>>: UnsafeUnpin, *const LeafNode<BackendName, Vec<ElementName>> is !null: UnsafeUnpin, PhantomData<Box<(BackendName, Vec<ElementName>)>>: UnsafeUnpin, *const LeafNode<OptionKey, OptionValue> is !null: UnsafeUnpin, PhantomData<Box<(OptionKey, OptionValue)>>: UnsafeUnpin, *const ArcInner<str> is !null: UnsafeUnpin, PhantomData<ArcInner<str>>: UnsafeUnpin, *const LeafNode<CapName, SetValZST> is !null: UnsafeUnpin, PhantomData<Box<(CapName, SetValZST)>>: UnsafeUnpin, *const LeafNode<StageIdx, StagePlan> is !null: UnsafeUnpin, PhantomData<Box<(StageIdx, StagePlan)>>: UnsafeUnpin, PhantomData<StageIdx>: UnsafeUnpin, PhantomData<Range<usize>>: UnsafeUnpin, *const LeafNode<BackendName, SelectedRules> is !null: UnsafeUnpin, PhantomData<Box<(BackendName, SelectedRules)>>: UnsafeUnpin, *const LeafNode<BackendName, SetValZST> is !null: UnsafeUnpin, PhantomData<Box<(BackendName, SetValZST)>>: UnsafeUnpin, *const LeafNode<CapId, SetValZST> is !null: UnsafeUnpin, PhantomData<Box<(CapId, SetValZST)>>: UnsafeUnpin, *const LeafNode<TableId, SetValZST> is !null: UnsafeUnpin, PhantomData<Box<(TableId, SetValZST)>>: UnsafeUnpin, PhantomData<PlanWarning>: UnsafeUnpin, PhantomData<Excluded>: UnsafeUnpin, *const LeafNode<StageIdx, BTreeSet<StageIdx>> is !null: UnsafeUnpin, PhantomData<Box<(StageIdx, BTreeSet<StageIdx>)>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<Src, Dst> LosslessTryInto<Dst> for Src
where Dst: LosslessTryFrom<Src>,

Source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
Source§

impl<Src, Dst> LossyInto<Dst> for Src
where Dst: LossyFrom<Src>,

Source§

fn lossy_into(self) -> Dst

Performs the conversion.
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> StrictAs for T

Source§

fn strict_as<Dst>(self) -> Dst
where T: StrictCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> StrictCastFrom<Src> for Dst
where Src: StrictCast<Dst>,

Source§

fn strict_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.