Skip to content

Commit c237c0a

Browse files
authored
subtype: replace leaf-bound typevars if they would result in Tuple{Union{}} otherwise (#49393)
This was a primary motivation for #49111. Previously, we'd see some some method specializations such as `convert(::Type{T}, ::T) where T<:Float64` (apparently from inference of some tuple convert specializations), which were not necessary to have.
1 parent d8fb5e7 commit c237c0a

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/subtype.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2774,10 +2774,9 @@ static jl_value_t *finish_unionall(jl_value_t *res JL_MAYBE_UNROOTED, jl_varbind
27742774
// given x<:T<:x, substitute x for T
27752775
varval = vb->ub;
27762776
}
2777-
// TODO: `vb.occurs_cov == 1` here allows substituting Tuple{<:X} => Tuple{X},
2778-
// which is valid but changes some ambiguity errors so we don't need to do it yet.
2779-
else if ((/*vb->occurs_cov == 1 || */is_leaf_bound(vb->ub)) &&
2780-
!var_occurs_invariant(u->body, u->var, 0)) {
2777+
// TODO: `vb.occurs_cov == 1`, we could also substitute Tuple{<:X} => Tuple{X},
2778+
// but it may change some ambiguity errors so we don't need to do it yet.
2779+
else if (vb->occurs_cov && is_leaf_bound(vb->ub) && !jl_has_free_typevars(vb->ub)) {
27812780
// replace T<:x with x in covariant position when possible
27822781
varval = vb->ub;
27832782
}

0 commit comments

Comments
 (0)