1
0
mirror of https://github.com/golang/go synced 2024-11-17 20:34:44 -07:00

cmd/compile/internal/types2: unexport Context.TypeHash

Context.TypeHash is not being used outside of the type checker, so
unexport it.

The TypeHash method is meant to hash instances, not arbitrary types, and
will soon be modified to differentiate origin types by pointer identity
(even if they are *Signature types).

Change-Id: Ia8d4a7c6350ce7f278b70630585efb0009fef63a
Reviewed-on: https://go-review.googlesource.com/c/go/+/363516
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Robert Findley 2021-11-11 19:07:28 -05:00
parent ede97290ed
commit 8b66b3d49f
5 changed files with 6 additions and 6 deletions

View File

@ -29,11 +29,11 @@ func NewContext() *Context {
} }
} }
// TypeHash returns a string representation of typ, which can be used as an exact // typeHash returns a string representation of typ, which can be used as an exact
// type hash: types that are identical produce identical string representations. // type hash: types that are identical produce identical string representations.
// If typ is a *Named type and targs is not empty, typ is printed as if it were // If typ is a *Named type and targs is not empty, typ is printed as if it were
// instantiated with targs. The result is guaranteed to not contain blanks (" "). // instantiated with targs. The result is guaranteed to not contain blanks (" ").
func (ctxt *Context) TypeHash(typ Type, targs []Type) string { func (ctxt *Context) typeHash(typ Type, targs []Type) string {
assert(ctxt != nil) assert(ctxt != nil)
assert(typ != nil) assert(typ != nil)
var buf bytes.Buffer var buf bytes.Buffer

View File

@ -57,7 +57,7 @@ func (check *Checker) instance(pos syntax.Pos, typ Type, targs []Type, ctxt *Con
case *Named: case *Named:
var h string var h string
if ctxt != nil { if ctxt != nil {
h = ctxt.TypeHash(t, targs) h = ctxt.typeHash(t, targs)
// typ may already have been instantiated with identical type arguments. In // typ may already have been instantiated with identical type arguments. In
// that case, re-use the existing instance. // that case, re-use the existing instance.
if named := ctxt.typeForHash(h, nil); named != nil { if named := ctxt.typeForHash(h, nil); named != nil {

View File

@ -251,7 +251,7 @@ func expandNamed(ctxt *Context, n *Named, instPos syntax.Pos) (tparams *TypePara
if n.orig.tparams.Len() == n.targs.Len() { if n.orig.tparams.Len() == n.targs.Len() {
// We must always have a context, to avoid infinite recursion. // We must always have a context, to avoid infinite recursion.
ctxt = check.bestContext(ctxt) ctxt = check.bestContext(ctxt)
h := ctxt.TypeHash(n.orig, n.targs.list()) h := ctxt.typeHash(n.orig, n.targs.list())
// ensure that an instance is recorded for h to avoid infinite recursion. // ensure that an instance is recorded for h to avoid infinite recursion.
ctxt.typeForHash(h, n) ctxt.typeForHash(h, n)

View File

@ -207,7 +207,7 @@ func (subst *subster) typ(typ Type) Type {
} }
// before creating a new named type, check if we have this one already // before creating a new named type, check if we have this one already
h := subst.ctxt.TypeHash(t.orig, newTArgs) h := subst.ctxt.typeHash(t.orig, newTArgs)
dump(">>> new type hash: %s", h) dump(">>> new type hash: %s", h)
if named := subst.ctxt.typeForHash(h, nil); named != nil { if named := subst.ctxt.typeForHash(h, nil); named != nil {
dump(">>> found %s", named) dump(">>> found %s", named)

View File

@ -431,7 +431,7 @@ func (check *Checker) instantiatedType(x syntax.Expr, targsx []syntax.Expr, def
} }
// create the instance // create the instance
h := check.conf.Context.TypeHash(origin, targs) h := check.conf.Context.typeHash(origin, targs)
// targs may be incomplete, and require inference. In any case we should de-duplicate. // targs may be incomplete, and require inference. In any case we should de-duplicate.
inst := check.conf.Context.typeForHash(h, nil) inst := check.conf.Context.typeForHash(h, nil)
// If inst is non-nil, we can't just return here. Inst may have been // If inst is non-nil, we can't just return here. Inst may have been