Skip to content

Commit

Permalink
Get rid of eval
Browse files Browse the repository at this point in the history
Fix JuliaCollections#48, at the cost of putting the variable in a poorly-performing global.

Not sure if this is acceptable. It's frustrating that Julia seemingly lacks the tools to deal with
this elegantly.

- If `const` worked in a local function, we'd just put `const` and be done with it.
- If `typeconst` existed for global variables, that would work too.

Memoization.jl uses generated functions, which causes other problems. And it feels like the
wrong solution too.
  • Loading branch information
cstjean authored and willow-ahrens committed Jan 5, 2021
1 parent 697ce88 commit db41394
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/Memoize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ macro memoize(args...)

fcachename = cache_name(f)
mod = __module__
fcache = isdefined(mod, fcachename) ?
getfield(mod, fcachename) :
Core.eval(mod, :(const $fcachename = $cache_dict))

body = quote
get!($fcache, ($(tup...),)) do
Expand All @@ -72,8 +69,10 @@ macro memoize(args...)
end

esc(quote
$fcachename = $cache_dict # this should be `const` for performance, but then this
# fails the local-function cache test.
$(combinedef(def_dict_unmemoized))
empty!($fcache)
empty!($fcachename)
Base.@__doc__ $(combinedef(def_dict))
end)

Expand Down

0 comments on commit db41394

Please sign in to comment.