JuliaCollections/Memoize.jl

Remove `eval` from at-memoize macro

オープン

#48 opened on 2020/02/19

 (4 件のコメント) (0 件のリアクション) (0 人の担当者)Julia (21 件のフォーク)github user discovery
help wanted

Repository metrics

Stars
 (198 個のスター)
PR merge metrics
 (平均マージ 11h 28m) (30d で 2 merged PRs)

説明

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

コントリビューターガイド