Skip to content

Commit

Permalink
use CC.add_invalidation_callback! if available (#573)
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk authored Nov 1, 2023
1 parent a06c4ad commit 6ca37dd
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/abstractinterpret/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,22 @@ function CC.setindex!(wvc::WorldView{<:AbstractAnalyzerView}, ci::CodeInstance,
analysis_cache[mi] = ci
end

struct JETCallback
analysis_cache::AnalysisCache
end

@static if VERSION v"1.11.0-DEV.798"

function add_jet_callback!(mi::MethodInstance, analysis_cache::AnalysisCache)
callback = JETCallback(analysis_cache)
CC.add_invalidation_callback!(callback, mi)
end
function (callback::JETCallback)(replaced::MethodInstance, max_world::UInt32)
delete!(callback.analysis_cache, replaced)
end

else

function add_jet_callback!(mi::MethodInstance, analysis_cache::AnalysisCache)
callback = JETCallback(analysis_cache)
if !isdefined(mi, :callbacks)
Expand All @@ -293,10 +309,7 @@ function add_jet_callback!(mi::MethodInstance, analysis_cache::AnalysisCache)
return nothing
end

struct JETCallback
analysis_cache::AnalysisCache
end
function (callback::JETCallback)(replaced::MethodInstance, max_world,
function (callback::JETCallback)(replaced::MethodInstance, max_world::UInt32,
seen::IdSet{MethodInstance} = IdSet{MethodInstance}())
push!(seen, replaced)
delete!(callback.analysis_cache, replaced)
Expand All @@ -311,6 +324,8 @@ function (callback::JETCallback)(replaced::MethodInstance, max_world,
return nothing
end

end

# local
# -----

Expand Down

0 comments on commit 6ca37dd

Please sign in to comment.