~/bend-docscommunity

src/rules/suspicious/hoist.bend fails

raw source on the hub · import 0xde9bb08f7de298b03207fb5797ede9a5/src/rules/suspicious/hoist.bend as Hoist

rule hoist: a fixed table built inside a def that calls itself, from inputs that do not change, and then indexed. The build runs again on every step. Build it once, outside the recursion. A build is a list or array literal, List.replicate / List.range / List.map / Array.new / Array.map, or a call to a def of this file whose body is itself one fixed table of more than eight cells; a def whose body cannot be seen (another module's) is not a build. A table of eight cells or fewer is left alone, and so is a build whose arguments depend on the step. A name that is not a carried parameter (a pattern binder, a value computed on the step) keeps the build; a case arm that does not recurse is cold; laws and proofs do not run (a def with no type at all fills a law: it is a proof). List.get itself stays with index.

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