def is_guarded

bend-lint-rules@0.2.0.0 · performance/repeated_call.bend:72

import bend-lint-rules@0.2.0.0/performance/repeated_call.bend as RepeatedCall
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
import bend-lint-rules@0.2.0.0/performance/missed_fork.bend as Fork

72# Whether a node below `path` may not run on the path of its branch, or runs as a copy made on purpose: under a lambda,
73# a value of a choice (Bool.pick, Bool.and, Bool.or), or a value of a parallel let.
74def is_guarded(path: List<&2, Lint.Above>, found: Bool) -> Bool:
75  match path found:
76    case _ True{}:
77      True{}
78    case Nil{} False{}:
79      False{}
80    case Con{Lint.Above{Lint.Node{Lint.Lambda{b, q}, n, s, k, f}, at}, rest} False{}:
81      True{}
82    case Con{Lint.Above{Lint.Node{Lint.Application{}, n, s, +kids, f}, at}, rest} False{}:
83      is_guarded(rest, Fork.is_choice(kids))
84    case Con{Lint.Above{Lint.Node{Lint.Destructure{q}, n, s, +kids, f}, at}, rest} False{}:
85      is_guarded(rest, Nat.is_gt(Deep.binders(kids, 0n), 1n) && Bool.not(Deep.is_last(kids, at)))
86    case Con{a, rest} False{}:
87      is_guarded(rest, False{})

Uses (11)

Used by (1)