cmd/compile/internal/types2: export Named.Orig as Named.Origin

This is a slightly adjusted port of CL 350996 from go/types to types2.

Change-Id: I8f5902ecb20a4b4d2a5ef0d3641d857bc3a618e2
Reviewed-on: https://go-review.googlesource.com/c/go/+/351170
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Robert Griesemer 2021-09-20 20:34:17 -07:00
parent 1367a60b06
commit 7dfe686a91
3 changed files with 6 additions and 8 deletions

View file

@ -115,7 +115,7 @@ func (g *irgen) typ0(typ types2.Type) *types.Type {
// Make sure the base generic type exists in type1 (it may // Make sure the base generic type exists in type1 (it may
// not yet if we are referecing an imported generic type, as // not yet if we are referecing an imported generic type, as
// opposed to a generic type declared in this package). // opposed to a generic type declared in this package).
_ = g.obj(typ.Orig().Obj()) _ = g.obj(typ.Origin().Obj())
// Create a forwarding type first and put it in the g.typs // Create a forwarding type first and put it in the g.typs
// map, in order to deal with recursive generic types // map, in order to deal with recursive generic types

View file

@ -296,7 +296,7 @@ func (pw *pkgWriter) typIdx(typ types2.Type, dict *writerDict) typeInfo {
// TODO(mdempsky): Why do we need to loop here? // TODO(mdempsky): Why do we need to loop here?
orig := typ orig := typ
for orig.TypeArgs() != nil { for orig.TypeArgs() != nil {
orig = orig.Orig() orig = orig.Origin()
} }
w.code(typeNamed) w.code(typeNamed)

View file

@ -87,13 +87,11 @@ func (check *Checker) newNamed(obj *TypeName, orig *Named, underlying Type, tpar
// Obj returns the type name for the declaration defining the named type t. For // Obj returns the type name for the declaration defining the named type t. For
// instantiated types, this is the type name of the base type. // instantiated types, this is the type name of the base type.
func (t *Named) Obj() *TypeName { func (t *Named) Obj() *TypeName { return t.orig.obj } // for non-instances this is the same as t.obj
return t.orig.obj // for non-instances this is the same as t.obj
}
// Orig returns the original generic type an instantiated type is derived from. // Origin returns the parameterized type from which the named type t is
// If t is not an instantiated type, the result is t. // instantiated. If t is not an instantiated type, the result is t.
func (t *Named) Orig() *Named { return t.orig } func (t *Named) Origin() *Named { return t.orig }
// TODO(gri) Come up with a better representation and API to distinguish // TODO(gri) Come up with a better representation and API to distinguish
// between parameterized instantiated and non-instantiated types. // between parameterized instantiated and non-instantiated types.