var global: seq[string]
    
    proc violation =
      var s = global
    
    proc q() = violation()
    
    proc p() {.gcsafe.} = q()
    
    
    Run

I do get a stack trace:
    
    
    temp2.nim(4, 6) Warning: 'violation' is not GC-safe as it accesses 'global' 
which is a global using GC'ed memory [GcUnsafe2]
    temp2.nim(7, 6) Warning: 'q' is not GC-safe as it calls 'violation' 
[GcUnsafe2]
    temp2.nim(9, 6) Error: 'p' is not GC-safe as it calls 'q'
    
    
    Run

Not always, because that's really hard to do plus you don't want the compiler 
to keep track of it in a way that causes an explosion of its memory consumption.

In practice it works better to annotate many of your procs directly with the 
effects you had in mind. It's for this very reason that I consider the effect 
"tracking" aspect of Nim its worst language wart. I tried to improve the 
situation, see for example <https://github.com/nim-lang/RFCs/issues/142> and 
the newer `.push raises: []` feature.

Reply via email to