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(®istry, "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
impl Plan
Sourcepub fn build(
registry: &Arc<FlmRegistry>,
request: &PlanRequest,
) -> Result<Plan, PlanError>
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.
Sourcepub fn for_workflow(
registry: &Arc<FlmRegistry>,
name: &str,
overrides: &Overrides,
) -> Result<Plan, PlanError>
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.
Sourcepub fn registry(&self) -> &Arc<FlmRegistry> ⓘ
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.
Sourcepub fn request(&self) -> &PlanRequest
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.
Sourcepub fn demands(&self) -> &BTreeSet<CapName>
pub fn demands(&self) -> &BTreeSet<CapName>
Every demanded capability, with collections replaced by their members, in name order.
Sourcepub fn key(&self) -> PlanKey
pub fn key(&self) -> PlanKey
The number that identifies the plan by everything it was built from: see
PlanKey.
Sourcepub fn manifest(&self, idx: StageIdx) -> Option<&StagePlan>
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.
Sourcepub fn manifests(&self) -> &BTreeMap<StageIdx, StagePlan>
pub fn manifests(&self) -> &BTreeMap<StageIdx, StagePlan>
The records the plan keeps about every registered stage, in registration order.
Sourcepub fn rewrite_names(&self) -> Vec<StageName>
pub fn rewrite_names(&self) -> Vec<StageName>
The names of the rewrite stages that will run, in the order they run.
Sourcepub fn order(&self) -> &[StageIdx]
pub fn order(&self) -> &[StageIdx]
The stages that will run after the rewrite stages, in the order they run.
Sourcepub fn stage_names(&self) -> Vec<StageName>
pub fn stage_names(&self) -> Vec<StageName>
The names of the stages that will run after the rewrite stages, in the order they run.
Sourcepub fn is_scheduled(&self, idx: StageIdx) -> bool
pub fn is_scheduled(&self, idx: StageIdx) -> bool
Whether the stage idx will run, as a rewrite stage or as a later stage.
Sourcepub fn scheduled_names(&self) -> Vec<StageName>
pub fn scheduled_names(&self) -> Vec<StageName>
The names of every stage that will run, rewrite stages included, in name order.
Sourcepub fn batches(&self) -> &[Range<usize>]
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.
Sourcepub fn batch_names(&self) -> Vec<Vec<StageName>>
pub fn batch_names(&self) -> Vec<Vec<StageName>>
The batches, each as the names of its stages in order.
Sourcepub fn first_io_batch(&self) -> Option<usize>
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.
Sourcepub fn selections(&self) -> &BTreeMap<BackendName, SelectedRules>
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.
Sourcepub fn selection(&self, backend: &str) -> Option<&SelectedRules>
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).
Sourcepub fn active_backends(&self) -> &BTreeSet<BackendName>
pub fn active_backends(&self) -> &BTreeSet<BackendName>
The backends that take part in this plan, in name order: those whose lowering stage is scheduled.
Sourcepub fn needed_names(&self) -> Vec<CapName>
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.
Sourcepub fn externals(&self) -> &BTreeSet<TableId>
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).
Sourcepub fn external_names(&self) -> Vec<CapName>
pub fn external_names(&self) -> Vec<CapName>
The names of the external tables of this plan, in the registry’s table order.
Sourcepub fn warnings(&self) -> &[PlanWarning]
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.
Sourcepub fn excluded(&self) -> &[Excluded]
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.
Sourcepub fn commit_order(&self) -> Vec<StageName>
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.
Sourcepub fn predecessors(&self, idx: StageIdx) -> Option<&BTreeSet<StageIdx>>
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.
Sourcepub fn per_tree_closure(&self, idx: StageIdx) -> Vec<StageIdx>
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).
Sourcepub fn render(&self) -> String
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§
Auto Trait Implementations§
impl !RefUnwindSafe for Plan
impl !UnwindSafe for Plan
impl Forget for Plan
impl Freeze for Planwhere
*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 Planwhere
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 Planwhere
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 Planwhere
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 Planwhere
*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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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