I'm trying to run some proc with threads and get this error:
crawl.nim(9, 6) Error: 'run_crawler' is not GC-safe as it calls 'build_jobs'
The problem is that there are lots of code that it uses. In this case it complains about the build_jobs proc, but it in itself uses lots of other procs.
Is there a way to discover what exactly in dependencies of build_jobs cause the GC-safe problem?
And is it possible to force Nim to run the code anyway?
var global: seq[string]
proc violation =
var s = global
proc q() = violation()
proc p() {.gcsafe.} = q()
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'
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.
In practice it works better to annotate many of your procs directly with the effects you had in mind.
Would it be a good way to prefer to use func instead of proc everywhere if it's possible?
Also, I wonder why func is not used more heavily, I see people mostly use proc even in cases where func could be used.