language/unneeded_plus.bend checks
raw source on the hub · import bend-lint-rules@0.3.7.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}) in a file of the check: the type it must
have can ask for the +. A file that uses it so is seen only if the check reads it: list it in the
config's entries.
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.7.0/linter/api/impl.bend as LintImpl import bend-lint-api@0.3.7.0/linter/api/spec.bend as Lint import bend-lint-api@0.3.7.0/shared.bend as Shared
Types
type Owner source · line 20 · raw
Data
What judging the binders of one definition reads: the definitions used as values (named, not called) in the files of the check, as it names them; the definition, as the check names it; and its binders that a match or a let takes apart.
Owner@values:List<&2, String> -> @target:String -> @matched:List<&2, U32> -> Owner
Definitions
def value.visit source · line 27 · raw
@+u:Unit -> @+path:List<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Above> -> @+node:0x534e77ab9e7d8d3c817c84cab8139f38/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 39 · raw
@nodes:List<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Node> -> Bool
def matched.visit source · line 48 · raw
@+u:Unit -> @+path:List<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Above> -> @+node:0x534e77ab9e7d8d3c817c84cab8139f38/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 72 · raw
@used:Maybe<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Quantity> -> Bool
Whether a binder used used times needs no +: none or one use.
def plus source · line 82 · raw
@syntax:0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Syntax -> Maybe<&2, U32>
The binder a node of this kind declares with +, if it does.
def is_parameter source · line 99 · raw
@syntax:0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Syntax -> Bool
def message source · line 106 · raw
@+name:String -> String
def is_needless source · line 115 · 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 128 · raw
@binder:Maybe<&2, U32> -> @+parameter:Bool -> @+owner:Owner -> @+span:Maybe<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Span> -> @+name:String -> @facts:List<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Fact> -> @out:List<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Finding> -> List<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/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 163 · raw
@+owner:Owner -> @+path:List<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Above> -> @+node:0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Node -> List<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Finding>
def defs source · line 168 · raw
@nodes:List<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Node> -> @+values:List<&2, String> -> @out:List<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Finding> -> List<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Finding>
def values source · line 198 · raw
@sources:List<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Source> -> @out:List<&2, String> -> List<&2, String>
The definitions used as values in sources, onto out.
def run source · line 213 · raw
@+here:0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Here -> 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Ask(List<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Finding>)
def rule source · line 216 · raw
0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Rule