~/bend-docscommunity

language/reused_binder.bend checks

raw source on the hub · import bend-lint-rules@0.3.8.0/language/reused_binder.bend as Reused_binder

language/reused_binder: a binder written without + that live code uses twice on one path, so the check fails ("consumed more than once"). Heuristics: it checks only the binders whose quantity the syntax gives for sure: a parameter or a let's name written without +, which can be used once on each path. It leaves out a pattern's field, whose quantity also comes from its scrutinee's type, and a law's bare parameter. Two uses are on one path unless they are in different cases of one match. Both values of a call count, so Bool.pick(T, c, x, x) uses x twice. Uses in types, and in an argument for an erased parameter (-P) of a definition of the check or of Base, are dead and do not count; an erased parameter of another function (a lambda, a field) is not seen. A binder that a match takes apart is skipped: in a case, it stands for the matched constructor. Bend's checker stops at its first error; this rule reports every such binder at once.

4 imports
import Base
import bend-lint-api@0.3.8.0/linter/api/impl.bend as LintImpl
import bend-lint-api@0.3.8.0/linter/api/spec.bend as Lint
import bend-lint-api@0.3.8.0/shared.bend as Shared

Types

type Once source · line 21 · raw

Data

A binder that can be used once: its number, and its name.

type Seen source · line 26 · raw

Data

The live uses of one binder among some nodes: the first, and the first that an earlier one on its path precedes, if any. Two uses are on one path unless a match parts them: its cases, and its scrutinees, are each a path of their own.

type Erased source · line 31 · raw

Data

The places, among the nodes of an application, of the arguments for each definition's erased parameters, by the name the check gives the definition.

Definitions

def message source · line 36 · raw

@+name:String -> String

Functions =========

def Once.of source · line 46 · raw

@+bare:Bool -> @+path:List<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Above> -> @+node:0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Node -> List<&2, Once>

The binders a definition declares that can be used once, as their syntax says for sure: a parameter written without + (unless one is bare: its quantity is its law's), and a let's name written without +. A pattern's field is left out: its quantity also comes from its scrutinee's type (a field of a List<&2, A> is reusable), which the rule cannot see.

def variable source · line 59 · raw

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

The binders that the variables among the nodes use: a binder used fewer than twice gives no finding.

def is_used source · line 68 · raw

@used:List<&2, U32> -> @+b:U32 -> @more:Nat -> Bool

Whether b is among used at least more more times: a finding needs two uses, so a binder used fewer than twice in its definition is not scanned.

def scrutinee source · line 79 · raw

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

The binders a match takes apart: the variables right under it, its scrutinees. In a case, they stand for the matched constructor.

def is_live_inside source · line 91 · raw

@+node:0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Node -> @live:Bool -> Bool

Whether the nodes under node, which is live if live, are: a body is; a type is not (an equality, a function or pair type, a type's arguments). An annotation's type, and a rewrite's motive, are not either: see scan.

def Erased.params source · line 107 · raw

@nodes:List<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Node> -> @+at:U32 -> @out:List<&2, U32> -> List<&2, U32>

The places of the erased parameters among a definition's nodes, from at (the first argument's), onto out.

def Erased.file source · line 118 · raw

@nodes:List<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Node> -> @out:Map<&2, Maybe<&2, List<&2, U32>>> -> Map<&2, Maybe<&2, List<&2, U32>>>

def Erased.of source · line 133 · raw

@sources:List<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Source> -> @out:Erased -> Erased

def Erased.dead source · line 142 · raw

@+node:0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Node -> @+erased:Erased -> List<&2, U32>

The places of the nodes under a node that are dead: an annotation's type, a rewrite's motive, and the arguments of an application for the erased parameters of the definition it calls.

def is_match source · line 159 · raw

@syntax:0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Syntax -> Bool

def Seen.of source · line 167 · raw

@+node:0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Node -> @b:U32 -> @live:Bool -> @under:Seen -> Seen

What a node's uses of b are: its own, if it is a live use, else under's, those under it.

def Seen.then source · line 175 · raw

@apart:Bool -> @seen:Seen -> @next:Seen -> Seen

The uses of seen, then those of next, the nodes after them: on one path, or, if apart, on paths of their own.

def scan source · line 187 · raw

@nodes:List<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Node> -> @+b:U32 -> @+erased:Erased -> @+live:Bool -> @+apart:Bool -> @+dead:List<&2, U32> -> @+at:U32 -> @seen:Seen -> Seen

The live uses of b among nodes, the nodes under one, after seen: live says whether they are live, apart whether each is a path of its own (a match's), and dead the places of those that are not (see Erased.dead); at counts the nodes.

def finding source · line 232 · raw

@second:Seen -> @name:String -> List<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Finding>

def judged source · line 239 · raw

@matched:Bool -> @twice:Bool -> @owner:0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Node -> @b:U32 -> @erased:Erased -> @name:String -> List<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Finding>

The finding about a binder of owner used twice on one path, unless a match takes it apart (matched) or it is used fewer than twice (twice).

def judge source · line 255 · raw

@+owner:0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Node -> @onces:List<&2, Once> -> @+matched:List<&2, U32> -> @+used:List<&2, U32> -> @+erased:Erased -> @out:List<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Finding> -> List<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Finding>

The finding about each of onces, binders of owner, used twice on one path, onto out; a binder a match takes apart (matched) is skipped.

def defs source · line 288 · raw

@nodes:List<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Node> -> @+erased:Erased -> @out:List<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Finding> -> List<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Finding>

def run source · line 319 · raw

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

def rule source · line 331 · raw

0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Rule