~/bend-docscommunity

bolt/rules/correctness/chars.bend fails

raw source on the hub · import 0x729eecea86ea5a2cdba3a2856a313bca/bolt/rules/correctness/chars.bend as Chars

rule chars: a match with more than eight character-literal arms (case '.':). Char is Chr{code: U32}, so such an arm is a U32 literal inside a constructor pattern, and bend's C backend pays for each one out of all proportion to its size -- about 90 MB, and the cost compounds through every def downstream of the one holding them (eighteen arms cost 1.57 GB and 8.3 s here, 0.10 GB and 0.7 s once rewritten). It is the literals, not the arms: a match over eighteen constructors costs nothing measurable.

Compare Char.to_u32(c) instead. Bind the fallback above the comparisons so it is a value, not a call, or bolt's own eager rule fires on it; and give the def the reusable quantity (+c: Char), since the code point and the fallback both consume it. Where the arms carry linear values, as bolt/lsp/frame.bend's do, leave the match alone: a cascade would break linearity and do every branch's work.

7 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 ../../../lazy/lazy.bend as Lazy
import ../tokens.bend as T