diff options
author | Matthew Dempsky <mdempsky@google.com> | 2020-12-01 01:31:29 -0800 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2020-12-01 17:15:40 +0000 |
commit | 63a6f08b39b8ccb0dbbd373572a04f1a089f3573 (patch) | |
tree | e5799d5b7250a402020e08a8d53958f7af5e7ced /src/cmd/compile/internal/types/type.go | |
parent | f2311462ab6f2359006f42b7febd19ce95a9bbcf (diff) | |
download | go-63a6f08b39b8ccb0dbbd373572a04f1a089f3573.tar.gz go-63a6f08b39b8ccb0dbbd373572a04f1a089f3573.zip |
[dev.regabi] cmd/compile: move setUnderlying to package types
Now that setUnderlying is decoupled from Nodes, it can be moved into
package types, where it really belongs.
[git-generate]
cd src/cmd/compile/internal/gc
rf '
mv setUnderlying SetUnderlying
mv SetUnderlying typex.go
mv typex.go cmd/compile/internal/types
'
cd ../types
rf '
mv typex.go type.go
'
Change-Id: I76e2d4d8a6df599f24a731c4d8e5774ec83a119c
Reviewed-on: https://go-review.googlesource.com/c/go/+/274433
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/types/type.go')
-rw-r--r-- | src/cmd/compile/internal/types/type.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/types/type.go b/src/cmd/compile/internal/types/type.go index 8499a36edc..2a65b713be 100644 --- a/src/cmd/compile/internal/types/type.go +++ b/src/cmd/compile/internal/types/type.go @@ -5,6 +5,7 @@ package types import ( + "cmd/compile/internal/base" "cmd/internal/obj" "cmd/internal/src" "fmt" @@ -1517,3 +1518,47 @@ var ( TypeVoid = newSSA("void") TypeInt128 = newSSA("int128") ) + +func SetUnderlying(t, underlying *Type) { + if underlying.Etype == TFORW { + // This type isn't computed yet; when it is, update n. + underlying.ForwardType().Copyto = append(underlying.ForwardType().Copyto, t) + return + } + + ft := t.ForwardType() + + // TODO(mdempsky): Fix Type rekinding. + t.Etype = underlying.Etype + t.Extra = underlying.Extra + t.Width = underlying.Width + t.Align = underlying.Align + t.Orig = underlying.Orig + + if underlying.NotInHeap() { + t.SetNotInHeap(true) + } + if underlying.Broke() { + t.SetBroke(true) + } + + // spec: "The declared type does not inherit any methods bound + // to the existing type, but the method set of an interface + // type [...] remains unchanged." + if t.IsInterface() { + *t.Methods() = *underlying.Methods() + *t.AllMethods() = *underlying.AllMethods() + } + + // Update types waiting on this type. + for _, w := range ft.Copyto { + SetUnderlying(w, t) + } + + // Double-check use of type as embedded type. + if ft.Embedlineno.IsKnown() { + if t.IsPtr() || t.IsUnsafePtr() { + base.ErrorfAt(ft.Embedlineno, "embedded type cannot be a pointer") + } + } +} |