Skip to content

Commit

Permalink
inference: fix #42090, make sure not to wrap Conditional in `Partia…
Browse files Browse the repository at this point in the history
…lStruct` (#42091)

(cherry picked from commit 03e7b23)
  • Loading branch information
aviatesk authored and staticfloat committed Dec 22, 2022
1 parent e9c99fa commit 3280a02
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ function abstract_eval_statement(interp::AbstractInterpreter, @nospecialize(e),
anyconst = false
allconst = true
for i = 2:length(e.args)
at = abstract_eval_value(interp, e.args[i], vtypes, sv)
at = widenconditional(abstract_eval_value(interp, e.args[i], vtypes, sv))
if !anyconst
anyconst = has_nontrivial_const_info(at)
end
Expand Down
23 changes: 23 additions & 0 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1719,6 +1719,29 @@ for expr25261 in opt25261[i:end]
end
@test foundslot

# https://github.com/JuliaLang/julia/issues/42090#issuecomment-911824851
# `PartialStruct` shoudln't wrap `Conditional`
let M = Module()
@eval M begin
struct BePartialStruct
val::Int
cond
end
end

rt = @eval M begin
Base.return_types((Union{Nothing,Int},)) do a
cond = a === nothing
obj = $(Expr(:new, M.BePartialStruct, 42, :cond))
r1 = getfield(obj, :cond) ? 0 : a # r1::Union{Nothing,Int}, not r1::Int (because PartialStruct doesn't wrap Conditional)
a = $(gensym(:anyvar))::Any
r2 = getfield(obj, :cond) ? a : nothing # r2::Any, not r2::Const(nothing) (we don't need to worry about constrait invalidation here)
return r1, r2 # ::Tuple{Union{Nothing,Int},Any}
end |> only
end
@test rt == Tuple{Union{Nothing,Int},Any}
end

function f25579(g)
h = g[]
t = (h === nothing)
Expand Down

0 comments on commit 3280a02

Please sign in to comment.