]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: better documentation around checkwidth
authorRobert Griesemer <gri@golang.org>
Mon, 29 Oct 2018 20:44:44 +0000 (13:44 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 31 Oct 2018 04:30:10 +0000 (04:30 +0000)
Change-Id: I5c7ec9676b5573c883c196459acea85aa9ff8130
Reviewed-on: https://go-review.googlesource.com/c/146021
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/gc/align.go
src/cmd/compile/internal/types/type.go

index fb761d2339758891df9a1e3ab29938206a63bdfa..87a7de547a30ce05b1a3e21cadef431f304f87cb 100644 (file)
@@ -208,7 +208,7 @@ func dowidth(t *types.Type) {
        }
 
        t.Width = -2
-       t.Align = 0
+       t.Align = 0 // 0 means use t.Width, below
 
        et := t.Etype
        switch et {
@@ -222,7 +222,7 @@ func dowidth(t *types.Type) {
                }
        }
 
-       w := int64(0)
+       var w int64
        switch et {
        default:
                Fatalf("dowidth: unknown type: %v", t)
@@ -366,7 +366,7 @@ func dowidth(t *types.Type) {
 
        t.Width = w
        if t.Align == 0 {
-               if w > 8 || w&(w-1) != 0 || w == 0 {
+               if w == 0 || w > 8 || w&(w-1) != 0 {
                        Fatalf("invalid alignment for %v", t)
                }
                t.Align = uint8(w)
@@ -423,12 +423,11 @@ func checkwidth(t *types.Type) {
                return
        }
 
-       if t.Deferwidth() {
-               return
+       // if type has not yet been pushed on deferredTypeStack yet, do it now
+       if !t.Deferwidth() {
+               t.SetDeferwidth(true)
+               deferredTypeStack = append(deferredTypeStack, t)
        }
-       t.SetDeferwidth(true)
-
-       deferredTypeStack = append(deferredTypeStack, t)
 }
 
 func defercheckwidth() {
@@ -443,6 +442,7 @@ func resumecheckwidth() {
        if defercalc == 0 {
                Fatalf("resumecheckwidth")
        }
+
        for len(deferredTypeStack) > 0 {
                t := deferredTypeStack[len(deferredTypeStack)-1]
                deferredTypeStack = deferredTypeStack[:len(deferredTypeStack)-1]
index e6e61274057244f75b7a6f4c0249dbde15eb95a9..39f4d2aa7b06bb12989bef9f95785b41a927953d 100644 (file)
@@ -141,7 +141,7 @@ type Type struct {
        Extra interface{}
 
        // Width is the width of this Type in bytes.
-       Width int64
+       Width int64 // valid if Align > 0
 
        methods    Fields
        allMethods Fields
@@ -156,16 +156,16 @@ type Type struct {
        Vargen int32 // unique name for OTYPE/ONAME
 
        Etype EType // kind of type
-       Align uint8 // the required alignment of this type, in bytes
+       Align uint8 // the required alignment of this type, in bytes (0 means Width and Align have not yet been computed)
 
        flags bitset8
 }
 
 const (
-       typeNotInHeap = 1 << iota // type cannot be heap allocated
-       typeBroke                 // broken type definition
-       typeNoalg                 // suppress hash and eq algorithm generation
-       typeDeferwidth
+       typeNotInHeap  = 1 << iota // type cannot be heap allocated
+       typeBroke                  // broken type definition
+       typeNoalg                  // suppress hash and eq algorithm generation
+       typeDeferwidth             // width computation has been deferred and type is on deferredTypeStack
        typeRecur
 )