Skip to content

Commit

Permalink
add deepcopy to Cached constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
jumerckx committed Dec 17, 2024
1 parent 588cebb commit 55d1527
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import ..Reactant:
make_tracer,
TracedToConcrete,
append_path,
TracedType
TracedType,
Cached
using ScopedValues
import ReactantCore: enable_tracing

Expand Down Expand Up @@ -284,7 +285,7 @@ function compile_mlir(f, args; kwargs...)
@ccall MLIR.API.mlir_c.RegisterDialects(ctx::MLIR.API.MlirContext)::Cvoid
MLIR.IR.context!(ctx) do
mod = MLIR.IR.Module(MLIR.IR.Location())
callcache = Dict()
callcache = Dict{Cached, @NamedTuple{f_name::String, mlir_result_types::Vector{MLIR.IR.Type}, traced_result::Any}}()
evalinfo = compile_mlir!(mod, f, args, callcache; kwargs...)
return mod, evalinfo...
end
Expand Down
3 changes: 3 additions & 0 deletions src/ControlFlow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ end

struct Cached
obj
# `deepcopy` is needed for when a Cached object is used as a key in a Dict.
# If the original object is mutated, the key should stay the same:
Cached(obj) = new(deepcopy(obj))
end
Base.:(==)(a::Cached, b::Cached) = recursive_equal(a.obj, b.obj)
Base.hash(a::Cached, h::UInt) = recursive_hash(a.obj, h)
Expand Down

0 comments on commit 55d1527

Please sign in to comment.