From baf2866956c2e03952383e19287a1e562cf09170 Mon Sep 17 00:00:00 2001 From: Robert Findley Date: Wed, 18 Aug 2021 13:22:38 -0400 Subject: [PATCH] go/types: move to an opaque environment for Instantiate To match the API proposal, switch the first argument to Instantiate to an opaque Environment handle, though for now this handle is unimplemented. Change-Id: I6207f0beafdf8497587abdad37db92f927db29b6 Reviewed-on: https://go-review.googlesource.com/c/go/+/343930 Trust: Robert Findley Run-TryBot: Robert Findley TryBot-Result: Go Bot Reviewed-by: Robert Griesemer --- src/go/types/instantiate.go | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/go/types/instantiate.go b/src/go/types/instantiate.go index 50341e064c6..8d7a9ecfb24 100644 --- a/src/go/types/instantiate.go +++ b/src/go/types/instantiate.go @@ -13,6 +13,19 @@ import ( "go/token" ) +// An Environment is an opaque type checking environment. It may be used to +// share identical type instances across type checked packages or calls to +// Instantiate. +// +// Currently, Environment is just a placeholder and has no effect on +// instantiation. +type Environment struct { + // Environment is currently un-implemented, because our instantiatedHash + // logic doesn't correctly handle Named type identity across multiple + // packages. + // TODO(rfindley): implement this. +} + // Instantiate instantiates the type typ with the given type arguments targs. // typ must be a *Named or a *Signature type, and its number of type parameters // must match the number of provided type arguments. The result is a new, @@ -20,8 +33,9 @@ import ( // *Signature). Any methods attached to a *Named are simply copied; they are // not instantiated. // -// If check is non-nil, it will be used to de-dupe the instance against -// previous instances with the same identity. +// If env is non-nil, it may be used to de-dupe the instance against previous +// instances with the same identity. This functionality is currently +// unimplemented. // // If verify is set and constraint satisfaction fails, the returned error may // be of dynamic type ArgumentError indicating which type argument did not @@ -29,8 +43,8 @@ import ( // // TODO(rfindley): change this function to also return an error if lengths of // tparams and targs do not match. -func Instantiate(check *Checker, typ Type, targs []Type, validate bool) (Type, error) { - inst := check.instance(token.NoPos, typ, targs) +func Instantiate(env *Environment, typ Type, targs []Type, validate bool) (Type, error) { + inst := (*Checker)(nil).instance(token.NoPos, typ, targs) var err error if validate { @@ -41,7 +55,7 @@ func Instantiate(check *Checker, typ Type, targs []Type, validate bool) (Type, e case *Signature: tparams = t.TParams().list() } - if i, err := check.verify(token.NoPos, tparams, targs); err != nil { + if i, err := (*Checker)(nil).verify(token.NoPos, tparams, targs); err != nil { return inst, ArgumentError{i, err} } }