src/lock/run.bend relies on unsafe/foreign
raw source on the hub · import ezx@1.16.0.0/src/lock/run.bend as Run
lock/run: the interpreter for ez lock. It reads the ledger and the
committed sources into a World, then loops: it asks the planner
(lock/plan.bend) what is still open, answers each question by IO, and adds
the answers to the World, until nothing is left to ask. Then it runs the
planner's plan. It decides nothing: which packages to read, whether their
bytes are the ones the ledger names, where an upgrade moves a pin, and what
is written are the planner's. That it reads and executes faithfully is
trusted in ez/app.bend. It answers a name's question by asking the hub once, and the
lock's by reading ez.lock.toml. Under --upgrade it also answers the
upgrade's questions (lock/up.bend): what git prints for refs, the default
branch and tags, ancestry, checkouts at a rev, the hub's manifest for a
moved hash, .gitignore, and the project's sources. A new checkout's package is walked
from its entry here, by K.pkg_of, which is interpreter code trusted
in ez/app.bend until ez add is converted.
18 imports
import Base import snap@1.4.0.0/main.bend as R import ../io/file.bend as F import ../hub/hub.bend as Web import ../hub/get.bend as Net import ../git/git.bend as Git import ../git/exec.bend as GX import ../pkg/pkg.bend as K import ../pkg/path.bend as P import ../share/say.bend as Say import ../share/spin.bend as Spin import ./lock.bend as L import ./world.bend as W import ./up.bend as Up import ./plan.bend as Plan import ../ws/run.bend as WsRun import ../ws/up.bend as WsUp import ../ws/joint.bend as J
Definitions
def env.text source · line 38 · raw
@res:Result<&1, &1, Pair(U32, String), String> -> String
an environment variable's text; unset, ""
def lib.or source · line 46 · raw
@+dir:String -> String
where packages live, which is with the project rather than in ~/.bend/lib
def bend.lib source · line 50 · raw
IO(String)
the BEND_LIB this project pins
def nonempty source · line 56 · raw
@ss:List<&2, String> -> List<&2, String>
the non-empty lines
def read.ledger source · line 65 · raw
IO(Maybe<&2, String>)
the ledger's text, or None when there is no ez.toml
def read.all source · line 69 · raw
@ps:List<&2, String> -> IO(List<&2, 0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Source>)
every listed path, read
def listed source · line 80 · raw
@ok:Bool -> @+text:String -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Listing)
what git listed, or why it could not
def read.listing source · line 93 · raw
IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Listing)
every .bend file git tracks under the current directory, with its text.
Untracked files are not a clone's, so they are not the lock's.
def gots source · line 103 · raw
@+how:0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.How -> @+manifest:String -> @gs:List<&2, 0x71927e9fe3c5d91fa7a64d2340a0fdac/src/hub/hub.Got> -> @acc:List<&2, String> -> 0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Answer
every text a fetch answered, or the first miss
def hub.all source · line 115 · raw
@+hub:String -> @+hash:String -> @fs:List<&2, 0x71927e9fe3c5d91fa7a64d2340a0fdac/src/pkg/pkg.Item> -> IO(List<&2, 0x71927e9fe3c5d91fa7a64d2340a0fdac/src/hub/hub.Got>)
every file of a hub package, fetched and checked against its sum
def hub.got source · line 126 · raw
@got:0x71927e9fe3c5d91fa7a64d2340a0fdac/src/hub/hub.Got -> @+hub:String -> @+hash:String -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Answer)
a hub package's files, once its manifest arrived
def answer.hub source · line 136 · raw
@+hub:String -> @+hash:String -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Answer)
a hub package: its manifest, then every file it names
def disk.all source · line 146 · raw
@+dir:String -> @fs:List<&2, 0x71927e9fe3c5d91fa7a64d2340a0fdac/src/pkg/pkg.Item> -> IO(List<&2, String>)
every file a tree's manifest names, read from beside it. A file that is not there reads as "", which does not hash to its sum.
def answer.lib source · line 157 · raw
@+dir:String -> @+manifest:String -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Answer)
a tree under BEND_LIB, as it is
def clone.miss source · line 164 · raw
@+work:String -> @+why:String -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Answer)
a checkout that could not be made or read is removed, and the question is answered with why
def clone.ran source · line 171 · raw
@ok:Bool -> @+work:String -> @+why:String -> @go:(@_:Unit -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Answer)) -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Answer)
a command of a clone that worked goes on with the clone; one that failed ends it
def clone.run source · line 179 · raw
@+work:String -> @what:String -> @args:List<&2, String> -> @go:(@_:Unit -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Answer)) -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Answer)
one git command of a clone, and the rest of the clone when it worked
def clone.walk source · line 185 · raw
@+work:String -> @+entry:String -> @+nar:String -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Answer)
the checkout's package, walked from its entry the way ez add walked it
def clone.entry source · line 194 · raw
@ok:Bool -> @+work:String -> @+entry:String -> @+url:String -> @+rev:String -> @+nar:String -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Answer)
the entry has to be in the checkout for there to be a package to walk
def clone.weigh source · line 202 · raw
@+work:String -> @+url:String -> @+rev:String -> @+entry:String -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Answer)
the checkout, weighed and walked
def answer.clone source · line 215 · raw
@+lib:String -> @+hash:String -> @+url:String -> @+rev:String -> @+entry:String -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Answer)
a git package whose tree is not under BEND_LIB: a shallow clone at the rev
the ledger pins, the way ez add and ez fetch clone, from the source the
question names, which the planner anchored at the project root. Nothing is
laid here; the plan lays the tree once it has checked it.
def git.seen source · line 229 · raw
@got:Maybe<&2, String> -> @+lib:String -> @+hash:String -> @+url:String -> @+rev:String -> @+entry:String -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Answer)
a tree already under BEND_LIB is read; a missing one is cloned
def answer.git source · line 244 · raw
@+lib:String -> @+hash:String -> @+url:String -> @+rev:String -> @+entry:String -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Answer)
a git package
def answer.pkg source · line 250 · raw
@+lib:String -> @+hash:String -> @src:0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/lock.Src -> @+hub:String -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Answer)
a package, from where its source says
def said source · line 261 · raw
@got:0x71927e9fe3c5d91fa7a64d2340a0fdac/src/hub/hub.Got -> 0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Answer
what the hub says a name names, as it said it; the planner reads the hash out of it
def answer.name source · line 269 · raw
@+hub:String -> @+nv:String -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Answer)
a name, asked of the hub once: GET <hub>/name/<nv>
def answer.lock source · line 277 · raw
IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Answer)
the lock being rewritten, "" when there is none
def answer source · line 283 · raw
@+lib:String -> @ask:0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Ask -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Answer)
one question, answered
def answer.all source · line 293 · raw
@+lib:String -> @asks:List<&2, 0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Ask> -> IO(List<&2, 0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Reply>)
every question, answered
def git.said source · line 307 · raw
@+what:String -> @args:List<&2, String> -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/up.Answer)
what git printed, and whether it succeeded, kept as it was
def answer.refs source · line 320 · raw
@+url:String -> @+ref:String -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/up.Answer)
the refs a ref could name: a tag, its peeled form, and a branch, all at once, because which of them exists is the question
def answer.head source · line 325 · raw
@+url:String -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/up.Answer)
HEAD on the remote, with the branch it is a symref to
def answer.tags source · line 329 · raw
@+url:String -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/up.Answer)
every tag on the remote
def answer.above source · line 333 · raw
@+lib:String -> @+url:String -> @+pin:String -> @+tip:String -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/up.Answer)
whether tip descends from pin, asked of a blobless bare clone
def tree.walk source · line 340 · raw
@+work:String -> @+at:String -> @+nar:String -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/up.Answer)
the checkout's package, walked from its entry the way ez add walks it, with
the directory its paths are written from, against the repo
def tree.entry source · line 350 · raw
@ok:Bool -> @+work:String -> @+at:String -> @+url:String -> @+rev:String -> @+nar:String -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/up.Answer)
the entry has to be in the checkout for there to be a package to walk
def answer.tree source · line 363 · raw
@+lib:String -> @+url:String -> @+rev:String -> @+entry:String -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/up.Answer)
a checkout at a rev: cloned, its .git removed, weighed, and walked. An
entry that was not recorded is read from the checkout. Nothing is laid and
nothing is noted: a tree the upgrade moves to is laid by the plan, once the
upgrade and the lock both succeed.
def answer.weigh source · line 378 · raw
@+url:String -> @+rev:String -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/up.Answer)
a commit's NAR hash, for a tool
def answer.hubhas source · line 384 · raw
@+hub:String -> @+hash:String -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/up.Answer)
the hub's manifest for a hash a dependency moved to
def answer.ignore source · line 390 · raw
IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/up.Answer)
the ignore file, "" when it is missing
def found.put source · line 396 · raw
@got:Maybe<&2, String> -> @+at:String -> @rest:0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/up.Answer -> 0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/up.Answer
one source in front of the rest, or the first that could not be read
def found.all source · line 408 · raw
@ps:List<&2, String> -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/up.Answer)
every listed source, read
def found.listed source · line 418 · raw
@ok:Bool -> @+text:String -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/up.Answer)
def answer.sources source · line 427 · raw
IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/up.Answer)
every Bend source of the project. Vendored trees and the gate's shadow live under .ez, and a checkout's .git is not source, so neither is rewritten.
def whole.miss source · line 435 · raw
@+work:String -> @+why:String -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/up.Answer)
a checkout ez add walks, which could not be made or read: removed, and
the question answered with why
def whole.ran source · line 442 · raw
@ok:Bool -> @+work:String -> @+why:String -> @go:(@_:Unit -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/up.Answer)) -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/up.Answer)
a command of the checkout that worked goes on with it; one that failed ends it
def whole.run source · line 450 · raw
@+work:String -> @what:String -> @args:List<&2, String> -> @go:(@_:Unit -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/up.Answer)) -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/up.Answer)
one git command of the checkout, and the rest of it when it worked
def whole.put source · line 456 · raw
@got:Maybe<&2, String> -> @+at:String -> @rest:List<&2, 0x71927e9fe3c5d91fa7a64d2340a0fdac/src/pkg/pkg.Source> -> List<&2, 0x71927e9fe3c5d91fa7a64d2340a0fdac/src/pkg/pkg.Source>
a file read, in front of the rest
def whole.read source · line 466 · raw
@+work:String -> @ps:List<&2, String> -> IO(List<&2, 0x71927e9fe3c5d91fa7a64d2340a0fdac/src/pkg/pkg.Source>)
every listed file of the checkout, read, with its path from the checkout's top. One that cannot be read as text, such as a link to a directory, is left out, as the walk would find it missing.
def whole.listed source · line 482 · raw
@ok:Bool -> @+work:String -> @+nar:String -> @+text:String -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/up.Answer)
the checkout, its .git removed, weighed, and every file of it read; then
removed. Nothing is laid: ez add lays the tree from its plan.
the files of a checkout, read, once find has listed them. A listing that
failed is refused rather than read: find writes what it could not reach
to stderr, which snap answers beside the paths (SNAP-ANS-4), and such a
line is no path of the package.
def whole.weigh source · line 494 · raw
@+work:String -> @+rev:String -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/up.Answer)
def whole.dir source · line 504 · raw
@ok:Bool -> @+work:String -> @+url:String -> @+rev:String -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/up.Answer)
a scratch directory made, or why it could not be
def answer.whole source · line 522 · raw
@+url:String -> @+rev:String -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/up.Answer)
a checkout at a rev for ez add: a shallow clone into a scratch directory
outside the project and BEND_LIB, weighed, and every file's text read, so
the planner walks the package itself. The scratch directory is removed
whether or not the clone worked, so a refused add leaves no trace.
def answer.up source · line 528 · raw
@+lib:String -> @ask:0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/up.Ask -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/up.Answer)
one of the upgrade's questions, answered
def answer.ups source · line 552 · raw
@+lib:String -> @asks:List<&2, 0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/up.Ask> -> IO(List<&2, 0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/up.Reply>)
every one of them, answered
def answer.queries source · line 565 · raw
@+lib:String -> @qs:List<&2, 0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/plan.Query> -> IO(List<&2, 0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/up.Reply>)
every query of the lock's upgrade: git is asked the question as the planner anchored it, and the answer is recorded under the question the upgrade looks it up by
def more source · line 576 · raw
@world:0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.World -> @rs:List<&2, 0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Reply> -> @us:List<&2, 0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/up.Reply> -> 0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.World
the World with more answers in it
def wrote source · line 585 · raw
@ok:Bool -> @+at:String -> IO(Unit)
a write that did not happen stops the command
def write source · line 593 · raw
@+at:String -> @text:String -> IO(Unit)
one file written, with the directory it goes in made first
def lay.all source · line 600 · raw
@+dir:String -> @fs:List<&2, 0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Source> -> IO(Unit)
every file of a tree, in order
def place source · line 610 · raw
@+lib:String -> @pl:0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/plan.Place -> String
where a place is
def exec source · line 620 · raw
@+lib:String -> @effect:0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/plan.Effect -> IO(Unit)
one effect
def exec.all source · line 639 · raw
@+lib:String -> @es:List<&2, 0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/plan.Effect> -> IO(Unit)
every effect, in order
def end.at source · line 650 · raw
@zero:Bool -> @+code:U32 -> @+why:String -> IO(Unit)
a status that is 0 ends nothing, so the program runs out and exits 0; any other exits with that status and the reason
def end source · line 660 · raw
@+outcome:0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/plan.Outcome -> IO(Unit)
how the command ends: with the status the planner gave its outcome
(Plan.status, laws/ExitStatusSaysFailure.bend), and the reason when it
refused
def exec.plan source · line 665 · raw
@+lib:String -> @pl:0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/plan.Plan -> IO(Unit)
a plan, executed
def loop.step source · line 676 · raw
@st:0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/plan.Step -> @+lib:String -> @back:0x71927e9fe3c5d91fa7a64d2340a0fdac/src/ws/up.Back -> @world:0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.World -> @go:(@_:0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.World -> IO(Unit)) -> IO(Unit)
the planner's step: its questions answered and the loop gone round again, or its plan run
def rounds source · line 693 · raw
Nat
the rounds the loop may take. Each round's questions come from the last
round's answers (a package's imports are known once git has answered for
it), so how many there will be is not known up front. This is a guard
against a planner that keeps asking, not a limit on a lock: running out of
it dies loudly. The walk inside each round takes its fuel from its inputs
(Plan.walk.fuel).
def loop source · line 698 · raw
@fuel:Nat -> @+lib:String -> @+back:0x71927e9fe3c5d91fa7a64d2340a0fdac/src/ws/up.Back -> @+world:0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.World -> IO(Unit)
the loop, under fuel. Every round adds at least one answer, since the planner never asks what the World answers already.
def settle.seen source · line 708 · raw
@got:Maybe<&2, String> -> @ask:0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Ask -> @answer:0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Answer -> @+lib:String -> @+hash:String -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Reply)
a member's package as the lock reads it: from BEND_LIB when a tree is laid
there under its hash, as a git package's is (git.seen), and fresh from
the committed tree, as the joint ledger walked it, otherwise
def settle.one source · line 718 · raw
@rp:0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Reply -> @+lib:String -> IO(0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Reply)
one member's package, so
def settle source · line 726 · raw
@rs:List<&2, 0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Reply> -> @+lib:String -> IO(List<&2, 0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Reply>)
every member's package, so
def run.planned source · line 738 · raw
@pd:0x71927e9fe3c5d91fa7a64d2340a0fdac/src/ws/run.Planned -> @+lib:String -> @up:Bool -> @only:String -> @here:String -> @ls:0x71927e9fe3c5d91fa7a64d2340a0fdac/src/lock/world.Listing -> IO(Unit)
the loop, on the ledger the lock is planned from, with the workspace's members already answered
def run source · line 747 · raw
@up:Bool -> @+only:String -> IO(Unit)
ez lock and ez lock --upgrade [--package only]: the directory it runs
in, the ledger and the listing read, every question answered, and the plan
run