-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: cache reports with internal ocde cache
- Loading branch information
Showing
6 changed files
with
144 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# global cache | ||
# ------------ | ||
|
||
struct InferenceReportCache{T<:InferenceErrorReport} | ||
st::ViewedVirtualStackTrace | ||
msg::String | ||
sig::String | ||
end | ||
const TPCACHE = Dict{UInt,Pair{UInt,InferenceReportCache}}() | ||
|
||
function get_report_cache(sv::InferenceState, cache::InferenceReportCache{T}) where {T<:InferenceErrorReport} | ||
cur_st = track_abstract_call_stack!((args...)->nothing, sv) | ||
st = append!(cur_st, cache.st) | ||
return T(st, cache.msg, cache.sig) | ||
end | ||
|
||
# code cache interface | ||
# -------------------- | ||
|
||
struct TPCache{NativeCache} | ||
interp::TPInterpreter | ||
native::NativeCache | ||
TPCache(interp, native::NativeCache) where {NativeCache} = new{NativeCache}(interp, native) | ||
end | ||
WorldView(tpc::TPCache, wr::WorldRange) = TPCache(tpc.interp, WorldView(tpc.native, wr)) | ||
|
||
CC.haskey(tpc::TPCache, mi::MethodInstance) = CC.haskey(tpc.native, mi) | ||
|
||
function CC.get(tpc::TPCache, mi::MethodInstance, default) | ||
ret = CC.get(tpc.native, mi, default) | ||
|
||
# cache hit | ||
if ret !== default | ||
key = hash(mi) | ||
if haskey(TPCACHE, key) | ||
interp_key, cache = TPCACHE[key] | ||
interp = tpc.interp | ||
if hash(interp) != interp_key | ||
frame = get_current_frame(interp) | ||
report = get_report_cache(frame, cache) | ||
push!(interp.reports, report) | ||
end | ||
end | ||
end | ||
|
||
return ret | ||
end | ||
|
||
CC.getindex(tpc::TPCache, mi::MethodInstance) = CC.getindex(tpc.native, mi) | ||
|
||
CC.setindex!(tpc::TPCache, ci::CodeInstance, mi::MethodInstance) = CC.setindex!(tpc.native, ci, mi) |