~/bend-docscommunity

src/rules/suspicious/unused.bend checks

raw source on the hub · import bolt@1.59.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 (the body is what is under the whole header, Calls.under, so -> IO(T): on the line after def f(..) -> is no part of it).

8 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
import ../calls.bend as Calls

Types

type Cell source · line 76 · raw

Data

a use's target, as the index holds it

type Hits source · line 86 · 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. It holds every use that resolves to a binder of the file and nothing else, so a lookup, a walk down to one leaf, answers for the uses themselves: a hit is a use and a miss is none (the proof of laws/UnusedReportsDeadBinders.bend). A miss used to be checked by a scan of every use, which made a file's unused binders times its uses: a 2.2 MB proof file spent 32 s there

Definitions

def lines source · line 21 · raw

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

the lines of these tokens, onto acc

def foreign.first source · line 29 · raw

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

is the statement an import?

def foreign.opens source · line 37 · raw

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

does a body open with an import?

def foreign source · line 46 · raw

@root:0xace24ae64a36369bd02380967fccdfd3/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 58 · raw

@k:0xace24ae64a36369bd02380967fccdfd3/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 what source · line 68 · raw

@k:0xace24ae64a36369bd02380967fccdfd3/src/syntax/bind.BindKind -> String

a binder's kind, for the message

def depth source · line 92 · raw

Nat

how many bits of a line the index branches on

def path source · line 96 · raw

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

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

def hits.cells source · line 104 · raw

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

the cells at a leaf, none elsewhere

def hits.lo source · line 114 · raw

@h:Hits -> Hits

a node's low half, empty elsewhere

def hits.hi source · line 124 · raw

@h:Hits -> Hits

a node's high half, empty elsewhere

def hits.near source · line 134 · raw

@b:Bool -> @h:Hits -> Hits

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

def hits.join source · line 142 · raw

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

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

def put source · line 150 · raw

@p:List<&2, Bool> -> @+h:Hits -> @+cell:Cell -> Hits

the index with one more cell, down its path

def hits.any source · line 158 · raw

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

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

def find source · line 166 · raw

@p:List<&2, Bool> -> @h: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 174 · raw

@tg:0xace24ae64a36369bd02380967fccdfd3/src/syntax/bind.Target -> @+h:Hits -> Hits

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

def index source · line 186 · raw

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

the index of every use's target

def seen source · line 195 · raw

@h:Hits -> @+line:U32 -> @+col:U32 -> Bool

is the binder at (line, col) the target of any use? The index of the uses answers

def check.go source · line 198 · raw

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

def check.on source · line 210 · raw

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

def check source · line 215 · raw

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

the rule