def after

bend-lint-rules@0.2.0.0 · performance/bang_after_fork.bend:77

import bend-lint-rules@0.2.0.0/performance/bang_after_fork.bend as BangAfterFork
import Base
import bend-lint-api@0.2.0.0/linter/lint.bend as Lint
import bend-lint-rules@0.2.0.0/performance/deep_call_in_fork.bend as Deep

77# Whether a fork runs before the node below `path`, in the same evaluation, or `found`: a let above it, whose rest of
78# block it is in, forks (a parallel let, or a value that forks), and no lambda (the rest of an IO step) comes between.
79def after(path: List<&2, Lint.Above>, +program: Program, found: Bool) -> Bool:
80  match path found:
81    case _ True{}:
82      True{}
83    case Nil{} False{}:
84      False{}
85    case Con{Lint.Above{Lint.Node{Lint.Lambda{b, q}, n, s, k, f}, at}, rest} False{}:
86      False{}
87    case Con{Lint.Above{Lint.Node{Lint.Body{}, n, s, k, f}, at}, rest} False{}:
88      False{}
89    case Con{Lint.Above{Lint.Node{Lint.Destructure{q}, n, s, +kids, f}, at}, rest} False{}:
90      after(
91        rest,
92        program,
93        let.forks(Deep.is_last(kids, at), Nat.is_gt(Deep.binders(kids, 0n), 1n), kids, program)
94      )
95    case Con{Lint.Above{Lint.Node{Lint.Let{}, n, s, +kids, f}, at}, rest} False{}:
96      after(rest, program, let.forks(Deep.is_last(kids, at), False{}, kids, program))
97    case Con{a, rest} False{}:
98      after(rest, program, False{})

Uses (10)

Used by (1)