Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 1 addition & 51 deletions src/analyses/activity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -393,58 +393,9 @@ Base.@nospecializeinfer @inline function active_reg_inner(
return ty
end

const ActivityCache = Dict{Tuple{Type, Bool, Bool, Bool}, ActivityState}()

const ActivityWorldCache = Ref(0)

const ActivityMethodCache = Core.MethodMatch[]
# given the current worldage of compilation, check if there are any methods
# of inactive_type which may invalidate the cache, and if so clear it.
function check_activity_cache_invalidations(world::UInt)
# We've already guaranteed that this world doesn't have any stale caches
if world <= ActivityWorldCache[]
return
end

invalid = true

tt = Tuple{typeof(EnzymeRules.inactive_type), Type}

methods = Core.MethodMatch[]
matches = Base._methods_by_ftype(tt, -1, world)
if matches === nothing
@assert ActivityCache.size() == 0
return
end

methods = Core.MethodMatch[]
for match in matches::Vector
push!(methods, match::Core.MethodMatch)
end

if methods == ActivityMethodCache
return
end

empty!(ActivityCache)
empty!(ActivityMethodCache)
for match in matches::Vector
push!(ActivityMethodCache, match::Core.MethodMatch)
end

ActivityWorldCache[] = world

end

Base.@nospecializeinfer @inline function active_reg(@nospecialize(ST::Type), world::UInt; justActive=false, UnionSret = false, AbstractIsMixed = false)
key = (ST, justActive, UnionSret, AbstractIsMixed)
if haskey(ActivityCache, key)
return ActivityCache[key]
end
set = Base.IdSet{Type}()
result = active_reg_inner(ST, set, world, justActive, UnionSret, AbstractIsMixed)
ActivityCache[key] = result
return result
return active_reg_inner(ST, set, world, justActive, UnionSret, AbstractIsMixed)
end

function active_reg_nothrow_generator(world::UInt, source::LineNumberNode, T, self, _)
Expand All @@ -462,7 +413,6 @@ function active_reg_nothrow_generator(world::UInt, source::LineNumberNode, T, se
Core.Compiler.LineInfoNode(@__MODULE__, :active_reg_nothrow, source.file, Int32(source.line), Int32(0))
]
end
check_activity_cache_invalidations(world)
ci.min_world = world
ci.max_world = typemax(UInt)

Expand Down
6 changes: 1 addition & 5 deletions src/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6049,9 +6049,7 @@ end
StrongZero
) #=abiwrap=#
tmp_job = if World isa Nothing
jb = Compiler.CompilerJob(mi, CompilerConfig(target, params; kernel = false))
check_activity_cache_invalidations(jb.world)
jb
Compiler.CompilerJob(mi, CompilerConfig(target, params; kernel = false))
else
Compiler.CompilerJob(mi, CompilerConfig(target, params; kernel = false), World)
end
Expand Down Expand Up @@ -6245,8 +6243,6 @@ function thunk_generator(world::UInt, source::Union{Method, LineNumberNode}, @no

mi === nothing && return stub(world, source, method_error)

check_activity_cache_invalidations(world)

min_world2 = Ref{UInt}(typemin(UInt))
max_world2 = Ref{UInt}(typemax(UInt))

Expand Down
Loading