From 73b448df236fb771a004e59295eb2763f543537e Mon Sep 17 00:00:00 2001 From: marius Date: Wed, 26 May 2021 17:49:38 -0700 Subject: [PATCH] allow memoized calls during module precompilation --- src/Memoization.jl | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Memoization.jl b/src/Memoization.jl index 9f80bc1..bafd474 100644 --- a/src/Memoization.jl +++ b/src/Memoization.jl @@ -37,11 +37,12 @@ end # compile-time for statically memoizable functions and improve # performance. @generated function get_cache(default::Base.Callable, func::F) where {F} - if statically_memoizable(F) - # If the function is statically memoizable, the first - # lookup is dynamic, but we also define a specialized - # get_cache method which makes every subsequent lookup - # static. + if statically_memoizable(F) && ccall(:jl_generating_output,Cint,())!=1 + # If the function is statically memoizable and were not + # current precompiling (in which case the @eval below is + # disallowed), then in addition to dynamically looking up the + # right cache, we also define a specialized `get_cache` which + # makes every subsequent lookup static. quote @eval @generated get_cache(::Base.Callable, ::$F) = caches[$(F.instance)] _get!(default, $caches, func)