Which integer subtypes in Nim bypass overflow checks under release optimization?
0 reputation · 08 Nov 2022, 20:50 UTC
Nim's integer overflow handling in release builds relies on wrapping arithmetic by default, which maps directly to machine-word operations and avoids runtime checks for performance. The --check:overflow flag and compiler configuration can enable overflow checks, but their interaction with user-defined integer subtypes, optimization pragmas, and external C library types remains ambiguous. Specifically, it is unclear whether checks are uniformly applied across all integer sizes or if certain subtypes bypass enforcement when optimization is active. This ambiguity affects both correctness guarantees and performance predictability in safety-critical modules.
Which integer subtypes in Nim are exempt from --check:overflow enforcement under -O3? How does the compiler decide where to insert overflow checks when optimization levels vary? What performance overhead is incurred when enabling checks in loops involving custom integer types?