performance/deep_call_in_fork.bend checks
raw source on the hub · import bend-lint-rules@0.1.1.0/performance/deep_call_in_fork.bend as Deep_call_in_fork
performance/deep_call_in_fork: a fork that calls a definition that calls itself outside a tail
position. A value of a parallel let (a b = f(x) g(y)), or of a let just before it, calls a definition
of the file whose call of itself is not the last thing it does.
Heuristics: Bend gives a call of itself that is not a tail call a frame per call ("bend guide
shaders"). In bend-lint's benchmark (Bend 2.0.36, on the CPU), such a call at each fork cut the speedup
from 10x to 1.9x; the same definition with a tail call kept the 10x. In a raytracer that splits its
rows that way at each of 9 fork levels, tail-recursive splits made it 4% to 8% faster on the CPU; in
Bend's slash boss demo, the same change changed no timing, as its list was short. The JS lane is not
measured. A tail position is the body of a definition, a case, or the rest of a block after its lets,
through annotations. A definition with a parallel let is a fork tree: its calls of itself are the
values of its forks, not frames, and it is not reported (Bend's matrix and Merkle benchmarks call such
trees in their forks).
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 ./gpu_fit.bend as GpuFit
Types
type Owner source · line 23 · 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, by the name the check gives it and as written.
Owner@deeps:List<&2, String> -> @target:String -> @name:String -> Owner
Definitions
def is_last source · line 30 · raw
@nodes:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Node> -> @at:U32 -> Bool
Whether at is the place of the last of nodes.
def is_tail source · line 35 · raw
@path:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Above> -> @ends:Bool -> Bool
Whether the node below path is in a tail position, if it ends the node above it (ends): the body of a definition
or a case, or the rest of a block after its lets, through annotations.
def deep.of source · line 55 · raw
@recursive:Bool -> @path:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Above> -> List<&2, Bool>
Whether a call of its definition to itself below path is outside a tail position.
def deep.visit source · line 62 · raw
@+u:Unit -> @+path:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Above> -> @+node:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Node -> List<&2, Bool>
def deep source · line 67 · raw
@nodes:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Node> -> @+forking:Bool -> @out:List<&2, String> -> List<&2, String>
The definitions among nodes that call themselves outside a tail position, as the check names them, onto out;
with forking false, not those with a parallel let, whose such calls are the values of their forks.
def is_pattern source · line 100 · raw
@syntax:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Syntax -> Bool
def binders source · line 109 · raw
@nodes:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Node> -> @n:Nat -> Nat
def leads source · line 121 · raw
@nodes:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Node> -> @many:Bool -> @one:Bool -> Bool
Whether a let leads to a fork: it is one (it binds many names), or it binds one (one), and the last of nodes,
the rest of its block, is a let that leads to one. The values of these lets are what a fork runs, or what runs just
before it.
def is_value source · line 139 · raw
@x:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Node -> @+parent:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Node -> @at:U32 -> Bool
Whether x, the node at at under parent, is a value of a fork, or of a let just before one: not a binder, nor the
rest of the block.
def is_inside source · line 145 · raw
@path:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Above> -> @x:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Node -> @found:Bool -> Bool
Whether x, below path, or a node above it, is a value of a fork, or found.
def message source · line 154 · raw
@+callee:String -> @loop:String -> String
def judge.deep source · line 163 · raw
@deep:Bool -> @path:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Above> -> @+node:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Node -> @callee:String -> @name:String -> List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Finding>
The finding about a call of a deep definition (if deep), when the call is in a fork.
def judge.call source · line 181 · raw
@+owner:Owner -> @path:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Above> -> @node:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Node -> @callee:String -> @+called:String -> List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Finding>
def visit source · line 198 · 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 211 · 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 239 · raw
@+here:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Here -> 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Ask(List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Finding>)
def rule source · line 243 · raw
0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Rule