Skip to content

Commit f88f3fd

Browse files
committed
Fix tests
1 parent 24219f3 commit f88f3fd

File tree

11 files changed

+27
-25
lines changed

11 files changed

+27
-25
lines changed

base/compiler/tfuncs.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,10 +1118,10 @@ function apply_type_tfunc(@nospecialize(headtypetype), @nospecialize args...)
11181118
elseif isconstType(headtypetype)
11191119
headtype = headtypetype.parameters[1]
11201120
else
1121-
return Type
1121+
return Any
11221122
end
11231123
if !isempty(args) && isvarargtype(args[end])
1124-
return Type
1124+
return isvarargtype(headtype) ? Any : Type
11251125
end
11261126
largs = length(args)
11271127
if headtype === Union
@@ -1164,7 +1164,7 @@ function apply_type_tfunc(@nospecialize(headtypetype), @nospecialize args...)
11641164
return allconst ? Const(ty) : Type{ty}
11651165
end
11661166
istuple = (headtype == Tuple)
1167-
if !istuple && !isa(headtype, UnionAll)
1167+
if !istuple && !isa(headtype, UnionAll) && !isvarargtype(headtype)
11681168
return Union{}
11691169
end
11701170
uw = unwrap_unionall(headtype)
@@ -1181,7 +1181,8 @@ function apply_type_tfunc(@nospecialize(headtypetype), @nospecialize args...)
11811181
aip1 = ai.parameters[1]
11821182
canconst &= !has_free_typevars(aip1)
11831183
push!(tparams, aip1)
1184-
elseif isa(ai, Const) && (isa(ai.val, Type) || isa(ai.val, TypeVar) || valid_tparam(ai.val))
1184+
elseif isa(ai, Const) && (isa(ai.val, Type) || isa(ai.val, TypeVar) ||
1185+
valid_tparam(ai.val) || (istuple && isa(ai.val, Core.VarargMarker)))
11851186
push!(tparams, ai.val)
11861187
elseif isa(ai, PartialTypeVar)
11871188
canconst = false
@@ -1247,11 +1248,11 @@ function apply_type_tfunc(@nospecialize(headtypetype), @nospecialize args...)
12471248
catch ex
12481249
# type instantiation might fail if one of the type parameters
12491250
# doesn't match, which could happen if a type estimate is too coarse
1250-
return Type{<:headtype}
1251+
return isvarargtype(headtype) ? Any : Type{<:headtype}
12511252
end
12521253
!uncertain && canconst && return Const(appl)
1253-
if isvarargtype(headtype)
1254-
return Type
1254+
if isvarargtype(appl)
1255+
return Any
12551256
end
12561257
if istuple
12571258
return Type{<:appl}

base/compiler/typelattice.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ widenconst(c::PartialTypeVar) = TypeVar
220220
widenconst(t::PartialStruct) = t.typ
221221
widenconst(t::Type) = t
222222
widenconst(t::TypeVar) = t
223+
widenconst(t::Core.VarargMarker) = t
223224

224225
issubstate(a::VarState, b::VarState) = (a.typ b.typ && a.undef <= b.undef)
225226

base/compiler/typeutils.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ function unioncomplexity(t::DataType)
196196
return c
197197
end
198198
unioncomplexity(u::UnionAll) = max(unioncomplexity(u.body), unioncomplexity(u.var.ub))
199+
unioncomplexity(t::Core.VarargMarker) = unioncomplexity(t.T)
199200
unioncomplexity(@nospecialize(x)) = 0
200201

201202
function improvable_via_constant_propagation(@nospecialize(t))

base/errorshow.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ function show_method_candidates(io::IO, ex::MethodError, @nospecialize kwargs=()
423423
# If isvarargtype then it checks whether the rest of the input arguments matches
424424
# the varargtype
425425
if Base.isvarargtype(sig[i])
426-
sigstr = (unwrap_unionall(sig[i]).parameters[1], "...")
426+
sigstr = (unwrap_unionall(sig[i]).T, "...")
427427
j = length(t_i)
428428
else
429429
sigstr = (sig[i],)
@@ -460,7 +460,7 @@ function show_method_candidates(io::IO, ex::MethodError, @nospecialize kwargs=()
460460
# It ensures that methods like f(a::AbstractString...) gets the correct
461461
# number of right_matches
462462
for t in arg_types_param[length(sig):end]
463-
if t <: rewrap_unionall(unwrap_unionall(sig[end]).parameters[1], method.sig)
463+
if t <: rewrap_unionall(unwrap_unionall(sig[end]).T, method.sig)
464464
right_matches += 1
465465
end
466466
end
@@ -473,7 +473,7 @@ function show_method_candidates(io::IO, ex::MethodError, @nospecialize kwargs=()
473473
for (k, sigtype) in enumerate(sig[length(t_i)+1:end])
474474
sigtype = isvarargtype(sigtype) ? unwrap_unionall(sigtype) : sigtype
475475
if Base.isvarargtype(sigtype)
476-
sigstr = ((sigtype::DataType).parameters[1], "...")
476+
sigstr = ((sigtype::Core.VarargMarker).T, "...")
477477
else
478478
sigstr = (sigtype,)
479479
end

base/methodshow.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ function argtype_decl(env, n, @nospecialize(sig::DataType), i::Int, nargs, isva:
3636
t = t.body
3737
end
3838
end
39-
ut = unwrap_unionall(t)
40-
tt, tn = ut.parameters[1], ut.parameters[2]
39+
ut = unwrap_unionall(t)::Core.VarargMarker
40+
tt, tn = ut.T, ut.N
4141
if isa(tn, TypeVar) && (tn === v1 || tn === v2)
4242
if tt === Any || (isa(tt, TypeVar) && (tt === v1 || tt === v2))
4343
return string(s, "..."), ""

base/tuple.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,9 @@ function tuple_type_tail(T::Type)
253253
else
254254
T.name === Tuple.name || throw(MethodError(tuple_type_tail, (T,)))
255255
if isvatuple(T) && length(T.parameters) == 1
256-
va = T.parameters[1]
257-
(isa(va, DataType) && isa(va.parameters[2], Int)) || return T
258-
return Tuple{Vararg{va.parameters[1], va.parameters[2]-1}}
256+
va = unwrap_unionall(T.parameters[1])::Core.VarargMarker
257+
isa(va.N, Int) || return T
258+
return Tuple{Vararg{va.T, va.N-1}}
259259
end
260260
return Tuple{argtail(T.parameters...)...}
261261
end

src/julia_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ STATIC_INLINE int jl_is_va_tuple(jl_datatype_t *t) JL_NOTSAFEPOINT
589589
STATIC_INLINE size_t jl_vararg_length(jl_value_t *v) JL_NOTSAFEPOINT
590590
{
591591
assert(jl_is_vararg_type(v));
592-
jl_value_t *len = jl_tparam1(jl_unwrap_unionall(v));
592+
jl_value_t *len = jl_unwrap_vararg_num(v);
593593
assert(jl_is_long(len));
594594
return jl_unbox_long(len);
595595
}

src/subtype.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3571,7 +3571,7 @@ static int tuple_morespecific(jl_datatype_t *cdt, jl_datatype_t *pdt, int invari
35713571
C = Tuple{AbstractArray, Int, Array}
35723572
we need A < B < C and A < C.
35733573
*/
3574-
return some_morespecific && cva && ckind == JL_VARARG_BOUND && num_occurs((jl_tvar_t*)jl_tparam1(jl_unwrap_unionall(clast)), env) > 1;
3574+
return some_morespecific && cva && ckind == JL_VARARG_BOUND && num_occurs((jl_tvar_t*)jl_unwrap_vararg_num(clast), env) > 1;
35753575
}
35763576

35773577
// Tuple{..., T} not more specific than Tuple{..., Vararg{S}} if S is diagonal

stdlib/Test/src/Test.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,8 +1578,7 @@ function constrains_param(var::TypeVar, @nospecialize(typ), covariant::Bool)
15781578
lastp = typ.parameters[fc]
15791579
vararg = Base.unwrap_unionall(lastp)
15801580
if vararg isa Core.VarargMarker
1581-
N = vararg.parameters[2]
1582-
constrains_param(var, N, covariant) && return true
1581+
constrains_param(var, vararg.N, covariant) && return true
15831582
# T = vararg.parameters[1] doesn't constrain var
15841583
else
15851584
constrains_param(var, lastp, covariant) && return true

test/compiler/inference.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,8 +1828,8 @@ end
18281828
@test Core.Compiler.return_type(Core.apply_type, Tuple{Type{Union},Any,Any}) == Type
18291829
@test Core.Compiler.return_type(Core.apply_type, Tuple{Type{Union},Int}) == Union{}
18301830
@test Core.Compiler.return_type(Core.apply_type, Tuple{Type{Union},Any,Int}) == Union{}
1831-
@test Core.Compiler.return_type(Core.apply_type, Tuple{Any}) == Type
1832-
@test Core.Compiler.return_type(Core.apply_type, Tuple{Any,Any}) == Type
1831+
@test Core.Compiler.return_type(Core.apply_type, Tuple{Any}) == Any
1832+
@test Core.Compiler.return_type(Core.apply_type, Tuple{Any,Any}) == Any
18331833

18341834
# PR 27351, make sure optimized type intersection for method invalidation handles typevars
18351835

@@ -2833,9 +2833,9 @@ end
28332833
@test Core.Compiler.return_type(apply26826, Tuple{typeof(fieldtype), Any, Any, Vararg}) == Type
28342834
@test Core.Compiler.return_type(apply26826, Tuple{typeof(fieldtype), Any, Any, Any, Vararg}) == Type
28352835
@test Core.Compiler.return_type(apply26826, Tuple{typeof(fieldtype), Any, Any, Any, Any, Vararg}) == Union{}
2836-
@test Core.Compiler.return_type(apply26826, Tuple{typeof(Core.apply_type), Vararg}) == Type
2837-
@test Core.Compiler.return_type(apply26826, Tuple{typeof(Core.apply_type), Any, Vararg}) == Type
2838-
@test Core.Compiler.return_type(apply26826, Tuple{typeof(Core.apply_type), Any, Any, Vararg}) == Type
2836+
@test Core.Compiler.return_type(apply26826, Tuple{typeof(Core.apply_type), Vararg}) == Any
2837+
@test Core.Compiler.return_type(apply26826, Tuple{typeof(Core.apply_type), Any, Vararg}) == Any
2838+
@test Core.Compiler.return_type(apply26826, Tuple{typeof(Core.apply_type), Any, Any, Vararg}) == Any
28392839
f_apply_cglobal(args...) = cglobal(args...)
28402840
@test Core.Compiler.return_type(f_apply_cglobal, Tuple{Vararg{Type{Int}}}) == Ptr
28412841
@test Core.Compiler.return_type(f_apply_cglobal, Tuple{Any, Vararg{Type{Int}}}) == Ptr

0 commit comments

Comments
 (0)