pub struct Run { /* private fields */ }Expand description
A run is one execution of one plan over one document; it owns the frozen trees, the store and the diagnostics.
Because a run owns everything it computes, one document may be run several times, under different plans, without one run seeing another’s results.
Construct a run with Run::new, give it the scope of a progress sheet
with Run::with_progress if it reports on one, then Run::execute it
to the end or Run::step through it. Read what it computed with Run::table,
Run::frozen_tree and Run::diagnostics. The module
documentation describes what happens in between; reading
results shows how an embedding
program reads an output.
§Examples
use std::sync::Arc;
use flm_core::model::doc::{Doc, DocContent, FragmentLayout};
use flm_core::core::plan::{Overrides, Plan};
use flm_core::core::registry::{PackageEntry, RegistryBuilder, RegistryInputs};
use flm_core::core::run::{Externals, Run, RunOptions, RunOutcome};
use flm_core::lang::{parse_fragment, FlmOrigin, FlmSource, ParseOptions};
use flm_core::stdlib::backends::text::TEXT_DOCUMENT;
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 = Arc::new(builder.build(&RegistryInputs::new())?);
let source = Arc::new(
FlmSource::new("Hello \\textbf{world}.").with_origin(FlmOrigin::new("hello.flm")),
);
let fragment = parse_fragment(
registry.lang(), source, FragmentLayout::default(), &ParseOptions::default(),
)?;
let mut content = DocContent::new();
content.place(Arc::new(fragment));
let doc = Arc::new(Doc::new(content));
let plan = Arc::new(Plan::for_workflow(®istry, "text", &Overrides::none())?);
let mut run = Run::new(doc, plan, Externals::none())?;
let outcome = run.execute(&RunOptions::new())?;
assert_eq!(outcome, RunOutcome::Finished);
let artifacts = run.table(TEXT_DOCUMENT)?.expect("the text workflow writes it");
let bytes = artifacts.entry().and_then(|a| a.as_bytes()).expect("one entry artifact");
assert_eq!(String::from_utf8_lossy(bytes).trim_end(), "Hello world.");Implementations§
Source§impl Run
impl Run
Sourcepub fn new(
doc: Arc<Doc>,
plan: Arc<Plan>,
externals: Externals,
) -> Result<Run, RunError>
pub fn new( doc: Arc<Doc>, plan: Arc<Plan>, externals: Externals, ) -> Result<Run, RunError>
Constructs a run of plan over doc, with the values of externals
installed into their external tables.
Nothing is executed here: this checks the inputs and resolves the
option values of every scheduled stage, so that every constructed run
has sound inputs. The module documentation lists the checks.
Execute the run with Run::execute or Run::step.
§Errors
Returns RunError::DocumentOption when the document sets a value for
an option type that is not bound at document level, and
RunError::MissingExternal, RunError::UnknownExternal,
RunError::NotExternal, RunError::ExternalType or
RunError::StampMismatch for a problem with the installs.
Sourcepub fn with_progress(self, scope: Scope) -> Run
pub fn with_progress(self, scope: Scope) -> Run
Gives the run the scope of a progress sheet under which it reports,
and declares the run’s rows under it, so that a host sees what is to
come. Call it before the first step; a run that is given no scope
reports under progress::Scope::none.
The rows, in this order:
- one row of kind
flm.run.rewrites, counted in items: the trees the rewrite stages run over. It starts when the rewrite stages begin and advances as each tree is done; - one row for each scheduled stage, in the plan’s order, whose kind is the stage’s name. It starts when the stage’s first call begins and ends when its last call returns. The row of a per-tree stage is counted in items, the trees of the run, and advances as each call returns; the row of a document-scope stage has no count.
The row of a stage that the error gate keeps from running, or that a cancellation keeps from starting, ends as not run. The row of a stage that panics, and every row running when the build is cancelled, ends as failed. A row is declared only for what the run has still to do: given after a step, the scope receives no row for that step.
The run reads the sheet’s cancellation through this scope; the module documentation lists where.
Sourcepub fn computed(&self) -> &Computed
pub fn computed(&self) -> &Computed
Returns the store: the values installed into external tables, and the tables that the steps run so far have produced.
Run::table reads one table of it, typed.
Sourcepub fn table<K: TableKey>(
&self,
key: K,
) -> Result<Option<&K::Table>, AccessError>
pub fn table<K: TableKey>( &self, key: K, ) -> Result<Option<&K::Table>, AccessError>
Reads one table of the store through a typed table key.
Ok(None) means that no value of the table is present yet: no stage of
the plan writes it, or the batch that writes it has not run yet.
Unlike a stage’s read, this read is not restricted to declared reads: a caller may read any table of the registry.
§Errors
Returns AccessError::UndeclaredRead when the registry declares no
table of that name (the error then gives _host as the stage and every
table of the registry as the declared reads), and
AccessError::TypeMismatch when the value type of key is not the
table’s declared value type.
Sourcepub fn frozen_tree(&self, id: TreeId) -> Option<&Arc<NodeTree<Flm>>>
pub fn frozen_tree(&self, id: TreeId) -> Option<&Arc<NodeTree<Flm>>>
Returns the frozen tree of one of the document’s trees: what the tree became after the last rewrite stage.
None before the rewrite stages have run, for a tree whose rewrite
failed, for a tree that the run’s walk does not reach
(Run::tree_order), and for an identifier that the document does not
use.
Sourcepub fn frozen_trees(
&self,
) -> impl Iterator<Item = (TreeId, &Arc<NodeTree<Flm>>)> + '_
pub fn frozen_trees( &self, ) -> impl Iterator<Item = (TreeId, &Arc<NodeTree<Flm>>)> + '_
Returns the run’s trees, each with its frozen tree, in the run’s order
of the trees (Run::tree_order).
Sourcepub fn tree_order(&self) -> &[TreeId]
pub fn tree_order(&self) -> &[TreeId]
Returns the run’s trees in the run’s order of the trees: the trees that the document’s walk, applied to the frozen trees, reaches, in the order in which it enters them. Empty before the rewrite stages have run.
A tree that the walk does not reach is not a tree of the run: a rewrite stage removed its placing node (for example, a user definition whose template does not use the argument that held it), or the tree that includes it failed its rewrite. Its content is dropped with the node that placed it, and no diagnostic reports it.
A placed tree is entered at the node that places it, so its nodes come
in the middle of the tree that places it: this order says which tree
comes first, not which node. Document order across trees is the order
of the walk (StageCx::walk).
Sourcepub fn walk(&self) -> impl Iterator<Item = (NodeAddr, NodeRef<'_, Flm>)> + '_
pub fn walk(&self) -> impl Iterator<Item = (NodeAddr, NodeRef<'_, Flm>)> + '_
Returns every node of every tree of the run, in document order, with
its address: the order of StageCx::walk,
the document’s walk applied to the frozen trees, a placed tree entered
at the node that places it. Empty before the rewrite stages have run.
A host that reads the run’s tables after the run, keyed by the
addresses of the frozen trees (a reference point’s, for instance),
finds the nodes they name here; the trees of Run::doc are the trees
as parsed, before the rewrites.
Sourcepub fn pipeline_diagnostics(&self) -> &FlmDiagnostics
pub fn pipeline_diagnostics(&self) -> &FlmDiagnostics
Returns only the diagnostics that the run produced, without the parse diagnostics.
Run::diagnostics is usually what a caller wants: it returns both.
Sourcepub fn diagnostics(&self) -> DiagnosticsView<'_>
pub fn diagnostics(&self) -> DiagnosticsView<'_>
Returns every diagnostic of the run: each fragment’s parse diagnostics, in the order in which the document’s walk reaches the fragments and once per fragment, then the diagnostics that the run produced.
Sourcepub fn stamp(&self) -> Stamp
pub fn stamp(&self) -> Stamp
Returns this run’s stamp: the registry digest, the rewrite stages it runs, and a digest of the option values those rewrite stages read.
To install a value that this run produced into an external table of
another run, pass this stamp to Externals::install; the other run
checks it. See Stamp.
Sourcepub fn is_done(&self) -> bool
pub fn is_done(&self) -> bool
Whether the run is over: it finished, stopped at the error gate, or was cancelled.
Sourcepub fn outcome(&self) -> Option<RunOutcome>
pub fn outcome(&self) -> Option<RunOutcome>
How the run ended, once it is over; None while steps remain.
Sourcepub fn step(&mut self, options: &RunOptions) -> Result<Step, RunError>
pub fn step(&mut self, options: &RunOptions) -> Result<Step, RunError>
Runs one step: the rewrite stages on the first call, then one batch of the plan per call, in order.
Returns Step::More while more steps remain and Step::Done once
the run is over; calling it again after that does nothing and returns
Step::Done. Before the first batch that holds a stage with effects
outside the store, the error gate may end the run (see
RunOptions). A build cancelled through the run’s progress sheet
ends the run, and the step under way produces nothing
(progress and cancellation). The first call also sets the diagnostic limit from
RunOptions::max_diagnostics. Stepping changes only when the work
happens, never what is computed.
§Errors
Returns RunError::Worker when no thread could be created to run the
batch on, and RunError::Store when an invariant of the store failed.
§Panics
A stage or a rewrite stage that panics propagates the panic out of this call. A panic means a defect in that stage; a problem with the document is reported as a diagnostic. The whole batch is collected before anything is folded into the store, so when a panic propagates, the store is untouched and the run has not advanced.
Sourcepub fn execute(&mut self, options: &RunOptions) -> Result<RunOutcome, RunError>
pub fn execute(&mut self, options: &RunOptions) -> Result<RunOutcome, RunError>
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Run
impl !UnwindSafe for Run
impl Forget for Run
impl Freeze for Runwhere
*const ArcInner<Doc> is !null: Freeze,
PhantomData<ArcInner<Doc>>: Freeze,
*const ArcInner<Plan> is !null: Freeze,
PhantomData<ArcInner<Plan>>: Freeze,
*const LeafNode<TableId, Arc<dyn Any + Send + Sync>> is !null: Freeze,
PhantomData<(Owned, LeafOrInternal)>: Freeze,
PhantomData<Box<(TableId, Arc<dyn Any + Send + Sync>)>>: Freeze,
*const u8 is !null: Freeze,
PhantomData<Diagnostic<FlmOrigin>>: Freeze,
*const LeafNode<TreeId, Arc<NodeTree<Flm>>> is !null: Freeze,
PhantomData<Box<(TreeId, Arc<NodeTree<Flm>>)>>: Freeze,
*const LeafNode<NodeAddr, TreeId> is !null: Freeze,
PhantomData<Box<(NodeAddr, TreeId)>>: Freeze,
PhantomData<TreeId>: Freeze,
PhantomData<NodeAddr>: Freeze,
*const LeafNode<TreeId, Vec<usize>> is !null: Freeze,
PhantomData<Box<(TreeId, Vec<usize>)>>: Freeze,
*const LeafNode<usize, TreeId> is !null: Freeze,
PhantomData<Box<(usize, TreeId)>>: Freeze,
*const LeafNode<StageIdx, Arc<ResolvedOptions>> is !null: Freeze,
PhantomData<Box<(StageIdx, Arc<ResolvedOptions>)>>: Freeze,
*const ArcInner<Source<FlmOrigin>> is !null: Freeze,
PhantomData<ArcInner<Source<FlmOrigin>>>: Freeze,
*const ArcInner<Shared> is !null: Freeze,
PhantomData<ArcInner<Shared>>: Freeze,
*const ArcInner<Row> is !null: Freeze,
PhantomData<ArcInner<Row>>: Freeze,
*const LeafNode<StageIdx, Pending> is !null: Freeze,
PhantomData<Box<(StageIdx, Pending)>>: Freeze,
impl Move for Run
impl Send for Runwhere
Arc<Doc>: Send,
Arc<Plan>: Send,
NodeRef<Owned, TableId, Arc<dyn Any + Send + Sync>, LeafOrInternal>: Send,
BoxRaw<(TableId, Arc<dyn Any + Send + Sync>)>: Send,
RawVecInner: Send,
BoxRaw<dyn DiagnosticData>: Send,
Arc<Source<FlmOrigin>>: Send,
NodeRef<Owned, TreeId, Arc<NodeTree<Flm>>, LeafOrInternal>: Send,
BoxRaw<(TreeId, Arc<NodeTree<Flm>>)>: Send,
NodeRef<Owned, NodeAddr, TreeId, LeafOrInternal>: Send,
BoxRaw<(NodeAddr, TreeId)>: Send,
NodeRef<Owned, TreeId, Vec<usize>, LeafOrInternal>: Send,
BoxRaw<(TreeId, Vec<usize>)>: Send,
NodeRef<Owned, usize, TreeId, LeafOrInternal>: Send,
BoxRaw<(usize, TreeId)>: Send,
NodeRef<Owned, StageIdx, Arc<ResolvedOptions>, LeafOrInternal>: Send,
BoxRaw<(StageIdx, Arc<ResolvedOptions>)>: Send,
Arc<Shared>: Send,
Arc<Row>: Send,
NodeRef<Owned, StageIdx, Pending, LeafOrInternal>: Send,
BoxRaw<(StageIdx, Pending)>: Send,
impl Sync for Runwhere
Arc<Doc>: Sync,
Arc<Plan>: Sync,
NodeRef<Owned, TableId, Arc<dyn Any + Send + Sync>, LeafOrInternal>: Sync,
BoxRaw<(TableId, Arc<dyn Any + Send + Sync>)>: Sync,
RawVecInner: Sync,
BoxRaw<dyn DiagnosticData>: Sync,
Arc<Source<FlmOrigin>>: Sync,
NodeRef<Owned, TreeId, Arc<NodeTree<Flm>>, LeafOrInternal>: Sync,
BoxRaw<(TreeId, Arc<NodeTree<Flm>>)>: Sync,
NodeRef<Owned, NodeAddr, TreeId, LeafOrInternal>: Sync,
BoxRaw<(NodeAddr, TreeId)>: Sync,
NodeRef<Owned, TreeId, Vec<usize>, LeafOrInternal>: Sync,
BoxRaw<(TreeId, Vec<usize>)>: Sync,
NodeRef<Owned, usize, TreeId, LeafOrInternal>: Sync,
BoxRaw<(usize, TreeId)>: Sync,
NodeRef<Owned, StageIdx, Arc<ResolvedOptions>, LeafOrInternal>: Sync,
BoxRaw<(StageIdx, Arc<ResolvedOptions>)>: Sync,
Arc<Shared>: Sync,
Arc<Row>: Sync,
NodeRef<Owned, StageIdx, Pending, LeafOrInternal>: Sync,
BoxRaw<(StageIdx, Pending)>: Sync,
impl Unpin for Runwhere
Arc<Doc>: Unpin,
Arc<Plan>: Unpin,
*const LeafNode<TableId, Arc<dyn Any + Send + Sync>> is !null: Unpin,
Box<(TableId, Arc<dyn Any + Send + Sync>)>: Unpin,
*const u8 is !null: Unpin,
Box<dyn DiagnosticData>: Unpin,
Arc<Source<FlmOrigin>>: Unpin,
*const LeafNode<TreeId, Arc<NodeTree<Flm>>> is !null: Unpin,
Box<(TreeId, Arc<NodeTree<Flm>>)>: Unpin,
*const LeafNode<NodeAddr, TreeId> is !null: Unpin,
Box<(NodeAddr, TreeId)>: Unpin,
*const LeafNode<TreeId, Vec<usize>> is !null: Unpin,
Box<(TreeId, Vec<usize>)>: Unpin,
*const LeafNode<usize, TreeId> is !null: Unpin,
Box<(usize, TreeId)>: Unpin,
*const LeafNode<StageIdx, Arc<ResolvedOptions>> is !null: Unpin,
Box<(StageIdx, Arc<ResolvedOptions>)>: Unpin,
Arc<Shared>: Unpin,
Arc<Row>: Unpin,
*const LeafNode<StageIdx, Pending> is !null: Unpin,
Box<(StageIdx, Pending)>: Unpin,
impl UnsafeUnpin for Runwhere
*const ArcInner<Doc> is !null: UnsafeUnpin,
PhantomData<ArcInner<Doc>>: UnsafeUnpin,
*const ArcInner<Plan> is !null: UnsafeUnpin,
PhantomData<ArcInner<Plan>>: UnsafeUnpin,
*const LeafNode<TableId, Arc<dyn Any + Send + Sync>> is !null: UnsafeUnpin,
PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin,
PhantomData<Box<(TableId, Arc<dyn Any + Send + Sync>)>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<Diagnostic<FlmOrigin>>: UnsafeUnpin,
*const LeafNode<TreeId, Arc<NodeTree<Flm>>> is !null: UnsafeUnpin,
PhantomData<Box<(TreeId, Arc<NodeTree<Flm>>)>>: UnsafeUnpin,
*const LeafNode<NodeAddr, TreeId> is !null: UnsafeUnpin,
PhantomData<Box<(NodeAddr, TreeId)>>: UnsafeUnpin,
PhantomData<TreeId>: UnsafeUnpin,
PhantomData<NodeAddr>: UnsafeUnpin,
*const LeafNode<TreeId, Vec<usize>> is !null: UnsafeUnpin,
PhantomData<Box<(TreeId, Vec<usize>)>>: UnsafeUnpin,
*const LeafNode<usize, TreeId> is !null: UnsafeUnpin,
PhantomData<Box<(usize, TreeId)>>: UnsafeUnpin,
*const LeafNode<StageIdx, Arc<ResolvedOptions>> is !null: UnsafeUnpin,
PhantomData<Box<(StageIdx, Arc<ResolvedOptions>)>>: UnsafeUnpin,
*const ArcInner<Source<FlmOrigin>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Source<FlmOrigin>>>: UnsafeUnpin,
*const ArcInner<Shared> is !null: UnsafeUnpin,
PhantomData<ArcInner<Shared>>: UnsafeUnpin,
*const ArcInner<Row> is !null: UnsafeUnpin,
PhantomData<ArcInner<Row>>: UnsafeUnpin,
*const LeafNode<StageIdx, Pending> is !null: UnsafeUnpin,
PhantomData<Box<(StageIdx, Pending)>>: 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