diff options
author | Keith Randall <khr@golang.org> | 2021-08-03 19:33:01 -0700 |
---|---|---|
committer | Keith Randall <khr@golang.org> | 2021-08-04 17:56:00 +0000 |
commit | b730a26729ec8c00c3e31e564f9b5cf8b1deb580 (patch) | |
tree | 31feea843b1cc4f86513c3b2a8f6937ee8c03139 /src/cmd/compile/internal/reflectdata/reflect.go | |
parent | e590cb64f940b2d4996a6e7773c1b855be952632 (diff) | |
download | go-b730a26729ec8c00c3e31e564f9b5cf8b1deb580.tar.gz go-b730a26729ec8c00c3e31e564f9b5cf8b1deb580.zip |
[dev.typeparams] cmd/compile: put shape types in their own package
Put shape types in the top level package called ".shape".
Name them using the serialization of the shape name, instead of
the .shapeN names.
This allows the linker to deduplicate instantiations across packages.
Not sure that this is entirely correct, as shapes in this package
may reference other packages (e.g. a field of a struct). But it seems
to work for now.
For the added test, when you look at the resulting binary (use the -k
option with run.go) it has only one instantiation of F, and 4 call sites:
$ objdump -d a.exe | grep _a\.F
1053cb0: e8 8b 00 00 00 callq 139 <_a.F[.shape.*uint8]>
1053ce9: e8 52 00 00 00 callq 82 <_a.F[.shape.*uint8]>
_a.F[.shape.*uint8]:
1053d90: e8 ab ff ff ff callq -85 <_a.F[.shape.*uint8]>
1053dc9: e8 72 ff ff ff callq -142 <_a.F[.shape.*uint8]>
Change-Id: I627f7e50210aabe4a10d0e2717d87b75ac82e99b
Reviewed-on: https://go-review.googlesource.com/c/go/+/339595
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/reflectdata/reflect.go')
-rw-r--r-- | src/cmd/compile/internal/reflectdata/reflect.go | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/reflectdata/reflect.go b/src/cmd/compile/internal/reflectdata/reflect.go index 19cf2a0a12..a8df7a1a24 100644 --- a/src/cmd/compile/internal/reflectdata/reflect.go +++ b/src/cmd/compile/internal/reflectdata/reflect.go @@ -947,7 +947,7 @@ func writeType(t *types.Type) *obj.LSym { } dupok := 0 - if tbase.Sym() == nil { // TODO(mdempsky): Probably need DUPOK for instantiated types too. + if tbase.Sym() == nil || tbase.HasShape() { // TODO(mdempsky): Probably need DUPOK for instantiated types too. dupok = obj.DUPOK } @@ -1738,6 +1738,11 @@ func NeedEmit(typ *types.Type) bool { // Need to emit to be safe (however, see TODO above). return true + case typ.HasShape(): + // Shape type; need to emit even though it lives in the .shape package. + // TODO: make sure the linker deduplicates them (see dupok in writeType above). + return true + default: // Should have been emitted by an imported package. return false |