LYR-CT0002
a compile-time evaluation over its budget
A comptime site, or a macro's expansion, runs more interpreter steps than its budget: 50 000 000 by default, or what comptimeBudget under [package] in the root lyric.toml sets.
Explanation
Each site has a budget of steps, so a loop that does not end at compile time ends the compilation with an error instead of hanging it. The budget is per site; one site's work does not count against another's.
Make the computation smaller, move it to run time, or raise comptimeBudget in the manifest.
Wrong
//- lyric.toml
[package]
name = "app"
version = "0.1.0"
comptimeBudget = 1000
//- src/main.lyr
fn count(n: int): int {
var i = 0;
while (i < n) {
i += 1;
}
return i;
}
fn main(): void {
let n = comptime count(1000000);
assert(n == 1000000);
}
Right
//- lyric.toml
[package]
name = "app"
version = "0.1.0"
comptimeBudget = 1000
//- src/main.lyr
fn count(n: int): int {
var i = 0;
while (i < n) {
i += 1;
}
return i;
}
fn main(): void {
let n = comptime count(100);
assert(n == 100);
}