performance/deep_call_in_fork.bend checks
raw source on the hub · import bend-lint-rules@0.3.5.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.3.5.0/linter/api/impl.bend as LintImpl import bend-lint-api@0.3.5.0/linter/api/spec.bend as Lint import bend-lint-api@0.3.5.0/shared.bend as Shared
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, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node> -> @at:U32 -> Bool
Whether at is the place of the last of nodes.
def is_tail source · line 35 · raw
@path:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.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, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.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, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Above> -> @+node:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node -> List<&2, Bool>
def deep.if source · line 67 · raw
@found:Bool -> @forking:Bool -> @k:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node> -> Bool
Whether a definition with the nodes k counts, if it calls itself outside a tail position (found): each does if
forking, else one without a parallel let.
def deep source · line 78 · raw
@nodes:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.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 114 · raw
@syntax:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Syntax -> Bool
def binders source · line 123 · raw
@nodes:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node> -> @n:Nat -> Nat
def leads source · line 135 · raw
@nodes:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.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 153 · raw
@x:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node -> @+parent:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.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 159 · raw
@path:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Above> -> @x:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.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 168 · raw
@+callee:String -> @loop:String -> String
def judge.deep source · line 177 · raw
@deep:Bool -> @path:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Above> -> @+node:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node -> @callee:String -> @name:String -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>
The finding about a call of a deep definition (if deep), when the call is in a fork.
def judge.call source · line 195 · raw
@+owner:Owner -> @path:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Above> -> @node:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node -> @callee:String -> @+called:String -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>
def visit source · line 212 · raw
@+owner:Owner -> @+path:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Above> -> @+node:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>
def defs source · line 225 · raw
@nodes:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node> -> @+deeps:List<&2, String> -> @out:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding> -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>
def run source · line 253 · raw
@+here:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Here -> 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Ask(List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>)
def rule source · line 257 · raw
0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Rule