~/bend-docscommunity

performance/loop_invariant_call.bend fails

raw source on the hub · import bend-lint-rules@0.1.0.0/performance/loop_invariant_call.bend as Loop_invariant_call

performance/loop_invariant_call: a call that gets the same arguments on every step of a loop, so it computes the same value each time: in a definition that calls itself, a call of a definition of the file that loops too, in the branch that repeats (the one with the loop's call of itself), whose arguments are literals, or parameters that the loop passes unchanged to each call of itself. Heuristics: clang hoists plain arithmetic out of a loop (and folds constants), but not a call of a definition that loops: Bend runs it through its own calls. Compute it once, before the loop, and pass it as a parameter. A definition that does not call itself is cheap, and not reported. A proof (a definition that fills a law, or returns an equality) does not run, and is skipped. A loop that repeats work on purpose, such as a benchmark's, is the case to expect.

3 imports
import Base
import bend-lint-api@0.1.0.0/linter/lint.bend as Lint
import bend-lint-api@0.1.0.0/shared/lists.bend as Lists