Re: Hiding sideeffect from compiler

2017-11-16 Thread Araq
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.

Re: Hiding sideeffect from compiler

2017-11-15 Thread cdome
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

Re: Hiding sideeffect from compiler

2017-11-15 Thread pwernersbach
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.

Re: Hiding sideeffect from compiler

2017-11-15 Thread Udiknedormin
@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

Re: Hiding sideeffect from compiler

2017-11-15 Thread Araq
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.

Re: Hiding sideeffect from compiler

2017-11-15 Thread Udiknedormin
@Araq That looks nasty! Wouldn't it confuse the compiler? Also --- it prevents inlining, I guess?

Re: Hiding sideeffect from compiler

2017-11-13 Thread Araq
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)()

Re: Hiding sideeffect from compiler

2017-11-12 Thread Udiknedormin
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.

Hiding sideeffect from compiler

2017-11-10 Thread cdome
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