~/bend-docscommunity

performance/dead_accumulator.bend checks

raw source on the hub · import bend-lint-rules@0.3.1.0/performance/dead_accumulator.bend as Dead_accumulator

performance/dead_accumulator: a parameter of a loop that only grows and is never read: each use of it is an argument of the loop's call of itself, at its own place, with something added to it (inside a constructor, such as x <> acc), and the loop never matches it, returns it, or gives it to another call. It is built on every step and freed at the end. Heuristics: measured on bend-ml's BPE encode (bend-ml-bpe-tokenizer, as llama.bend uses it): its done keeps the rules applied so far, for its proofs, and encode drops it; a 48,900-entry list built and freed for each word was half of the time to tokenize 19 KB of text (26.1 s, against 11.5 s with -done), with the same ids and the same proofs. A parameter that the loop passes unchanged is not reported: it grows nothing. A use in a type or a proof does not count, as it does not run: the fix, an erased parameter (-acc), keeps it there. Only the loop's own calls are read; a call of the loop through another definition, or through a template, is not.

4 imports
import Base
import bend-lint-api@0.3.1.0/linter/api/impl.bend as LintImpl
import bend-lint-api@0.3.1.0/linter/api/spec.bend as Lint
import bend-lint-api@0.3.1.0/shared.bend as Shared

Types

type Owner source · line 22 · raw

Data

What judging the uses of one parameter reads: its loop's name (as the check names it), the place of the parameter among the loop's parameters (as a call's arguments are), and its binder.

Definitions

def message source · line 27 · raw

@+name:String -> @loop:String -> String

Functions =========

def kind source · line 37 · raw

@path:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Above> -> @target:String -> @at:U32 -> @grown:Bool -> U32

How a use of the parameter below path ends: 0 if it is read (in anything but the loop's call of itself, at the parameter's place), 1 if it is passed there as it is, 2 if it is passed there with something added (grown).

def use.visit source · line 66 · raw

@+owner:Owner -> @+path:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Above> -> @+node:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node -> List<&2, U32>

How the parameter is used at a node, below path, if the node is a use of it in live code.

def is_dead source · line 80 · raw

@q:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Quantity -> @+kinds:List<&2, U32> -> Bool

Whether a parameter of quantity q that is used as kinds says is a dead accumulator: it is there at run time, it is only passed to the loop's own calls, and grows in one at least.

def params source · line 93 · raw

@nodes:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node> -> @+loop:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node -> @+target:String -> @+name:String -> @+at:U32 -> @out:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding> -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>

The findings about the parameters among nodes, a definition's, onto out; at is the place of the first.

def defs source · line 126 · raw

@nodes:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node> -> @out:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding> -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>

def run source · line 135 · raw

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

def rule source · line 138 · raw

0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Rule