assertions
nimony/lib/std/assertions.nim
const assertionsEnabled: boolWhether
assertexpands to anything at all. Follows Nim's convention:-d:releaseKEEPS assertions,-d:dangerremoves them, and-d:noAssertionsremoves them on its own — the last one so a build can drop the checks without also turning off bound checks and overflow checks, which is what you want when profiling: anassertcosts a compare, a branch and a string literal at every call site, and those are not what is being measured.proc raiseAssert(msg: string)template assert(cond: bool; msg: string)template assertRc(r: ref T not nil; expected: int64; tag: string)Diagnostic for ref-count tracking.
ris aref T, internally a pointer to{rc: int, d: T}(seearc.nim); reads the rc field at offset 0 and aborts when it differs fromexpected.arcDecreturns true when rc goes negative, so a fresh ref has rc=0 (= 1 logical reference); each=dupadds +1, each=destroyadds -1. UseassertRc(myRef, 0)after construction orassertRc(myRef, n)after n duplications to catch over- or under-counting before the symptom (UAF, double-free, leak) drifts far from the cause.template assertRcAlive(r: ref T not nil; tag: string)Looser assertRc: only fail when rc has already gone negative (i.e. the block has been freed and we're walking dangling memory). Useful when the exact rc varies with =dup/=destroy interleaving but you still want to catch use-after-free quickly. Also rejects bogus pointers (large absolute rc) since arcDec'd-into-positive-billions still indicates the block was reused for an unrelated allocation.