mirror of
https://github.com/golang/go
synced 2024-11-22 20:40:03 -07:00
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:
parent
c7e354d9d1
commit
baf2866956
@ -13,6 +13,19 @@ import (
|
|||||||
"go/token"
|
"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.
|
// 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
|
// 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,
|
// 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
|
// *Signature). Any methods attached to a *Named are simply copied; they are
|
||||||
// not instantiated.
|
// not instantiated.
|
||||||
//
|
//
|
||||||
// If check is non-nil, it will be used to de-dupe the instance against
|
// If env is non-nil, it may be used to de-dupe the instance against previous
|
||||||
// previous instances with the same identity.
|
// instances with the same identity. This functionality is currently
|
||||||
|
// unimplemented.
|
||||||
//
|
//
|
||||||
// If verify is set and constraint satisfaction fails, the returned error may
|
// If verify is set and constraint satisfaction fails, the returned error may
|
||||||
// be of dynamic type ArgumentError indicating which type argument did not
|
// 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
|
// TODO(rfindley): change this function to also return an error if lengths of
|
||||||
// tparams and targs do not match.
|
// tparams and targs do not match.
|
||||||
func Instantiate(check *Checker, typ Type, targs []Type, validate bool) (Type, error) {
|
func Instantiate(env *Environment, typ Type, targs []Type, validate bool) (Type, error) {
|
||||||
inst := check.instance(token.NoPos, typ, targs)
|
inst := (*Checker)(nil).instance(token.NoPos, typ, targs)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
if validate {
|
if validate {
|
||||||
@ -41,7 +55,7 @@ func Instantiate(check *Checker, typ Type, targs []Type, validate bool) (Type, e
|
|||||||
case *Signature:
|
case *Signature:
|
||||||
tparams = t.TParams().list()
|
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}
|
return inst, ArgumentError{i, err}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user