diff options
author | Robert Griesemer <gri@golang.org> | 2021-07-29 22:24:37 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2021-08-02 21:08:34 +0000 |
commit | c3c19731a9dd128b5b81c9062416804a5a4893d2 (patch) | |
tree | 22d847f13ce74754f021f7a20aaf9334c40f22fd /src/cmd/compile/internal/types2/named.go | |
parent | 156eeb40a6d918bcac82871af1b8e428a5414159 (diff) | |
download | go-c3c19731a9dd128b5b81c9062416804a5a4893d2.tar.gz go-c3c19731a9dd128b5b81c9062416804a5a4893d2.zip |
[dev.typeparams] cmd/compile/internal/types2: move instance.go contents into named.go (cleanup)
This just moves the code around the instance type into named.go
where it belongs. While at it, also removed some left-over references
to instance types (which are gone). Removed instance.go.
Change-Id: I302a86ca50675b0be54f6138fa47f48f00f9c98f
Reviewed-on: https://go-review.googlesource.com/c/go/+/338469
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'src/cmd/compile/internal/types2/named.go')
-rw-r--r-- | src/cmd/compile/internal/types2/named.go | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/types2/named.go b/src/cmd/compile/internal/types2/named.go index 96f2db1429..8ded197df5 100644 --- a/src/cmd/compile/internal/types2/named.go +++ b/src/cmd/compile/internal/types2/named.go @@ -4,7 +4,10 @@ package types2 -import "sync" +import ( + "cmd/compile/internal/syntax" + "sync" +) // TODO(gri) Clean up Named struct below; specifically the fromRHS field (can we use underlying?). @@ -252,3 +255,36 @@ func (n *Named) setUnderlying(typ Type) { n.underlying = typ } } + +// instance holds position information for use in lazy instantiation. +// +// TODO(rfindley): come up with a better name for this type, now that its usage +// has changed. +type instance struct { + pos syntax.Pos // position of type instantiation; for error reporting only + posList []syntax.Pos // position of each targ; for error reporting only +} + +// expand ensures that the underlying type of n is instantiated. +// The underlying type will be Typ[Invalid] if there was an error. +func (n *Named) expand() { + if n.instance != nil { + // n must be loaded before instantiation, in order to have accurate + // tparams. This is done implicitly by the call to n.TParams, but making it + // explicit is harmless: load is idempotent. + n.load() + inst := n.check.instantiate(n.instance.pos, n.orig.underlying, n.TParams().list(), n.targs, n.instance.posList) + n.underlying = inst + n.fromRHS = inst + n.instance = nil + } +} + +// expand expands uninstantiated named types and leaves all other types alone. +// expand does not recurse. +func expand(typ Type) Type { + if t, _ := typ.(*Named); t != nil { + t.expand() + } + return typ +} |