~/bend-docscommunity

src/rules/suspicious/index.bend fails

raw source on the hub · import 0xde9bb08f7de298b03207fb5797ede9a5/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