]> Cypherpunks.ru repositories - gostls13.git/commit
[dev.typeparams] cmd/compile/internal/types2: recursive substitution must terminate...
authorRobert Griesemer <gri@golang.org>
Fri, 9 Jul 2021 02:57:24 +0000 (19:57 -0700)
committerRobert Griesemer <gri@golang.org>
Fri, 9 Jul 2021 17:36:59 +0000 (17:36 +0000)
commitf2ed30c31edf67bd753a10891dfeb5aeb65c95dd
tree8ffb0b786f355886d256a904023a151b0b0f9b35
parent69d945fc6e80475c163f96ba86fe716e77bb0104
[dev.typeparams] cmd/compile/internal/types2: recursive substitution must terminate (bug fix)

When types2.Instantiate is called externally, no *Checker is provided and
substitution doesn't have access to Checker.typMap; and instantiation of
recursive generic types leads to an infinite recursion in subst.

There was a local subster.cache but it was only set and never used.
Replaced subster.cache with subster.typMap, which is set to the global
Checker.typMap if available, and set to a local map otherwise. This
prevents such infinite recursions. Added a simple test.

More generally, because we don't have a global type map for external
instantiations, instantiating the same type twice, independently but
with the same type arguments, will result in two different types. This
is not correct. We need to provide some form of context for external
instantiations (which means the importers). This is a separate but
related issue which is not yet addressed (filed #47103).

Change-Id: I541556c677db54f7396fd0c88c7467894dfcf2e7
Reviewed-on: https://go-review.googlesource.com/c/go/+/333383
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/api_test.go
src/cmd/compile/internal/types2/subst.go