~/bend-docscommunity

src/rules/pedantic/index.bend checks

raw source on the hub · import bolt@1.44.0.0/src/rules/pedantic/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: src/rules/table.bend) is left alone; String.get always stays here. A get that is the def's own self-call is exempt: the step of a def named List.get or String.get itself (Base's), which walks one cell per call.

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 24 · raw

@nn:0x4fbe18d4c1bba3b659645f7db7caf56f/src/syntax/tree.Node -> Bool

is the chain exactly one number?

def held source · line 32 · raw

@+list:Bool -> @coll:0x4fbe18d4c1bba3b659645f7db7caf56f/src/syntax/tree.Node -> @+fixed:List<&2, String> -> Bool

a fixed table (src/rules/table.bend) is left alone

def named source · line 40 · raw

@+tt:String -> @+self:String -> @+get:String -> Bool

is the call named get, and not the def's own (self)?

def walk source · line 44 · raw

@nn:0x4fbe18d4c1bba3b659645f7db7caf56f/src/syntax/tree.Node -> @+path:String -> @+fixed:List<&2, String> -> @+self:String -> List<&2, 0x4fbe18d4c1bba3b659645f7db7caf56f/src/finding.Finding>

every List.get / String.get call at a computed index, but self's own

def check.go source · line 67 · raw

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

def check source · line 83 · raw

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

the rule