JuliaCollections/Memoize.jl

Remove `eval` from at-memoize macro

Aperta

#48 aperta il 19 feb 2020

 (4 commenti) (0 reazioni) (0 assegnatari)Julia (21 fork)github user discovery
help wanted

Metriche repository

Star
 (198 stelle)
Metriche merge PR
 (Merge medio 11h 28m) (2 PR mergiate in 30 g)

Descrizione

Right now, the @memoize macro creates the cache dictionary using eval: https://github.com/JuliaCollections/Memoize.jl/blob/1709785afc1eed40d7d35e6c3ebe5ae7e076f57e/src/Memoize.jl#L49-L52 This is generally considered a bad idea in macros, and until recently, also caused an error here because the code was evaling into the Memoize package (see #32).

Right now, using eval gives the following behavior:

  1. all memoized methods of a given function share the memoization cache
  2. if a method is overwritten, the cache is cleared, and any other global resources created/held by the previous version of that method are released: https://github.com/JuliaCollections/Memoize.jl/blob/1709785afc1eed40d7d35e6c3ebe5ae7e076f57e/test/runtests.jl#L257-L266

I made one attempt to simply use a different cache dictionary for each method of a given function (https://github.com/JuliaCollections/Memoize.jl/compare/JuliaCollections:1709785...JuliaCollections:a9170e5). This mostly works, but as-is causes the test above to fail, because the old cache is not released when the method is overwritten.

There may be an easy way around this, but it's not obvious to me right now.

Thoughts and/or pull requests welcome!

Cc: @cstjean

Guida contributor