Skip to content

Commit f230d48

Browse files
vtjnashKristofferC
authored andcommitted
Compiler: fix unsoundness of getfield_tfunc on Tuple Types (#57275)
This was noted in the original review of that PR by the PR author, but was for some reason not fixed at that time: #46693 (comment) (cherry picked from commit db874ff)
1 parent 589f5e5 commit f230d48

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

base/compiler/typeutils.jl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,8 @@ function isTypeDataType(@nospecialize t)
3636
isType(t) && return false
3737
# Could be Union{} at runtime
3838
t === Core.TypeofBottom && return false
39-
if t.name === Tuple.name
40-
# If we have a Union parameter, could have been redistributed at runtime,
41-
# e.g. `Tuple{Union{Int, Float64}, Int}` is a DataType, but
42-
# `Union{Tuple{Int, Int}, Tuple{Float64, Int}}` is typeequal to it and
43-
# is not.
44-
return all(isTypeDataType, t.parameters)
45-
end
46-
return true
39+
# Return true if `t` is not covariant
40+
return t.name !== Tuple.name
4741
end
4842

4943
has_extended_info(@nospecialize x) = (!isa(x, Type) && !isvarargtype(x)) || isType(x)

test/compiler/inline.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,6 +1745,7 @@ let getfield_tfunc(@nospecialize xs...) =
17451745
Core.Compiler.getfield_tfunc(Core.Compiler.fallback_lattice, xs...)
17461746
@test getfield_tfunc(Type, Core.Const(:parameters)) !== Union{}
17471747
@test !isa(getfield_tfunc(Type{Tuple{Union{Int, Float64}, Int}}, Core.Const(:name)), Core.Const)
1748+
@test !isa(getfield_tfunc(Type{Tuple{Any}}, Core.Const(:name)), Core.Const)
17481749
end
17491750
@test fully_eliminated(Base.ismutable, Tuple{Base.RefValue})
17501751

0 commit comments

Comments
 (0)