~/bend-docscommunity

planner.bend relies on unsafe/foreign

raw source on the hub · import bend-kit-planner@0.4.0.0/planner.bend as Planner

Dependency plans with proved order and closure, incremental invalidation, and a build runner.

5 imports
import Base
import bend-kit-bytes@0.3.3.0/bytes.bend as Bytes
import bend-kit-hash@0.3.0.4/hash.bend as Hash
import bend-kit-files@0.3.1.0/files.bend as Files
import bend-kit-process@0.5.0.1/process.bend as Proc

Types

type Node source · line 9 · raw

@-K:Data -> Data

A node and the nodes it requires. Its prerequisites must succeed before it runs.

type Error source · line 12 · raw

@-K:Data -> Data

type Status source · line 20 · raw

Data

type Entry source · line 30 · raw

@-K:Data -> Data

type Action source · line 33 · raw

Data

type Pool source · line 400 · raw

@-K:Data -> Data

The statuses so far, the nodes whose commands run now, and every node started, latest first.

type Fin source · line 404 · raw

@-K:Data -> Data

A command finished: its node, and whether it exited 0.

type Step source · line 407 · raw

Data

type Task source · line 538 · raw

Data

A node with its command and the source files it reads.

type Stamp source · line 707 · raw

Data

A node and the hash of its command, prerequisites, and inputs.

type Ran source · line 829 · raw

Data

What a command left: its exit code and the last 4096 octets of its stdout and stderr, or why it did not start.

type Log source · line 833 · raw

Data

type Outcome source · line 837 · raw

Data

A planned node, its status, and what its command left; None when no command ran.

type Msg source · line 897 · raw

Data

A finished command, as its job reports it.

type Ledger source · line 900 · raw

Data

Definitions

def when source · line 41 · raw

@-A:Type -> @rest:(@_:Unit -> A) -> @hit:Bool -> @yes:A -> A

def rev source · line 80 · raw

@-K:Data -> @xs:List<&2, K> -> @acc:List<&2, K> -> List<&2, K>

def cat source · line 87 · raw

@-K:Data -> @xs:List<&2, K> -> @ys:List<&2, K> -> List<&2, K>

def go.node source · line 152 · raw

@-K:Data -> @-R:Type -> @m:Maybe<&2, List<&2, K>> -> @missing:(@_:Unit -> R) -> @child:(@_:List<&2, K> -> R) -> R

def go.open source · line 159 · raw

@-K:Data -> @-R:Type -> @open:Bool -> @m:(@_:Unit -> Maybe<&2, List<&2, K>>) -> @loop:(@_:Unit -> R) -> @missing:(@_:Unit -> R) -> @child:(@_:List<&2, K> -> R) -> R

def go.at source · line 167 · raw

@-K:Data -> @-R:Type -> @seen:Bool -> @open:(@_:Unit -> Bool) -> @m:(@_:Unit -> Maybe<&2, List<&2, K>>) -> @skip:(@_:Unit -> R) -> @loop:(@_:Unit -> R) -> @missing:(@_:Unit -> R) -> @child:(@_:List<&2, K> -> R) -> R

One node d: skip it when done, report a cycle when open, report it when missing, else visit its prerequisites.

def go.then source · line 177 · raw

@-K:Data -> @r:Result<&2, &2, Error<K>, List<&2, K>> -> @k:(@_:List<&2, K> -> Result<&2, &2, Error<K>, List<&2, K>>) -> Result<&2, &2, Error<K>, List<&2, K>>

def go.out source · line 184 · raw

@-K:Data -> @ds:List<&2, K> -> @done:List<&2, K> -> Result<&2, &2, Error<K>, List<&2, K>>

def plan.ok source · line 211 · raw

@-K:Data -> @c:Bool -> @p:List<&2, K> -> Result<&2, &2, Error<K>, List<&2, K>>

def invalidate.if source · line 234 · raw

@-K:Data -> @hit:Bool -> @x:K -> @acc:List<&2, K> -> List<&2, K>

def Status.ok source · line 263 · raw

@s:Status -> Bool

def Status.selected source · line 275 · raw

@s:Status -> Bool

Built, Fresh, or Failed: the node was not skipped.

def ok.at source · line 282 · raw

@m:Maybe<&2, Status> -> Bool

def selected.at source · line 289 · raw

@m:Maybe<&2, Status> -> Bool

def decide.ready source · line 304 · raw

@go:Bool -> @stale:Bool -> Action

def outcome source · line 333 · raw

@rs:List<&2, Bool> -> Status

def Action.status source · line 341 · raw

@a:Action -> @rs:List<&2, Bool> -> Maybe<&2, Status>

The status that action a records; a Run takes its result from the head of rs.

def record source · line 350 · raw

@-K:Data -> @m:Maybe<&2, Status> -> @st:List<&2, Entry<K>> -> @x:K -> List<&2, Entry<K>>

def step source · line 357 · raw

@-K:Data -> @a:Action -> @st:List<&2, Entry<K>> -> @x:K -> @rs:List<&2, Bool> -> List<&2, Entry<K>>

def step.rest source · line 360 · raw

@a:Action -> @rs:List<&2, Bool> -> List<&2, Bool>

def keys source · line 379 · raw

@-K:Data -> @st:List<&2, Entry<K>> -> List<&2, K>

def le source · line 390 · raw

@a:Nat -> @b:Nat -> Bool

a <= b.

def Fin.status source · line 425 · raw

@ok:Bool -> Status

def finish.if source · line 432 · raw

@-K:Data -> @run:Bool -> @+y:K -> @ok:Bool -> @st:List<&2, Entry<K>> -> @running:List<&2, K> -> @dropped:List<&2, K> -> @log:List<&2, K> -> Pool<K>

def decide.par.room source · line 445 · raw

@room:Bool -> Step

def decide.par.go source · line 452 · raw

@go:Bool -> @stale:Bool -> @room:Bool -> Step

def decide.par.wait source · line 463 · raw

@busy:Bool -> @go:Bool -> @stale:Bool -> @room:Bool -> Step

def apply source · line 491 · raw

@-K:Data -> @a:Step -> @pool:Pool<K> -> @+x:K -> Pool<K>

def par.at source · line 504 · raw

@-R:Type -> @a:Step -> @wait:(@_:Unit -> R) -> @go:(@_:Unit -> R) -> R

def Run source · line 542 · raw

@-A:Type -> Type

def Run.pure source · line 545 · raw

@-A:Type -> @x:A -> Run(A)

def Run.fail source · line 548 · raw

@-A:Type -> @e:Pair(U32, String) -> Run(A)

def Run.next source · line 551 · raw

@-A:Type -> @-B:Type -> @r:Result<&1, &1, Pair(U32, String), A> -> @f:(@_:A -> Run(B)) -> Run(B)

def Run.bind source · line 558 · raw

@-A:Type -> @-B:Type -> @m:Run(A) -> @f:(@_:A -> Run(B)) -> Run(B)

def Run.lift source · line 561 · raw

@-A:Type -> @m:IO(A) -> Run(A)

def Task.node source · line 564 · raw

@t:Task -> Node<String>

def graph source · line 569 · raw

@ts:List<&2, Task> -> List<&2, Node<String>>

def task source · line 577 · raw

@ts:List<&2, Task> -> @+k:String -> Maybe<&2, Task>

The first task named k.

def id.char source · line 584 · raw

@c:Char -> Bool

def id.chars source · line 588 · raw

@s:String -> Bool

def id.ok source · line 596 · raw

@+s:String -> Bool

A stamp file holds one id per line, so an id is printable ASCII and not empty.

def ids.bad source · line 599 · raw

@ts:List<&2, Task> -> Maybe<&2, String>

def Error.show source · line 606 · raw

@e:Error<String> -> String

def Status.show source · line 617 · raw

@s:Status -> String

def text source · line 629 · raw

@s:String -> String

Each code point in decimal, so distinct strings give distinct text.

def texts source · line 636 · raw

@xs:List<&2, String> -> String

def digest.of source · line 643 · raw

@r:Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, 0xd6aea21c4de95b225a135a3c995751a3/hash.W64) -> String

def digest source · line 648 · raw

@b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> String

def file.end source · line 651 · raw

@empty:Bool -> @f:File -> @acc:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> @b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> @k:(@_:File -> @_:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> IO(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes)) -> IO(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes)

def file.got source · line 660 · raw

@r:Pair(File, Result<&1, &1, Pair(U32, String), 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes>) -> @acc:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> @k:(@_:File -> @_:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> IO(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes)) -> IO(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes)

def file.more source · line 671 · raw

@n:Nat -> @f:File -> @acc:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> IO(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes)

The rest of f, read 1 MiB at a time, in at most n reads.

def file.opened source · line 681 · raw

@r:Result<&1, &1, Pair(U32, String), File> -> IO(String)

def file.stamp source · line 689 · raw

@path:String -> IO(String)

"m" when path does not open, else "f" and the hash of its octets.

def inputs.stamp source · line 692 · raw

@xs:List<&2, String> -> @+dir:String -> @acc:String -> IO(String)

def Task.stamp source · line 700 · raw

@t:Task -> @+dir:String -> IO(String)

The hash of the command, the prerequisites, and every input file.

def lookup source · line 710 · raw

@xs:List<&2, Stamp> -> @+k:String -> Maybe<&2, String>

def stamps.now source · line 717 · raw

@p:List<&2, String> -> @+ts:List<&2, Task> -> @+dir:String -> @acc:List<&2, Stamp> -> IO(List<&2, Stamp>)

def same source · line 726 · raw

@a:Maybe<&2, String> -> @b:Maybe<&2, String> -> Bool

def changed source · line 734 · raw

@p:List<&2, String> -> @+old:List<&2, Stamp> -> @+now:List<&2, Stamp> -> List<&2, String>

The nodes of p whose stamp now is not the recorded one.

def after.new source · line 742 · raw

@st:List<&2, Entry<String>> -> @+now:List<&2, Stamp> -> List<&2, Stamp>

The stamps of the nodes that ended Built or Fresh, and the old stamps of nodes the run did not reach.

def after.keep source · line 750 · raw

@old:List<&2, Stamp> -> @+done:List<&2, String> -> List<&2, Stamp>

def after source · line 758 · raw

@+st:List<&2, Entry<String>> -> @+now:List<&2, Stamp> -> @old:List<&2, Stamp> -> List<&2, Stamp>

def stamps.line source · line 761 · raw

@e:Stamp -> String

def stamps.lines source · line 766 · raw

@xs:List<&2, Stamp> -> String

def stamps.show source · line 773 · raw

@xs:List<&2, Stamp> -> String

def stamps.entry source · line 776 · raw

@fields:List<&2, String> -> List<&2, Stamp>

def stamps.parse source · line 783 · raw

@lines:List<&2, String> -> List<&2, Stamp>

def stamps.got source · line 790 · raw

@r:Pair(File, Result<&1, &1, Pair(U32, String), String>) -> IO(List<&2, Stamp>)

def stamps.opened source · line 801 · raw

@r:Result<&1, &1, Pair(U32, String), File> -> IO(List<&2, Stamp>)

def stamps.read source · line 809 · raw

@path:String -> IO(List<&2, Stamp>)

The recorded stamps; none when the file does not open.

def stamps.closed source · line 812 · raw

@r:Pair(File, Result<&1, &1, Pair(U32, String), Unit>) -> Run(Unit)

def stamps.write source · line 820 · raw

@+path:String -> @xs:List<&2, Stamp> -> Run(Unit)

Writes through path.tmp and a rename, so a reader sees the old file or the new one.

def Ran.ok source · line 840 · raw

@r:Ran -> Bool

def tail.of source · line 847 · raw

@r:Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> String

def tail source · line 853 · raw

@b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> String

The last 4096 octets of b, one Char per octet.

def run.ran source · line 858 · raw

@r:Result<&1, &1, Pair(U32, String), Pair(U32, Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes))> -> Ran

def run.argv source · line 866 · raw

@argv:List<&2, String> -> @dir:String -> IO(Maybe<&2, Ran>)

Runs argv in dir; None for a group with no command.

def run.task source · line 874 · raw

@dir:String -> @m:Maybe<&2, Task> -> IO(Maybe<&2, Ran>)

def run.ok source · line 882 · raw

@m:Maybe<&2, Ran> -> Bool

A group succeeds; a command succeeds when it exits 0.

def run.log source · line 889 · raw

@+x:String -> @m:Maybe<&2, Ran> -> @logs:List<&2, Log> -> List<&2, Log>

def run.job source · line 903 · raw

@dir:String -> @m:Maybe<&2, Task> -> @+x:String -> @chan:Chan(Msg) -> IO(Unit)

def run.msg source · line 909 · raw

@m:Maybe<&1, Msg> -> @+pool:Pool<String> -> @+logs:List<&2, Log> -> @k:(@_:Pool<String> -> @_:List<&2, Log> -> IO(Ledger)) -> IO(Ledger)

def run.recv source · line 917 · raw

@+chan:Chan(Msg) -> @+pool:Pool<String> -> @+logs:List<&2, Log> -> @k:(@_:Pool<String> -> @_:List<&2, Log> -> IO(Ledger)) -> IO(Ledger)

Takes the next finished command, then goes on with k.

def run.drain source · line 921 · raw

@n:Nat -> @+pool:Pool<String> -> @+logs:List<&2, Log> -> @+chan:Chan(Msg) -> IO(Ledger)

Waits for n running commands.

def Pool.busy source · line 928 · raw

@pool:Pool<String> -> Nat

def par.case source · line 933 · raw

@-R:Type -> @a:Step -> @wait:(@_:Unit -> R) -> @start:(@_:Unit -> R) -> @other:(@_:Unit -> R) -> R

def run.par source · line 943 · raw

@n:Nat -> @p:List<&2, String> -> @+ts:List<&2, Task> -> @+g:List<&2, Node<String>> -> @+stale:List<&2, String> -> @+limit:Nat -> @+pool:Pool<String> -> @+logs:List<&2, Log> -> @+dir:String -> @+chan:Chan(Msg) -> IO(Ledger)

par, with each finish from a running job. Each wait finishes a node started earlier, so n = 1 + |p| is enough.

def ran.find source · line 962 · raw

@logs:List<&2, Log> -> @+k:String -> Maybe<&2, Ran>

def outcome.of source · line 969 · raw

@m:Maybe<&2, Status> -> @+x:String -> @r:Maybe<&2, Ran> -> @rest:List<&2, Outcome> -> List<&2, Outcome>

def outcomes source · line 977 · raw

@p:List<&2, String> -> @+st:List<&2, Entry<String>> -> @+logs:List<&2, Log> -> List<&2, Outcome>

Each node of p that has a status, in plan order.

def build.ids source · line 984 · raw

@m:Maybe<&2, String> -> Run(Unit)

def build.plan source · line 991 · raw

@r:Result<&2, &2, Error<String>, List<&2, String>> -> Run(List<&2, String>)

def build.done source · line 998 · raw

@+path:String -> @p:List<&2, String> -> @+now:List<&2, Stamp> -> @old:List<&2, Stamp> -> @l:Ledger -> Run(List<&2, Outcome>)

def build source · line 1007 · raw

@+tasks:List<&2, Task> -> @+targets:List<&2, String> -> @+dir:String -> @+path:String -> @+jobs:U32 -> Run(List<&2, Outcome>)

Plans targets, runs each stale task in dir, up to jobs at once, reuses the rest, and records stamps in path. The result is each planned node with its status and command output, in plan order.

Templates

template member source · line 49 · raw

@-K:Data -> @-eq:(@_:K -> @_:K -> Bool) -> @xs:List<&2, K> -> @+k:K -> Bool

eq(k, x) for some x of xs.

template all_in source · line 57 · raw

@-K:Data -> @-eq:(@_:K -> @_:K -> Bool) -> @xs:List<&2, K> -> @+ys:List<&2, K> -> Bool

Every x of xs is a member of ys.

template any_in source · line 65 · raw

@-K:Data -> @-eq:(@_:K -> @_:K -> Bool) -> @xs:List<&2, K> -> @+ys:List<&2, K> -> Bool

Some x of xs is a member of ys.

template distinct source · line 73 · raw

@-K:Data -> @-eq:(@_:K -> @_:K -> Bool) -> @xs:List<&2, K> -> Bool

No element occurs twice.

template deps source · line 95 · raw

@-K:Data -> @-eq:(@_:K -> @_:K -> Bool) -> @g:List<&2, Node<K>> -> @+k:K -> Maybe<&2, List<&2, K>>

The prerequisites of the first node named k; None when no node is.

template deps.or_nil source · line 102 · raw

@-K:Data -> @-eq:(@_:K -> @_:K -> Bool) -> @+g:List<&2, Node<K>> -> @+k:K -> List<&2, K>

template ordered.node source · line 108 · raw

@-K:Data -> @-eq:(@_:K -> @_:K -> Bool) -> @m:Maybe<&2, List<&2, K>> -> @+done:List<&2, K> -> Bool

template ordered source · line 116 · raw

@-K:Data -> @-eq:(@_:K -> @_:K -> Bool) -> @p:List<&2, K> -> @+g:List<&2, Node<K>> -> @+done:List<&2, K> -> Bool

Each node is defined, is not in done, and has every prerequisite in done; it then joins done.

template needed source · line 126 · raw

@-K:Data -> @-eq:(@_:K -> @_:K -> Bool) -> @r:List<&2, K> -> @+g:List<&2, Node<K>> -> @+want:List<&2, K> -> Bool

Over the plan reversed: each node is in want, a target or a prerequisite of a later node.

template valid source · line 134 · raw

@-K:Data -> @-eq:(@_:K -> @_:K -> Bool) -> @+g:List<&2, Node<K>> -> @+ts:List<&2, K> -> @+p:List<&2, K> -> Bool

p is a dependency order of exactly the closure of ts.

template cyc source · line 142 · raw

@-K:Data -> @-eq:(@_:K -> @_:K -> Bool) -> @path:List<&2, K> -> @+k:K -> @+acc:List<&2, K> -> List<&2, K>

The open path from the node eq to k, nearest last, then acc.

template cycle source · line 149 · raw

@-K:Data -> @-eq:(@_:K -> @_:K -> Bool) -> @path:List<&2, K> -> @+k:K -> Error<K>

template go source · line 193 · raw

@-K:Data -> @-eq:(@_:K -> @_:K -> Bool) -> @fuel:Nat -> @ds:List<&2, K> -> @+g:List<&2, Node<K>> -> @+path:List<&2, K> -> @+done:List<&2, K> -> Result<&2, &2, Error<K>, List<&2, K>>

A depth-first walk of ds. path holds the open nodes, nearest first; done the finished ones, last first. Each level of path costs one unit of fuel.

template plan.check source · line 218 · raw

@-K:Data -> @-eq:(@_:K -> @_:K -> Bool) -> @+g:List<&2, Node<K>> -> @+ts:List<&2, K> -> @r:Result<&2, &2, Error<K>, List<&2, K>> -> Result<&2, &2, Error<K>, List<&2, K>>

template plan source · line 228 · raw

@-K:Data -> @-eq:(@_:K -> @_:K -> Bool) -> @+g:List<&2, Node<K>> -> @+ts:List<&2, K> -> Result<&2, &2, Error<K>, List<&2, K>>

The closure of ts in dependency order, each node once; or why there is none. A path never repeats a node, and each node on it is defined, so one level per node is enough fuel.

template invalidate.go source · line 241 · raw

@-K:Data -> @-eq:(@_:K -> @_:K -> Bool) -> @p:List<&2, K> -> @+g:List<&2, Node<K>> -> @+changed:List<&2, K> -> @+acc:List<&2, K> -> List<&2, K>

template invalidate source · line 250 · raw

@-K:Data -> @-eq:(@_:K -> @_:K -> Bool) -> @p:List<&2, K> -> @+g:List<&2, Node<K>> -> @+changed:List<&2, K> -> List<&2, K>

The nodes of p that changed or require a stale node, latest first.

template status source · line 256 · raw

@-K:Data -> @-eq:(@_:K -> @_:K -> Bool) -> @st:List<&2, Entry<K>> -> @+k:K -> Maybe<&2, Status>

template ready source · line 297 · raw

@-K:Data -> @-eq:(@_:K -> @_:K -> Bool) -> @ds:List<&2, K> -> @+st:List<&2, Entry<K>> -> Bool

Every node of ds is Built or Fresh in st.

template decide.node source · line 315 · raw

@-K:Data -> @-eq:(@_:K -> @_:K -> Bool) -> @m:Maybe<&2, List<&2, K>> -> @stale:Bool -> @+st:List<&2, Entry<K>> -> Action

template decide.seen source · line 322 · raw

@-K:Data -> @-eq:(@_:K -> @_:K -> Bool) -> @seen:Bool -> @+g:List<&2, Node<K>> -> @+stale:List<&2, K> -> @+st:List<&2, Entry<K>> -> @+x:K -> Action

template decide source · line 330 · raw

@-K:Data -> @-eq:(@_:K -> @_:K -> Bool) -> @+g:List<&2, Node<K>> -> @+stale:List<&2, K> -> @+st:List<&2, Entry<K>> -> @+x:K -> Action

What to do with x: run it, mark it without a run, or pass it.

template exec source · line 368 · raw

@-K:Data -> @-eq:(@_:K -> @_:K -> Bool) -> @p:List<&2, K> -> @+g:List<&2, Node<K>> -> @+stale:List<&2, K> -> @+st:List<&2, Entry<K>> -> @+rs:List<&2, Bool> -> List<&2, Entry<K>>

The model of a run: rs holds the result of each command, in order. Statuses are newest first.

template drop source · line 418 · raw

@-K:Data -> @-eq:(@_:K -> @_:K -> Bool) -> @xs:List<&2, K> -> @+y:K -> List<&2, K>

xs without the nodes eq to y.

template finish source · line 440 · raw

@-K:Data -> @-eq:(@_:K -> @_:K -> Bool) -> @pool:Pool<K> -> @e:Fin<K> -> Pool<K>

The pool after e; a finish for a node that does not run changes nothing.

template decide.par.node source · line 470 · raw

@-K:Data -> @-eq:(@_:K -> @_:K -> Bool) -> @m:Maybe<&2, List<&2, K>> -> @+st:List<&2, Entry<K>> -> @+running:List<&2, K> -> @stale:Bool -> @room:Bool -> Step

template decide.par.seen source · line 477 · raw

@-K:Data -> @-eq:(@_:K -> @_:K -> Bool) -> @seen:Bool -> @+g:List<&2, Node<K>> -> @+stale:List<&2, K> -> @+limit:Nat -> @+st:List<&2, Entry<K>> -> @+running:List<&2, K> -> @+x:K -> Step

template decide.par source · line 486 · raw

@-K:Data -> @-eq:(@_:K -> @_:K -> Bool) -> @+g:List<&2, Node<K>> -> @+stale:List<&2, K> -> @+limit:Nat -> @pool:Pool<K> -> @+x:K -> Step

What to do with x in a parallel run.

template par source · line 513 · raw

@-K:Data -> @-eq:(@_:K -> @_:K -> Bool) -> @es:List<&2, Fin<K>> -> @p:List<&2, K> -> @+g:List<&2, Node<K>> -> @+stale:List<&2, K> -> @+limit:Nat -> @+pool:Pool<K> -> Pool<K>

The model of a parallel run. Nodes start in plan order, up to limit at once; es holds the finishes, in the order they arrive. A node that must wait takes the next finish; the run stops when it must wait and no finish is left.