]> Cypherpunks repositories - gostls13.git/commitdiff
internal/reflectlite: updates reflectlite to match runtime rtype/mapType
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Fri, 27 Sep 2019 09:38:14 +0000 (16:38 +0700)
committerKeith Randall <khr@golang.org>
Sat, 5 Oct 2019 23:03:47 +0000 (23:03 +0000)
CL 191198 updated runtime rtype and mapType without adopting the changes
to reflectlite, causing mismatch between them.

This CL updates those changes to reflectlite.

Fixes #34486

Change-Id: I2bb043673d997f97bb0b12c4ad471474803b2160
Reviewed-on: https://go-review.googlesource.com/c/go/+/197559
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
src/internal/reflectlite/set_test.go
src/internal/reflectlite/type.go

index 817e4beae1bd9fa02bd4e3c8e22e28276005a14a..a610499d084274f90f19d0114d3d41128ce9408a 100644 (file)
@@ -39,6 +39,8 @@ var implementsTests = []struct {
        {new(notASTExpr), new(ast.Expr), false},
        {new(ast.Expr), new(notASTExpr), false},
        {new(*notAnExpr), new(notASTExpr), true},
+       {new(mapError), new(error), true},
+       {new(*mapError), new(error), true},
 }
 
 type notAnExpr struct{}
@@ -53,6 +55,13 @@ type notASTExpr interface {
        exprNode()
 }
 
+type mapError map[string]string
+
+func (mapError) Error() string { return "mapError" }
+
+var _ error = mapError{}
+var _ error = new(mapError)
+
 func TestImplements(t *testing.T) {
        for _, tt := range implementsTests {
                xv := TypeOf(tt.x).Elem()
index c706319a8e24adb8f2086ecf54b2a35fae7a25ed..e90071c67cfef800a23321ea6c00e8301e147adc 100644 (file)
@@ -137,6 +137,10 @@ const (
 
        // tflagNamed means the type has a name.
        tflagNamed tflag = 1 << 2
+
+       // tflagRegularMemory means that equal and hash functions can treat
+       // this type as a single region of t.size bytes.
+       tflagRegularMemory tflag = 1 << 3
 )
 
 // rtype is the common implementation of most values.
@@ -145,26 +149,18 @@ const (
 // rtype must be kept in sync with ../runtime/type.go:/^type._type.
 type rtype struct {
        size       uintptr
-       ptrdata    uintptr  // number of bytes in the type that can contain pointers
-       hash       uint32   // hash of type; avoids computation in hash tables
-       tflag      tflag    // extra type information flags
-       align      uint8    // alignment of variable with this type
-       fieldAlign uint8    // alignment of struct field with this type
-       kind       uint8    // enumeration for C
-       alg        *typeAlg // algorithm table
-       gcdata     *byte    // garbage collection data
-       str        nameOff  // string form
-       ptrToThis  typeOff  // type for pointer to this type, may be zero
-}
-
-// a copy of runtime.typeAlg
-type typeAlg struct {
-       // function for hashing objects of this type
-       // (ptr to object, seed) -> hash
-       hash func(unsafe.Pointer, uintptr) uintptr
+       ptrdata    uintptr // number of bytes in the type that can contain pointers
+       hash       uint32  // hash of type; avoids computation in hash tables
+       tflag      tflag   // extra type information flags
+       align      uint8   // alignment of variable with this type
+       fieldAlign uint8   // alignment of struct field with this type
+       kind       uint8   // enumeration for C
        // function for comparing objects of this type
        // (ptr to object A, ptr to object B) -> ==?
-       equal func(unsafe.Pointer, unsafe.Pointer) bool
+       equal     func(unsafe.Pointer, unsafe.Pointer) bool
+       gcdata    *byte   // garbage collection data
+       str       nameOff // string form
+       ptrToThis typeOff // type for pointer to this type, may be zero
 }
 
 // Method on non-interface type
@@ -244,8 +240,11 @@ type interfaceType struct {
 // mapType represents a map type.
 type mapType struct {
        rtype
-       key        *rtype // map key type
-       elem       *rtype // map element (value) type
+       key    *rtype // map key type
+       elem   *rtype // map element (value) type
+       bucket *rtype // internal bucket structure
+       // function for hashing keys (ptr to key, seed) -> hash
+       hasher     func(unsafe.Pointer, uintptr) uintptr
        keysize    uint8  // size of key slot
        valuesize  uint8  // size of value slot
        bucketsize uint16 // size of bucket
@@ -685,7 +684,7 @@ func (t *rtype) AssignableTo(u Type) bool {
 }
 
 func (t *rtype) Comparable() bool {
-       return t.alg != nil && t.alg.equal != nil
+       return t.equal != nil
 }
 
 // implements reports whether the type V implements the interface type T.