Error codes

E0421: not a compile-time constant, or a raw assert that fails

In a terminal: auk explain E0421 prints this page.

On this page

The runtime's dialect (docs/lowlevel.md) settles some things when it compiles: the memory order of an atomic, the initializers of raw let, raw var and export var, and the layout checks of raw assert. These must be constant expressions (literals, other raw lets, raw.size_of<T>(), raw.offset_of<T>(.f), arithmetic), and a raw assert must hold.

Wrong#

toml
[package]
name = "auk_rt"
version = "0.1.0"
effects = ["raw"]
auk
fn get(p: raw.Ptr<i64>, o: raw.Order): i64 uses raw = raw.atomic_load(p, o)

Fixed#

auk
fn get(p: raw.Ptr<i64>): i64 uses raw = raw.atomic_load(p, raw.Order.Acquire)

Common causes#

  • A memory order passed as a value: write raw.Order.X at each atomic.
  • A global initialized with a function call: compute it at startup instead.
  • A raw assert on a layout that changed: update the raw struct or the C header together.

Stuck on a word? Try the glossary. Got a compiler error? Look up its code. Improve this page