planner.bend relies on unsafe/foreign
raw source on the hub · import bend-kit-planner@0.3.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.
Node@-K:Data -> @id:K -> @deps:List<&2, K> -> Node<K>
type Error source · line 12 · raw
@-K:Data -> Data
Missing@-K:Data -> @node:K -> @chain:List<&2, K> -> Error<K>
node is undefined; chain is the requirement path from a target to the node that names it.
Cycle@-K:Data -> @path:List<&2, K> -> Error<K>
Each node requires the next, and the last is the first.
Refused@-K:Data -> Error<K>
The candidate failed the plan check. This is a planner bug.
type Status source · line 20 · raw
Data
BuiltStatus
The command ran and exited 0.
FreshStatus
The node was not stale, so its command did not run.
FailedStatus
The command ran and failed.
SkippedStatus
The node is undefined, or a prerequisite did not succeed.
type Entry source · line 30 · raw
@-K:Data -> Data
Entry@-K:Data -> @node:K -> @status:Status -> Entry<K>
type Action source · line 33 · raw
Data
RunAction
Run the command, then record Built or Failed.
Mark@status:Status -> Action
Record this status without a run.
PassAction
The node already has a status.
type Task source · line 390 · raw
Data
A node with its command and the source files it reads.
Task@id:String -> @deps:List<&2, String> -> @argv:List<&2, String> -> @inputs:List<&2, String> -> Task
argv is the command and its arguments; an empty argv is a group with no command.
type Stamp source · line 559 · raw
Data
A node and the hash of its command, prerequisites, and inputs.
Stamp@node:String -> @hash:String -> Stamp
type Ran source · line 681 · 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.
Exited@code:U32 -> @out:String -> @err:String -> Ran
Unstarted@error:String -> Ran
type Log source · line 685 · raw
Data
Log@node:String -> @ran:Ran -> Log
type Outcome source · line 689 · raw
Data
A planned node, its status, and what its command left; None when no command ran.
Outcome@node:String -> @status:Status -> @ran:Maybe<&2, Ran> -> Outcome
type Ledger source · line 692 · raw
Data
Ledger@st:List<&2, Entry<String>> -> @logs:List<&2, Log> -> Ledger
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 Run source · line 394 · raw
@-A:Type -> Type
def Run.pure source · line 397 · raw
@-A:Type -> @x:A -> Run(A)
def Run.fail source · line 400 · raw
@-A:Type -> @e:Pair(U32, String) -> Run(A)
def Run.next source · line 403 · raw
@-A:Type -> @-B:Type -> @r:Result<&1, &1, Pair(U32, String), A> -> @f:(@_:A -> Run(B)) -> Run(B)
def Run.bind source · line 410 · raw
@-A:Type -> @-B:Type -> @m:Run(A) -> @f:(@_:A -> Run(B)) -> Run(B)
def Run.lift source · line 413 · raw
@-A:Type -> @m:IO(A) -> Run(A)
def Task.node source · line 416 · raw
@t:Task -> Node<String>
def graph source · line 421 · raw
@ts:List<&2, Task> -> List<&2, Node<String>>
def task source · line 429 · raw
@ts:List<&2, Task> -> @+k:String -> Maybe<&2, Task>
The first task named k.
def id.char source · line 436 · raw
@c:Char -> Bool
def id.chars source · line 440 · raw
@s:String -> Bool
def id.ok source · line 448 · 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 451 · raw
@ts:List<&2, Task> -> Maybe<&2, String>
def Error.show source · line 458 · raw
@e:Error<String> -> String
def Status.show source · line 469 · raw
@s:Status -> String
def text source · line 481 · raw
@s:String -> String
Each code point in decimal, so distinct strings give distinct text.
def texts source · line 488 · raw
@xs:List<&2, String> -> String
def digest.of source · line 495 · raw
@r:Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, 0xd6aea21c4de95b225a135a3c995751a3/hash.W64) -> String
def digest source · line 500 · raw
@b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> String
def file.end source · line 503 · 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 512 · 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 523 · 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 533 · raw
@r:Result<&1, &1, Pair(U32, String), File> -> IO(String)
def file.stamp source · line 541 · raw
@path:String -> IO(String)
"m" when path does not open, else "f" and the hash of its octets.
def inputs.stamp source · line 544 · raw
@xs:List<&2, String> -> @+dir:String -> @acc:String -> IO(String)
def Task.stamp source · line 552 · raw
@t:Task -> @+dir:String -> IO(String)
The hash of the command, the prerequisites, and every input file.
def lookup source · line 562 · raw
@xs:List<&2, Stamp> -> @+k:String -> Maybe<&2, String>
def stamps.now source · line 569 · raw
@p:List<&2, String> -> @+ts:List<&2, Task> -> @+dir:String -> @acc:List<&2, Stamp> -> IO(List<&2, Stamp>)
def same source · line 578 · raw
@a:Maybe<&2, String> -> @b:Maybe<&2, String> -> Bool
def changed source · line 586 · 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 594 · 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 602 · raw
@old:List<&2, Stamp> -> @+done:List<&2, String> -> List<&2, Stamp>
def after source · line 610 · raw
@+st:List<&2, Entry<String>> -> @+now:List<&2, Stamp> -> @old:List<&2, Stamp> -> List<&2, Stamp>
def stamps.line source · line 613 · raw
@e:Stamp -> String
def stamps.lines source · line 618 · raw
@xs:List<&2, Stamp> -> String
def stamps.show source · line 625 · raw
@xs:List<&2, Stamp> -> String
def stamps.entry source · line 628 · raw
@fields:List<&2, String> -> List<&2, Stamp>
def stamps.parse source · line 635 · raw
@lines:List<&2, String> -> List<&2, Stamp>
def stamps.got source · line 642 · raw
@r:Pair(File, Result<&1, &1, Pair(U32, String), String>) -> IO(List<&2, Stamp>)
def stamps.opened source · line 653 · raw
@r:Result<&1, &1, Pair(U32, String), File> -> IO(List<&2, Stamp>)
def stamps.read source · line 661 · raw
@path:String -> IO(List<&2, Stamp>)
The recorded stamps; none when the file does not open.
def stamps.closed source · line 664 · raw
@r:Pair(File, Result<&1, &1, Pair(U32, String), Unit>) -> Run(Unit)
def stamps.write source · line 672 · 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 695 · raw
@r:Ran -> Bool
def tail.of source · line 702 · raw
@r:Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes) -> String
def tail source · line 708 · raw
@b:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> String
The last 4096 octets of b, one Char per octet.
def run.ran source · line 713 · raw
@r:Result<&1, &1, Pair(U32, String), Pair(U32, Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes))> -> Ran
def run.argv source · line 721 · 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 729 · raw
@dir:String -> @m:Maybe<&2, Task> -> IO(Maybe<&2, Ran>)
def run.ok source · line 737 · raw
@m:Maybe<&2, Ran> -> Bool
A group succeeds; a command succeeds when it exits 0.
def run.log source · line 744 · raw
@+x:String -> @m:Maybe<&2, Ran> -> @logs:List<&2, Log> -> List<&2, Log>
def act source · line 751 · raw
@-R:Type -> @a:Action -> @run:(@_:Unit -> R) -> @other:(@_:Unit -> R) -> R
def run.loop source · line 759 · raw
@p:List<&2, String> -> @+ts:List<&2, Task> -> @+g:List<&2, Node<String>> -> @+stale:List<&2, String> -> @+st:List<&2, Entry<String>> -> @+logs:List<&2, Log> -> @+dir:String -> IO(Ledger)
exec, with each Run's result from the task's command.
def ran.find source · line 773 · raw
@logs:List<&2, Log> -> @+k:String -> Maybe<&2, Ran>
def outcomes source · line 780 · raw
@st:List<&2, Entry<String>> -> @+logs:List<&2, Log> -> @acc:List<&2, Outcome> -> List<&2, Outcome>
def build.ids source · line 787 · raw
@m:Maybe<&2, String> -> Run(Unit)
def build.plan source · line 794 · raw
@r:Result<&2, &2, Error<String>, List<&2, String>> -> Run(List<&2, String>)
def build.done source · line 801 · raw
@+path:String -> @+now:List<&2, Stamp> -> @old:List<&2, Stamp> -> @l:Ledger -> Run(List<&2, Outcome>)
def build source · line 810 · raw
@+tasks:List<&2, Task> -> @+targets:List<&2, String> -> @+dir:String -> @+path:String -> Run(List<&2, Outcome>)
Plans targets, runs each stale task in dir, 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.