]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: rename Type.IsPtr to Type.IsPtrShaped
authorMatthew Dempsky <mdempsky@google.com>
Mon, 28 Mar 2016 17:55:44 +0000 (10:55 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 30 Mar 2016 19:11:16 +0000 (19:11 +0000)
Previously, t.IsPtr() reported whether t was represented with a
pointer, but some of its callers expected it to report whether t is an
actual Go pointer. Resolve this by renaming t.IsPtr to t.IsPtrShaped
and adding a new t.IsPtr method to report Go pointer types.

Updated a couple callers in gc/ssa.go to use IsPtr instead of
IsPtrShaped.

Passes toolstash -cmp.

Updates #15028.

Change-Id: I0a8154b5822ad8a6ad296419126ad01a3d2a5dc5
Reviewed-on: https://go-review.googlesource.com/21232
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
src/cmd/compile/internal/gc/ssa.go
src/cmd/compile/internal/gc/type.go
src/cmd/compile/internal/ssa/rewrite.go
src/cmd/compile/internal/ssa/type.go
src/cmd/compile/internal/ssa/type_test.go

index 3eb462ecb4d4754d9a25f0bc8eba67cdcf006aa7..11a478add1384311baae1c464f897c80b247cebd 100644 (file)
@@ -1512,14 +1512,14 @@ func (s *state) expr(n *Node) *ssa.Value {
                // We don't want pointers accidentally classified
                // as not-pointers or vice-versa because of copy
                // elision.
-               if to.IsPtr() != from.IsPtr() {
+               if to.IsPtrShaped() != from.IsPtrShaped() {
                        return s.newValue2(ssa.OpConvert, to, x, s.mem())
                }
 
                v := s.newValue1(ssa.OpCopy, to, x) // ensure that v has the right type
 
                // CONVNOP closure
-               if to.Etype == TFUNC && from.IsPtr() {
+               if to.Etype == TFUNC && from.IsPtrShaped() {
                        return v
                }
 
@@ -1999,7 +1999,7 @@ func (s *state) expr(n *Node) *ssa.Value {
                // So here we ensure that we are selecting the underlying pointer
                // when we build an eface.
                // TODO: get rid of this now that structs can be SSA'd?
-               for !data.Type.IsPtr() {
+               for !data.Type.IsPtrShaped() {
                        switch {
                        case data.Type.IsArray():
                                data = s.newValue1I(ssa.OpArrayIndex, data.Type.ElemType(), 0, data)
@@ -2351,7 +2351,7 @@ func (s *state) zeroVal(t *Type) *ssa.Value {
 
        case t.IsString():
                return s.constEmptyString(t)
-       case t.IsPtr():
+       case t.IsPtrShaped():
                return s.constNil(t)
        case t.IsBoolean():
                return s.constBool(false)
@@ -3026,7 +3026,7 @@ func (s *state) storeTypeScalars(t *Type, left, right *ssa.Value, skip skipMask)
        switch {
        case t.IsBoolean() || t.IsInteger() || t.IsFloat() || t.IsComplex():
                s.vars[&memVar] = s.newValue3I(ssa.OpStore, ssa.TypeMem, t.Size(), left, right, s.mem())
-       case t.IsPtr() || t.IsMap() || t.IsChan():
+       case t.IsPtrShaped():
                // no scalar fields.
        case t.IsString():
                if skip&skipLen != 0 {
@@ -3066,7 +3066,7 @@ func (s *state) storeTypeScalars(t *Type, left, right *ssa.Value, skip skipMask)
 // do *left = right for all pointer parts of t.
 func (s *state) storeTypePtrs(t *Type, left, right *ssa.Value) {
        switch {
-       case t.IsPtr() || t.IsMap() || t.IsChan():
+       case t.IsPtrShaped():
                s.vars[&memVar] = s.newValue3I(ssa.OpStore, ssa.TypeMem, s.config.PtrSize, left, right, s.mem())
        case t.IsString():
                ptr := s.newValue1(ssa.OpStringPtr, Ptrto(Types[TUINT8]), right)
@@ -3098,7 +3098,7 @@ func (s *state) storeTypePtrs(t *Type, left, right *ssa.Value) {
 // do *left = right with a write barrier for all pointer parts of t.
 func (s *state) storeTypePtrsWB(t *Type, left, right *ssa.Value) {
        switch {
-       case t.IsPtr() || t.IsMap() || t.IsChan():
+       case t.IsPtrShaped():
                s.rtcall(writebarrierptr, true, nil, left, right)
        case t.IsString():
                ptr := s.newValue1(ssa.OpStringPtr, Ptrto(Types[TUINT8]), right)
index 2240a59c16fe97bb047a7d192e25a84916765a18..ca8e2a030b680cc1801653f3693206f3ff12824e 100644 (file)
@@ -810,7 +810,18 @@ func (t *Type) IsComplex() bool {
        return t.Etype == TCOMPLEX64 || t.Etype == TCOMPLEX128
 }
 
+// IsPtr reports whether t is a regular Go pointer type.
+// This does not include unsafe.Pointer.
 func (t *Type) IsPtr() bool {
+       return t.Etype == TPTR32 || t.Etype == TPTR64
+}
+
+// IsPtrShaped reports whether t is represented by a single machine pointer.
+// In addition to regular Go pointer types, this includes map, channel, and
+// function types and unsafe.Pointer. It does not include array or struct types
+// that consist of a single pointer shaped type.
+// TODO(mdempsky): Should it? See golang.org/issue/15028.
+func (t *Type) IsPtrShaped() bool {
        return t.Etype == TPTR32 || t.Etype == TPTR64 || t.Etype == TUNSAFEPTR ||
                t.Etype == TMAP || t.Etype == TCHAN || t.Etype == TFUNC
 }
index 76fc335e0d5c9dd40448c17854931f5bbb3711c3..3ee6b00d05f889f6a1c268404e3b8886d17432bd 100644 (file)
@@ -84,7 +84,7 @@ func is8BitInt(t Type) bool {
 }
 
 func isPtr(t Type) bool {
-       return t.IsPtr()
+       return t.IsPtrShaped()
 }
 
 func isSigned(t Type) bool {
index 8851e35579d5265c200091e98faa4841b07b679a..9643b07556749bd94b1dd6239f00f7b83815d4ea 100644 (file)
@@ -17,7 +17,7 @@ type Type interface {
        IsSigned() bool
        IsFloat() bool
        IsComplex() bool
-       IsPtr() bool
+       IsPtrShaped() bool
        IsString() bool
        IsSlice() bool
        IsArray() bool
@@ -60,7 +60,7 @@ func (t *CompilerType) IsInteger() bool      { return false }
 func (t *CompilerType) IsSigned() bool       { return false }
 func (t *CompilerType) IsFloat() bool        { return false }
 func (t *CompilerType) IsComplex() bool      { return false }
-func (t *CompilerType) IsPtr() bool          { return false }
+func (t *CompilerType) IsPtrShaped() bool    { return false }
 func (t *CompilerType) IsString() bool       { return false }
 func (t *CompilerType) IsSlice() bool        { return false }
 func (t *CompilerType) IsArray() bool        { return false }
index bc55f8e8d03caa7797b819e038049d6ca0f06ef2..cd80abf03f4c4c151dca7b4deafc4e3242ea422d 100644 (file)
@@ -31,7 +31,7 @@ func (t *TypeImpl) IsInteger() bool      { return t.Integer }
 func (t *TypeImpl) IsSigned() bool       { return t.Signed }
 func (t *TypeImpl) IsFloat() bool        { return t.Float }
 func (t *TypeImpl) IsComplex() bool      { return t.Complex }
-func (t *TypeImpl) IsPtr() bool          { return t.Ptr }
+func (t *TypeImpl) IsPtrShaped() bool    { return t.Ptr }
 func (t *TypeImpl) IsString() bool       { return t.string }
 func (t *TypeImpl) IsSlice() bool        { return t.slice }
 func (t *TypeImpl) IsArray() bool        { return t.array }