diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 51d91c4..71951eb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ on: jobs: check: - uses: Emerging-Patterns/actions/.github/workflows/nix-flake-check.yml@feaa011dafd85fecb67aa058fbcf6424cf605e86 + uses: Emerging-Patterns/actions/.github/workflows/nix-flake-check.yml@4ea982dc3e7839b05bc0bd65a3e4a2868d44e1a1 # The README's install, followed without nix on a fresh checkout: bend, # `sh bootstrap.sh`, the build, then the proof gate with the built ez. diff --git a/bolt.bend b/bolt.bend index bae9863..946edac 100644 --- a/bolt.bend +++ b/bolt.bend @@ -32,18 +32,3 @@ def coverage() -> String: # law claims one computed case and no guarantee, and nothing exempts one. def closed() -> String: "error" - -# Rules bolt 1.23 to 1.27 added or widened, which fire on code that predates -# them: `pick` (C003, a search bound above its pick: src/ws/joint.bend, -# src/ws/workspace.bend), `concat` (U004, an append passed through a -# continuation: src/check/serve.bend, src/io/file.bend) and `prefix` (U017, a -# take compared to a literal: src/tool/run.bend). They are advice until those -# six findings are fixed, and go back to their groups' level then. -def pick() -> String: - "warn" - -def concat() -> String: - "warn" - -def prefix() -> String: - "warn" diff --git a/ez.lock.toml b/ez.lock.toml index 44654f7..e3ffb93 100644 --- a/ez.lock.toml +++ b/ez.lock.toml @@ -125,8 +125,8 @@ LICENSE = "309f5aae946e4db157750e002fb179a74ed0fe27fce09a7be68a6977b14f205f" [tools] [tools.bolt] git = "https://github.com/Emerging-Patterns/bolt" -rev = "9700daf3a447089a8795d311912014382a74a2a9" -tag = "v1.27.0" +rev = "26391508a28b69077aaf59b75a80f774a455bca5" +tag = "v1.66.0" root = "." -narHash = "sha256-0S48j2dongVcvP5Oms5a+s5I12sIy91KAgwW0bP7pxM=" +narHash = "sha256-gldg9U4c/Rq1W/9sdhxSPCbujQ8LpHR8edQwbM3tNXM=" entry = "main.bend" diff --git a/ez.toml b/ez.toml index baf8042..c7e3548 100644 --- a/ez.toml +++ b/ez.toml @@ -28,8 +28,8 @@ entry = "main.bend" [tools] [tools.bolt] git = "https://github.com/Emerging-Patterns/bolt" -rev = "9700daf3a447089a8795d311912014382a74a2a9" -tag = "v1.27.0" +rev = "26391508a28b69077aaf59b75a80f774a455bca5" +tag = "v1.66.0" root = "." -narHash = "sha256-0S48j2dongVcvP5Oms5a+s5I12sIy91KAgwW0bP7pxM=" +narHash = "sha256-gldg9U4c/Rq1W/9sdhxSPCbujQ8LpHR8edQwbM3tNXM=" entry = "main.bend" diff --git a/laws/LicenseGoesAlong.bend b/laws/LicenseGoesAlong.bend index 4e3632c..3d147f2 100644 --- a/laws/LicenseGoesAlong.bend +++ b/laws/LicenseGoesAlong.bend @@ -22,7 +22,7 @@ law license_goes_along: for rest: List<&2, K.Task> for lic: String for here: {K.Here{lic} == K.find(tree, K.beside(file)) : K.Look} - {K.visit.put(K.Going{}, tree, sc, text, file, ns, eb, seen, out, rest) + {K.visit.put(K.Going{}, tree, K.Opened{file, ns, text, sc}, eb, seen, out, rest) == K.State{file <> seen, K.Hit{K.raw_of(ns, eb), text} <> K.Hit{K.beside(K.raw_of(ns, eb)), lic} <> List.append(&2, K.Hit, diff --git a/laws/NoLicenseAsBefore.bend b/laws/NoLicenseAsBefore.bend index 7b94e20..b45dc9e 100644 --- a/laws/NoLicenseAsBefore.bend +++ b/laws/NoLicenseAsBefore.bend @@ -15,7 +15,7 @@ law no_license_as_before: for out: List<&2, K.Hit> for rest: List<&2, K.Task> for none: {K.Absent{} == K.find(tree, K.beside(file)) : K.Look} - {K.visit.put(K.Going{}, tree, sc, text, file, ns, eb, seen, out, rest) + {K.visit.put(K.Going{}, tree, K.Opened{file, ns, text, sc}, eb, seen, out, rest) == K.State{file <> seen, K.Hit{K.raw_of(ns, eb), text} <> List.append(&2, K.Hit, K.foreigns(tree, Path.dir(file), K.nsdir(ns), K.scan.foreign(sc)), out), diff --git a/proofs/LicenseAsked.bend b/proofs/LicenseAsked.bend index f1be794..12183b0 100644 --- a/proofs/LicenseAsked.bend +++ b/proofs/LicenseAsked.bend @@ -8,7 +8,7 @@ def Laws.license_asked(tree, text, file, ns, eb, seen, out, rest, unasked): %unasked : {K.visit.put(K.asked(_, K.beside(file), _u => K.named.check(K.unnamed(K.scan.mods(K.scan(text))), _v => K.foreign.check(tree, Path.dir(file), K.nsdir(ns), K.scan.foreign(K.scan(text))))), - tree, K.scan(text), text, file, ns, eb, seen, out, rest) + tree, K.Opened{file, ns, text, K.scan(text)}, eb, seen, out, rest) == K.State{seen, out, K.Asking{K.beside(file)}, K.Task{file, ns} <> rest} : K.State} {==} diff --git a/proofs/NamedImportIsHubDependency.bend b/proofs/NamedImportIsHubDependency.bend index 4745c2b..441f39a 100644 --- a/proofs/NamedImportIsHubDependency.bend +++ b/proofs/NamedImportIsHubDependency.bend @@ -44,7 +44,7 @@ law unnamed_at: {K.visit.put(K.asked(l, K.beside(file), _u => K.named.check(K.unnamed(K.scan.mods(K.scan(text))), _v => K.foreign.check(tree, Path.dir(file), K.nsdir(ns), K.scan.foreign(K.scan(text))))), - tree, K.scan(text), text, file, ns, eb, seen, out, rest) + tree, K.Opened{file, ns, text, K.scan(text)}, eb, seen, out, rest) == K.State{seen, out, K.Unnamed{K.unnamed(K.scan.mods(K.scan(text)))}, K.Task{file, ns} <> rest} : K.State} @@ -53,20 +53,20 @@ def unnamed_at(l, tree, text, file, ns, eb, seen, out, rest, g, n): case K.Here{_x}: %n : {K.visit.put(K.named.check.at(_, K.unnamed(K.scan.mods(K.scan(text))), _v => K.foreign.check(tree, Path.dir(file), K.nsdir(ns), K.scan.foreign(K.scan(text)))), - tree, K.scan(text), text, file, ns, eb, seen, out, rest) + tree, K.Opened{file, ns, text, K.scan(text)}, eb, seen, out, rest) == K.State{seen, out, K.Unnamed{K.unnamed(K.scan.mods(K.scan(text)))}, K.Task{file, ns} <> rest} : K.State} {==} case K.Absent{}: %n : {K.visit.put(K.named.check.at(_, K.unnamed(K.scan.mods(K.scan(text))), _v => K.foreign.check(tree, Path.dir(file), K.nsdir(ns), K.scan.foreign(K.scan(text)))), - tree, K.scan(text), text, file, ns, eb, seen, out, rest) + tree, K.Opened{file, ns, text, K.scan(text)}, eb, seen, out, rest) == K.State{seen, out, K.Unnamed{K.unnamed(K.scan.mods(K.scan(text)))}, K.Task{file, ns} <> rest} : K.State} {==} case K.Unasked{}: - Eq.bit.absurd2(&2, {K.visit.put(K.Asking{K.beside(file)}, tree, K.scan(text), text, file, ns, - eb, seen, out, rest) + Eq.bit.absurd2(&2, {K.visit.put(K.Asking{K.beside(file)}, + tree, K.Opened{file, ns, text, K.scan(text)}, eb, seen, out, rest) == K.State{seen, out, K.Unnamed{K.unnamed(K.scan.mods(K.scan(text)))}, K.Task{file, ns} <> rest} : K.State}, g) diff --git a/proofs/lemmas/DistinctWalkSteps.bend b/proofs/lemmas/DistinctWalkSteps.bend index fd35eab..f731e8f 100644 --- a/proofs/lemmas/DistinctWalkSteps.bend +++ b/proofs/lemmas/DistinctWalkSteps.bend @@ -119,8 +119,8 @@ law pick_distinct: for bad: String for e: {D1.packs.distinct(packs) == True{} : Bool} for hs: {Bool.or(L.has(packs, hash), L.seen.holds(asks, hash)) == seen : Bool} - {D1.packs.distinct(P.walk.packs(P.step.pick(seen, orgs, ns, js, hash, rest, packs, - asks, bad))) == True{} : Bool} + {D1.packs.distinct(P.walk.packs(P.step.pick(seen, orgs, ns, js, hash, + P.Walk{rest, packs, asks, bad}))) == True{} : Bool} def pick_distinct(ns, seen, orgs, js, hash, rest, packs, asks, bad, e, hs): match seen: diff --git a/proofs/lemmas/LockPlannerFacts.bend b/proofs/lemmas/LockPlannerFacts.bend index 10a7437..2815650 100644 --- a/proofs/lemmas/LockPlannerFacts.bend +++ b/proofs/lemmas/LockPlannerFacts.bend @@ -987,9 +987,9 @@ law pick_pins: for asks: List<&2, String> for bad: String for e: {D1.pinned.all(orgs, packs) == packs : List<&2, L.Pack>} - {D1.pinned.all(orgs, P.walk.packs(P.step.pick(seen, orgs, ns, js, hash, rest, - packs, asks, bad))) - == P.walk.packs(P.step.pick(seen, orgs, ns, js, hash, rest, packs, asks, bad)) + {D1.pinned.all(orgs, P.walk.packs(P.step.pick(seen, orgs, ns, js, hash, + P.Walk{rest, packs, asks, bad}))) + == P.walk.packs(P.step.pick(seen, orgs, ns, js, hash, P.Walk{rest, packs, asks, bad})) : List<&2, L.Pack>} def pick_pins(ns, seen, orgs, js, hash, rest, packs, asks, bad, e): @@ -1501,7 +1501,7 @@ law mv.fine_hub: for +man: String for srcs: List<&2, String> for +br: String - {mv.fine(Up.dep.hub(hb, M.Dep{hn, hh, he, src}, hash, r, root2, nar2, man, srcs, br), hn) + {mv.fine(Up.dep.hub(hb, M.Dep{hn, hh, he, src}, hash, Up.Moved{r, root2, nar2, man, srcs}, br), hn) == (hn, True{}) : String & Bool} def mv.fine_hub(hb, _hn, _hh, _he, src, _hash, _r, _root2, _nar2, _man, _srcs, _br): @@ -2167,12 +2167,12 @@ law a.hub: for ea: {U.aim(True{}, M.Git{url, r0, tg, rt0, nr0, vd}) == am : U.Aim} for et: {up.tip(am, rs, url) == Up.At{tip, tag, br} : Up.Tip} for eco: {Up.checkout(rs, Up.Tree{url, tip, he}) == Up.Co{nar1, root1, man1, srcs1} : Up.Co} - {again(Up.dep.hub(hb, M.Dep{hn, hh, he, M.Git{url, r0, tg, rt0, nr0, vd}}, Up.hash.of(man1), tip, root1, nar1, man1, - srcs1, br), g, rs, only, hub) - == M1.still(Up.dep.hub(hb, M.Dep{hn, hh, he, M.Git{url, r0, tg, rt0, nr0, vd}}, Up.hash.of(man1), tip, root1, nar1, - man1, srcs1, br), - fsays(again(Up.dep.hub(hb, M.Dep{hn, hh, he, M.Git{url, r0, tg, rt0, nr0, vd}}, Up.hash.of(man1), tip, root1, - nar1, man1, srcs1, br), g, rs, only, hub))) : Up.Fate} + {again(Up.dep.hub(hb, M.Dep{hn, hh, he, M.Git{url, r0, tg, rt0, nr0, vd}}, Up.hash.of(man1), + Up.Moved{tip, root1, nar1, man1, srcs1}, br), g, rs, only, hub) + == M1.still(Up.dep.hub(hb, M.Dep{hn, hh, he, M.Git{url, r0, tg, rt0, nr0, vd}}, Up.hash.of(man1), + Up.Moved{tip, root1, nar1, man1, srcs1}, br), + fsays(again(Up.dep.hub(hb, M.Dep{hn, hh, he, M.Git{url, r0, tg, rt0, nr0, vd}}, Up.hash.of(man1), + Up.Moved{tip, root1, nar1, man1, srcs1}, br), g, rs, only, hub))) : Up.Fate} def a.hub( hb, @@ -2684,7 +2684,7 @@ law hub_back: for manifest: String for srcs: List<&2, String> for +branch: String - {M1.back(Up.dep.hub(hubbed, dep, hash, rev, root, nar, manifest, srcs, branch), dep) == dep : M.Dep} + {M1.back(Up.dep.hub(hubbed, dep, hash, Up.Moved{rev, root, nar, manifest, srcs}, branch), dep) == dep : M.Dep} def hub_back(hubbed, dep, hash, rev, root, nar, manifest, srcs, branch): match hubbed: diff --git a/proofs/lemmas/UpgradeKeeps.bend b/proofs/lemmas/UpgradeKeeps.bend index 7957819..e76bc02 100644 --- a/proofs/lemmas/UpgradeKeeps.bend +++ b/proofs/lemmas/UpgradeKeeps.bend @@ -86,7 +86,7 @@ law st.hub: for +man: String for srcs: List<&2, String> for +br: String - st.fate(Up.dep.hub(hb, M.Dep{hn, hh, he, src}, hash, r, root2, nar2, man, srcs, br), + st.fate(Up.dep.hub(hb, M.Dep{hn, hh, he, src}, hash, Up.Moved{r, root2, nar2, man, srcs}, br), M.Dep{hn, hh, he, src}) def st.hub(hb, _hn, _hh, _he, src, _hash, _r, _root2, _nar2, _man, _srcs, _br): diff --git a/proofs/lemmas/UpgradeKeepsNames.bend b/proofs/lemmas/UpgradeKeepsNames.bend index de2fe17..d87c8eb 100644 --- a/proofs/lemmas/UpgradeKeepsNames.bend +++ b/proofs/lemmas/UpgradeKeepsNames.bend @@ -63,7 +63,7 @@ law hub_name: for manifest: String for srcs: List<&2, String> for +branch: String - {fate.name(Up.dep.hub(hubbed, dep, hash, rev, root, nar, manifest, srcs, branch), M.dep.name(dep)) + {fate.name(Up.dep.hub(hubbed, dep, hash, Up.Moved{rev, root, nar, manifest, srcs}, branch), M.dep.name(dep)) == M.dep.name(dep) : String} def hub_name(hubbed, dep, hash, rev, root, nar, manifest, srcs, branch): diff --git a/proofs/lemmas/UpgradeMoves.bend b/proofs/lemmas/UpgradeMoves.bend index d874363..474e3bf 100644 --- a/proofs/lemmas/UpgradeMoves.bend +++ b/proofs/lemmas/UpgradeMoves.bend @@ -148,8 +148,9 @@ law mv.ok_hub: for +man: String for srcs: List<&2, String> for e: {Up.onward(rs, Up.Above{url, rev, r}) == Up.Asc{True{}} : Up.Asc} - {mv.ok(Up.dep.hub(hb, mv.git(hn, hh, he, url, rev, tag, root, nar, vend), hash, r, root2, - nar2, man, srcs, br), Up.At{r, tg, br}, rs, mv.git(hn, hh, he, url, rev, tag, root, nar, vend)) + {mv.ok(Up.dep.hub(hb, mv.git(hn, hh, he, url, rev, tag, root, nar, vend), hash, + Up.Moved{r, root2, nar2, man, srcs}, br), Up.At{r, tg, br}, rs, + mv.git(hn, hh, he, url, rev, tag, root, nar, vend)) == True{} : Bool} def mv.ok_hub( @@ -1192,8 +1193,9 @@ law mv.live_hub: for +nar2: String for +man: String for srcs: List<&2, String> - {mv.live(Up.dep.hub(hb, mv.git(hn, hh, he, url, rev, tag, root, nar, vend), hash, tip, root2, - nar2, man, srcs, br), tip, mv.git(hn, hh, he, url, rev, tag, root, nar, vend)) == True{} : Bool} + {mv.live(Up.dep.hub(hb, mv.git(hn, hh, he, url, rev, tag, root, nar, vend), hash, + Up.Moved{tip, root2, nar2, man, srcs}, br), tip, + mv.git(hn, hh, he, url, rev, tag, root, nar, vend)) == True{} : Bool} def mv.live_hub( hb, diff --git a/src/add/run.bend b/src/add/run.bend index 1ab0f39..4ddb82f 100644 --- a/src/add/run.bend +++ b/src/add/run.bend @@ -63,7 +63,7 @@ def loop.step(st: AR.Next, +lib: String, world: AR.World, go: AR.World -> IO(Uni # import graph, as `ez lock` does (`Run.rounds`). This is only a guard against # a planner that keeps asking, and running out of it dies loudly. def rounds() -> Nat: - U32.to_nat(100000) + 100000n # the loop, under fuel. Every round adds an answer, since the planner never # asks what the World answers already, so the fuel is only a guard. diff --git a/src/check/framing.bend b/src/check/framing.bend index b5934e3..b51ab0a 100644 --- a/src/check/framing.bend +++ b/src/check/framing.bend @@ -160,7 +160,7 @@ def loop.on(state: Run, rest: Listener -> IO(Unit)) -> IO(Unit): # Bend has no unbounded loop, so "forever" is a count no test run will reach, a # thousand runs of a thousand connections; a server has no input to size it by. def thousand() -> Nat: - U32.to_nat(1000) + 1000n # connections served for as long as the fuel lasts. Bend has no unbounded loop, # so "forever" is a count no test run will reach: a thousand runs of a thousand diff --git a/src/check/kit.bend b/src/check/kit.bend index 26abbb2..f7cbd27 100644 --- a/src/check/kit.bend +++ b/src/check/kit.bend @@ -13,7 +13,3 @@ def say(ok: Bool, name: String, got: String, want: String) -> IO(Unit): # passes when two strings are equal def eq_str(name: String, +got: String, +want: String) -> IO(Unit): say(String.eq(got, want), name, got, want) - -# passes when two U32 are equal -def eq_u32(name: String, got: U32, want: U32) -> IO(Unit): - eq_str(name, U32.show(got), U32.show(want)) diff --git a/src/check/oracle.bend b/src/check/oracle.bend index f19c258..4c02722 100644 --- a/src/check/oracle.bend +++ b/src/check/oracle.bend @@ -692,7 +692,7 @@ def loop.on(state: Run, dir: String, rest: String -> Listener -> IO(Unit)) -> IO # Bend has no unbounded loop, so "forever" is a count no test run will reach, a # thousand runs of a thousand connections; a server has no input to size it by. def thousand() -> Nat: - U32.to_nat(1000) + 1000n # connections served for as long as the fuel lasts. Bend has no unbounded loop, # so "forever" is a count no test run will reach: a thousand runs of a thousand diff --git a/src/check/serve.bend b/src/check/serve.bend index 7a42c52..bf0576e 100644 --- a/src/check/serve.bend +++ b/src/check/serve.bend @@ -111,19 +111,6 @@ def clen(hs: List<&2, String>) -> U32: case h <> t: clen.at(h, clen(t)) -# whether a request has arrived whole -def complete.of(message: Msg) -> Bool: - match message: - case MPartial{}: - False{} - case MFull{head, body}: - U32.is_ge(size(body), clen(head)) - -# whether what has been read so far is the whole request: its head has ended and -# its body is as long as the head said it would be -def complete(text: String) -> Bool: - complete.of(msg.of(text)) - # an answer's bytes, framed by its length. Every one of them states that length # and says the connection closes, because bend, curl and nix's fetcher all read # a body to the length they were promised and then expect the socket to shut. @@ -187,85 +174,135 @@ def pieces(sock: Socket, width: Nat, +text: String) -> IO(Unit): sock2 : Socket <- piece.go(String.length(text), width, sock, text) Socket.close(sock2) +# what has been read so far, the chunks newest first, put back in order +def recv.text(parts: List<&2, String>) -> String: + String.concat(List.reverse(&2, String, parts)) + # an empty chunk means the client stopped writing, whole request or not -def recv.chunk( - chunk: String, - sock: Socket, - acc: String, - rest: Socket -> String -> IO(Socket & String) -) -> IO(Socket & String): - match chunk: +def recv.chunk(text: String) -> Maybe<&1, String>: + match text: case SNil{}: - IO.pure(Socket & String, (sock, acc)) + None{} case SCon{c, t}: - rest(sock, acc ++ SCon{c, t}) + Some{SCon{c, t}} -# None is the peer done sending. Some is the bytes, and an empty chunk is -# the same end. -def recv.taken( - chunk: Maybe<&1, String>, - sock: Socket, - acc: String, - rest: Socket -> String -> IO(Socket & String) -) -> IO(Socket & String): - match chunk: - case None{}: - recv.chunk("", sock, acc, rest) - case Some{text}: - recv.chunk(text, sock, acc, rest) - -# a failed read ends the request as surely as a closed peer -def recv.got( - received: Result<&1, &1, U32 & String, Maybe<&1, String>>, - sock: Socket, - acc: String, - rest: Socket -> String -> IO(Socket & String) -) -> IO(Socket & String): +# what one read gave: a chunk, or None when the peer is done sending, the +# read failed or the chunk was empty, all of which end the request +def recv.got(received: Result<&1, &1, U32 & String, Maybe<&1, String>>) -> Maybe<&1, String>: match received: case Fail{_e}: - IO.pure(Socket & String, (sock, acc)) + None{} case Done{chunk}: - recv.taken(chunk, sock, acc, rest) + Maybe.bind(&1, String, String, chunk, recv.chunk) # the socket comes back paired with what it read -def recv.next( - got: Socket & Result<&1, &1, U32 & String, Maybe<&1, String>>, - acc: String, - rest: Socket -> String -> IO(Socket & String) -) -> IO(Socket & String): +def recv.one.of( + got: Socket & Result<&1, &1, U32 & String, Maybe<&1, String>> +) -> IO(Socket & Maybe<&1, String>): (sock, r) = got - recv.got(r, sock, acc, rest) + IO.pure(Socket & Maybe<&1, String>, (sock, recv.got(r))) + +# one read off the socket, and the socket back +def recv.one(sock: Socket) -> IO(Socket & Maybe<&1, String>): + do IO>: + got : Socket & Result<&1, &1, U32 & String, Maybe<&1, String>> <- TCP.recv(sock, 65536) + recv.one.of(got) + +# a chunk taken into the parts and the walk gone on, or the request as it +# stands once the reads have ended +def recv.then( + read: Socket & Maybe<&1, String>, + parts: List<&2, String>, + rest: Socket -> String -> List<&2, String> -> IO(Socket & String) +) -> IO(Socket & String): + (sock, chunk) = read + match chunk: + case None{}: + IO.pure(Socket & String, (sock, recv.text(parts))) + case Some{+text}: + rest(sock, text, text <> parts) -# nothing more is asked for once the whole request is in hand +# a request that is whole is done; one that is not reads one more chunk and +# goes on with it def recv.more( done: Bool, sock: Socket, - acc: String, - rest: Socket -> String -> IO(Socket & String) + parts: List<&2, String>, + rest: Socket -> String -> List<&2, String> -> IO(Socket & String) ) -> IO(Socket & String): match done: case True{}: - IO.pure(Socket & String, (sock, acc)) + IO.pure(Socket & String, (sock, recv.text(parts))) case False{}: do IO: - got : Socket & Result<&1, &1, U32 & String, Maybe<&1, String>> <- TCP.recv(sock, 65536) - recv.next(got, acc, rest) + read : Socket & Maybe<&1, String> <- recv.one(sock) + recv.then(read, parts, rest) + +# the body, once the head is settled: each chunk is counted as it comes, so +# the request is put together once, when the body is as long as `need` +def recv.body( + fuel: Nat, + sock: Socket, + parts: List<&2, String>, + +have: U32, + +need: U32 +) -> IO(Socket & String): + match fuel: + case 0n: + IO.pure(Socket & String, (sock, recv.text(parts))) + case 1n+f: + recv.more(U32.is_ge(have, need), sock, parts, + s => c => ps => recv.body(f, s, ps, U32.add(have, size(c)), need)) + +# a head that has ended. While nothing of the body has come, the next chunk +# may still move where the head ends, so the head is looked at again. Once a +# byte of the body has come, the head is settled and every later chunk is +# body, so the body goes on by count. +def recv.head.full( + empty: Bool, + +have: U32, + +need: U32, + fuel: Nat, + sock: Socket, + parts: List<&2, String>, + again: Socket -> String -> List<&2, String> -> IO(Socket & String) +) -> IO(Socket & String): + match empty: + case True{}: + recv.more(U32.is_ge(have, need), sock, parts, again) + case False{}: + recv.more(U32.is_ge(have, need), sock, parts, + s => c => ps => recv.body(fuel, s, ps, U32.add(have, size(c)), need)) + +# the head not yet whole: one more chunk read. Whole: on to the body +def recv.head.at( + message: Msg, + fuel: Nat, + sock: Socket, + parts: List<&2, String>, + again: Socket -> String -> List<&2, String> -> IO(Socket & String) +) -> IO(Socket & String): + match message: + case MPartial{}: + recv.more(False{}, sock, parts, again) + case MFull{head, +body}: + recv.head.full(String.is_empty(body), size(body), clen(head), fuel, sock, parts, again) # a whole request read off a socket, one chunk at a time until the head has # ended and the body is as long as Content-Length promised -def recv.go(fuel: Nat, sock: Socket, +acc: String) -> IO(Socket & String): +def recv.head(fuel: Nat, sock: Socket, +parts: List<&2, String>) -> IO(Socket & String): match fuel: case 0n: - IO.pure(Socket & String, (sock, acc)) - case 1n+f: - recv.more(complete(acc), sock, acc, s => a => recv.go(f, s, a)) + IO.pure(Socket & String, (sock, recv.text(parts))) + case 1n+(+f): + recv.head.at(msg.of(recv.text(parts)), f, sock, parts, s => _c => ps => recv.head(f, s, ps)) # the reads a request may take, 64 KiB at most each: 256 MiB, past any request # a test sends. How long a request is is not known until its head has arrived, # so the reads cannot be counted up front. def reads() -> Nat: - U32.to_nat(4096) + 4096n # a whole request read off a socket, and the socket it came on def request(sock: Socket) -> IO(Socket & String): - recv.go(reads(), sock, "") + recv.head(reads(), sock, []) diff --git a/src/doctor/run.bend b/src/doctor/run.bend index 5c68a8c..83d48ee 100644 --- a/src/doctor/run.bend +++ b/src/doctor/run.bend @@ -112,7 +112,7 @@ def loop.step(st: DP.Step, +lib: String, world: DW.World, go: DW.World -> IO(Uni # has answered, so this is a guard against a planner that keeps asking, not # a limit on a project: running out of it dies loudly. def rounds() -> Nat: - U32.to_nat(100000) + 100000n # the loop, under fuel. Every round adds at least one answer, since the # planner never asks what the World answers already, and the lock check asks diff --git a/src/ez/app.bend b/src/ez/app.bend index 1b37839..d20773b 100644 --- a/src/ez/app.bend +++ b/src/ez/app.bend @@ -30,6 +30,20 @@ import ../io/file.bend as F import ../ez/line.bend as L import ../ws/run.bend as WsRun +# `ez add`: the target, ref, entry and rename the line bound, in the member +def dispatch.add(+matched: Shake.Matched) -> IO(Unit): + +target = L.get(matched, "target") + +ref = L.get(matched, "ref") + +entry = L.get(matched, "entry") + +rename = L.get(matched, "rename") + WsRun.in.member(_u => Cmd.add(target, ref, entry, rename)) + +# `ez lock`: `--upgrade` and the package it is limited to, at the root +def dispatch.lock(+matched: Shake.Matched) -> IO(Unit): + +up = Shake.on(matched, "upgrade") + +only = L.get(matched, "package") + WsRun.at.root(_u => Cmd.lock(up, only)) + # what a subcommand runs. `L.line` never runs `CHelp`, which names no # command; it is here so the match is whole, and it writes the help a bare # `ez` would. The directories `ez check` and `ez build` write into are made @@ -41,18 +55,12 @@ def dispatch(sub: L.Sub, +matched: Shake.Matched, +as: List<&2, String>) -> IO(U Cmd.init(L.get(matched, "name"), L.get(matched, "entry"), L.get(matched, "description")) case L.CAdd{}: - +target = L.get(matched, "target") - +ref = L.get(matched, "ref") - +entry = L.get(matched, "entry") - +rename = L.get(matched, "rename") - WsRun.in.member(_u => Cmd.add(target, ref, entry, rename)) + dispatch.add(matched) case L.CRemove{}: +name = L.get(matched, "name") WsRun.in.member(_u => Cmd.remove(name)) case L.CLock{}: - +up = Shake.on(matched, "upgrade") - +only = L.get(matched, "package") - WsRun.at.root(_u => Cmd.lock(up, only)) + dispatch.lock(matched) case L.CFetch{}: WsRun.at.root(_u => Cmd.fetch()) case L.CCheck{}: diff --git a/src/ez/line.bend b/src/ez/line.bend index 7761b90..ef74730 100644 --- a/src/ez/line.bend +++ b/src/ez/line.bend @@ -43,39 +43,71 @@ type Sub is Data: CToolUpgrade{} CHelp{} +# `ez init`: a name, an entry and the one-line description +def spec.init() -> Shake.Sub: + Shake.sub("init", "scaffold a project: ez.toml, ignore, entry, src/", + [ + Shake.pos("name", "package name", False{}, None{}, []), + Shake.pos("entry", "entry file", False{}, None{}, []), + Shake.opt("description", None{}, Some{"description"}, + "one line: the entry's first line, which the hub shows", False{}, None{}, []) + ], []) + +# `ez add`: a target, its ref and entry, and the name to record it under +def spec.add() -> Shake.Sub: + Shake.sub("add", "record a git or hub package", + [ + Shake.pos("target", "owner/repo, git url, path, or name@version", True{}, None{}, + []), + Shake.pos("ref", "commit, tag or branch", False{}, None{}, []), + Shake.pos("entry", "entry file", False{}, None{}, []), + Shake.opt("rename", None{}, Some{"rename"}, + "record it under this name, ahead of its own (a TOML bare key)", + False{}, None{}, []) + ], []) + +# `ez lock`: `--upgrade` and the one package it may be limited to +def spec.lock() -> Shake.Sub: + Shake.sub("lock", "resolve every import, write ez.lock.toml", + [ + Shake.flag("upgrade", None{}, Some{"upgrade"}, + "re-pin git deps and tools that moved, then write the lock"), + Shake.opt("package", None{}, Some{"package"}, + "with --upgrade, only this dependency or tool", False{}, None{}, []) + ], []) + +# a `tool` subcommand that names a target and may name the entry to build +def spec.tool.target(+name: String, +about: String) -> Shake.Sub: + Shake.sub(name, about, + [ + Shake.pos("target", "owner/repo, git url, path, or name@version", True{}, None{}, + []), + Shake.opt("entry", None{}, Some{"entry"}, + "build this file of the checkout, not the one it names", False{}, None{}, []) + ], []) + +# `ez tool`: the group, with `sync` and the three that take a target +def spec.tool() -> Shake.Sub: + Shake.sub("tool", "build or run another project's binary", [], [ + Shake.sub("sync", "build and link every pinned tool at its lock rev", + [], []), + spec.tool.target("run", "fetch, build and run the binary a repo declares"), + spec.tool.target("install", "build the binary and link it on PATH"), + spec.tool.target("upgrade", "rebuild when the commit moved, and refresh the link") + ]) + # the program: every command, and the flags and positionals it binds def spec() -> Shake.Cli: Shake.app("ez", "dependency tracking and builds for Bend 2", None{}, [], [ - Shake.sub("init", "scaffold a project: ez.toml, ignore, entry, src/", - [ - Shake.pos("name", "package name", False{}, None{}, []), - Shake.pos("entry", "entry file", False{}, None{}, []), - Shake.opt("description", None{}, Some{"description"}, - "one line: the entry's first line, which the hub shows", False{}, None{}, []) - ], []), - Shake.sub("add", "record a git or hub package", - [ - Shake.pos("target", "owner/repo, git url, path, or name@version", True{}, None{}, - []), - Shake.pos("ref", "commit, tag or branch", False{}, None{}, []), - Shake.pos("entry", "entry file", False{}, None{}, []), - Shake.opt("rename", None{}, Some{"rename"}, - "record it under this name, ahead of its own (a TOML bare key)", - False{}, None{}, []) - ], []), + spec.init(), + spec.add(), Shake.sub("remove", "drop a package from the ledger", [ Shake.pos("name", "package name", True{}, None{}, []) ], []), - Shake.sub("lock", "resolve every import, write ez.lock.toml", - [ - Shake.flag("upgrade", None{}, Some{"upgrade"}, - "re-pin git deps and tools that moved, then write the lock"), - Shake.opt("package", None{}, Some{"package"}, - "with --upgrade, only this dependency or tool", False{}, None{}, []) - ], []), + spec.lock(), Shake.sub("fetch", "fill BEND_LIB from the lock", [], []), Shake.sub("check", "check the entry, without running it", [], []), Shake.sub("build", "build the entry to a native binary", @@ -83,31 +115,7 @@ def spec() -> Shake.Cli: Shake.pos("out", "output path", False{}, None{}, []) ], []), Shake.sub("run", "check and run the entry", [], []), - Shake.sub("tool", "build or run another project's binary", [], [ - Shake.sub("sync", "build and link every pinned tool at its lock rev", - [], []), - Shake.sub("run", "fetch, build and run the binary a repo declares", - [ - Shake.pos("target", "owner/repo, git url, path, or name@version", True{}, None{}, - []), - Shake.opt("entry", None{}, Some{"entry"}, - "build this file of the checkout, not the one it names", False{}, None{}, []) - ], []), - Shake.sub("install", "build the binary and link it on PATH", - [ - Shake.pos("target", "owner/repo, git url, path, or name@version", True{}, None{}, - []), - Shake.opt("entry", None{}, Some{"entry"}, - "build this file of the checkout, not the one it names", False{}, None{}, []) - ], []), - Shake.sub("upgrade", "rebuild when the commit moved, and refresh the link", - [ - Shake.pos("target", "owner/repo, git url, path, or name@version", True{}, None{}, - []), - Shake.opt("entry", None{}, Some{"entry"}, - "build this file of the checkout, not the one it names", False{}, None{}, []) - ], []) - ]), + spec.tool(), Shake.sub("publish", "send the entry to the hub, under ez's 0x name", [], []), Shake.sub("test", "run every */tests/*.bend against its trailer", [], []), diff --git a/src/fetch/run.bend b/src/fetch/run.bend index b98f45c..4dd85e9 100644 --- a/src/fetch/run.bend +++ b/src/fetch/run.bend @@ -95,7 +95,7 @@ def loop.step(st: FP.Step, +lib: String, world: FW.World, go: FW.World -> IO(Uni # once, so this is only a guard against a planner that keeps asking, and # running out of it dies loudly. def rounds() -> Nat: - U32.to_nat(10) + 10n # the loop, under fuel. A package asks at most twice, for its tree under # BEND_LIB and for its fetch, and every round answers what it asked, so the diff --git a/src/fetch/world.bend b/src/fetch/world.bend index f67ed98..5575afc 100644 --- a/src/fetch/world.bend +++ b/src/fetch/world.bend @@ -25,7 +25,6 @@ # them itself. import Base import ../toml/toml.bend as T -import ../lock/lock.bend as L import ../lock/world.bend as W import ../lock/up.bend as Up diff --git a/src/io/file.bend b/src/io/file.bend index be87689..c7798a6 100644 --- a/src/io/file.bend +++ b/src/io/file.bend @@ -2,26 +2,32 @@ # and chunked reads; this is the loop over them. import Base -# the handle closed, and whatever was gathered -def slurp.end(file: File, acc: String) -> IO(String): +# the handle closed, and whatever was gathered. The chunks are gathered +# newest first, so each read is one prepend, and put in order once here. +def slurp.end(file: File, acc: List<&2, String>) -> IO(String): do IO: File.close(file) - return acc + return String.concat(List.reverse(&2, String, acc)) # an empty chunk means the end of the file -def slurp.cut(chunk: String, file: File, acc: String, rest: File -> String -> IO(String)) -> IO(String): +def slurp.cut( + chunk: String, + file: File, + acc: List<&2, String>, + rest: File -> List<&2, String> -> IO(String) +) -> IO(String): match chunk: case SNil{}: slurp.end(file, acc) case SCon{c, t}: - rest(file, acc ++ SCon{c, t}) + rest(file, SCon{c, t} <> acc) # a failed read ends the file as surely as an empty one def slurp.more( res: Result<&1, &1, U32 & String, String>, file: File, - acc: String, - rest: File -> String -> IO(String) + acc: List<&2, String>, + rest: File -> List<&2, String> -> IO(String) ) -> IO(String): match res: case Fail{_e}: @@ -32,14 +38,14 @@ def slurp.more( # the handle comes back paired with what it read def slurp.next( got: File & Result<&1, &1, U32 & String, String>, - acc: String, - rest: File -> String -> IO(String) + acc: List<&2, String>, + rest: File -> List<&2, String> -> IO(String) ) -> IO(String): (file, r) = got slurp.more(r, file, acc, rest) # the whole file, read in chunks until one is empty, or the fuel is -def slurp(fuel: Nat, file: File, acc: String) -> IO(String): +def slurp(fuel: Nat, file: File, acc: List<&2, String>) -> IO(String): match fuel: case 0n: slurp.end(file, acc) @@ -52,7 +58,7 @@ def slurp(fuel: Nat, file: File, acc: String) -> IO(String): # /proc file reports 0 bytes and a file past 4 GiB fails to report, so these # are read until they end, up to 100000 reads of 64 KiB, past any file ez reads def unsized() -> Nat: - U32.to_nat(100000) + 100000n # a size of 0 is no size to go by; any other is read to def reads.given(none: Bool, bytes: U32) -> Nat: @@ -78,7 +84,7 @@ def reads.of(res: Result<&1, &1, U32 & String, U32>) -> Nat: # a file read whole, with fuel enough for the size it reported def read.sized(got: File & Result<&1, &1, U32 & String, U32>) -> IO(String): (file, r) = got - slurp(reads.of(r), file, "") + slurp(reads.of(r), file, []) # what an opened file holds, or nothing when it would not open def read.opened(res: Result<&1, &1, U32 & String, File>) -> IO(Maybe<&2, String>): diff --git a/src/lock/plan.bend b/src/lock/plan.bend index ef7f944..812f4de 100644 --- a/src/lock/plan.bend +++ b/src/lock/plan.bend @@ -113,22 +113,21 @@ def step.look( case Found{v}: step.verdict(v, ns, src, hash, rest, packs, asks, bad) -# a hash already resolved, or already asked about, is passed over +# a hash already resolved, or already asked about, is passed over. `wk` is +# the walk with the hash popped off its queue. def step.pick( seen: Bool, +orgs: List<&2, L.Origin>, +ns: List<&2, L.Name>, +js: List<&2, W.Judged>, +hash: String, - rest: List<&2, String>, - packs: List<&2, L.Pack>, - asks: List<&2, String>, - bad: String + wk: Walk ) -> Walk: match seen: case True{}: - Walk{rest, packs, asks, bad} + wk case False{}: + Walk{rest, packs, asks, bad} = wk step.look(look(js, hash), ns, L.origin(orgs, hash), hash, rest, packs, asks, bad) # the next hash of the queue, or the walk as it is when the queue is empty @@ -145,8 +144,8 @@ def step.pop( case []: Walk{[], packs, asks, bad} case +h <> t: - step.pick(Bool.or(L.has(packs, h), L.seen.holds(asks, h)), orgs, ns, js, h, t, - packs, asks, bad) + step.pick(Bool.or(L.has(packs, h), L.seen.holds(asks, h)), orgs, ns, js, h, + Walk{t, packs, asks, bad}) # one step of the walk def walk.step(+orgs: List<&2, L.Origin>, +ns: List<&2, L.Name>, +js: List<&2, W.Judged>, wk: Walk) -> Walk: diff --git a/src/lock/run.bend b/src/lock/run.bend index ee1795a..48e2f57 100644 --- a/src/lock/run.bend +++ b/src/lock/run.bend @@ -691,7 +691,7 @@ def loop.step(st: Plan.Step, +lib: String, back: WsUp.Back, world: W.World, go: # it dies loudly. The walk inside each round takes its fuel from its inputs # (`Plan.walk.fuel`). def rounds() -> Nat: - U32.to_nat(100000) + 100000n # the loop, under fuel. Every round adds at least one answer, since the # planner never asks what the World answers already. diff --git a/src/lock/up.bend b/src/lock/up.bend index e249723..952ed81 100644 --- a/src/lock/up.bend +++ b/src/lock/up.bend @@ -648,20 +648,16 @@ def dep.moved( line.if(Bool.not(String.is_empty(drop)), name ++ ": vendored .ez/lib/" ++ hash)), [Laid{hash, nar, manifest, srcs}]} +# the checkout a moved pin lands on: the rev it advances to, and the root, +# NAR hash, manifest and sources the checkout at that rev has +type Moved is Data: + Moved{rev: String, root: String, nar: String, manifest: String, srcs: List<&2, String>} + # the hub's word on the new hash -def dep.hub( - hubbed: Hubbed, - +dep: M.Dep, - +hash: String, - +rev: String, - +root: String, - +nar: String, - manifest: String, - srcs: List<&2, String>, - +branch: String -) -> Fate: +def dep.hub(hubbed: Hubbed, +dep: M.Dep, +hash: String, moved: Moved, +branch: String) -> Fate: match hubbed: case Clear{}: + Moved{rev, root, nar, manifest, srcs} = moved dep.moved(dep, hash, rev, root, nar, manifest, srcs, branch) case Clash{}: Halts{"ez: " ++ M.dep.name(dep) ++ ": hub digest does not match " ++ hash} @@ -676,7 +672,7 @@ def dep.advance(co: Co, +rs: List<&2, Reply>, +hub: String, +dep: M.Dep, +rev: S match co: case Co{nar, root, +manifest, srcs}: +hash = hash.of(manifest) - dep.hub(hubbed(rs, HubHas{hub, hash}), dep, hash, rev, root, nar, manifest, srcs, + dep.hub(hubbed(rs, HubHas{hub, hash}), dep, hash, Moved{rev, root, nar, manifest, srcs}, branch) case CoWait{ask}: Waits{[ask]} diff --git a/src/pkg/bench/scan.bend b/src/pkg/bench/scan.bend index 3076f5a..7907f10 100644 --- a/src/pkg/bench/scan.bend +++ b/src/pkg/bench/scan.bend @@ -160,7 +160,7 @@ def at(xs: List<&2, String>, index: Nat) -> String: def start(as: List<&2, String>) -> IO(Unit): match as: case Nil{}: - IO.print(run("new", U32.to_nat(200000))) + IO.print(run("new", 200000n)) case Con{h, t}: IO.print(run(h, U32.to_nat(Maybe.default(&2, U32, U32.read(at(t, 0n)), 200000)))) diff --git a/src/pkg/pkg.bend b/src/pkg/pkg.bend index 2d8a06d..ffe2c56 100644 --- a/src/pkg/pkg.bend +++ b/src/pkg/pkg.bend @@ -795,6 +795,11 @@ type Stop is Data: Spent{} Unnamed{nv: String} +# a file the walk opened: its path, the name it was reached through, its +# text and that text's scan +type Opened is Data: + Opened{file: String, ns: String, text: String, sc: Scan} + # the walk so far: the files already visited, what was found, whether it has # stopped, and the files still to visit type State is Data: @@ -959,6 +964,38 @@ def foreign.check(+tree: Tree, +dir: String, +nd: String, ats: List<&2, String>) foreign.judge(outside(at), tree, at, P.join(nd, h), _u => foreign.check(tree, dir, nd, t)) +# a file kept: itself, the LICENSE beside it and its foreign bodies found, +# and the modules it imports queued first +def visit.keep( + +tree: Tree, + opened: Opened, + eb: String, + seen: List<&2, String>, + out: List<&2, Hit>, + rest: List<&2, Task> +) -> State: + Opened{+file, +ns, text, +sc} = opened + +d = P.dir(file) + +nd = nsdir(ns) + +raw = raw_of(ns, eb) + State{file <> seen, + Hit{raw, text} <> List.append(&2, Hit, + license.put(find(tree, beside(file)), beside(raw)), + List.append(&2, Hit, foreigns(tree, d, nd, scan.foreign(sc)), out)), + Going{}, + List.append(&2, Task, tasks(d, nd, scan.mods(sc)), rest)} + +# a file whose walk stopped stays queued, to be visited again +def visit.halt( + stop: Stop, + opened: Opened, + seen: List<&2, String>, + out: List<&2, Hit>, + rest: List<&2, Task> +) -> State: + Opened{file, ns, _text, _sc} = opened + State{seen, out, stop, Task{file, ns} <> rest} + # a file whose LICENSE and foreign bodies are all settled: itself, the # LICENSE beside it and its foreign bodies found, and the modules it imports # put at the front of the queue, so the walk goes depth first the way bend's @@ -967,10 +1004,7 @@ def foreign.check(+tree: Tree, +dir: String, +nd: String, ats: List<&2, String>) def visit.put( fstop: Stop, +tree: Tree, - +sc: Scan, - +text: String, - +file: String, - +ns: String, + opened: Opened, eb: String, seen: List<&2, String>, out: List<&2, Hit>, @@ -978,25 +1012,17 @@ def visit.put( ) -> State: match fstop: case Going{}: - +d = P.dir(file) - +nd = nsdir(ns) - +raw = raw_of(ns, eb) - State{file <> seen, - Hit{raw, text} <> List.append(&2, Hit, - license.put(find(tree, beside(file)), beside(raw)), - List.append(&2, Hit, foreigns(tree, d, nd, scan.foreign(sc)), out)), - Going{}, - List.append(&2, Task, tasks(d, nd, scan.mods(sc)), rest)} + visit.keep(tree, opened, eb, seen, out, rest) case Missing{at}: - State{seen, out, Missing{at}, Task{file, ns} <> rest} + visit.halt(Missing{at}, opened, seen, out, rest) case Climbs{at}: - State{seen, out, Climbs{at}, Task{file, ns} <> rest} + visit.halt(Climbs{at}, opened, seen, out, rest) case Asking{at}: - State{seen, out, Asking{at}, Task{file, ns} <> rest} + visit.halt(Asking{at}, opened, seen, out, rest) case Spent{}: - State{seen, out, Spent{}, Task{file, ns} <> rest} + visit.halt(Spent{}, opened, seen, out, rest) case Unnamed{nv}: - State{seen, out, Unnamed{nv}, Task{file, ns} <> rest} + visit.halt(Unnamed{nv}, opened, seen, out, rest) # a file that imports a name the hub rules out stops the walk, naming it, as # bend refuses to load it; any other goes on to its foreign bodies @@ -1026,7 +1052,7 @@ def visit.found( visit.put(asked(find(tree, beside(file)), beside(file), _u => named.check(unnamed(scan.mods(sc)), _v => foreign.check(tree, P.dir(file), nsdir(ns), scan.foreign(sc)))), - tree, sc, text, file, ns, eb, seen, out, rest) + tree, Opened{file, ns, text, sc}, eb, seen, out, rest) # a module that is imported and not there stops the walk, since a package # missing a file is not the package bend would publish. One the walk was not @@ -1560,7 +1586,7 @@ def resumed.fuel(+tree: Tree, +st: State) -> Nat: # is a guard against a walk that keeps asking, not a limit on a package: a # package of more files than this is refused, never hashed short. def asks() -> Nat: - U32.to_nat(100000) + 100000n # the walk over what has been read so far, and each file it asks for read # and handed back, until it no longer asks diff --git a/src/pub/run.bend b/src/pub/run.bend index c13c95f..55f69d0 100644 --- a/src/pub/run.bend +++ b/src/pub/run.bend @@ -25,7 +25,6 @@ import ../io/file.bend as F import ../lock/run.bend as Run import ../tool/run.bend as ToolRun import ../tool/world.bend as TW -import ../hub/hub.bend as Web import ../hub/get.bend as Net import ../share/env.bend as Env import ./world.bend as PW @@ -94,7 +93,7 @@ def loop.step(st: PP.Step, +lib: String, world: PW.World, go: PW.World -> IO(Uni # against a planner that keeps asking, not a limit on a package: running out # of it dies loudly. def rounds() -> Nat: - U32.to_nat(100000) + 100000n # the loop, under fuel. The walk asks for one file a round, so the fuel is a # guard against a planner that keeps asking, not a limit on a package. diff --git a/src/share/cap.bend b/src/share/cap.bend index e0124c0..de62d32 100644 --- a/src/share/cap.bend +++ b/src/share/cap.bend @@ -9,7 +9,6 @@ import Base import snap@1.4.0.0/main.bend as R import ./env.bend as Env -import ./args.bend as Args # how many gigabytes one `bend` may have. 8 is what fits beside the rest of # this machine; a project whose closure costs more says so in EZ_CAP. diff --git a/src/share/say.bend b/src/share/say.bend index a629d87..46439e7 100644 --- a/src/share/say.bend +++ b/src/share/say.bend @@ -149,11 +149,6 @@ def drift(+name: String, +tag: String, +rev: String, +old: String, +new: String) old ++ " on the pin, " ++ new ++ " in the tree). `ez lock --upgrade` cannot fix a drifted pin. Update the dependency hash, re-add the package, or check the tag." -# a drift judged before the tree was weighed, so there are not two hashes to show -def stuck(+name: String) -> String: - "ez: " ++ name ++ - ": the pin drifted. `ez lock --upgrade` cannot fix a drifted pin. Update the dependency hash, re-add the package, or check the tag." - # a `[tools.` section in the ledger text. The parser is not asked: a ledger # that does not parse can still have named the command. def has.tools(+text: String) -> Bool: diff --git a/src/tool/run.bend b/src/tool/run.bend index 9383543..2d60722 100644 --- a/src/tool/run.bend +++ b/src/tool/run.bend @@ -68,7 +68,7 @@ def said.rev(ls: List<&2, String>) -> String: # a line that is an absolute path, as `rev-parse --show-toplevel` prints one def line.abs(+line: String) -> Bool: - String.eq(String.take(line, 1n), "/") + String.starts_with(line, "/") # the first line that is an absolute path, or "" def said.abs(ls: List<&2, String>) -> String: @@ -278,7 +278,7 @@ def loop.step(st: TP.Step, world: TW.World, go: TW.World -> IO(Unit)) -> IO(Unit # is only a guard against a planner that keeps asking, and running out of it # dies loudly. def rounds() -> Nat: - U32.to_nat(100) + 100n # the loop, under fuel. Every round adds an answer, since the planner never # asks what the World answers already, and it asks at most five rounds, so diff --git a/src/ws/joint.bend b/src/ws/joint.bend index 2a62f25..9f366f8 100644 --- a/src/ws/joint.bend +++ b/src/ws/joint.bend @@ -160,10 +160,10 @@ def bit.eq(aa: Bool, bb: Bool) -> Bool: Bool.not(bb) # whether two sources are one -def source.eq(aa: M.Source, bb: M.Source) -> Bool: - match aa: +def source.eq(left: M.Source, right: M.Source) -> Bool: + match left: case M.Hub{an}: - match bb: + match right: case M.Hub{bn}: String.eq(an, bn) case M.Git{_u, _r, _t, _o, _n, _v}: @@ -171,7 +171,7 @@ def source.eq(aa: M.Source, bb: M.Source) -> Bool: case M.Member{_p, _m}: False{} case M.Git{au, ar, at, ao, an, av}: - match bb: + match right: case M.Hub{_bn}: False{} case M.Git{bu, br, bt, bo, bn, bv}: @@ -181,7 +181,7 @@ def source.eq(aa: M.Source, bb: M.Source) -> Bool: case M.Member{_p, _m}: False{} case M.Member{ap, am}: - match bb: + match right: case M.Hub{_bn}: False{} case M.Git{_u, _r, _t, _o, _n, _v}: @@ -682,14 +682,21 @@ def resolve(+root: M.Manifest, ms: List<&2, Member>, +files: List<&2, K.Source>) # --------------------------------------------------------------------------- # the answers the lock reads a member's package from +# the text of the file at the path, or the search gone on past it +def text.at.hit(hit: Bool, ft: String, rest: Unit -> String) -> String: + match hit: + case True{}: + ft + case False{}: + rest(Unit{}) + # a file's text in a walk's files, "" when it holds none at that path def text.at(fs: List<&2, K.Source>, +at: String) -> String: match fs: case []: "" case K.Source{+fa, ft} <> tl: - rest = text.at(tl, at) - Bool.pick(String, String.eq(fa, at), ft, rest) + text.at.hit(String.eq(fa, at), ft, _u => text.at(tl, at)) # the texts of a walk's files, in its manifest's order def texts(sums: List<&2, K.Item>, +fs: List<&2, K.Source>) -> List<&2, String>: diff --git a/src/ws/workspace.bend b/src/ws/workspace.bend index b4b0d8f..84336ad 100644 --- a/src/ws/workspace.bend +++ b/src/ws/workspace.bend @@ -301,14 +301,21 @@ def unnested(ls: List<&2, Ledger>) -> Bool: rest = unnested(tl) Bool.and(Bool.not(ledger.nested(hd)), rest) +# the member whose ledger has a `[workspace]` table, or the search gone on +def nested.hit(hit: Bool, hd: Ledger, rest: Unit -> String) -> String: + match hit: + case True{}: + segs.text(ledger.dir(hd)) + case False{}: + rest(Unit{}) + # the first member whose ledger has a `[workspace]` table, "" for none def nested(ls: List<&2, Ledger>) -> String: match ls: case []: "" case +hd <> tl: - rest = nested(tl) - Bool.pick(String, ledger.nested(hd), segs.text(ledger.dir(hd)), rest) + nested.hit(ledger.nested(hd), hd, _u => nested(tl)) # the package name of every ledger, in order def names.of(ls: List<&2, Ledger>) -> List<&2, String>: @@ -344,14 +351,21 @@ def distinct(ns: List<&2, String>) -> Bool: rest = distinct(tl) Bool.and(Bool.not(named(tl, hd)), rest) +# the name that is in the list again, or the search gone on +def twice.hit(hit: Bool, hd: String, rest: Unit -> String) -> String: + match hit: + case True{}: + hd + case False{}: + rest(Unit{}) + # the first name in the list twice, "" for none def twice(ns: List<&2, String>) -> String: match ns: case []: "" case +hd <> +tl: - rest = twice(tl) - Bool.pick(String, named(tl, hd), hd, rest) + twice.hit(named(tl, hd), hd, _u => twice(tl)) # whether the root is a member def root.member(root: Root) -> Bool: diff --git a/tests/fetch.bend b/tests/fetch.bend index e8d8c90..0ab9feb 100644 --- a/tests/fetch.bend +++ b/tests/fetch.bend @@ -5,7 +5,6 @@ # It is under tests/ rather than hub/tests/ because it drives a socket, and the # unit tests beside the code are about what can be said without one. import Base -import ../src/hub/hub.bend as Hub import ../src/hub/get.bend as Net import snap@1.4.0.0/main.bend as R import ../src/check/kit.bend as Check diff --git a/tests/hub.bend b/tests/hub.bend index 9738b51..3b709b3 100644 --- a/tests/hub.bend +++ b/tests/hub.bend @@ -76,15 +76,15 @@ def go(+repo: String, +root: String, +port: String) -> IO(Unit): do IO: W.mkdir(root ++ "/app") W.mkdir(root ++ "/empty") - +a : String <- publish(root ++ "/hub", "src/lib.bend", + +lib : String <- publish(root ++ "/hub", "src/lib.bend", "import Base\n\n# double the number\ndef double(+x: U32) -> U32:\n" ++ " (x * 2 : U32)\n") - +b : String <- publish(root ++ "/hub", "src/mid.bend", - "import Base\nimport " ++ a ++ "/src/lib.bend as A\n\n" ++ + +mid : String <- publish(root ++ "/hub", "src/mid.bend", + "import Base\nimport " ++ lib ++ "/src/lib.bend as A\n\n" ++ "# four times the number\ndef quad(+x: U32) -> U32:\n" ++ " A.double(A.double(x))\n") _w : Bool <- F.write(root ++ "/app/main.bend", - "import Base\nimport " ++ b ++ "/src/mid.bend as B\n\n" ++ + "import Base\nimport " ++ mid ++ "/src/mid.bend as B\n\n" ++ "def main() -> U32:\n B.quad(11)\n") +pid : String <- W.spawn(W.inside(root ++ "/hub", ["python3", "-m", "http.server", port, "--bind", "127.0.0.1"])) @@ -97,7 +97,7 @@ def go(+repo: String, +root: String, +port: String) -> IO(Unit): hs : List<&2, String> <- named(at) Check.eq_str("the lock names both packages, the direct one and its own " ++ "dependency", String.join(hs, "\n"), - String.join(List.sort(~String, ~String.is_le, [a, b]), "\n")) + String.join(List.sort(~String, ~String.is_le, [lib, mid]), "\n")) restore(repo, root ++ "/app", "http://127.0.0.1:" ++ port) W.stop(pid) +good : String <- build(root ++ "/app", root ++ "/app/.ez/lib")