Commit 88adc338 authored by Michael Fraenkel's avatar Michael Fraenkel Committed by Brad Fitzpatrick

context: remove dependency on reflect

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/+/164239Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 9a8979de
......@@ -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}
......
......@@ -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",
......
......@@ -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 {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment