Skip to content

Commit

Permalink
Compiler: fix unsoundness of getfield_tfunc on Tuple Types (#57275)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
vtjnash authored Feb 13, 2025
1 parent 40fbc88 commit db874ff
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
10 changes: 2 additions & 8 deletions Compiler/src/typeutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,8 @@ function isTypeDataType(@nospecialize t)
isType(t) && return false
# Could be Union{} at runtime
t === Core.TypeofBottom && return false
if t.name === Tuple.name
# If we have a Union parameter, could have been redistributed at runtime,
# e.g. `Tuple{Union{Int, Float64}, Int}` is a DataType, but
# `Union{Tuple{Int, Int}, Tuple{Float64, Int}}` is typeequal to it and
# is not.
return all(isTypeDataType, t.parameters)
end
return true
# Return true if `t` is not covariant
return t.name !== Tuple.name
end

has_extended_info(@nospecialize x) = (!isa(x, Type) && !isvarargtype(x)) || isType(x)
Expand Down
1 change: 1 addition & 0 deletions Compiler/test/inline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1769,6 +1769,7 @@ let getfield_tfunc(@nospecialize xs...) =
Compiler.getfield_tfunc(Compiler.fallback_lattice, xs...)
@test getfield_tfunc(Type, Core.Const(:parameters)) !== Union{}
@test !isa(getfield_tfunc(Type{Tuple{Union{Int, Float64}, Int}}, Core.Const(:name)), Core.Const)
@test !isa(getfield_tfunc(Type{Tuple{Any}}, Core.Const(:name)), Core.Const)
end
@test fully_eliminated(Base.ismutable, Tuple{Base.RefValue})

Expand Down

0 comments on commit db874ff

Please sign in to comment.