Mutable struct vs closure

That’s not what @pure means, unfortunately.

Afaik @pure also asserts to the compiler that the function is side-effect free, which is not true in your case. The compiler also cares about side-effects that are invisible to users that adhere to the published API. This specific case might still be OK in practice, but you are lying to the compiler. Hell if I know how @pure, serialization of your module’s global state (during precompilation), multithreading, etc all interact, now and in the future. And yes, your function is decidedly non-thread-safe: Two threads resizing the cache at the same time can probably segfault.

PS: Also everything @dawbarton said.

3 Likes