~/bend-docscommunity

src/rules/suspicious/fuel.bend fails

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

rule fuel: a call to a def of the same file, its name then (, passes a Nat literal (1000n: digits, then n) where that def takes its fuel. A fuel parameter is known by its name alone (its first lowercase name before the colon): fuel, gas, steps or budget, or any name starting with fuel. The fuel-0 arm returns what it has, so input past the literal comes out cut short, with no error (a JSON printer that stopped at 1000 tasks). Inside a law, the checker unrolls the fixed fuel and hangs. Derive the fuel from the input's size (Nat.mul(size, 4n)) or take it as a parameter. A literal of any size counts, an exact repeat count such as 3n included. Only an argument that is one literal token alone counts: U32.to_nat(1000), a let-bound literal and a parenthesized (7n) are not seen. A def's own calls are exempt: its step passes fuel - 1, not a literal.

9 imports
import Base
import ../../src.bend as Src
import ../../lazy/lazy.bend as Lazy
import ../../finding.bend as F
import ../../syntax/lex.bend as Lex
import ../../syntax/tree.bend as Tree
import ../../syntax/bind.bend as Bind
import ../calls.bend as Calls
import ../tokens.bend as T