[dev.typeparams] cmd/compile: introduce OCONVIDATA op

This operation computes just the data field needed to put its argument
into an interface. Used by generics because we produce the type field
of an interface using dictionaries (instead of statically).

With this operation defined, we can now assert that shape types
are never marked as used in interfaces (the only previous use
was IDATA(CONVIFACE(t))).

Change-Id: Idb1eb5f3b238285cb99413d382599c0621b7681a
Reviewed-on: https://go-review.googlesource.com/c/go/+/337109
Trust: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
This commit is contained in:
Keith Randall 2021-07-23 18:10:58 -07:00
parent 9f928f9318
commit 77e0bf294c
13 changed files with 161 additions and 145 deletions

View file

@ -1461,24 +1461,18 @@ func (subst *subster) convertUsingDictionary(pos src.XPos, v ir.Node, gn ir.Node
rt = subst.getDictionaryType(pos, ix)
}
// Convert value to an interface type, so the data field is what we want.
if !v.Type().IsInterface() {
v = ir.NewConvExpr(v.Pos(), ir.OCONVIFACE, nil, v)
typed(types.NewInterface(types.LocalPkg, nil), v)
// Figure out what the data field of the interface will be.
var data ir.Node
if v.Type().IsInterface() {
data = ir.NewUnaryExpr(pos, ir.OIDATA, v)
} else {
data = ir.NewConvExpr(pos, ir.OCONVIDATA, nil, v)
}
// At this point, v is an interface type with a data word we want.
// But the type word represents a gcshape type, which we don't want.
// Replace with the instantiated type loaded from the dictionary.
data := ir.NewUnaryExpr(pos, ir.OIDATA, v)
typed(types.Types[types.TUNSAFEPTR], data)
// Build an interface from the type and data parts.
var i ir.Node = ir.NewBinaryExpr(pos, ir.OEFACE, rt, data)
typed(dst, i)
// TODO: we're throwing away the type word of the original version
// of m here (it would be OITAB(m)), which probably took some
// work to generate. Can we avoid generating it at all?
// (The linker will throw them away if not needed, so it would just
// save toolchain work, not binary size.)
return i
}