~/bend-docscommunity

src/rules/suspicious/unused.bend checks

raw source on the hub · import 0xd96f2ab40f5df4925c42e96d0ba857ff/src/rules/suspicious/unused.bend as Unused

rule unused: a name bound by a let, a do-bind, a lambda, or as a parameter is never used. Pattern binders are exempt: naming every field of Tok{k, t, l, c} reads better than _. So are names starting with _, erased parameters (-x), which exist to be unused, a law's for names (hypotheses the proof takes by position), and every parameter of a foreign def (one whose body starts with import), which its C and JS bodies read, however its header is wrapped.

7 imports
import Base
import ../../src.bend as Src
import ../../lazy/lazy.bend as Lazy
import ../../finding.bend as F
import ../../syntax/bind.bend as Bind
import ../../syntax/tree.bend as Tree
import ../../syntax/lex.bend as Lex

Types

type Cell source · line 64 · raw

Data

a use's target, as the index holds it

type Hits source · line 71 · raw

Data

the targets of the uses, as a binary trie on the low bits of each target's line, a leaf holding the cells that reach it. A hit in it is a use; a miss is checked against the uses themselves (seen), so the index only has to be sound, never complete, and a lookup is a walk down, not a scan of every use

Definitions

def lines source · line 17 · raw

@ts:List<&2, 0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/lex.Tok> -> @acc:List<&2, U32> -> List<&2, U32>

the lines of these tokens, onto acc

def foreign source · line 26 · raw

@root:0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/tree.Node -> List<&2, U32>

every header line of the defs whose body is import "./x.c", however the header is wrapped

def reportable source · line 36 · raw

@kk:0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/bind.BindKind -> @+note:String -> @+line:U32 -> @+foreign_lines:List<&2, U32> -> Bool

does a binder of this kind count? Erased and foreign parameters do not

def used source · line 46 · raw

@uses:List<&2, 0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/bind.Use> -> @+line:U32 -> @+col:U32 -> Bool

is the binder at (line, col) the target of any use?

def what source · line 56 · raw

@kk:0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/bind.BindKind -> String

a binder's kind, for the message

def depth source · line 77 · raw

Nat

how many bits of a line the index branches on

def path source · line 81 · raw

@dd:Nat -> @+key:U32 -> List<&2, Bool>

a line's way down the index: its low bits, lowest first

def hits.cells source · line 89 · raw

@hh:Hits -> List<&2, Cell>

the cells at a leaf, none elsewhere

def hits.lo source · line 99 · raw

@hh:Hits -> Hits

a node's low half, empty elsewhere

def hits.hi source · line 109 · raw

@hh:Hits -> Hits

a node's high half, empty elsewhere

def hits.near source · line 119 · raw

@bb:Bool -> @hh:Hits -> Hits

the half of a node a bit goes down, empty elsewhere

def hits.join source · line 127 · raw

@bb:Bool -> @sub:Hits -> @far:Hits -> Hits

a node whose half down a bit is sub, and the other half far

def put source · line 135 · raw

@pp:List<&2, Bool> -> @+hh:Hits -> @+cell:Cell -> Hits

the index with one more cell, down its path

def hits.any source · line 143 · raw

@cs:List<&2, Cell> -> @+line:U32 -> @+col:U32 -> Bool

is the cell at (line, col) among these?

def find source · line 151 · raw

@pp:List<&2, Bool> -> @hh:Hits -> @+line:U32 -> @+col:U32 -> Bool

is the cell at (line, col) at the end of a path through the index?

def index.one source · line 159 · raw

@tg:0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/bind.Target -> @+hh:Hits -> Hits

a use's target into the index, when it is a binder of the file

def index source · line 171 · raw

@uses:List<&2, 0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/bind.Use> -> Hits

the index of every use's target

def seen source · line 180 · raw

@hh:Hits -> @+uses:List<&2, 0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/bind.Use> -> @+line:U32 -> @+col:U32 -> Bool

is the binder at (line, col) the target of any use? The index answers a hit at once; only a miss reads the uses

def check.go source · line 183 · raw

@binds:List<&2, 0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/bind.Bind> -> @+hh:Hits -> @+uses:List<&2, 0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/bind.Use> -> @+fl:List<&2, U32> -> @+path:String -> List<&2, 0xd96f2ab40f5df4925c42e96d0ba857ff/src/finding.Finding>

def check.on source · line 200 · raw

@bb:0xd96f2ab40f5df4925c42e96d0ba857ff/src/syntax/bind.Bound -> @fl:List<&2, U32> -> @path:String -> List<&2, 0xd96f2ab40f5df4925c42e96d0ba857ff/src/finding.Finding>

def check source · line 205 · raw

@ss:0xd96f2ab40f5df4925c42e96d0ba857ff/src/src.Src -> List<&2, 0xd96f2ab40f5df4925c42e96d0ba857ff/src/finding.Finding>

the rule