~/bend-docscommunity

src/rules/suspicious/unused.bend checks

raw source on the hub · import bolt@1.31.0.0/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. A name read anywhere is a use, in a dependent arrow's types too (@+x: U32 -> S reads S). 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, which its C and JS bodies read: one whose body's first statement is import, wherever its header's -> and return type fall (a header that does not end in : runs on through the body's statements up to one that does, as -> IO(T): on the line after def f(..) ->).

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 116 · raw

Data

a use's target, as the index holds it

type Hits source · line 123 · 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 20 · raw

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

the lines of these tokens, onto acc

def colon.kind source · line 28 · raw

@kk:0xadc35cd376767f3fd033070f0162d682/src/syntax/lex.TokKind -> Bool

is a token of this kind a :?

def colon source · line 36 · raw

@nn:0xadc35cd376767f3fd033070f0162d682/src/syntax/tree.Node -> Bool

is the node a : leaf?

def foreign.ends source · line 45 · raw

@kids:0xadc35cd376767f3fd033070f0162d682/src/syntax/tree.Node -> @last:Bool -> Bool

does a statement's own chain end in a : leaf? last: whether the node before the chain did

def foreign.first source · line 53 · raw

@sk:0xadc35cd376767f3fd033070f0162d682/src/syntax/tree.StmtKind -> Bool

is the statement an import?

def foreign.opens source · line 63 · raw

@body:0xadc35cd376767f3fd033070f0162d682/src/syntax/tree.Node -> @open:Bool -> Bool

does the body open with an import once the def's header is over? While the header is open (its tokens so far do not end in :), each statement is more of it: -> IO(T): on the line after def f(..) ->

def foreign source · line 76 · raw

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

every header line of the defs whose body is import "./x.c", wherever the header's -> and return type fall

def reportable source · line 88 · raw

@kk:0xadc35cd376767f3fd033070f0162d682/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 98 · raw

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

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

def what source · line 108 · raw

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

a binder's kind, for the message

def depth source · line 129 · raw

Nat

how many bits of a line the index branches on

def path source · line 133 · 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 141 · raw

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

the cells at a leaf, none elsewhere

def hits.lo source · line 151 · raw

@hh:Hits -> Hits

a node's low half, empty elsewhere

def hits.hi source · line 161 · raw

@hh:Hits -> Hits

a node's high half, empty elsewhere

def hits.near source · line 171 · raw

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

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

def hits.join source · line 179 · 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 187 · raw

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

the index with one more cell, down its path

def hits.any source · line 195 · raw

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

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

def find source · line 203 · 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 211 · raw

@tg:0xadc35cd376767f3fd033070f0162d682/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 223 · raw

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

the index of every use's target

def seen source · line 232 · raw

@hh:Hits -> @+uses:List<&2, 0xadc35cd376767f3fd033070f0162d682/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 235 · raw

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

def check.on source · line 253 · raw

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

def check source · line 258 · raw

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

the rule