Skip to content

Commit

Permalink
fix copy_report dev mode validation
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed May 21, 2024
1 parent 67f53a3 commit 93ba9d8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/abstractinterpret/abstractanalyzer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ function add_new_report!(analyzer::AbstractAnalyzer, result::InferenceResult, @n
end

function add_cached_report!(analyzer::AbstractAnalyzer, caller::InferenceResult, @nospecialize(cached::InferenceErrorReport))
cached = copy_report′(cached)
cached = copy_report_stable(cached)
push!(get_reports(analyzer, caller), cached)
return cached
end
Expand Down
14 changes: 7 additions & 7 deletions src/abstractinterpret/inferenceerrorreport.jl
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,10 @@ function InferenceErrorReport() end
# ----------

"""
copy_report(report::Report) where Report<:InferenceErrorReport -> new::Report
copy_report(orig::Report) where Report<:InferenceErrorReport -> new::Report
Returns new `new::Report`, that should be identical to the original `report::Report`, except
that `new.vst` is copied from `report.vst` so that the further modification on `report.vst`
Returns new `new::Report`, that should be identical to the original `orig::Report`, except
that `new.vst` is copied from `orig.vst` so that the further modification on `orig.vst`
that may happen in later abstract interpretation doesn't affect `new.vst`.
"""
@noinline copy_report(report::InferenceErrorReport) = (@nospecialize;
Expand Down Expand Up @@ -501,20 +501,20 @@ report_color(::InferenceErrorReport) = ERROR_COLOR
end
end

# type stable version (assuming it satisfies the interface correctly)
function copy_report′(@nospecialize report::InferenceErrorReport)
# type stable version (assuming all reports satisfy the interface requirements)
function copy_report_stable(@nospecialize report::InferenceErrorReport)
@static if JET_DEV_MODE
new = copy_report(report)
Report = typeof(report)
if !isa(new, Report)
if !(new isa Report)
error(lazy"""
bad `$InferenceErrorReport` interface:
`$copy_report(::$Report)` should return new `$Report`.
See the documentation of `$InferenceErrorReport` and `$copy_report`
""")
end
new = new::InferenceErrorReport
if report.vst === new.vst && (@static JET_DEV_MODE ? report.vst == new.vst : true)
if report.vst === new.vst
error(lazy"""
bad `$InferenceErrorReport` interface:
`$copy_report(report::$Report).vst` should be a copy of `report.vst`.
Expand Down
4 changes: 2 additions & 2 deletions src/abstractinterpret/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ end
# cache
# =====

cache_report!(cache::Vector{InferenceErrorReport}, @nospecialize(report::InferenceErrorReport)) =
push!(cache, copy_report′(report)::InferenceErrorReport)
cache_report!(cache::Vector{InferenceErrorReport}, @nospecialize report::InferenceErrorReport) =
push!(cache, copy_report_stable(report))

struct AbstractAnalyzerView{Analyzer<:AbstractAnalyzer}
analyzer::Analyzer
Expand Down

0 comments on commit 93ba9d8

Please sign in to comment.