Skip to main content

Compiler

Struct Compiler 

Source
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

Source

pub fn registry(&self) -> &Registry

The registry the compiler resolves functions in.

Source

pub fn check(&self, def: &WorkflowDef) -> Vec<Issue>

Every issue compile_one finds in def, whether or not it rejects the workflow.

Source

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.

Source

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

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");

Trait Implementations§

Source§

impl Clone for Compiler

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Compiler

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> 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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.