Esc

large_stack_array

Finds a local fixed array bigger than max_stack_array_bytes (default 64 KiB).

Category pedantic, allow by default.

Off by default; the example is shown with the rule enabled.

Example
#import "Basic";

main :: () {
    scratch: [1 << 20] u8;
    scratch[0] = 1;

    print("%\n", scratch[0]);
}
Diagnostic
warning[large_stack_array]: `scratch` is 1 MiB on the stack, past the limit of 64 KiB
  --> example.jai:4:5
   |
 4 |     scratch: [1 << 20] u8;
   |     ^^^^^^^
   |
   = help: allocate it (`NewArray`, `alloc`), use a resizable array, or keep it in a global
Fixed
#import "Basic";

main :: () {
    scratch := NewArray(1 << 20, u8);
    defer free(scratch.data);
    scratch[0] = 1;

    print("%\n", scratch[0]);
}

Locals live on the stack, which is small (a thread's is often 1 MiB or less) and shared with deep recursion, so a local of a megabyte can overflow it with no message beyond a crash.