Skip to content

Commit

Permalink
fix #38888, pessimistic sparam inference with concrete upper bound
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Dec 15, 2020
1 parent da38c6b commit db9bf3e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
2 changes: 1 addition & 1 deletion base/compiler/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ end
const nonfunction_mt = typename(SimpleVector).mt

function get_compileable_sig(method::Method, @nospecialize(atypes), sparams::SimpleVector)
isa(atypes, DataType) || return Nothing
isa(atypes, DataType) || return nothing
mt = ccall(:jl_method_table_for, Any, (Any,), atypes)
mt === nothing && return nothing
return ccall(:jl_normalize_to_compilable_sig, Any, (Any, Any, Any, Any),
Expand Down
32 changes: 23 additions & 9 deletions src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -3483,18 +3483,32 @@ jl_value_t *jl_type_intersection_env_s(jl_value_t *a, jl_value_t *b, jl_svec_t *
}
}
}
if (sz == 0 && szb > 0) {
while (jl_is_unionall(b)) {
env[i++] = (jl_value_t*)((jl_unionall_t*)b)->var;
b = ((jl_unionall_t*)b)->body;
}
sz = szb;
}
if (penv) {
jl_value_t *btemp;
if (sz == 0 && szb > 0) {
btemp = b;
while (jl_is_unionall(btemp)) {
env[i++] = (jl_value_t*)((jl_unionall_t*)btemp)->var;
btemp = ((jl_unionall_t*)btemp)->body;
}
sz = szb;
}
btemp = b;
jl_svec_t *e = jl_alloc_svec(sz);
*penv = e;
for(i=0; i < sz; i++)
jl_svecset(e, i, env[i]);
for(i=0; i < sz; i++) {
assert(jl_is_unionall(btemp));
jl_value_t *ei = env[i];
if (jl_is_typevar(ei)) {
jl_tvar_t *vi = (jl_tvar_t*)ei;
if (jl_is_concrete_type(vi->ub) && vi->ub != (jl_value_t*)jl_datatype_type &&
vi->ub != (jl_value_t*)jl_uniontype_type && vi->ub != (jl_value_t*)jl_unionall_type &&
!var_occurs_invariant(((jl_unionall_t*)btemp)->body, ((jl_unionall_t*)btemp)->var, 0))
ei = vi->ub;
}
jl_svecset(e, i, ei);
btemp = ((jl_unionall_t*)btemp)->body;
}
}
bot:
JL_GC_POP();
Expand Down
7 changes: 7 additions & 0 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2979,3 +2979,10 @@ gVarargInt(x::Int) = 1
gVarargInt(x) = 2
fVarargInt(::Tuple{Vararg{Int, N}}) where {N} = Val{gVarargInt(N)}()
@test only(Base.return_types(fVarargInt, Tuple{Tuple{Vararg{Int}}})) == Val{1}

# issue #38888
struct S38888{T}
S38888(x::S) where {S<:Int} = new{S}()
end
f38888() = S38888(Base.inferencebarrier(3))
@test f38888() isa S38888

0 comments on commit db9bf3e

Please sign in to comment.