Skip to content

Commit 575a732

Browse files
authored
use IdDict{MethodInstance} instead of Dict{MethodInstance} (#534)
1 parent c93216d commit 575a732

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

src/Cthulhu.jl

-2
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,6 @@ end
266266
get_effects(codeinst::CodeInstance) = CC.decode_effects(codeinst.ipo_purity_bits)
267267
get_effects(codeinst::CodeInfo) = CC.decode_effects(codeinst.purity)
268268
get_effects(src::InferredSource) = src.effects
269-
get_effects(unopt::Dict{Union{MethodInstance, InferenceResult}, InferredSource}, mi::MethodInstance) =
270-
haskey(unopt, mi) ? get_effects(unopt[mi]) : Effects()
271269
get_effects(result::InferenceResult) = result.ipo_effects
272270
get_effects(result::CC.ConstPropResult) = get_effects(result.result)
273271
get_effects(result::CC.ConcreteResult) = result.effects

src/interface.jl

+4-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ get_excts(interp::CthulhuInterpreter, key::InferenceKey) = get(interp.exception_
8181
# a sensible default cursor for a MethodInstance
8282
AbstractCursor(interp::AbstractInterpreter, mi::MethodInstance) = CthulhuCursor(mi)
8383

84-
get_effects(interp::CthulhuInterpreter, mi::MethodInstance, opt::Bool) =
85-
get_effects(opt ? interp.opt : interp.unopt, mi)
84+
function get_effects(interp::CthulhuInterpreter, mi::MethodInstance, opt::Bool)
85+
effects = opt ? interp.opt : interp.unopt
86+
return haskey(effects, mi) ? get_effects(effects[mi]) : Effects()
87+
end
8688

8789
mutable struct CustomToggle
8890
onoff::Bool

src/interpreter.jl

+5-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ struct OptimizedSource
2323
end
2424

2525
const InferenceKey = Union{MethodInstance,InferenceResult}
26-
const InferenceDict{T} = Dict{InferenceKey, T}
26+
const InferenceDict{T} = IdDict{InferenceKey, T}
27+
const OptimizationDict = IdDict{MethodInstance, CodeInstance}
2728
const PC2Remarks = Vector{Pair{Int, String}}
2829
const PC2Effects = Dict{Int, Effects}
2930
const PC2Excts = Dict{Int, Any}
@@ -32,7 +33,7 @@ struct CthulhuInterpreter <: AbstractInterpreter
3233
native::AbstractInterpreter
3334

3435
unopt::InferenceDict{InferredSource}
35-
opt::Dict{MethodInstance, CodeInstance}
36+
opt::OptimizationDict
3637

3738
remarks::InferenceDict{PC2Remarks}
3839
effects::InferenceDict{PC2Effects}
@@ -43,7 +44,7 @@ function CthulhuInterpreter(interp::AbstractInterpreter=NativeInterpreter())
4344
return CthulhuInterpreter(
4445
interp,
4546
InferenceDict{InferredSource}(),
46-
Dict{MethodInstance, CodeInstance}(),
47+
OptimizationDict(),
4748
InferenceDict{PC2Remarks}(),
4849
InferenceDict{PC2Effects}(),
4950
InferenceDict{PC2Excts}())
@@ -69,7 +70,7 @@ CC.lock_mi_inference(interp::CthulhuInterpreter, mi::MethodInstance) = nothing
6970
CC.unlock_mi_inference(interp::CthulhuInterpreter, mi::MethodInstance) = nothing
7071
CC.method_table(interp::CthulhuInterpreter) = method_table(interp.native)
7172
struct CthulhuCache
72-
cache::Dict{MethodInstance, CodeInstance}
73+
cache::OptimizationDict
7374
end
7475

7576
CC.code_cache(interp::CthulhuInterpreter) = WorldView(CthulhuCache(interp.opt), WorldRange(get_world_counter(interp)))

0 commit comments

Comments
 (0)