Keep in mind though that this "my code is logically without side effects" is
useless in a multi-threaded environment. It can be as logical as you want, the
tables will cause threaded code to crash.
I am fine with Araq's solution.
Passing cache table as argument is not an option, because it needs to be
updated on every request which is a side effect. Returning a copy of table on
every call is not an option either, as its size is 64GB. It is cache of matrices
In regards to cdome's original question, I think tricking the compiler to
ignore side effects for a certain function is the wrong way to go about this.
If the memoization table was passed as a function parameter, the function would
have no side effects, with no tricks involved.
@Araq Oh, I shold bold it I mean Nim optimization and inlining, not C's ones...
as weird as it sounds. I mean, any pattern-template or pattern-macro which
matches a noSideEffect routine would match here, despite the fact this routine
has side effects, actually. I guess whenever it's good or not
Well it's not "nasty", 'cast' is used to circumvent the type system. Probably
needs better documentation in the manual. Pretty sure the C backend can see
through the cast and inline it anyway.
@Araq That looks nasty! Wouldn't it confuse the compiler? Also --- it prevents
inlining, I guess?
There is a way to hide this, but I don't know if it's a good idea for your use
case.
proc sideEffect(a, b: string) = echo a, b
proc lacksSideEffect() {.noSideEffect.} =
cast[proc (a, b: string) {.nimcall, noSideEffect.}](sideEffect)()
I don't think it's something you should actually do as the compiler can do
certain optimizations when it knows a routine has no side effects.
Optimizations which may opt out your side effects, I guess.
Hi, I am actively using Nim's side effect tracking system and marking procs
with noSideEffect pretty much everywhere. I have external requirement not to
have side effects and Nim helps here quite a bit.
However, I have place in a code that logically I don't have side effects, but
physically I