JuliaCollections/Memoize.jl

Remove `eval` from at-memoize macro

Aberta

#48 aberto em 19 de fev. de 2020

 (4 comentários) (0 reação) (0 responsável)Julia (21 forks)github user discovery
help wanted

Métricas do repositório

Stars
 (198 estrelas)
Métricas de merge de PR
 (Mesclagem média 11h 28m) (2 fundiu PRs em 30d)

Description

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

Guia do colaborador