Skip to content

Commit

Permalink
Update variables after normalizing varargs (#28812)
Browse files Browse the repository at this point in the history
This code was a bit odd. It started by normalzing the varargs, but
then used `va0` and `va1` from the original, unnormalized type.
Either the unormalized version was intended in which case normalizing
first was wasteful, or the normalized version was intended in which
case the code was incorrct. Talking with Jeff, he believes the latter
was intended, so update the code to do that instead.
  • Loading branch information
Keno authored Aug 25, 2018
1 parent a5bfabc commit 9107365
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1131,9 +1131,9 @@ static jl_value_t *inst_datatype_inner(jl_datatype_t *dt, jl_svec_t *p, jl_value
}

jl_datatype_t *ndt = NULL;
JL_GC_PUSH2(&p, &ndt);

jl_value_t *last = iparams[ntp - 1];
JL_GC_PUSH3(&p, &ndt, &last);

int isvatuple = 0;
if (istuple && ntp > 0 && jl_is_vararg_type(last)) {
isvatuple = 1;
Expand All @@ -1149,17 +1149,13 @@ static jl_value_t *inst_datatype_inner(jl_datatype_t *dt, jl_svec_t *p, jl_value
JL_GC_POP();
return (jl_value_t*)jl_anytuple_type;
}
{
JL_GC_PUSH1(&last);
jl_value_t *last2 = normalize_vararg(last);
if (last2 != last) {
last = last2;
p = jl_alloc_svec(ntp);
for (size_t i = 0; i < ntp-1; i++)
jl_svecset(p, i, iparams[i]);
jl_svecset(p, ntp-1, last);
}
JL_GC_POP();
int did_normalize = 0;
jl_value_t *last2 = normalize_vararg(last);
if (last2 != last) {
last = last2;
did_normalize = 1;
va = jl_unwrap_unionall(last);
va0 = jl_tparam0(va); va1 = jl_tparam1(va);
}
if (jl_is_long(va1)) {
ssize_t nt = jl_unbox_long(va1);
Expand All @@ -1183,6 +1179,12 @@ static jl_value_t *inst_datatype_inner(jl_datatype_t *dt, jl_svec_t *p, jl_value
return ndt;
}
}
if (did_normalize) {
p = jl_alloc_svec(ntp);
for (size_t i = 0; i < ntp-1; i++)
jl_svecset(p, i, iparams[i]);
jl_svecset(p, ntp-1, last);
}
}

// move array of instantiated parameters to heap; we need to keep it
Expand Down
4 changes: 4 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6702,3 +6702,7 @@ end
@test_throws ErrorException Array{Int, 2}(undef, 0, -10)
@test_throws ErrorException Array{Int, 2}(undef, -10, 0)
@test_throws ErrorException Array{Int, 2}(undef, -1, -1)

# issue #28812
@test Tuple{Vararg{Array{T},3} where T} === Tuple{Array,Array,Array}
@test Tuple{Vararg{Array{T} where T,3}} === Tuple{Array,Array,Array}

0 comments on commit 9107365

Please sign in to comment.