E3032

E3032 — A chain of generic instantiations that does not end — f<N - 1>() whose base case is never reached. Reported here rather than left to run out of stack, which gave no file, no line and no message.

What the compiler reports

Error[E3032]{{.*}}generic calls deep and was stopped

The fragments the test suite holds the compiler to. An ellipsis marks text the test does not constrain; the emitted message also carries a source location.

A program that triggers it

//
// Part of the Vx Project, under the Apache License v2.0 with LLVM Exceptions.
// See LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// A generic recursion that never reaches its base case is reported, not crashed on.
//
// The base case returns, but the call after the `if` is checked anyway, so `N` goes
// 2, 1, 0, -1, -2 and never stops. Each round is a new instance checked inside the
// last, which used to take the compiler's stack down with no file and no message.
//

fn countdown<const N : i32>() -> i32 {
  if comptime N == 0 {
    return 0;
  }
  return countdown<N - 1>() + 1;
}

fn main() -> i32 {
  return countdown<3>();
}

From tests/frontend/fail/const_generic_runaway_instantiation.vx, which asserts this diagnostic on every commit.

Related