]> Cypherpunks repositories - gostls13.git/commit
[dev.typeparams] cmd/compile: put shape types in their own package
authorKeith Randall <khr@golang.org>
Wed, 4 Aug 2021 02:33:01 +0000 (19:33 -0700)
committerKeith Randall <khr@golang.org>
Wed, 4 Aug 2021 17:56:00 +0000 (17:56 +0000)
commitb730a26729ec8c00c3e31e564f9b5cf8b1deb580
tree31feea843b1cc4f86513c3b2a8f6937ee8c03139
parente590cb64f940b2d4996a6e7773c1b855be952632
[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>
src/cmd/compile/internal/reflectdata/reflect.go
src/cmd/compile/internal/typecheck/subr.go
test/typeparam/dedup.dir/a.go [new file with mode: 0644]
test/typeparam/dedup.dir/b.go [new file with mode: 0644]
test/typeparam/dedup.dir/c.go [new file with mode: 0644]
test/typeparam/dedup.dir/main.go [new file with mode: 0644]
test/typeparam/dedup.go [new file with mode: 0644]
test/typeparam/dedup.out [new file with mode: 0644]