Skip to content

inference: properly compare vararg-tuple PartialStructs #44966

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

Merged
merged 2 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,6 @@ function abstract_apply(interp::AbstractInterpreter, argtypes::Vector{Any}, sv::
# This is vararg, we're not gonna be able to do any inling,
# drop the info
info = nothing

tail = tuple_tail_elem(unwrapva(ct[end]), cti)
push!(ctypes´, push!(ct[1:(end - 1)], tail))
else
Expand All @@ -1300,8 +1299,9 @@ function abstract_apply(interp::AbstractInterpreter, argtypes::Vector{Any}, sv::
lct = length(ct)
# truncate argument list at the first Vararg
for i = 1:lct-1
if isvarargtype(ct[i])
ct[i] = tuple_tail_elem(ct[i], ct[(i+1):lct])
cti = ct[i]
if isvarargtype(cti)
ct[i] = tuple_tail_elem(unwrapva(cti), ct[(i+1):lct])
resize!(ct, i)
break
end
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/typelimits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ function issimplertype(@nospecialize(typea), @nospecialize(typeb))
if typea isa PartialStruct
aty = widenconst(typea)
for i = 1:length(typea.fields)
ai = typea.fields[i]
ai = unwrapva(typea.fields[i])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is Vararg{T,N} simpler-than T? I think so, per the comment in __limit_type_size, but just wanted to confirm

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the main reason that justifies this change is that ai is finally compared with fieldtype(aty, i)/getfield_tfunc(typeb, Const(i)), which essentially unwraps Vararg{T} to T.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is not symmetric in the arguments, so that reasoning does not justify it

bi = fieldtype(aty, i)
is_lattice_equal(ai, bi) && continue
tni = _typename(widenconst(ai))
Expand Down
5 changes: 5 additions & 0 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4092,6 +4092,11 @@ end
Core.Compiler.return_type(+, NTuple{2, Rational})
end == Rational

# https://github.com/JuliaLang/julia/issues/44965
let t = Core.Compiler.tuple_tfunc(Any[Core.Const(42), Vararg{Any}])
@test Core.Compiler.issimplertype(t, t)
end

# https://github.com/JuliaLang/julia/issues/44763
global x44763::Int = 0
increase_x44763!(n) = (global x44763; x44763 += n)
Expand Down