]> Cypherpunks repositories - gostls13.git/commitdiff
context: remove dependency on reflect
authorMichael Fraenkel <michael.fraenkel@gmail.com>
Wed, 27 Feb 2019 20:27:42 +0000 (15:27 -0500)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 25 Mar 2019 16:31:40 +0000 (16:31 +0000)
Make context depend on reflectlite instead of reflect in effort to
eventually make net no longer depend on unicode tables.

With this CL we're down to just:

    net -> context -> fmt -> unicode tables

The next CL can remove context -> fmt.

Updates #30440

Change-Id: I7f5df15f975d9dc862c59aa8477c1cfd6ff4967e
Reviewed-on: https://go-review.googlesource.com/c/go/+/164239
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/context/context.go
src/go/build/deps_test.go
src/internal/reflectlite/type.go

index 21a40d59477b4bc3277b4a2a036c9cb9e9d209b0..36f83c7b5b2b202708654a3d3840bc3af9da6394 100644 (file)
@@ -50,7 +50,7 @@ package context
 import (
        "errors"
        "fmt"
-       "reflect"
+       "internal/reflectlite"
        "sync"
        "time"
 )
@@ -468,7 +468,7 @@ func WithValue(parent Context, key, val interface{}) Context {
        if key == nil {
                panic("nil key")
        }
-       if !reflect.TypeOf(key).Comparable() {
+       if !reflectlite.TypeOf(key).Comparable() {
                panic("key is not comparable")
        }
        return &valueCtx{parent, key, val}
index df1d8dd3b373200b652640d0284e72b0fa3c24a8..e9ea0fabd80cfd559232ee02659a0ce8bcf5d0f3 100644 (file)
@@ -249,7 +249,7 @@ var pkgDeps = map[string][]string{
        "compress/gzip":                  {"L4", "compress/flate"},
        "compress/lzw":                   {"L4"},
        "compress/zlib":                  {"L4", "compress/flate"},
-       "context":                        {"errors", "fmt", "reflect", "sync", "time"},
+       "context":                        {"errors", "fmt", "internal/reflectlite", "sync", "time"},
        "database/sql":                   {"L4", "container/list", "context", "database/sql/driver", "database/sql/internal"},
        "database/sql/driver":            {"L4", "context", "time", "database/sql/internal"},
        "debug/dwarf":                    {"L4"},
@@ -324,7 +324,7 @@ var pkgDeps = map[string][]string{
        // do networking portably, it must have a small dependency set: just L0+basic os.
        "net": {
                "L0", "CGO",
-               "context", "math/rand", "os", "reflect", "sort", "syscall", "time",
+               "context", "math/rand", "os", "sort", "syscall", "time",
                "internal/nettrace", "internal/poll", "internal/syscall/unix",
                "internal/syscall/windows", "internal/singleflight", "internal/race",
                "golang.org/x/net/dns/dnsmessage", "golang.org/x/net/lif", "golang.org/x/net/route",
index 70c3723de79d01a07f5da02dd0371203ca765f5c..9767ffbd0d61b479ce767930793dc6e03f775072 100644 (file)
@@ -44,6 +44,9 @@ type Type interface {
        // AssignableTo reports whether a value of the type is assignable to type u.
        AssignableTo(u Type) bool
 
+       // Comparable reports whether values of this type are comparable.
+       Comparable() bool
+
        // Elem returns a type's element type.
        // It panics if the type's Kind is not Ptr.
        Elem() Type
@@ -663,6 +666,10 @@ func (t *rtype) AssignableTo(u Type) bool {
        return directlyAssignable(uu, t) || implements(uu, t)
 }
 
+func (t *rtype) Comparable() bool {
+       return t.alg != nil && t.alg.equal != nil
+}
+
 // implements reports whether the type V implements the interface type T.
 func implements(T, V *rtype) bool {
        if T.Kind() != Interface {