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

Fix tmerge for (partially) const types with undef fields #43812

Merged
merged 3 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 6 additions & 2 deletions base/compiler/typelimits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,12 @@ function tmerge(@nospecialize(typea), @nospecialize(typeb))
fields = Vector{Any}(undef, type_nfields)
anyconst = false
for i = 1:type_nfields
ity = tmerge(getfield_tfunc(typea, Const(i)),
getfield_tfunc(typeb, Const(i)))
ai = getfield_tfunc(typea, Const(i))
bi = getfield_tfunc(typeb, Const(i))
ity = tmerge(ai, bi)
if ai === Union{} || bi == Union{}
martinholters marked this conversation as resolved.
Show resolved Hide resolved
ity = widenconst(ity)
end
fields[i] = ity
anyconst |= has_nontrivial_const_info(ity)
end
Expand Down
18 changes: 18 additions & 0 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3988,3 +3988,21 @@ end |> only == Int
end
end |> only === Union{UnionNarrowingByIsdefinedA, UnionNarrowingByIsdefinedB}
end

# issue #43784
@testset "issue #43784" begin
init = Base.ImmutableDict{Any,Any}()
a = Const(init)
b = Core.PartialStruct(typeof(init), Any[Const(init), Any, Any])
c = Core.Compiler.tmerge(a, b)
@test ⊑(a, c)
@test ⊑(b, c)

function f()
g = init
while true
g = Base.ImmutableDict(g, 1=>2)
end
end
@test Base.return_types(f, ()) |> only === Union{}
end
martinholters marked this conversation as resolved.
Show resolved Hide resolved