MAX_EXPANSION

Constant MAX_EXPANSION 

Source
pub const MAX_EXPANSION: u64 = 100_000;
Expand description

How many nodes a module’s macros may produce, in total.

MAX_DEPTH and [Nesting] bound how deep expansion goes and neither bounds how much it makes, which is 14’s F17: a macro that doubles its output at each of a few levels is shallow, terminating, and enormous. Eight nestings of a two-line macro is 256 copies of its argument; sixty nestings is 10^18 of them, which is more nodes than a machine has bytes — and every one of those programs is six lines long and passes every other limit the front end has.

So the meter is what expansion produces, charged per node and shared by the whole module — per module because that is what a compile is, and because a per-call budget would let a program spend it as many times as it has calls (docs/82 §82.5 is the same arithmetic one subsystem over).

The number is measured rather than declared. Across every program in this repository — the corpus, both benchmark suites, both SICP chapters, the examples and the standard library — the largest total expansion is 138 nodes (sicp/ch3.beck; examples/todo.beck’s page is 94), so a hundred thousand is about 725× the biggest real one. It is also about seventeen nestings of a doubling macro, which is a few dozen characters more source than a program that compiles — and that is the room a limit wants when what it separates is legitimate from absurd rather than big from small.

macro_bomb.rs is the gate, in both directions: the tree still compiles, and a doubling macro is refused.