Skip to content

Commit

Permalink
use abstract_throw if available (#583)
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk authored Dec 12, 2023
1 parent 8a69a9a commit fd96b2f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
9 changes: 9 additions & 0 deletions src/analyzers/jetanalyzer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,15 @@ function CC.abstract_eval_value(analyzer::JETAnalyzer, @nospecialize(e), vtypes:
return ret
end

@static if VERSION v"1.11.0-DEV.1080"
function CC.abstract_throw(analyzer::JETAnalyzer, argtypes::Vector{Any}, sv::InferenceState)
ft = popfirst!(argtypes)
ReportPass(analyzer)(SeriousExceptionReport, analyzer, sv, argtypes)
pushfirst!(argtypes, ft)
return @invoke CC.abstract_throw(analyzer::AbstractAnalyzer, argtypes::Vector{Any}, sv::InferenceState)
end
end

function CC.builtin_tfunction(analyzer::JETAnalyzer,
@nospecialize(f), argtypes::Vector{Any}, sv::InferenceState) # `AbstractAnalyzer` isn't overloaded on `return_type`
ret = @invoke CC.builtin_tfunction(analyzer::AbstractAnalyzer,
Expand Down
24 changes: 9 additions & 15 deletions test/analyzers/test_jetanalyzer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -409,23 +409,17 @@ end
end
end

func_undef_keyword(a; kw) = a, kw # `kw` can be undefined
@testset "UndefKeywordError" begin
isa2(t) = x -> isa(x, t)
let
m = gen_virtual_module()
result = Core.eval(m, quote
foo(a; #= can be undef =# kw) = a, kw
$report_call(foo, (Any,))
end)
@test !isempty(get_reports_with_test(result))
@test any(get_reports_with_test(result)) do r
r isa SeriousExceptionReport || return false
err = r.err
err isa UndefKeywordError && err.var === :kw
end
# there shouldn't be duplicated report for the `throw` call
@test !any(isa2(UncaughtExceptionReport), get_reports_with_test(result))
result = report_call(func_undef_keyword, (Any,))
@test !isempty(get_reports_with_test(result))
@test any(get_reports_with_test(result)) do r
r isa SeriousExceptionReport || return false
err = r.err
err isa UndefKeywordError && err.var === :kw
end
# there shouldn't be duplicated report for the `throw` call
@test !any(r->isa(r,UncaughtExceptionReport), get_reports_with_test(result))
end

func_invalid_index(xs, i) = xs[i]
Expand Down

0 comments on commit fd96b2f

Please sign in to comment.