aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/noder/stencil.go
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2021-07-23 18:10:58 -0700
committerKeith Randall <khr@golang.org>2021-07-24 15:57:01 +0000
commit77e0bf294cc431d5608c183d56b6aadbb95b09b0 (patch)
tree0acfce3c498e01a17f73ce5edab40c08fdd9616f /src/cmd/compile/internal/noder/stencil.go
parent9f928f9318efb9e6a9d45e7ed959afaaee4b7315 (diff)
downloadgo-77e0bf294cc431d5608c183d56b6aadbb95b09b0.tar.gz
go-77e0bf294cc431d5608c183d56b6aadbb95b09b0.zip
[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>
Diffstat (limited to 'src/cmd/compile/internal/noder/stencil.go')
-rw-r--r--src/cmd/compile/internal/noder/stencil.go22
1 files changed, 8 insertions, 14 deletions
diff --git a/src/cmd/compile/internal/noder/stencil.go b/src/cmd/compile/internal/noder/stencil.go
index 85538f590dc..e308dd7a05b 100644
--- a/src/cmd/compile/internal/noder/stencil.go
+++ b/src/cmd/compile/internal/noder/stencil.go
@@ -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
}