]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: move setUnderlying to package types
authorMatthew Dempsky <mdempsky@google.com>
Tue, 1 Dec 2020 09:31:29 +0000 (01:31 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 1 Dec 2020 17:15:40 +0000 (17:15 +0000)
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>
src/cmd/compile/internal/gc/iimport.go
src/cmd/compile/internal/gc/typecheck.go
src/cmd/compile/internal/types/type.go

index 57c5e621829c8de20748a7c35627fee6160f637d..0696d05c11050c6d97b77ca549010a44482f72a1 100644 (file)
@@ -316,7 +316,7 @@ func (r *importReader) doDecl(n ir.Node) {
                // after the underlying type has been assigned.
                defercheckwidth()
                underlying := r.typ()
-               setUnderlying(t, underlying)
+               types.SetUnderlying(t, underlying)
                resumecheckwidth()
 
                if underlying.IsInterface() {
index d9ec06c531e972a72c939902aaae037976f1e92f..6858b51699dfaf7e49380d0ed51b15b3db46d59b 100644 (file)
@@ -3427,50 +3427,6 @@ func checkMapKeys() {
        mapqueue = nil
 }
 
-func setUnderlying(t, underlying *types.Type) {
-       if underlying.Etype == types.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")
-               }
-       }
-}
-
 func typecheckdeftype(n *ir.Name) {
        if enableTrace && base.Flag.LowerT {
                defer tracePrint("typecheckdeftype", n)(nil)
@@ -3492,7 +3448,7 @@ func typecheckdeftype(n *ir.Name) {
        errorsBefore := base.Errors()
        n.Ntype = typecheckNtype(n.Ntype)
        if underlying := n.Ntype.Type(); underlying != nil {
-               setUnderlying(t, underlying)
+               types.SetUnderlying(t, underlying)
        } else {
                n.SetDiag(true)
                n.SetType(nil)
index 8499a36edc8f51ff67dfdd486a58a97481fb59f0..2a65b713be868ca1c9714c3e0c8e82516b568b53 100644 (file)
@@ -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")
+               }
+       }
+}