Skip to content

Commit

Permalink
allow memoized calls during module precompilation
Browse files Browse the repository at this point in the history
  • Loading branch information
marius311 committed May 27, 2021
1 parent 71a89f1 commit 73b448d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/Memoization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 73b448d

Please sign in to comment.