Eager.work: def of bolt@1.27.0.0 Import: import bolt@1.27.0.0/src/rules/suspicious/eager.bend as Eager Lines 102-147 of bolt@1.27.0.0/src/rules/suspicious/eager.bend: https://jend.leeeet.dev/read.txt?path=bolt@1.27.0.0/src/rules/suspicious/eager.bend&start_line=102&end_line=147 import Base import bolt@1.27.0.0/src/finding.bend as F import bolt@1.27.0.0/src/syntax/lex.bend as Lex import bolt@1.27.0.0/src/syntax/tree.bend as Tree # the work under a def's body: hot says the node sits in a branch argument of # a `Bool.pick` (so it runs whatever the condition), seg counts the arguments # of the pick whose group this chain is (0 the type, 1 the condition, 2 and 3 # the branches; 9 for a chain that is not a pick's), and keep is what hot # returns to at the next comma of a chain that is not a pick's, so a `=>` # clears hot for the lambda's own body and not for the arguments after it. A # leaf moves the state by its kind (work.hot, work.seg); a `=>` or a comma # before a group names no call, so that group is walked as any other def work( nn: Tree.Node, +ns: List<&2, String>, +self: String, +path: String, +hot: Bool, +seg: U32, +keep: Bool ) -> List<&2, F.Finding>: match nn: case Tree.NCons{Tree.Leaf{Lex.Tok{+k, +t, +l, +c}}, Tree.NCons{Tree.Group{Lex.Tok{_, +o, _, _}, +kids, _}, rest}}: +now = work.hot(k, hot, seg, keep) +call = Bool.and(work.name(k), String.eq(o, "(")) +is_pick = Bool.and(call, String.eq(t, "Bool.pick")) +known = List.contains(~String, ~String.eq, ns, t) +mine = Bool.and(Bool.not(String.eq(t, self)), known) +report = Bool.and(now, Bool.and(call, mine)) +inner = Bool.and(now, Bool.not(is_pick)) +more = List.concat(&2, F.Finding, [work(kids, ns, self, path, inner, Bool.pick(U32, is_pick, 0, 9), inner), work(rest, ns, self, path, now, work.seg(k, seg), keep)]) Bool.pick(List<&2, F.Finding>, report, F.Finding{path, l, c, U32.from_nat(String.length(t)), "eager", t ++ " is called in a branch of Bool.pick, which evaluates both branches, so it runs whatever the condition; bind it above the pick, or branch with `match` on the condition."} <> more, more) case Tree.NCons{Tree.Leaf{Lex.Tok{+k, t, l, c}}, rest}: work(rest, ns, self, path, work.hot(k, hot, seg, keep), work.seg(k, seg), keep) case Tree.NCons{Tree.Group{open, +kids, close}, rest}: List.concat(&2, F.Finding, [work(kids, ns, self, path, hot, 9, hot), work(rest, ns, self, path, hot, seg, keep)]) case Tree.NCons{Tree.Stmt{kind, +kids, body}, rest}: List.concat(&2, F.Finding, [work(kids, ns, self, path, False{}, 9, False{}), work(body, ns, self, path, False{}, 9, False{}), work(rest, ns, self, path, hot, seg, keep)]) case Tree.NCons{h, rest}: work(rest, ns, self, path, hot, seg, keep) case other: Nil{} Uses (19): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool.and https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool.not https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool.pick https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List.concat https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List.contains https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String.append https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String.eq https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String.length https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32 https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.from_nat https://jend.leeeet.dev/definition.txt?path=bolt@1.27.0.0/src/finding.bend&name=Finding https://jend.leeeet.dev/definition.txt?path=bolt@1.27.0.0/src/rules/suspicious/eager.bend&name=work.hot https://jend.leeeet.dev/definition.txt?path=bolt@1.27.0.0/src/rules/suspicious/eager.bend&name=work.name https://jend.leeeet.dev/definition.txt?path=bolt@1.27.0.0/src/rules/suspicious/eager.bend&name=work.seg https://jend.leeeet.dev/definition.txt?path=bolt@1.27.0.0/src/syntax/lex.bend&name=Tok https://jend.leeeet.dev/definition.txt?path=bolt@1.27.0.0/src/syntax/tree.bend&name=Node