language/decreasing_call.bend checks
raw source on the hub · import bend-lint-rules@0.3.1.0/language/decreasing_call.bend as Decreasing_call
language/decreasing_call: a call of a definition to itself that Bend cannot prove smaller, so the check
fails ("a decreasing self-call").
Heuristics: as Bend's checker does, it reads the arguments left to right against the parameters:
each must be passed unchanged until one is smaller, a field that a match on that parameter took
apart (p of case 1n+p:). Erased parameters do not count. An argument that is a call, or another
variable, is not smaller. One that is a literal or a constructor is left to the checker: the rule
does not report it. Bend's checker stops at its first error; this rule reports every such call at
once. An @unsafe definition (def f?) may call itself freely, and a call in a type (a pair type
A & B, a type's arguments, an equality) is not checked.
4 imports
import Base import bend-lint-api@0.3.1.0/linter/api/impl.bend as LintImpl import bend-lint-api@0.3.1.0/linter/api/spec.bend as Lint import bend-lint-api@0.3.1.0/shared.bend as Shared
Types
type Param source · line 19 · raw
Data
A parameter: its binder, whether it is erased (it does not count), and its name.
Param@binder:U32 -> @erased:Bool -> @name:String -> Param
type Smaller source · line 23 · raw
Data
A binder known smaller than the parameter or field root: a field a match took apart from it.
Smaller@root:U32 -> @field:U32 -> Smaller
type Verdict source · line 28 · raw
Data
What the arguments of a call say: it decreases; it does not, at the argument numbered at (from 0)
for the parameter param, or with every argument unchanged; or the rule cannot tell.
DecreasesVerdict
Fails@at:Nat -> @param:String -> Verdict
UnchangedVerdict
UnknownVerdict
type Loop source · line 36 · raw
Data
What judging a definition's calls of itself reads: its parameters, the binders its lets bind (an argument that is one stands for its value, which the rule does not follow), and the file's text.
Loop@params:List<&2, Param> -> @lets:List<&2, U32> -> @text:String -> Loop
Definitions
def Param.is_erased source · line 41 · raw
@bare:Bool -> @quantity:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Quantity -> Bool
Functions =========
def Param.all source · line 48 · raw
@nodes:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node> -> @out:List<&2, Param> -> List<&2, Param>
def roots source · line 66 · raw
@smaller:List<&2, Smaller> -> @+binder:U32 -> @out:List<&2, U32> -> List<&2, U32>
The roots that binder is smaller than, with binder itself.
def pairs.of source · line 77 · raw
@+r:U32 -> @fs:List<&2, U32> -> @out:List<&2, Smaller> -> List<&2, Smaller>
def pairs source · line 84 · raw
@rs:List<&2, U32> -> @+fs:List<&2, U32> -> @out:List<&2, Smaller> -> List<&2, Smaller>
def taken source · line 93 · raw
@scrutinees:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node> -> @patterns:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node> -> @+smaller:List<&2, Smaller> -> List<&2, Smaller>
What a case's patterns take apart: each pattern, a constructor, makes its variables smaller than its scrutinee, and than all that scrutinee is smaller than.
def known.at source · line 119 · raw
@parent:Maybe<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node> -> @node:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node -> @smaller:List<&2, Smaller> -> List<&2, Smaller>
What a case below parent takes apart, if node is one and parent its match.
def known source · line 137 · raw
@chain:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Above> -> @parent:Maybe<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node> -> @smaller:List<&2, Smaller> -> List<&2, Smaller>
What the cases above a call (chain, outermost first; parent is the node above the first) take apart.
def is_smaller source · line 148 · raw
@smaller:List<&2, Smaller> -> @hit:Bool -> @+root:U32 -> @+field:U32 -> Bool
def step source · line 159 · raw
@same:Bool -> @smaller:Bool -> @local:Bool -> @at:Nat -> @param:String -> Maybe<&2, Verdict>
What one argument, a variable, says: none to read on (it is the parameter, unchanged), else the verdict: it decreases (a field a match took apart), the rule cannot tell (a let's name), or it fails.
def verdict source · line 171 · raw
@params:List<&2, Param> -> @args:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node> -> @told:Maybe<&2, Verdict> -> @+smaller:List<&2, Smaller> -> @+lets:List<&2, U32> -> @+at:Nat -> Verdict
The verdict on a call's arguments against the parameters, from the one numbered at.
def ordinal source · line 206 · raw
@n:Nat -> String
def message source · line 209 · raw
@verdict:Verdict -> @loop:String -> @source:String -> @args:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node> -> String
def finding source · line 224 · raw
@verdict:Verdict -> @span:Maybe<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Span> -> @loop:String -> @source:String -> @args:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node> -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>
def call source · line 240 · raw
@+loop:Loop -> @path:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Above> -> @node:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>
The findings about a call of its definition to itself, below path.
def calls source · line 265 · raw
@recursive:Bool -> @loop:Loop -> @path:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Above> -> @node:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>
The same, if node is a live call of its definition to itself (recursive).
def visit source · line 277 · raw
@+loop:Loop -> @+path:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Above> -> @+node:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>
def let source · line 281 · raw
@+u:Unit -> @+path:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Above> -> @+node:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node -> List<&2, U32>
The binders the lets of a definition bind, below path.
def defs source · line 292 · raw
@nodes:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node> -> @+text:String -> @out:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding> -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>
The findings in each definition among nodes, onto out. An @unsafe definition (def f?) may call itself freely.
def run source · line 321 · raw
@+here:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Here -> 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Ask(List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>)
def rule source · line 324 · raw
0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Rule