~/bend-docscommunity

performance/unused_result.bend checks

raw source on the hub · import bend-lint-rules@0.3.6.0/performance/unused_result.bend as Unused_result

performance/unused_result: a value that a loop binds and never uses, and that is data, not a number: a lambda's parameter or a let's name, in a definition that calls itself. Bend computes every value it binds, so this one is built, and then walked to be freed, on every step. Heuristics: measured on llama.bend (SmolLM2-135M, CPU): its generation loop binds each layer's activations and never uses them; building them empty made each token 19% to 25% faster, with the same tokens. The cost grows with the value: a small one costs little to ignore. It reads how often the checker found each binder used, and the type it gave it; numbers, and records of numbers only, are those of performance/gpu_fit, and cost nothing to drop. An erased binder holds nothing at run time, and a step of a do block (x : T <- m, a call of a bind) gets its value from the monad, used or not.

5 imports
import Base
import bend-lint-api@0.3.6.0/linter/api/impl.bend as LintImpl
import bend-lint-api@0.3.6.0/linter/api/spec.bend as Lint
import bend-lint-api@0.3.6.0/shared.bend as Shared
import ./gpu_fit.bend as GpuFit

Types

type Unused source · line 20 · raw

Data

A binder a loop never uses: where it is written, its name, the loop's name, and the type the checker gave it.

type Owner source · line 24 · raw

Data

What judging the binders of one definition reads: whether it is a loop (it calls itself), and its name as written.

Definitions

def message source · line 29 · raw

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

Functions =========

def loop.visit source · line 39 · raw

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

def is_step source · line 44 · raw

@path:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Above> -> Bool

Whether a lambda below path is the rest of a step of a do block (x : T <- m, the last argument of a call of a bind): its value comes from the monad, which makes it whether it is used or not.

def is_binder source · line 65 · raw

@syntax:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Syntax -> @path:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Above> -> Bool

Whether a node of this kind, below path, binds a value at run time: a lambda's parameter (not a do step's), or a let's name (a binding, or the one pattern variable of a let), not erased.

def unused source · line 86 · raw

@facts:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Fact> -> Maybe<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.TypeRef>

The type of a binder its facts say is never used, if they do.

def unused.of source · line 95 · raw

@binder:Bool -> @ty:Maybe<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.TypeRef> -> @span:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Span -> @name:String -> @loop:String -> List<&2, Unused>

def visit source · line 108 · raw

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

def defs source · line 116 · raw

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

The binders that the loops among nodes never use, onto out (last first).

def types source · line 149 · raw

@found:List<&2, Unused> -> @out:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.TypeRef> -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.TypeRef>

def judged source · line 157 · raw

@found:List<&2, Unused> -> @shown:List<&2, String> -> @+slots:List<&2, 0xda2c3ef989ea20b0751946884b7c6eef/performance/gpu_fit.Slot> -> @out:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding> -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>

The findings about the unused binders whose types, as shown, are data: not numbers, nor records of numbers only.

def run source · line 184 · raw

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

def rule source · line 191 · raw

0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Rule