aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/reflectdata/reflect.go
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2021-06-09 19:30:16 -0700
committerKeith Randall <khr@golang.org>2021-07-21 21:04:15 +0000
commita7a17f0ca86d252dc1ef20b5852c352ade5f8610 (patch)
treefdc726eb6a687dfb988e927fdef467cd393bfaa1 /src/cmd/compile/internal/reflectdata/reflect.go
parent897970688b326f7baa8ad8e3330fb552d94b0014 (diff)
downloadgo-a7a17f0ca86d252dc1ef20b5852c352ade5f8610.tar.gz
go-a7a17f0ca86d252dc1ef20b5852c352ade5f8610.zip
[dev.typeparams] cmd/compile: introduce named gcshape types
Still 1-1 with real types, but now with their own names! Shape types are implicitly convertible to (and convertible from) the types they represent. Change-Id: I0133a8d8fbeb369380574b075a32b3c987e314d5 Reviewed-on: https://go-review.googlesource.com/c/go/+/335170 Run-TryBot: Keith Randall <khr@golang.org> Trust: Keith Randall <khr@golang.org> Trust: Dan Scales <danscales@google.com> Reviewed-by: Dan Scales <danscales@google.com>
Diffstat (limited to 'src/cmd/compile/internal/reflectdata/reflect.go')
-rw-r--r--src/cmd/compile/internal/reflectdata/reflect.go33
1 files changed, 30 insertions, 3 deletions
diff --git a/src/cmd/compile/internal/reflectdata/reflect.go b/src/cmd/compile/internal/reflectdata/reflect.go
index b20fc8cccc..2236c7f1cf 100644
--- a/src/cmd/compile/internal/reflectdata/reflect.go
+++ b/src/cmd/compile/internal/reflectdata/reflect.go
@@ -302,6 +302,9 @@ func MapIterType(t *types.Type) *types.Type {
// methods returns the methods of the non-interface type t, sorted by name.
// Generates stub functions as needed.
func methods(t *types.Type) []*typeSig {
+ if t.HasShape() {
+ return nil
+ }
// method type
mt := types.ReceiverBaseType(t)
@@ -1215,6 +1218,7 @@ func NeedRuntimeType(t *types.Type) {
if t.HasTParam() {
// Generic types don't have a runtime type descriptor (but will
// have a dictionary)
+ // TODO: also shape type here?
return
}
if _, ok := signatset[t]; !ok {
@@ -1276,6 +1280,9 @@ func writeITab(lsym *obj.LSym, typ, iface *types.Type) {
for _, m := range methods(typ) {
if m.name == sigs[0].Sym {
entries = append(entries, m.isym)
+ if m.isym == nil {
+ panic("NO ISYM")
+ }
sigs = sigs[1:]
if len(sigs) == 0 {
break
@@ -1764,6 +1771,17 @@ func methodWrapper(rcvr *types.Type, method *types.Field, forItab bool) *obj.LSy
// an embedded field) which is an interface method.
// TODO: check that we do the right thing when method is an interface method.
generic = true
+
+ targs := rcvr.RParams()
+ if rcvr.IsPtr() {
+ targs = rcvr.Elem().RParams()
+ }
+ // TODO: why do shape-instantiated types exist?
+ for _, t := range targs {
+ if t.HasShape() {
+ base.Fatalf("method on type instantiated with shapes targ:%+v rcvr:%+v", t, rcvr)
+ }
+ }
}
newnam := ir.MethodSym(rcvr, method.Sym)
lsym := newnam.Linksym()
@@ -1881,9 +1899,13 @@ func methodWrapper(rcvr *types.Type, method *types.Field, forItab bool) *obj.LSy
}
args = append(args, ir.ParamNames(tfn.Type())...)
- // TODO: Once we enter the gcshape world, we'll need a way to look up
- // the stenciled implementation to use for this concrete type. Essentially,
- // erase the concrete types and replace them with gc shape representatives.
+ // Target method uses shaped names.
+ targs2 := make([]*types.Type, len(targs))
+ for i, t := range targs {
+ targs2[i] = typecheck.Shaped[t]
+ }
+ targs = targs2
+
sym := typecheck.MakeInstName(ir.MethodSym(methodrcvr, method.Sym), targs, true)
if sym.Def == nil {
// Currently we make sure that we have all the instantiations
@@ -1975,6 +1997,11 @@ func getDictionary(gf *types.Sym, targs []*types.Type) ir.Node {
if len(targs) == 0 {
base.Fatalf("%s should have type arguments", gf.Name)
}
+ for _, t := range targs {
+ if t.HasShape() {
+ base.Fatalf("dictionary for %s should only use concrete types: %+v", gf.Name, t)
+ }
+ }
sym := typecheck.MakeDictName(gf, targs, true)