~/bend-docscommunity

performance/dead_accumulator.bend checks

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

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

Types

type Owner source · line 21 · 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 26 · raw

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

Functions =========

def kind source · line 36 · raw

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

@+owner:Owner -> @+path:List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Above> -> @+node:0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.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 79 · raw

@q:0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.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 92 · raw

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

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

def defs source · line 125 · raw

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

def run source · line 134 · raw

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

def rule source · line 137 · raw

0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Rule