diff options
author | Robert Griesemer <gri@golang.org> | 2021-04-28 16:14:12 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2021-05-05 04:48:30 +0000 |
commit | 9e0facd26ecefa5a3aa5bfd9e4034fe6d4b2f64e (patch) | |
tree | 835fb49ae5641b27d5c1a11d0876664991d26924 /src/cmd/compile/internal/types2/subst.go | |
parent | caf4c9434b0c9b3f27e1c5e620b2acb0e46a74bb (diff) | |
download | go-9e0facd26ecefa5a3aa5bfd9e4034fe6d4b2f64e.tar.gz go-9e0facd26ecefa5a3aa5bfd9e4034fe6d4b2f64e.zip |
cmd/compile/internal/types2: implement types2.Instantiate
Instantiation support for imports. This is experimental
but it also doesn't affect Go 1.17 as this code is not
executed unless we enable generics (in the parser).
Change-Id: If2da09ac3a557ec6a180707a53f75f3ce354f3e9
Reviewed-on: https://go-review.googlesource.com/c/go/+/314773
Trust: Robert Griesemer <gri@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Diffstat (limited to 'src/cmd/compile/internal/types2/subst.go')
-rw-r--r-- | src/cmd/compile/internal/types2/subst.go | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/src/cmd/compile/internal/types2/subst.go b/src/cmd/compile/internal/types2/subst.go index d089317f7d..c8e428c183 100644 --- a/src/cmd/compile/internal/types2/subst.go +++ b/src/cmd/compile/internal/types2/subst.go @@ -308,6 +308,9 @@ func (subst *subster) typ(typ Type) Type { embeddeds, ecopied := subst.typeList(t.embeddeds) if mcopied || types != t.types || ecopied { iface := &Interface{methods: methods, types: types, embeddeds: embeddeds} + if subst.check == nil { + panic("internal error: cannot instantiate interfaces yet") + } subst.check.posMap[iface] = subst.check.posMap[t] // satisfy completeInterface requirement subst.check.completeInterface(nopos, iface) return iface @@ -327,12 +330,14 @@ func (subst *subster) typ(typ Type) Type { } case *Named: - subst.check.indent++ - defer func() { - subst.check.indent-- - }() - dump := func(format string, args ...interface{}) { - if subst.check.conf.Trace { + // dump is for debugging + dump := func(string, ...interface{}) {} + if subst.check != nil && subst.check.conf.Trace { + subst.check.indent++ + defer func() { + subst.check.indent-- + }() + dump = func(format string, args ...interface{}) { subst.check.trace(subst.pos, format, args...) } } @@ -377,17 +382,21 @@ func (subst *subster) typ(typ Type) Type { // before creating a new named type, check if we have this one already h := instantiatedHash(t, new_targs) dump(">>> new type hash: %s", h) - if named, found := subst.check.typMap[h]; found { - dump(">>> found %s", named) - subst.cache[t] = named - return named + if subst.check != nil { + if named, found := subst.check.typMap[h]; found { + dump(">>> found %s", named) + subst.cache[t] = named + return named + } } // create a new named type and populate caches to avoid endless recursion tname := NewTypeName(subst.pos, t.obj.pkg, t.obj.name, nil) named := subst.check.newNamed(tname, t, t.underlying, t.tparams, t.methods) // method signatures are updated lazily named.targs = new_targs - subst.check.typMap[h] = named + if subst.check != nil { + subst.check.typMap[h] = named + } subst.cache[t] = named // do the substitution |