~/bend-docscommunity

performance/deep_call_in_fork.bend checks

raw source on the hub · import bend-lint-rules@0.2.0.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).

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

Types

type Owner source · line 22 · 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.

Definitions

def is_last source · line 29 · raw

@nodes:List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Node> -> @at:U32 -> Bool

Whether at is the place of the last of nodes.

def is_tail source · line 34 · raw

@path:List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/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 54 · raw

@recursive:Bool -> @path:List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/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 61 · raw

@+u:Unit -> @+path:List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Above> -> @+node:0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Node -> List<&2, Bool>

def deep.if source · line 66 · raw

@found:Bool -> @forking:Bool -> @k:List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.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 77 · raw

@nodes:List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/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 113 · raw

@syntax:0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Syntax -> Bool

def binders source · line 122 · raw

@nodes:List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Node> -> @n:Nat -> Nat

def leads source · line 134 · raw

@nodes:List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/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 152 · raw

@x:0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Node -> @+parent:0xd69a1e32f167d67a827d0d362dfcf729/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 158 · raw

@path:List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Above> -> @x:0xd69a1e32f167d67a827d0d362dfcf729/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 167 · raw

@+callee:String -> @loop:String -> String

def judge.deep source · line 176 · raw

@deep:Bool -> @path:List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Above> -> @+node:0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Node -> @callee:String -> @name:String -> List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/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 194 · raw

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

def visit source · line 211 · raw

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

def defs source · line 224 · raw

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

def run source · line 252 · raw

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

def rule source · line 256 · raw

0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Rule