From 93ba9d8a44a3a8f7855a94f8e51483086cffa46a Mon Sep 17 00:00:00 2001 From: Shuhei Kadowaki Date: Tue, 21 May 2024 19:50:38 +0900 Subject: [PATCH] fix `copy_report` dev mode validation --- src/abstractinterpret/abstractanalyzer.jl | 2 +- src/abstractinterpret/inferenceerrorreport.jl | 14 +++++++------- src/abstractinterpret/typeinfer.jl | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/abstractinterpret/abstractanalyzer.jl b/src/abstractinterpret/abstractanalyzer.jl index 24cf96415..de4152475 100644 --- a/src/abstractinterpret/abstractanalyzer.jl +++ b/src/abstractinterpret/abstractanalyzer.jl @@ -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 diff --git a/src/abstractinterpret/inferenceerrorreport.jl b/src/abstractinterpret/inferenceerrorreport.jl index 07882184d..abb12fc4f 100644 --- a/src/abstractinterpret/inferenceerrorreport.jl +++ b/src/abstractinterpret/inferenceerrorreport.jl @@ -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; @@ -501,12 +501,12 @@ 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`. @@ -514,7 +514,7 @@ function copy_report′(@nospecialize report::InferenceErrorReport) """) 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`. diff --git a/src/abstractinterpret/typeinfer.jl b/src/abstractinterpret/typeinfer.jl index 45b3cb02e..27018fb5f 100644 --- a/src/abstractinterpret/typeinfer.jl +++ b/src/abstractinterpret/typeinfer.jl @@ -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