Skip to content

Commit

Permalink
inference: handle cases where :the_exception is used independently
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
aviatesk committed Dec 14, 2024
1 parent fe5ed17 commit 02d3e41
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Compiler/src/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions Compiler/test/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 02d3e41

Please sign in to comment.