Skip to content

Commit 5fc54e2

Browse files
committed
update caching behavior from extension
1 parent e176896 commit 5fc54e2

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

‎docs/src/Changelog.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ When releasing a new version, move the "Unreleased" changes to a new version sec
2828

2929
- Extend VectorInterface compat to include v0.7
3030
- Require TensorKitSectors v0.3.10
31-
- `@cached` can be used from other modules, such as package extensions, which then own the cache of the methods they add; these caches are shown with their module in `global_cache_info` (internal)
31+
- `@cached` can be used from other modules, such as package extensions, which then own the cache of the methods they add; these caches are shown with their module in `global_cache_info` after registration in `__init__` (internal)
3232
- The `TreeTransformer`s used in index manipulations are now constructed and cached per storagetype of the destination tensor, which is also a dispatch point for storage-specific transformers with their own cache (internal)
3333

3434
### Deprecated

‎src/auxiliary/caches.jl‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ end
5656

5757
# timer sections are controlled by the `timeit_debug_enabled` switch of the module using `@cached`
5858
_timeit_expr(label, ex) =
59-
Expr(:macrocall, GlobalRef(TimerOutputs, Symbol("@timeit_debug")), LineNumberNode(@__LINE__, @__FILE__), GLOBAL_TIMER, label, ex)
59+
Expr(:macrocall, GlobalRef(TimerOutputs, Symbol("@timeit_debug")), LineNumberNode(@__LINE__, @__FILE__), GlobalRef(@__MODULE__, :GLOBAL_TIMER), label, ex)
6060

6161
macro cached(ex)
6262
return _cached(__module__, ex)
@@ -221,11 +221,12 @@ function _cached(mod::Module, ex)
221221
:const,
222222
Expr(:(=), globalcachename, :($LRU{Any, Any}(; maxsize = $DEFAULT_GLOBALCACHE_SIZE[])))
223223
)
224-
# caches of other modules (e.g. extensions adding methods) are registered with their module
225-
registername = mod === (@__MODULE__) ? globalcachename : Symbol(nameof(mod), ".", globalcachename)
226-
fglobalcacheregister = Expr(
227-
:call, :push!, GLOBAL_CACHES, :($(QuoteNode(registername)) => $globalcachename)
228-
)
224+
# Other modules register their caches explicitly from `__init__`, since
225+
# mutations of this registry during their precompilation do not survive loading.
226+
fglobalcacheregister = mod === (@__MODULE__) ? Expr(
227+
:call, :push!, GlobalRef(@__MODULE__, :GLOBAL_CACHES),
228+
:($(QuoteNode(globalcachename)) => $globalcachename)
229+
) : nothing
229230

230231
# # total expression
231232
return esc(

0 commit comments

Comments
 (0)