Commit fde4b9ed authored by Robert Griesemer's avatar Robert Griesemer

cmd/compile: better documentation around checkwidth

Change-Id: I5c7ec9676b5573c883c196459acea85aa9ff8130
Reviewed-on: https://go-review.googlesource.com/c/146021
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: default avatarMatthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 84b96c21
...@@ -208,7 +208,7 @@ func dowidth(t *types.Type) { ...@@ -208,7 +208,7 @@ func dowidth(t *types.Type) {
} }
t.Width = -2 t.Width = -2
t.Align = 0 t.Align = 0 // 0 means use t.Width, below
et := t.Etype et := t.Etype
switch et { switch et {
...@@ -222,7 +222,7 @@ func dowidth(t *types.Type) { ...@@ -222,7 +222,7 @@ func dowidth(t *types.Type) {
} }
} }
w := int64(0) var w int64
switch et { switch et {
default: default:
Fatalf("dowidth: unknown type: %v", t) Fatalf("dowidth: unknown type: %v", t)
...@@ -366,7 +366,7 @@ func dowidth(t *types.Type) { ...@@ -366,7 +366,7 @@ func dowidth(t *types.Type) {
t.Width = w t.Width = w
if t.Align == 0 { 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) Fatalf("invalid alignment for %v", t)
} }
t.Align = uint8(w) t.Align = uint8(w)
...@@ -423,12 +423,11 @@ func checkwidth(t *types.Type) { ...@@ -423,12 +423,11 @@ func checkwidth(t *types.Type) {
return return
} }
if t.Deferwidth() { // if type has not yet been pushed on deferredTypeStack yet, do it now
return if !t.Deferwidth() {
t.SetDeferwidth(true)
deferredTypeStack = append(deferredTypeStack, t)
} }
t.SetDeferwidth(true)
deferredTypeStack = append(deferredTypeStack, t)
} }
func defercheckwidth() { func defercheckwidth() {
...@@ -443,6 +442,7 @@ func resumecheckwidth() { ...@@ -443,6 +442,7 @@ func resumecheckwidth() {
if defercalc == 0 { if defercalc == 0 {
Fatalf("resumecheckwidth") Fatalf("resumecheckwidth")
} }
for len(deferredTypeStack) > 0 { for len(deferredTypeStack) > 0 {
t := deferredTypeStack[len(deferredTypeStack)-1] t := deferredTypeStack[len(deferredTypeStack)-1]
deferredTypeStack = deferredTypeStack[:len(deferredTypeStack)-1] deferredTypeStack = deferredTypeStack[:len(deferredTypeStack)-1]
......
...@@ -141,7 +141,7 @@ type Type struct { ...@@ -141,7 +141,7 @@ type Type struct {
Extra interface{} Extra interface{}
// Width is the width of this Type in bytes. // Width is the width of this Type in bytes.
Width int64 Width int64 // valid if Align > 0
methods Fields methods Fields
allMethods Fields allMethods Fields
...@@ -156,16 +156,16 @@ type Type struct { ...@@ -156,16 +156,16 @@ type Type struct {
Vargen int32 // unique name for OTYPE/ONAME Vargen int32 // unique name for OTYPE/ONAME
Etype EType // kind of type 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 flags bitset8
} }
const ( const (
typeNotInHeap = 1 << iota // type cannot be heap allocated typeNotInHeap = 1 << iota // type cannot be heap allocated
typeBroke // broken type definition typeBroke // broken type definition
typeNoalg // suppress hash and eq algorithm generation typeNoalg // suppress hash and eq algorithm generation
typeDeferwidth typeDeferwidth // width computation has been deferred and type is on deferredTypeStack
typeRecur typeRecur
) )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment