reflect: do not escape Value.Type

Types are either static (for compiler-created types) or heap
allocated and always reachable (for reflection-created types, held
in the central map). So there is no need to escape types.

With CL 408826 reflect.Value does not always escape. Some functions
that escapes Value.typ would make the Value escape without this CL.

Had to add a special case for the inliner to keep (*Value).Type
still inlineable.

Change-Id: I7c14d35fd26328347b509a06eb5bd1534d40775f
Reviewed-on: https://go-review.googlesource.com/c/go/+/413474
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Cherry Mui 2022-06-17 13:06:16 -04:00
parent 0ac72f8b96
commit be4fe08b57
7 changed files with 170 additions and 122 deletions

View file

@ -229,6 +229,9 @@ func SetEnvs(e []string) { envs = e }
// For benchmarking.
func BenchSetType(n int, x any) {
// Escape x to ensure it is allocated on the heap, as we are
// working on the heap bits here.
Escape(x)
e := *efaceOf(&x)
t := e._type
var size uintptr