~/bend-docscommunity

performance/unused_result.bend checks

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

4 imports
import Base
import bend-lint-api@0.2.1.0/linter/lint.bend as Lint
import bend-lint-api@0.2.1.0/shared/lists.bend as Lists
import ./gpu_fit.bend as GpuFit

Types

type Unused source · line 19 · 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 23 · 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 28 · raw

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

Functions =========

def loop.visit source · line 38 · raw

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

def is_step source · line 43 · raw

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

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

@facts:List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Fact> -> Maybe<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.TypeRef>

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

def unused.of source · line 94 · raw

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

def visit source · line 107 · raw

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

def defs source · line 115 · raw

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

@found:List<&2, Unused> -> @out:List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.TypeRef> -> List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.TypeRef>

def judged source · line 156 · raw

@found:List<&2, Unused> -> @shown:List<&2, String> -> @+slots:List<&2, 0xe3a0709d4d0e98d88d93b335b279fce6/performance/gpu_fit.Slot> -> @out:List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Finding> -> List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Finding>

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

def run source · line 183 · raw

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

def rule source · line 190 · raw

0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Rule