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 <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-08-18 13:22:38 -04:00
parent c7e354d9d1
commit baf2866956

View file

@ -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}
}
}