]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: move to an opaque environment for Instantiate
authorRobert Findley <rfindley@google.com>
Wed, 18 Aug 2021 17:22:38 +0000 (13:22 -0400)
committerRobert Findley <rfindley@google.com>
Mon, 23 Aug 2021 13:07:07 +0000 (13:07 +0000)
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>
src/go/types/instantiate.go

index 50341e064c698a44e9dbb82fc616e54a3f77ae91..8d7a9ecfb24efefc0d5b045c9572c08661206bca 100644 (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}
                }
        }