Skip to content

Effects tracking includes when nimvm: blocks (exceptions, gcsafe, etc) even at runtime #26049

Description

@tersec

Nim Version

Nim Compiler Version 2.2.10 [Linux: amd64]
Compiled at 2026-05-27
Copyright (c) 2006-2026 by Andreas Rumpf

active boot switches: -d:release
Nim Compiler Version 2.2.11 [Linux: amd64]
Compiled at 2026-07-27
Copyright (c) 2006-2026 by Andreas Rumpf

git hash: a0d09f01c511b40800d93e8ad23cfcf8939fffed
active boot switches: -d:release
Nim Compiler Version 2.3.1 [Linux: amd64]
Compiled at 2026-07-27
Copyright (c) 2006-2026 by Andreas Rumpf

git hash: 2d8114929450ad621a2ef0108bbf1267c45145fc
active boot switches: -d:release

Description

var b: string
proc p(): string {.gcsafe.} =
  when nimvm:
    doAssert false
    result = b
discard p()

The GC safety should only be an issue in the compiletime/VM environment. Outside of that, it doesn't access globals/violate GC safety. If one removes {.gcsafe.}, it runs and does not assert at runtime, i.e. that result = b effect has not fired.

Current Output

/tmp/w.nim(2, 6) Error: 'p' is not GC-safe as it accesses 'b' which is a global using GC'ed memory

Expected Output

Not tracking VM-only effects in runtime-only codepaths

Known Workarounds

No response

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions