src/remove/relock.bend source
src/remove/relock.bend on the hub · documented module
# remove/relock: `ez remove` as it runs, the remove and the lock in one plan# (laws/AddRemoveRelock.bend). The remove is planned as before (`RP.plan`,# remove/plan.bend); once it is known to succeed, the plain `ez lock`# planner is run over the World it leaves (`R.world`, relock/relock.bend):# the ledger the remove writes, the `.bend` files git lists, and the lock's# answers, which the lock's interpreter gives as `ez lock` gives them.## The plan, when both succeed: the remove's effects, then the lock's, the# lock last. When either refuses, a refusal with no effect at all. A `.bend`# file git lists that still imports the dependency removed makes the lock# refuse, since ez.toml no longer names it, and so the remove.import Baseimport ./plan.bend as RPimport ../lock/plan.bend as Pimport ../lock/world.bend as Wimport ../relock/relock.bend as R# what `ez remove` reads: the remove's World, the directory it runs in, the# `.bend` files git lists, and the answers to the lock's questionstype World is Data: World{remove: RP.World, here: String, listing: W.Listing, locks: List<&2, W.Reply>}# the remove's Worlddef remove(world: World) -> RP.World: World{r, _here, _listing, _locks} = world r# the ledger's text the remove readdef ledger.was(rw: RP.World) -> Maybe<&2, String>: RP.World{_n, l, _ig} = rw l# the World a plain `ez lock` reads once the remove has rundef lock.world(world: World) -> W.World: World{+r, +here, listing, locks} = world R.world(here, R.ledger(RP.plan(r), ledger.was(r)), listing, locks)# the plan of that lockdef lock(world: World) -> P.Plan: P.plan(lock.world(world))# what is added after the lock's reason when the lock refusesdef tail() -> String: "\nez: ez remove wrote nothing, since it writes ez.toml and ez.lock.toml together;" ++ " a .bend file that still imports what it removes has to stop first"# `ez remove` over a World: the remove, then the lock over what it leavesdef plan(world: World) -> P.Plan: World{+r, +here, +listing, +locks} = world R.join(RP.plan(r), lock(World{r, here, listing, locks}), [], tail())# whether `ez remove` refuses on a Worlddef refuses(world: World) -> Bool: R.refuses(plan(world))# what the interpreter does next: answer the lock's questions, or run the plantype Next is Data: AskLock{asks: List<&2, W.Ask>} Planned{plan: P.Plan}# the lock's step, once the remove succeedsdef next.lock(st: P.Step, +world: World) -> Next: match st: case P.Asking{as, ups, ns}: AskLock{R.asks(P.Asking{as, ups, ns})} case P.Run{_pl}: Planned{plan(world)}# the remove refused is the plan; otherwise the lock is nextdef next.made(refused: Bool, +world: World) -> Next: match refused: case True{}: Planned{plan(world)} case False{}: next.lock(P.step(lock.world(world)), world)# what the interpreter does next on a Worlddef next(+world: World) -> Next: next.made(R.refuses(RP.plan(remove(world))), world)# the World with more of the lock's answers in itdef more(world: World, rs: List<&2, W.Reply>) -> World: World{r, here, listing, locks} = world World{r, here, listing, List.append(&2, W.Reply, locks, rs)}