From 02d3e413d849237794b0c896ed8d717804ef1b7b Mon Sep 17 00:00:00 2001 From: Shuhei Kadowaki Date: Sat, 14 Dec 2024 23:59:57 +0900 Subject: [PATCH] inference: handle cases where `:the_exception` is used independently `Expr(:the_exception)` is handled by the interpreter in all cases, however, inference assumes it is only used within frames containing `try/catch`. This commit corrects that assumption. --- Compiler/src/abstractinterpretation.jl | 6 +++++- Compiler/test/inference.jl | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Compiler/src/abstractinterpretation.jl b/Compiler/src/abstractinterpretation.jl index 2efd8a2b7264f..2316a32799368 100644 --- a/Compiler/src/abstractinterpretation.jl +++ b/Compiler/src/abstractinterpretation.jl @@ -3240,7 +3240,11 @@ function abstract_eval_throw_undef_if_not(interp::AbstractInterpreter, e::Expr, end function abstract_eval_the_exception(::AbstractInterpreter, sv::InferenceState) - (;handlers, handler_at) = sv.handler_info::HandlerInfo + (;handler_info) = sv + if handler_info === nothing + return the_exception_info(Any) + end + (;handlers, handler_at) = handler_info return the_exception_info(handlers[handler_at[sv.currpc][2]].exct) end abstract_eval_the_exception(::AbstractInterpreter, ::IRInterpretationState) = the_exception_info(Any) diff --git a/Compiler/test/inference.jl b/Compiler/test/inference.jl index c8b599adb1323..ddc15ccae524b 100644 --- a/Compiler/test/inference.jl +++ b/Compiler/test/inference.jl @@ -6125,3 +6125,8 @@ function func_swapglobal!_must_throw(x) end @test Base.infer_return_type(func_swapglobal!_must_throw, (Int,); interp=SwapGlobalInterp()) === Union{} @test !Compiler.is_effect_free(Base.infer_effects(func_swapglobal!_must_throw, (Int,); interp=SwapGlobalInterp()) ) + +@eval get_exception() = $(Expr(:the_exception)) +@test Base.infer_return_type() do + get_exception() +end <: Any