Skip to content

Commit

Permalink
invalidate internal code cache anyway when JET hasn't analyzed it yet
Browse files Browse the repository at this point in the history
this will of course slow down analysis peformance, but should give us 
more correct analysis

it reveals the truth of lots of hidden false positives though ...
  • Loading branch information
aviatesk committed Oct 22, 2020
1 parent 19fb19d commit 4eb2bcc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 14 additions & 7 deletions src/jetcache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,26 @@ CC.WorldView(tpc::JETCache, args...) = WorldView(tpc, WorldRange(args...))

CC.haskey(tpc::JETCache, mi::MethodInstance) = CC.haskey(tpc.native, mi)

const ANALYZED_LINFOS = IdSet{MethodInstance}() # keeps `MethodInstances` analyzed by JET
const ERRORNEOUS_LINFOS = IdDict{MethodInstance,Symbol}() # keeps `MethodInstances` analyzed as "errorneous" by JET

function CC.get(tpc::JETCache, mi::MethodInstance, default)
force_invalidate_self_code_cache(mi) && return default
# if we haven't analyzed this linfo, just invalidate native code cache and force analysis by JET
if mi ANALYZED_LINFOS
push!(ANALYZED_LINFOS, mi)
return default
end

ret = CC.get(tpc.native, mi, default)

isa(ret, CodeInstance) || return default
# cache isn't really found
if ret === default
return ret
end

# cache hit, now we need to invalidate the cache lookup if this `mi` has been profiled
# as erroneous by JET or is seemingly erroneous (checked by its return type annotation);
# otherwise the error reports that can occur from this frame will just be ignored
# as erroneous by JET analysis; otherwise the error reports that can occur from this
# frame will just be ignored
force_inference = false

if haskey(ERRORNEOUS_LINFOS, mi)
Expand All @@ -32,9 +42,6 @@ function CC.get(tpc::JETCache, mi::MethodInstance, default)
if ERRORNEOUS_LINFOS[mi] !== get_id(tpc.interp)
force_inference = true
end
elseif isdefined(ret, :rettype) && ret.rettype === Bottom
# return type is annotated as `Bottom` (by native compiler), let's force inference
force_inference = true
end

return force_inference ? default : ret
Expand Down
2 changes: 0 additions & 2 deletions src/reports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ const Lineage = IdSet{MethodInstance}
is_lineage(linfo::MethodInstance, report::InferenceErrorReport) = is_lineage(linfo, report.lineage)
is_lineage(linfo::MethodInstance, lineage::Lineage) = linfo in lineage

const ERRORNEOUS_LINFOS = IdDict{MethodInstance,Symbol}()

macro reportdef(ex, kwargs...)
T = first(ex.args)
args = map(ex.args) do x
Expand Down

0 comments on commit 4eb2bcc

Please sign in to comment.