From c237c0ad0aae0af74f782239e3ff4705c70c8941 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Thu, 20 Apr 2023 11:35:26 -0400 Subject: [PATCH] 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. --- src/subtype.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/subtype.c b/src/subtype.c index 5b05e8197a420..9b85c0ceb703c 100644 --- a/src/subtype.c +++ b/src/subtype.c @@ -2774,10 +2774,9 @@ static jl_value_t *finish_unionall(jl_value_t *res JL_MAYBE_UNROOTED, jl_varbind // given x<:T<:x, substitute x for T varval = vb->ub; } - // TODO: `vb.occurs_cov == 1` here allows substituting Tuple{<:X} => Tuple{X}, - // which is valid but changes some ambiguity errors so we don't need to do it yet. - else if ((/*vb->occurs_cov == 1 || */is_leaf_bound(vb->ub)) && - !var_occurs_invariant(u->body, u->var, 0)) { + // TODO: `vb.occurs_cov == 1`, we could also substitute Tuple{<:X} => Tuple{X}, + // but it may change some ambiguity errors so we don't need to do it yet. + else if (vb->occurs_cov && is_leaf_bound(vb->ub) && !jl_has_free_typevars(vb->ub)) { // replace T<:x with x in covariant position when possible varval = vb->ub; }