src/rules/suspicious/index.bend checks
raw source on the hub · import 0x582b4b0fdf3dafdeecc8c3bfddc5e4db/src/rules/suspicious/index.bend as Index
rule index: a def that calls itself also calls List.get(..) or
String.get(..). Both walk the cons list from the head to the index, so a
per-index loop is quadratic (AppSprout's sort went from 39 s to 0.9 s
walking the list itself). Walk the list in the recursion, or materialize
what the loop needs in one pass. A get anywhere in the def is reported,
one in a base arm that runs once included. A literal index of any size
(List.get(.., xs, 0n), 5000n) is exempt, as are laws and proofs (a def
with no type at all fills a law: it is a proof). A
List.get on a fixed table (a literal, a sized array, a constant
List.replicate) is table's finding instead, so the two rules do not
both report that call. String.get is never table's: it stays here.
8 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 import ./table.bend as Table
Definitions
def literal source · line 22 · raw
@nn:0x582b4b0fdf3dafdeecc8c3bfddc5e4db/src/syntax/tree.Node -> Bool
is the chain exactly one number?
def held source · line 30 · raw
@+list:Bool -> @coll:0x582b4b0fdf3dafdeecc8c3bfddc5e4db/src/syntax/tree.Node -> @+fixed:List<&2, String> -> Bool
a fixed table is reported by table, not here
def walk source · line 38 · raw
@nn:0x582b4b0fdf3dafdeecc8c3bfddc5e4db/src/syntax/tree.Node -> @+path:String -> @+fixed:List<&2, String> -> List<&2, 0x582b4b0fdf3dafdeecc8c3bfddc5e4db/src/finding.Finding>
every List.get / String.get call at a computed index
def check.go source · line 60 · raw
@ds:List<&2, 0x582b4b0fdf3dafdeecc8c3bfddc5e4db/src/rules/calls.Def> -> @+mods:List<&2, String> -> @+path:String -> @acc:List<&2, List<&2, 0x582b4b0fdf3dafdeecc8c3bfddc5e4db/src/finding.Finding>> -> List<&2, 0x582b4b0fdf3dafdeecc8c3bfddc5e4db/src/finding.Finding>
def check source · line 76 · raw
@ss:0x582b4b0fdf3dafdeecc8c3bfddc5e4db/src/src.Src -> List<&2, 0x582b4b0fdf3dafdeecc8c3bfddc5e4db/src/finding.Finding>
the rule