3 ms·
Yes and yes. From the manual: > If none of its parameters have the type var T or ref T or ptr T this means no locations are modified. It is a static error to m
by nepeckman 8y ago
Yes and yes. From the manual:
> If none of its parameters have the type var T or ref T or ptr T this means no locations are modified. It is a static error to mark a proc/iterator to have no side effect if the compiler cannot verify this.
I'm not sure how many compiler optimizations are possible, but I do know that procs marked with no side effect are automatically considered thread safe.
- e12e 8y agoWhat if your func iamsafe calls the proc imodifyglobals? More generally, can a "func" call a proc and remain a func?
- nepeckman 8y agoI'm not really a Nim expert, but I did a quick test on the scenario you laid out with these results: iamsafe could not call imodifyglobals, but could call a proc with no side effects. I'd guess that a func can call out to any proc that the compiler knows is side effect free, with the compiler erring on the side of caution.
- dom96 8y agoYep, AFAIK the compiler will do its best to infer the effects and most of the time it does a pretty good job.
- PMunch 8y agoNope, it can only call other side-effect free things. Note however if you call a procedure from a function the function will try to see if the proc is actually side effect free, just not marked as such. So you can still call a proc, but only if it could've been a func.