Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use abstract_throw if available #583

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading