Skip to content

Commit

Permalink
inference: incorporate stackoverflow possibility into exc type modeli…
Browse files Browse the repository at this point in the history
…ng (JuliaLang#52268)

Currently `exc_bestguess` does not take into account the possibility of
stackoverflow error, causing the inconsistency between exception type
modeling and `:nothrow` modeling. This commit fixes it up.
  • Loading branch information
aviatesk authored and mkitti committed Dec 9, 2023
1 parent e0dfd9b commit bd58df2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions base/compiler/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,9 @@ function typeinf_edge(interp::AbstractInterpreter, method::Method, @nospecialize
update_valid_age!(caller, frame.valid_worlds)
effects = adjust_effects(Effects(), method)
exc_bestguess = refine_exception_type(frame.exc_bestguess, effects)
# this call can fail into an infinite cycle, so incorporate this fact into
# `exc_bestguess` by merging `StackOverflowError` into it
exc_bestguess = tmerge(typeinf_lattice(interp), Core.StackOverflowError, exc_bestguess)
return EdgeCallResult(frame.bestguess, exc_bestguess, nothing, effects)
end

Expand Down
5 changes: 3 additions & 2 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -423,12 +423,13 @@ A14009(a::T) where {T} = A14009{T}()
f14009(a) = rand(Bool) ? f14009(A14009(a)) : a
code_typed(f14009, (Int,))
code_llvm(devnull, f14009, (Int,))
@test Base.infer_exception_type(f14009, (Int,)) != Union{}

mutable struct B14009{T}; end
g14009(a) = g14009(B14009{a})
code_typed(g14009, (Type{Int},))
code_llvm(devnull, f14009, (Int,))

code_llvm(devnull, g14009, (Type{Int},))
@test Base.infer_exception_type(g14009, (Type{Int},)) == StackOverflowError

# issue #9232
arithtype9232(::Type{T},::Type{T}) where {T<:Real} = arithtype9232(T)
Expand Down

0 comments on commit bd58df2

Please sign in to comment.