~/bend-docscommunity

language/unneeded_plus.bend checks

raw source on the hub · import bend-lint-rules@0.1.1.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.

3 imports
import Base
import bend-lint-api@0.1.1.0/linter/lint.bend as Lint
import bend-lint-api@0.1.1.0/shared/lists.bend as Lists

Types

type Owner source · line 17 · 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 24 · raw

@+u:Unit -> @+path:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Above> -> @+node:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.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 36 · raw

@nodes:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Node> -> Bool

def matched.visit source · line 45 · raw

@+u:Unit -> @+path:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Above> -> @+node:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.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 69 · raw

@used:Maybe<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Quantity> -> Bool

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

def plus source · line 79 · raw

@syntax:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Syntax -> Maybe<&2, U32>

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

def is_parameter source · line 96 · raw

@syntax:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Syntax -> Bool

def message source · line 103 · raw

@+name:String -> String

def is_needless source · line 112 · 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 125 · raw

@binder:Maybe<&2, U32> -> @+parameter:Bool -> @+owner:Owner -> @+span:Maybe<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Span> -> @+name:String -> @facts:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Fact> -> @out:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Finding> -> List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.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 160 · raw

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

def defs source · line 165 · raw

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

def run source · line 194 · raw

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

def rule source · line 198 · raw

0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Rule