~/bend-docscommunity

src/rules/suspicious/concat.bend checks

raw source on the hub · import bolt@1.52.0.0/src/rules/suspicious/concat.bend as Concat

rule concat: a def passes itself a parameter grown at the end, p ++ x or List.append(.., p, ys) (String.append(p, ..) too), as the argument in p's own position, the slot it carries; p grown into another slot is not a finding. The argument is that append written in place, inside any number of parentheses ((p ++ x)), or a lone name read from a let: the nearest q = .. or +q = .. of that name before the call in its block or an enclosing one, whose right side is such an append (a later let of the name shadows it; other binders, a typed or destructuring let and a do-bind do not count). A String and a List are cons lists, so appending copies all of p: the loop is quadratic, with right output (a text step that cost three times the render; a JSON stringify). Prepend (x <> acc) and reverse once at the end, build with h <> go(t), or gather pieces and join them once.

The same append passed on through a continuation is the same loop one hop removed (cont): an argument of a call of a function-typed parameter (rest(file, List.append(&2, U32, acc, b <> t)), where rest is fl => a => slurp(f, fl, a)) that appends onto any parameter of the def, read the same way (in place, in parentheses, or a lone name through its let). A + parameter the body reads more than once is left alone: it builds a value it also uses elsewhere (path ++ "/" ++ name), not an accumulator. Prepend each chunk and reverse once at the end; the accumulator's type changes along the chain (ez's slurp, native: 14.75 s -> 0.36 s at 16 MB).

7 imports
import Base
import ../../src.bend as Src
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

Types

type Let source · line 87 · raw

Data

a let of one plain name in scope: the name, and what its right side appends onto

Definitions

def lone.name source · line 35 · raw

@nn:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> Maybe<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/lex.Tok>

a leaf that is a lowercase name: its token. The rule matches a leaf's kind here and in bound.is_eq only; the rest reads kinds through these

def lone source · line 43 · raw

@nn:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> Maybe<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/lex.Tok>

a chain that is exactly one lowercase name: its token

def appended source · line 51 · raw

@+tt:String -> @as:List<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node> -> Maybe<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/lex.Tok>

the list a call appends onto: List.append's first list, String.append's first

def onto.call source · line 57 · raw

@hh:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> @kids:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> Maybe<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/lex.Tok>

a leaf, then a group: the call's append

def onto.next source · line 65 · raw

@+hh:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> @h2:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> Maybe<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/lex.Tok>

a first cell, then the second: a name then ++, or a call

def onto source · line 76 · raw

@aa:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> Maybe<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/lex.Tok>

the name an argument appends onto, p ++ .. or an append call, inside any number of parentheses

def find source · line 91 · raw

@lets:List<&2, Let> -> @+name:String -> Maybe<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/lex.Tok>

what the nearest let of the name appends onto; nothing when no let binds it

def via.of source · line 99 · raw

@mm:Maybe<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/lex.Tok> -> @+lets:List<&2, Let> -> Maybe<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/lex.Tok>

what the let of a lone name appends onto

def via source · line 107 · raw

@aa:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> @+lets:List<&2, Let> -> Maybe<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/lex.Tok>

the name an argument appends onto, when it is a lone name read from a let

def either source · line 111 · raw

@aa:Maybe<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/lex.Tok> -> @bb:Maybe<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/lex.Tok> -> Maybe<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/lex.Tok>

the first maybe when it holds a token, else the second

def seen source · line 119 · raw

@+aa:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> @+lets:List<&2, Let> -> Maybe<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/lex.Tok>

the name an argument appends onto, in place or through a let

def bound.eq source · line 123 · raw

@kk:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/lex.TokKind -> Bool

an =

def bound.of source · line 131 · raw

@mm:Maybe<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/lex.Tok> -> @+h2:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> @rhs:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> Maybe<&2, Let>

a name, then =, then the right side: the let

def bound.named source · line 139 · raw

@+hh:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> @+h2:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> @rhs:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> Maybe<&2, Let>

a plain name, then =, then the right side: the let

def bound.plus source · line 143 · raw

@+h1:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> @+h2:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> @rest:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> Maybe<&2, Let>

+, then a plain name, = and the right side: the let

def bound source · line 153 · raw

@kids:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> Maybe<&2, Let>

the let a statement's own tokens make, when it binds one plain name with =, bare or +

def push source · line 162 · raw

@mm:Maybe<&2, Let> -> @+lets:List<&2, Let> -> List<&2, Let>

the lets in scope after one more, when there is one

def hit source · line 170 · raw

@mm:Maybe<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/lex.Tok> -> @+slot:String -> @+path:String -> @+acc:List<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/finding.Finding> -> List<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/finding.Finding>

a finding when the name is the parameter of the argument's own slot

def hits source · line 187 · raw

@as:List<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node> -> @+params:List<&2, String> -> @+lets:List<&2, Let> -> @+path:String -> @acc:List<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/finding.Finding> -> List<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/finding.Finding>

the findings on a self-call's arguments, each against the parameter in its position (params, from the argument's own slot on)

def after source · line 203 · raw

@kind:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.StmtKind -> @+kids:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> @+lets:List<&2, Let> -> List<&2, Let>

the lets a statement leaves in scope for the statements after it

def walk source · line 211 · raw

@nn:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> @+name:String -> @+params:List<&2, String> -> @+lets:List<&2, Let> -> @+path:String -> List<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/finding.Finding>

every self-call's arguments, with the lets in scope

def check.go source · line 234 · raw

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

def check source · line 244 · raw

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

the rule

def plus source · line 254 · raw

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

does a parameter's chain open with +?

def uses source · line 262 · raw

@nn:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> @+name:String -> Nat

how many times a plain name is read under the node

def keep.again source · line 276 · raw

@+isplus:Bool -> @more:Nat -> Bool

past the first read: a second one drops a + parameter

def keep source · line 286 · raw

@+isplus:Bool -> @count:Nat -> Bool

may an append onto the parameter be reported? Any parameter but a + one the body reads more than once: that one builds a value it also uses elsewhere (path ++ "/" ++ name), not an accumulator

def accs.go source · line 293 · raw

@ps:List<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node> -> @+body:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> @+acc:List<&2, String> -> List<&2, String>

def accs source · line 302 · raw

@sig:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> @+body:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> List<&2, String>

the parameters an append onto may be reported

def conts.go source · line 305 · raw

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

def conts source · line 314 · raw

@sig:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> List<&2, String>

the function-typed parameters, rest: File -> List<&2, U32> -> IO(..): the continuations a call may pass an accumulator through

def hit.cont source · line 318 · raw

@mm:Maybe<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/lex.Tok> -> @+accs:List<&2, String> -> @+path:String -> @+acc:List<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/finding.Finding> -> List<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/finding.Finding>

a finding when the name is one of the reportable parameters

def hits.cont source · line 334 · raw

@as:List<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node> -> @+accs:List<&2, String> -> @+lets:List<&2, Let> -> @+path:String -> @acc:List<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/finding.Finding> -> List<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/finding.Finding>

the findings on a continuation call's arguments

def cwalk source · line 348 · raw

@nn:0xfb394c8f685b7b3a6abb1443099643d8/src/syntax/tree.Node -> @+conts:List<&2, String> -> @+accs:List<&2, String> -> @+lets:List<&2, Let> -> @+path:String -> List<&2, 0xfb394c8f685b7b3a6abb1443099643d8/src/finding.Finding>

every continuation call's arguments, with the lets in scope

def cont.go source · line 371 · raw

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

def cont source · line 381 · raw

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

the rule's other half: appends passed on through a continuation