pub struct Compiler { /* private fields */ }Expand description
Compiles definitions against one Registry, so everything it compiles
shares one set of functions and one vocabulary.
Each workflow compiles on its own: an unregistered function, or any other Rejected issue, rejects only its own workflow.
use dataflow_rs::Registry;
use dataflow_rs::def::{ParseOptions, parse};
use dataflow_rs::program::{CompileOptions, IssueCode};
use serde_json::json;
let compiler = Registry::default().compiler(CompileOptions::default());
let json = json!({"id": "w", "tasks": [
{"id": "t", "function": {"name": "fetch"}}
]});
let def = parse(&json, ParseOptions::default()).def.unwrap();
let issues = compiler.compile_one(&def).unwrap_err();
assert_eq!(issues[0].code, IssueCode::UnknownFunction);
assert_eq!(issues[0].path.to_string(), "tasks[0].function.name");
assert_eq!(compiler.check(&def), issues);Implementations§
Source§impl Compiler
impl Compiler
Sourcepub fn check(&self, def: &WorkflowDef) -> Vec<Issue>
pub fn check(&self, def: &WorkflowDef) -> Vec<Issue>
Every issue compile_one finds in def, whether
or not it rejects the workflow.
Sourcepub fn check_steps(&self, steps: &Value, root: &str) -> Vec<Issue>
pub fn check_steps(&self, steps: &Value, root: &str) -> Vec<Issue>
Every issue in a fragment of steps that would sit at root in a
workflow, such as tasks[2].tasks or loop.setup: its parse issues,
then its compile issues, every path under root.
The fragment is parsed as parse reads a
workflow’s steps, with the compat reader on. A root under loop.setup
makes setup steps, and each tasks key in root past the first adds
one group of depth. The steps compile only when nothing in the parse is
Rejected, and a fragment has no workflow condition, loop or workflow
lint. A host function’s prepare sees an empty workflow id.
A root that is not an authored path is PARSE_FAILED at the empty
path. A root that holds no steps, one neither ending in a tasks key
nor loop.setup, is PARSE_FAILED at the root, and so is a fragment
that is not an array.
Sourcepub fn compile_one(&self, def: &WorkflowDef) -> Result<Compiled, Vec<Issue>>
pub fn compile_one(&self, def: &WorkflowDef) -> Result<Compiled, Vec<Issue>>
Compiles one workflow.
Err holds every issue, in walk order, when any is Rejected. Ok
holds the workflow and its Defects and Advisories, so seeing them
takes no second compile.
Source§impl Compiler
impl Compiler
Sourcepub fn link(
&self,
workflows: impl IntoIterator<Item = CompiledWorkflow>,
) -> Program
pub fn link( &self, workflows: impl IntoIterator<Item = CompiledWorkflow>, ) -> Program
Links compiled workflows into a Program. It never fails.
Workflows sort by priority, ascending, with input order breaking
ties; the sorted position is the WorkflowIx. Tasks are numbered
from zero over every workflow’s task table in that order, setup first,
so a workflow’s tasks are contiguous. Workflows sharing an id are all
kept, as v3 keeps them.
§Panics
When a workflow was compiled under another registry: its functions, operators and secrets need not be the program’s. A registry and its clones are one registry, so every compiler made from them links the others’ workflows, until one of them registers a function or a layer, which gives it a table of its own.
use dataflow_rs::Registry;
use dataflow_rs::def::{ParseOptions, parse};
use dataflow_rs::program::CompileOptions;
use serde_json::json;
let compiler = Registry::default().compiler(CompileOptions::default());
let json = json!({"id": "w", "tasks": [
{"id": "t", "function": {"name": "log", "input": {"message": "hi"}}}
]});
let def = parse(&json, ParseOptions::default()).def.unwrap();
let program = compiler.link([compiler.compile_one(&def).unwrap().workflow]);
assert_eq!(program.workflows()[0].id, "w");
assert_eq!(program.tasks()[0].id, "t");