~/bend-docscommunity

src/rules/suspicious/scan.bend checks

raw source on the hub · import bolt@1.20.0.0/src/rules/suspicious/scan.bend as Scan

rule scan: a def that calls itself and, on the same step, hands a parameter it carries unchanged to a walk. Every step walks that list again: O(|A| * |B|), A what the def walks and B what it carries. Index it once outside the loop, or merge two sorted walks. A parameter is carried when every self-call passes it back as that same lone name in its own position (hoist's notion). A call is a name token (plain or dotted), then a ( group, and what it walks is some of its arguments, counted from 0. A Base list search walks its list: argument 2 of List.contains, List.find, List.filter and List.length, 3 of List.any and List.all, 4 of List.foldl and List.foldr; a Base walk that rebuilds the list (List.map, List.append, ...) makes output, not a search, and is left alone. A def of this file walks, when it calls itself, its first live parameter that some self-call does not pass back unchanged (the one it shrinks), unless that parameter is a Nat or a String (a count, such as fuel, or a text); and each parameter its body, anywhere, passes as the lone name of an argument a call walks, of a Base search or of a def listed before it. A def of another module is not seen. A call reports when it is not a self-call and an argument it walks is exactly the lone name of a carried parameter: anything else there (a literal table, an expression, a name the step binds) is left alone. The step is what hoist reads as hot: the def's body, a case arm's body only when it calls the def, never a case pattern, and never the rest of a chain after => (a lambda's body, a Lazy thunk, runs when it is called). Laws and proofs do not run (a def with no type at all fills a law: it is a proof), and a law file is skipped whole. One finding per call, on its callee.

9 imports
import Base
import ../../src.bend as Src
import ../../paths.bend as Paths
import ../../finding.bend as F
import ../../syntax/lex.bend as Lex
import ../../syntax/tree.bend as Tree
import ../calls.bend as Calls
import ../../lazy/lazy.bend as Lazy
import ./hoist.bend as Hoist

Types

type Walk source · line 37 · raw

Data

a def of this file, and one argument it walks

Definitions

def opt source · line 41 · raw

@mm:Maybe<&2, Nat> -> List<&2, Nat>

the answer as a list: none or one

def base_at source · line 49 · raw

@+tt:String -> List<&2, Nat>

the list argument of a Base list search

def file_at source · line 56 · raw

@ws:List<&2, Walk> -> @+tt:String -> List<&2, Nat>

the arguments the defs of this file named tt walk

def slots source · line 65 · raw

@+tt:String -> @+ws:List<&2, Walk> -> List<&2, Nat>

the arguments a callee walks: a Base walk's list, and those the defs of this file record

def name_tok source · line 69 · raw

@tok:0x6da2affe27298531acb4879fbe88e96d/src/syntax/lex.Tok -> Maybe<&2, String>

a leaf that is a plain name: its text

def name_of source · line 77 · raw

@nn:0x6da2affe27298531acb4879fbe88e96d/src/syntax/tree.Node -> Maybe<&2, String>

the argument, when it is exactly one plain name

def keep_in source · line 85 · raw

@mm:Maybe<&2, String> -> @+names:List<&2, String> -> Maybe<&2, String>

the name, when the list holds it

def first source · line 93 · raw

@aa:Maybe<&2, String> -> @bb:Maybe<&2, String> -> Maybe<&2, String>

the first of two answers that has one

def found source · line 101 · raw

@ss:List<&2, Nat> -> @+as:List<&2, 0x6da2affe27298531acb4879fbe88e96d/src/syntax/tree.Node> -> @+names:List<&2, String> -> Maybe<&2, String>

the first walked argument that is the lone name of one of the names

def index_of source · line 110 · raw

@ps:List<&2, String> -> @+nm:String -> @+ii:Nat -> Maybe<&2, Nat>

where a name sits among the parameter names

def index_in source · line 118 · raw

@mm:Maybe<&2, String> -> @+ps:List<&2, String> -> Maybe<&2, Nat>

where the name sits among the parameter names, when there is a name

def params_at source · line 126 · raw

@ss:List<&2, Nat> -> @+as:List<&2, 0x6da2affe27298531acb4879fbe88e96d/src/syntax/tree.Node> -> @+ps:List<&2, String> -> List<&2, Nat>

the parameters that sit, as lone names, at walked arguments

def pass_hit source · line 135 · raw

@kk:0x6da2affe27298531acb4879fbe88e96d/src/syntax/lex.TokKind -> @+open:Bool -> @+tt:String -> @kids:0x6da2affe27298531acb4879fbe88e96d/src/syntax/tree.Node -> @+ps:List<&2, String> -> @+ws:List<&2, Walk> -> List<&2, Nat>

a call's walked parameters, when its callee is a name and it is a call

def passes source · line 152 · raw

@nn:0x6da2affe27298531acb4879fbe88e96d/src/syntax/tree.Node -> @+ps:List<&2, String> -> @+ws:List<&2, Walk> -> List<&2, Nat>

the parameters a body passes, anywhere, as an argument some call walks

def moves source · line 167 · raw

@+pp:0x6da2affe27298531acb4879fbe88e96d/src/syntax/tree.Node -> @+carried:List<&2, String> -> Bool

a live parameter that some self-call does not pass back unchanged

def scalar source · line 171 · raw

@+pp:0x6da2affe27298531acb4879fbe88e96d/src/syntax/tree.Node -> Bool

a count or a text: a loop down one scans no list

def place source · line 176 · raw

@+pp:0x6da2affe27298531acb4879fbe88e96d/src/syntax/tree.Node -> @+ii:Nat -> Maybe<&2, Nat>

where the parameter a def shrinks sits, unless it is a count or a text

def own.go source · line 179 · raw

@ps:List<&2, 0x6da2affe27298531acb4879fbe88e96d/src/syntax/tree.Node> -> @+carried:List<&2, String> -> @+ii:Nat -> Maybe<&2, Nat>

def own source · line 188 · raw

@+sig:0x6da2affe27298531acb4879fbe88e96d/src/syntax/tree.Node -> @+body:0x6da2affe27298531acb4879fbe88e96d/src/syntax/tree.Node -> @+name:String -> Maybe<&2, Nat>

where the parameter a def shrinks sits, when it calls itself and it is no count or text

def tag source · line 193 · raw

@ns:List<&2, Nat> -> @+name:String -> @+ws:List<&2, Walk> -> List<&2, Walk>

one walk of the def for each argument

def walks.go source · line 200 · raw

@ds:List<&2, 0x6da2affe27298531acb4879fbe88e96d/src/rules/calls.Def> -> @+ws:List<&2, Walk> -> List<&2, Walk>

def walks source · line 209 · raw

@ds:List<&2, 0x6da2affe27298531acb4879fbe88e96d/src/rules/calls.Def> -> List<&2, Walk>

the defs of this file that walk, each with an argument it walks, in order

def lead.go source · line 213 · raw

@ps:List<&2, 0x6da2affe27298531acb4879fbe88e96d/src/syntax/tree.Node> -> @+carried:List<&2, String> -> String

the name of the parameter a def shrinks, "" for none

def cite source · line 222 · raw

@mm:Maybe<&2, String> -> @+tt:String -> @+line:U32 -> @+col:U32 -> @+self:String -> @+lead:String -> @+path:String -> List<&2, 0x6da2affe27298531acb4879fbe88e96d/src/finding.Finding>

a finding on the callee, naming the carried list

def on_name source · line 240 · raw

@+hot:Bool -> @+open:Bool -> @+tt:String -> @+line:U32 -> @+col:U32 -> @kids:0x6da2affe27298531acb4879fbe88e96d/src/syntax/tree.Node -> @+self:String -> @+ws:List<&2, Walk> -> @+carried:List<&2, String> -> @+lead:String -> @+path:String -> List<&2, 0x6da2affe27298531acb4879fbe88e96d/src/finding.Finding>

a hot call of a walk other than the def, a walked argument carried

def call_hit source · line 257 · raw

@kk:0x6da2affe27298531acb4879fbe88e96d/src/syntax/lex.TokKind -> @+hot:Bool -> @+open:Bool -> @+tt:String -> @+line:U32 -> @+col:U32 -> @kids:0x6da2affe27298531acb4879fbe88e96d/src/syntax/tree.Node -> @+self:String -> @+ws:List<&2, Walk> -> @+carried:List<&2, String> -> @+lead:String -> @+path:String -> List<&2, 0x6da2affe27298531acb4879fbe88e96d/src/finding.Finding>

a call's finding, when its callee is a name

def walk source · line 280 · raw

@nn:0x6da2affe27298531acb4879fbe88e96d/src/syntax/tree.Node -> @+self:String -> @+ws:List<&2, Walk> -> @+carried:List<&2, String> -> @+lead:String -> @+path:String -> @+hot:Bool -> List<&2, 0x6da2affe27298531acb4879fbe88e96d/src/finding.Finding>

the walks of carried lists on a hot path

def run source · line 314 · raw

@+sig:0x6da2affe27298531acb4879fbe88e96d/src/syntax/tree.Node -> @+body:0x6da2affe27298531acb4879fbe88e96d/src/syntax/tree.Node -> @+name:String -> @+ws:List<&2, Walk> -> @+path:String -> List<&2, 0x6da2affe27298531acb4879fbe88e96d/src/finding.Finding>

one def's walk, its carried parameters and the one it shrinks read once

def check.go source · line 318 · raw

@ds:List<&2, 0x6da2affe27298531acb4879fbe88e96d/src/rules/calls.Def> -> @+ws:List<&2, Walk> -> @+path:String -> @acc:List<&2, List<&2, 0x6da2affe27298531acb4879fbe88e96d/src/finding.Finding>> -> List<&2, 0x6da2affe27298531acb4879fbe88e96d/src/finding.Finding>

def check.on source · line 334 · raw

@+ds:List<&2, 0x6da2affe27298531acb4879fbe88e96d/src/rules/calls.Def> -> @+path:String -> List<&2, 0x6da2affe27298531acb4879fbe88e96d/src/finding.Finding>

the findings over a file's defs, their walks read once

def check source · line 338 · raw

@ss:0x6da2affe27298531acb4879fbe88e96d/src/src.Src -> List<&2, 0x6da2affe27298531acb4879fbe88e96d/src/finding.Finding>

the rule; a law file is skipped whole, before its walks are read