]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: remove Type haspointers caches
authorJosh Bleecher Snyder <josharian@gmail.com>
Thu, 30 Mar 2017 04:04:00 +0000 (21:04 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Thu, 30 Mar 2017 18:47:26 +0000 (18:47 +0000)
Even very large Types are not very big.
The haspointer cache looks like premature optimization.
Removing them has no detectable compiler performance impact,
and it removes mutable shared state used by the backend.

Updates #15756

Change-Id: I2d2cf03f470f5eef5bcd50ff693ef6a01d481700
Reviewed-on: https://go-review.googlesource.com/38912
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/compile/internal/gc/pgen_test.go
src/cmd/compile/internal/gc/sizeof_test.go
src/cmd/compile/internal/gc/type.go

index f0ebbe0b90d68d2fc63235d9fa1af8b5fd6a1121..0a95e69c34670ce18b4967e52dcccb1bdeb816e0 100644 (file)
@@ -11,11 +11,17 @@ import (
 )
 
 func typeWithoutPointers() *Type {
-       return &Type{Etype: TSTRUCT, Extra: &StructType{Haspointers: 1}} // haspointers -> false
+       t := typ(TSTRUCT)
+       f := &Field{Type: typ(TINT)}
+       t.SetFields([]*Field{f})
+       return t
 }
 
 func typeWithPointers() *Type {
-       return &Type{Etype: TSTRUCT, Extra: &StructType{Haspointers: 2}} // haspointers -> true
+       t := typ(TSTRUCT)
+       f := &Field{Type: typ(TPTR64)}
+       t.SetFields([]*Field{f})
+       return t
 }
 
 // Test all code paths for cmpstackvarlt.
index 644b9a0736e0fd269a7340bc100813bf0c28c4cd..06a3bf5bb810a3626a7511a892977f53cfe1f97a 100644 (file)
@@ -34,7 +34,7 @@ func TestSizeof(t *testing.T) {
                {StructType{}, 12, 24},
                {InterType{}, 4, 8},
                {ChanType{}, 8, 16},
-               {ArrayType{}, 16, 24},
+               {ArrayType{}, 12, 16},
                {InterMethType{}, 4, 8},
                {DDDFieldType{}, 4, 8},
                {FuncArgsType{}, 4, 8},
index 75f98ee7f07428df75d46d2b5a7dcd608a050a6a..225a72e41e81e9c9c379964f0a34f22444baa38d 100644 (file)
@@ -245,8 +245,7 @@ type StructType struct {
        // Map links such structs back to their map type.
        Map *Type
 
-       Funarg      Funarg // type of function arguments for arg struct
-       Haspointers uint8  // 0 unknown, 1 no, 2 yes
+       Funarg Funarg // type of function arguments for arg struct
 }
 
 // Fnstruct records the kind of function argument
@@ -304,9 +303,8 @@ func (t *Type) ChanType() *ChanType {
 
 // ArrayType contains Type fields specific to array types.
 type ArrayType struct {
-       Elem        *Type // element type
-       Bound       int64 // number of elements; <0 if unknown yet
-       Haspointers uint8 // 0 unknown, 1 no, 2 yes
+       Elem  *Type // element type
+       Bound int64 // number of elements; <0 if unknown yet
 }
 
 // SliceType contains Type fields specific to slice types.
@@ -1315,38 +1313,19 @@ func haspointers(t *Type) bool {
                TUINT64, TUINTPTR, TFLOAT32, TFLOAT64, TCOMPLEX64, TCOMPLEX128, TBOOL:
                return false
 
-       case TSLICE:
-               return true
-
        case TARRAY:
-               at := t.Extra.(*ArrayType)
-               if at.Haspointers != 0 {
-                       return at.Haspointers-1 != 0
-               }
-
-               ret := false
-               if t.NumElem() != 0 { // non-empty array
-                       ret = haspointers(t.Elem())
+               if t.NumElem() == 0 { // empty array has no pointers
+                       return false
                }
-
-               at.Haspointers = 1 + uint8(obj.Bool2int(ret))
-               return ret
+               return haspointers(t.Elem())
 
        case TSTRUCT:
-               st := t.StructType()
-               if st.Haspointers != 0 {
-                       return st.Haspointers-1 != 0
-               }
-
-               ret := false
                for _, t1 := range t.Fields().Slice() {
                        if haspointers(t1.Type) {
-                               ret = true
-                               break
+                               return true
                        }
                }
-               st.Haspointers = 1 + uint8(obj.Bool2int(ret))
-               return ret
+               return false
        }
 
        return true