~/bend-docscommunity

performance/eager_branch.bend checks

raw source on the hub · import bend-lint-rules@0.1.1.0/performance/eager_branch.bend as Eager_branch

performance/eager_branch: a value that Bend computes even when it is not needed, and that calls a definition of the file that calls itself outside a tail position: a value of Bool.pick, or the right side of && or ||. These are functions, so their arguments are computed before they choose; a match runs only its chosen case. Heuristics: measured on the CPU, a Bool.pick whose unused value called a doubly recursive fib took 0.28 s, against 0.055 s for a match. A loop whose calls of itself are all tail calls is not reported: clang drops it when its value is unused (under Bool.pick, a 2G-step loop cost nothing measurable), though the JS lane still runs it. A loop's own call in && or || is never a tail call. A call of a definition that does not call itself, or of Base, is cheap and not reported. A value in a lambda, a type or an equation does not run, and is skipped; an erased argument (a proof's) is not told from a live one. A loop that is short in practice makes a finding that costs little to ignore.

4 imports
import Base
import bend-lint-api@0.1.1.0/linter/lint.bend as Lint
import bend-lint-api@0.1.1.0/shared/lists.bend as Lists
import ./deep_call_in_fork.bend as Deep

Types

type Eager source · line 21 · raw

Data

A value Bend computes whether needed or not: what computes it ("pick", "&&" or "||"), and the value.

type Owner source · line 26 · raw

Data

What judging the calls in one definition reads: the definitions of the file that call themselves outside a tail position (as the check names them), and the definition, as the check names it.

Definitions

def eager source · line 33 · raw

@kids:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Node> -> @+at:U32 -> String

Functions ========= What an application with the nodes kids computes whether needed or not, as its node at at is one of its arguments: "pick" for a value of Bool.pick, "&&" or "||" for their right side, "" for none.

def Eager.of source · line 57 · raw

@+kind:String -> @value:Maybe<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Node> -> Maybe<&2, Eager>

def eagerly source · line 62 · raw

@path:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Above> -> @found:Maybe<&2, Eager> -> Maybe<&2, Eager>

The eager value a call below path is in, if one is above it and no lambda comes between. found stops the walk once one is found.

def why source · line 77 · raw

@+kind:String -> @+callee:String -> String

def message source · line 92 · raw

@kind:String -> @+callee:String -> @own:Bool -> String

def judged source · line 107 · raw

@eager:Maybe<&2, Eager> -> @callee:String -> @own:Bool -> List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Finding>

def looping source · line 114 · raw

@hit:Bool -> @path:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Above> -> @callee:String -> @own:Bool -> List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Finding>

def visit source · line 126 · raw

@+owner:Owner -> @+path:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Above> -> @+node:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Node -> List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Finding>

def defs source · line 147 · raw

@nodes:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Node> -> @+deeps:List<&2, String> -> @out:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Finding> -> List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Finding>

def run source · line 175 · raw

@+here:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Here -> 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Ask(List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Finding>)

def rule source · line 179 · raw

0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Rule