From: Robert Findley Date: Mon, 14 Feb 2022 01:27:55 +0000 (-0500) Subject: go/types, types2: no need to revert tparam renaming in inference results X-Git-Tag: go1.18rc1~26 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=875a6d40107d560473d1590425a096dd4cee346f;p=gostls13.git go/types, types2: no need to revert tparam renaming in inference results This is a follow up to CL 385494. In early patch sets of that CL, renamed type parameters were substituted in arguments, which meant that they could leak into the inference results. However, we subsequently realized that we could instead substitute in the signature parameters. In this case it is not possible for the substituted type parameters to appear in the resulting type arguments, so there is no need to un-substitute. Change-Id: I4da45b0b8d7ad809d0ddfa7061ae5f6f07895540 Reviewed-on: https://go-review.googlesource.com/c/go/+/385574 Trust: Robert Findley Run-TryBot: Robert Findley TryBot-Result: Gopher Robot Reviewed-by: Robert Griesemer --- diff --git a/src/cmd/compile/internal/types2/infer.go b/src/cmd/compile/internal/types2/infer.go index 6259e287ae..2d6f26c0c9 100644 --- a/src/cmd/compile/internal/types2/infer.go +++ b/src/cmd/compile/internal/types2/infer.go @@ -116,16 +116,6 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type, tparams = tparams2 params = check.subst(pos, params, renameMap, nil).(*Tuple) - - // If we replaced any type parameters, their replacements may occur in - // the resulting inferred type arguments. Make sure we use the original - // type parameters in the result. - defer func() { - unrenameMap := makeRenameMap(tparams2, tparams) - for i, res := range result { - result[i] = check.subst(pos, res, unrenameMap, nil) - } - }() } } diff --git a/src/go/types/infer.go b/src/go/types/infer.go index 18ec81edd4..8f22144c83 100644 --- a/src/go/types/infer.go +++ b/src/go/types/infer.go @@ -115,16 +115,6 @@ func (check *Checker) infer(posn positioner, tparams []*TypeParam, targs []Type, tparams = tparams2 params = check.subst(posn.Pos(), params, renameMap, nil).(*Tuple) - - // If we replaced any type parameters, their replacements may occur in - // the resulting inferred type arguments. Make sure we use the original - // type parameters in the result. - defer func() { - unrenameMap := makeRenameMap(tparams2, tparams) - for i, res := range result { - result[i] = check.subst(posn.Pos(), res, unrenameMap, nil) - } - }() } }