]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: remove struct tags from unexported types
authorIan Lance Taylor <iant@golang.org>
Thu, 28 Jun 2018 22:44:41 +0000 (15:44 -0700)
committerIan Lance Taylor <iant@golang.org>
Thu, 28 Jun 2018 23:06:00 +0000 (23:06 +0000)
Before CL 4281055 in 2011, the reflect package was quite different.
rtype, then called commonType, was embedded in exported structs with
names like StructType. In order to avoid accidental conversions
between pointers to these public structs, which sometimes had
identical fields, the embedded commonType fields were tagged.

In CL 4281055 the formerly public structs were unexported, and all
access was done through the Type interface. At that point the field
tags in the reflect structs were no longer useful.

In Go 1.8 the language was changed to ignore struct field tags when
converting between types. This made the field tags in the reflect
structs doubly useless.

This CL simply removes them.

Fixes #20914

Change-Id: I9af4d6d0709276a91a6b6ee5323cad9dcd0cd0a0
Reviewed-on: https://go-review.googlesource.com/121475
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/reflect/type.go

index a7d660fbefd4780b6912fc7f1e0a3ea7fd51554e..58cfc0e884035984d3123eb42d07c002966148cf 100644 (file)
@@ -290,9 +290,7 @@ const (
 )
 
 // rtype is the common implementation of most values.
-// It is embedded in other, public struct types, but always
-// with a unique tag like `reflect:"array"` or `reflect:"ptr"`
-// so that code cannot convert from, say, *arrayType to *ptrType.
+// It is embedded in other struct types.
 //
 // rtype must be kept in sync with ../runtime/type.go:/^type._type.
 type rtype struct {
@@ -350,7 +348,7 @@ const (
 
 // arrayType represents a fixed array type.
 type arrayType struct {
-       rtype `reflect:"array"`
+       rtype
        elem  *rtype // array element type
        slice *rtype // slice type
        len   uintptr
@@ -358,9 +356,9 @@ type arrayType struct {
 
 // chanType represents a channel type.
 type chanType struct {
-       rtype `reflect:"chan"`
-       elem  *rtype  // channel element type
-       dir   uintptr // channel direction (ChanDir)
+       rtype
+       elem *rtype  // channel element type
+       dir  uintptr // channel direction (ChanDir)
 }
 
 // funcType represents a function type.
@@ -375,7 +373,7 @@ type chanType struct {
 //             [2]*rtype    // [0] is in, [1] is out
 //     }
 type funcType struct {
-       rtype    `reflect:"func"`
+       rtype
        inCount  uint16
        outCount uint16 // top bit is set if last input parameter is ...
 }
@@ -388,14 +386,14 @@ type imethod struct {
 
 // interfaceType represents an interface type.
 type interfaceType struct {
-       rtype   `reflect:"interface"`
+       rtype
        pkgPath name      // import path
        methods []imethod // sorted by hash
 }
 
 // mapType represents a map type.
 type mapType struct {
-       rtype         `reflect:"map"`
+       rtype
        key           *rtype // map key type
        elem          *rtype // map element (value) type
        bucket        *rtype // internal bucket structure
@@ -410,14 +408,14 @@ type mapType struct {
 
 // ptrType represents a pointer type.
 type ptrType struct {
-       rtype `reflect:"ptr"`
-       elem  *rtype // pointer element (pointed at) type
+       rtype
+       elem *rtype // pointer element (pointed at) type
 }
 
 // sliceType represents a slice type.
 type sliceType struct {
-       rtype `reflect:"slice"`
-       elem  *rtype // slice element type
+       rtype
+       elem *rtype // slice element type
 }
 
 // Struct field
@@ -437,7 +435,7 @@ func (f *structField) embedded() bool {
 
 // structType represents a struct type.
 type structType struct {
-       rtype   `reflect:"struct"`
+       rtype
        pkgPath name
        fields  []structField // sorted by offset
 }