Skip to main content

Run

Struct Run 

Source
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(&registry, "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

Source

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.

Source

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.

Source

pub fn doc(&self) -> &Arc<Doc> ⓘ

The document being processed.

Source

pub fn plan(&self) -> &Arc<Plan> ⓘ

The plan being run.

Source

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.

Source

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.

Source

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.

Source

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).

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn is_done(&self) -> bool

Whether the run is over: it finished, stopped at the error gate, or was cancelled.

Source

pub fn outcome(&self) -> Option<RunOutcome>

How the run ended, once it is over; None while steps remain.

Source

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.

Source

pub fn execute(&mut self, options: &RunOptions) -> Result<RunOutcome, RunError>

Runs every remaining step, and returns how the run ended.

§Errors

The same as Run::step, which this calls until the run is over.

§Panics

A stage or a rewrite stage that panics propagates the panic out of this call; see Run::step.

Trait Implementations§

Source§

impl Debug for Run

Source§

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

Formats the value using the given formatter. Read more
Source§

impl TreeSource for Run

Source§

fn tree_of(&self, id: TreeId) -> Option<&NodeTree<Flm>>

Looks the id up among the run’s frozen trees, the trees its tables were computed over.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Run

§

impl !UnwindSafe for Run

§

impl Forget for Run

§

impl Freeze for Run
where *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 Run
where 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 Run
where 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 Run
where 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 Run
where *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> 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.