Skip to content

Commit db9bf3e

Browse files
committed
fix #38888, pessimistic sparam inference with concrete upper bound
1 parent da38c6b commit db9bf3e

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

base/compiler/utilities.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ end
139139
const nonfunction_mt = typename(SimpleVector).mt
140140

141141
function get_compileable_sig(method::Method, @nospecialize(atypes), sparams::SimpleVector)
142-
isa(atypes, DataType) || return Nothing
142+
isa(atypes, DataType) || return nothing
143143
mt = ccall(:jl_method_table_for, Any, (Any,), atypes)
144144
mt === nothing && return nothing
145145
return ccall(:jl_normalize_to_compilable_sig, Any, (Any, Any, Any, Any),

src/subtype.c

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3483,18 +3483,32 @@ jl_value_t *jl_type_intersection_env_s(jl_value_t *a, jl_value_t *b, jl_svec_t *
34833483
}
34843484
}
34853485
}
3486-
if (sz == 0 && szb > 0) {
3487-
while (jl_is_unionall(b)) {
3488-
env[i++] = (jl_value_t*)((jl_unionall_t*)b)->var;
3489-
b = ((jl_unionall_t*)b)->body;
3490-
}
3491-
sz = szb;
3492-
}
34933486
if (penv) {
3487+
jl_value_t *btemp;
3488+
if (sz == 0 && szb > 0) {
3489+
btemp = b;
3490+
while (jl_is_unionall(btemp)) {
3491+
env[i++] = (jl_value_t*)((jl_unionall_t*)btemp)->var;
3492+
btemp = ((jl_unionall_t*)btemp)->body;
3493+
}
3494+
sz = szb;
3495+
}
3496+
btemp = b;
34943497
jl_svec_t *e = jl_alloc_svec(sz);
34953498
*penv = e;
3496-
for(i=0; i < sz; i++)
3497-
jl_svecset(e, i, env[i]);
3499+
for(i=0; i < sz; i++) {
3500+
assert(jl_is_unionall(btemp));
3501+
jl_value_t *ei = env[i];
3502+
if (jl_is_typevar(ei)) {
3503+
jl_tvar_t *vi = (jl_tvar_t*)ei;
3504+
if (jl_is_concrete_type(vi->ub) && vi->ub != (jl_value_t*)jl_datatype_type &&
3505+
vi->ub != (jl_value_t*)jl_uniontype_type && vi->ub != (jl_value_t*)jl_unionall_type &&
3506+
!var_occurs_invariant(((jl_unionall_t*)btemp)->body, ((jl_unionall_t*)btemp)->var, 0))
3507+
ei = vi->ub;
3508+
}
3509+
jl_svecset(e, i, ei);
3510+
btemp = ((jl_unionall_t*)btemp)->body;
3511+
}
34983512
}
34993513
bot:
35003514
JL_GC_POP();

test/compiler/inference.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2979,3 +2979,10 @@ gVarargInt(x::Int) = 1
29792979
gVarargInt(x) = 2
29802980
fVarargInt(::Tuple{Vararg{Int, N}}) where {N} = Val{gVarargInt(N)}()
29812981
@test only(Base.return_types(fVarargInt, Tuple{Tuple{Vararg{Int}}})) == Val{1}
2982+
2983+
# issue #38888
2984+
struct S38888{T}
2985+
S38888(x::S) where {S<:Int} = new{S}()
2986+
end
2987+
f38888() = S38888(Base.inferencebarrier(3))
2988+
@test f38888() isa S38888

0 commit comments

Comments
 (0)