~/bend-docscommunity

language/unneeded_plus.bend checks

raw source on the hub · import bend-lint-rules@0.3.2.0/language/unneeded_plus.bend as Unneeded_plus

language/unneeded_plus: a binder written with + that its body uses at most once on each path, so the + claims a reuse that never happens. Heuristics: it reads how often the checker found each binder used, the most over its branches. A binder that a match or a let takes apart is skipped: its + also makes its fields reusable. So is a parameter of a definition used as a value (OnFile{run}): the type it must have can ask for the +. The + costs no speed: the compiler counts references from the uses, not from the +. Removing 1,049 such + from Bend's slash boss demo, three-bodies and a raytracer left their C unchanged.

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

Types

type Owner source · line 18 · raw

Data

What judging the binders of one definition reads: the definitions of the file used as values (named, not called), as the check names them; the definition, as the check names it; and its binders that a match or a let takes apart.

Definitions

def value.visit source · line 25 · raw

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

The definition a reference below path names, if it is used as a value: not as the function of an application.

def is_constructed source · line 37 · raw

@nodes:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node> -> Bool

def matched.visit source · line 46 · raw

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

The binder a variable below path uses, if it is taken apart there: it is a match's scrutinee, or the value of a let with a constructor pattern (Vert{x, y} = v).

def is_once source · line 70 · raw

@used:Maybe<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Quantity> -> Bool

Whether a binder used used times needs no +: none or one use.

def plus source · line 80 · raw

@syntax:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Syntax -> Maybe<&2, U32>

The binder a node of this kind declares with +, if it does.

def is_parameter source · line 97 · raw

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

def message source · line 104 · raw

@+name:String -> String

def is_needless source · line 113 · raw

@once:Bool -> @parameter:Bool -> @owner:Owner -> @b:U32 -> Bool

Whether a + binder its body uses at most once (once) needs no +: not if a match takes it apart, nor if it is a parameter of a definition used as a value: the type it must have can ask for the +.

def judged source · line 126 · raw

@binder:Maybe<&2, U32> -> @+parameter:Bool -> @+owner:Owner -> @+span:Maybe<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Span> -> @+name:String -> @facts:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Fact> -> @out:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding> -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>

The findings about a + binder (binder, if the node declares one) that its facts say its body uses at most once.

def visit source · line 161 · raw

@+owner:Owner -> @+path:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Above> -> @+node:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>

def defs source · line 166 · raw

@nodes:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node> -> @+values:List<&2, String> -> @out:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding> -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>

def run source · line 195 · raw

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

def rule source · line 199 · raw

0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Rule