Skip to content

Commit 8bb339e

Browse files
committed
refactor: introduce HashConsingWrapper for improved WeakKeyDict
1 parent fcd6b52 commit 8bb339e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/types.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,15 @@ function exprtype(x::BasicSymbolic)
8686
end
8787
end
8888

89-
const wvd = TaskLocalValue{WeakValueDict{UInt, BasicSymbolic}}(WeakValueDict{UInt, BasicSymbolic})
89+
mutable struct HashConsingWrapper
90+
bs::BasicSymbolic
91+
end
92+
93+
Base.hash(x::HashConsingWrapper, h::UInt) = hash2(x.bs, h)
94+
95+
Base.isequal(x::HashConsingWrapper, y::HashConsingWrapper) = isequal_with_metadata(x.bs, y.bs)
96+
97+
const wkd = TaskLocalValue{WeakKeyDict{HashConsingWrapper, Nothing}}(WeakKeyDict{HashConsingWrapper, Nothing})
9098

9199
# Same but different error messages
92100
@noinline error_on_type() = error("Internal error: unreachable reached!")

0 commit comments

Comments
 (0)