diff options
author | Dan Scales <danscales@google.com> | 2021-08-02 11:07:45 -0700 |
---|---|---|
committer | Dan Scales <danscales@google.com> | 2021-08-02 21:26:07 +0000 |
commit | e56234a30544c043b45601ce01601e3a03e00d63 (patch) | |
tree | 85615813898f63a28e1b8446454ab06d0f8a045e | |
parent | c3c19731a9dd128b5b81c9062416804a5a4893d2 (diff) | |
download | go-e56234a30544c043b45601ce01601e3a03e00d63.tar.gz go-e56234a30544c043b45601ce01601e3a03e00d63.zip |
[dev.typeparams] cmd/compile: simple shape cleanups
- Changed some early returns to asserts (instantiateMethods and Shapify
should never take a shape arg)
- Added suggested change (by Ingo) to use copy() in getInstantiation()
- Clarified that shape types never have methods in Shapify(), removed
some TODO comments.
Change-Id: Ia2164ffe670a777f7797bbb45c7ef5e6e9e15357
Reviewed-on: https://go-review.googlesource.com/c/go/+/338971
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
-rw-r--r-- | src/cmd/compile/internal/noder/stencil.go | 9 | ||||
-rw-r--r-- | src/cmd/compile/internal/typecheck/subr.go | 10 |
2 files changed, 7 insertions, 12 deletions
diff --git a/src/cmd/compile/internal/noder/stencil.go b/src/cmd/compile/internal/noder/stencil.go index 037f309a82..c006c4af44 100644 --- a/src/cmd/compile/internal/noder/stencil.go +++ b/src/cmd/compile/internal/noder/stencil.go @@ -474,10 +474,7 @@ func (g *irgen) buildClosure(outer *ir.Func, x ir.Node) ir.Node { func (g *irgen) instantiateMethods() { for i := 0; i < len(g.instTypeList); i++ { typ := g.instTypeList[i] - if typ.HasShape() { - // Shape types should not have any methods. - continue - } + assert(!typ.HasShape()) // Mark runtime type as needed, since this ensures that the // compiler puts out the needed DWARF symbols, when this // instantiated type has a different package from the local @@ -782,9 +779,7 @@ func (g *irgen) getInstantiation(nameNode *ir.Name, shapes []*types.Type, isMeth if !t.HasShape() { if s1 == nil { s1 = make([]*types.Type, len(shapes)) - for j := 0; j < i; j++ { - s1[j] = shapes[j] - } + copy(s1[0:i], shapes[0:i]) } s1[i] = typecheck.Shapify(t) } else if s1 != nil { diff --git a/src/cmd/compile/internal/typecheck/subr.go b/src/cmd/compile/internal/typecheck/subr.go index 968d7a0d6d..25db24259c 100644 --- a/src/cmd/compile/internal/typecheck/subr.go +++ b/src/cmd/compile/internal/typecheck/subr.go @@ -1338,6 +1338,9 @@ func genericTypeName(sym *types.Sym) string { // Shapify takes a concrete type and returns a GCshape type that can // be used in place of the input type and still generate identical code. +// No methods are added - all methods calls directly on a shape should +// be done by converting to an interface using the dictionary. +// // TODO: this could take the generic function and base its decisions // on how that generic function uses this type argument. For instance, // if it doesn't use it as a function argument/return value, then @@ -1345,9 +1348,7 @@ func genericTypeName(sym *types.Sym) string { // differ in how they get passed as arguments). For now, we only // unify two different types if they are identical in every possible way. func Shapify(t *types.Type) *types.Type { - if t.IsShape() { - return t // TODO: is this right? - } + assert(!t.HasShape()) // Map all types with the same underlying type to the same shape. u := t.Underlying() @@ -1358,7 +1359,7 @@ func Shapify(t *types.Type) *types.Type { } if s := shaped[u]; s != nil { - return s //TODO: keep? + return s } sym := Lookup(fmt.Sprintf(".shape%d", snum)) @@ -1370,7 +1371,6 @@ func Shapify(t *types.Type) *types.Type { s.SetHasShape(true) name.SetType(s) name.SetTypecheck(1) - // TODO: add methods to s that the bound has? shaped[u] = s return s } |