3 ms·
can someone expound on what this does exactly and how it works? Will the compiler try to statically verify that it is actually pure and error if it can't? Does
by gameswithgo 8y ago
can someone expound on what this does exactly and how it works? Will the compiler try to statically verify that it is actually pure and error if it can't? Does it unlock optimizations or other features?
- nepeckman 8y agoYes 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.