From 0ac72f8b96166c8aa3953d27f4fd3d33fb9e51cf Mon Sep 17 00:00:00 2001 From: Cherry Mui Date: Fri, 27 May 2022 15:44:40 -0400 Subject: reflect: allow Value be stack allocated Currently, reflect.ValueOf forces the referenced object to be heap allocated. This CL makes it possible to be stack allocated. We need to be careful to make sure the compiler's escape analysis can do the right thing, e.g. channel send, map assignment, unsafe pointer conversions. Tests will be added in a later CL. CL 408827 might help ensure the correctness. Change-Id: I8663651370c7c8108584902235062dd2b3f65954 Reviewed-on: https://go-review.googlesource.com/c/go/+/408826 Run-TryBot: Cherry Mui Reviewed-by: David Chase TryBot-Result: Gopher Robot Reviewed-by: Austin Clements --- src/runtime/map.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/runtime/map.go') diff --git a/src/runtime/map.go b/src/runtime/map.go index 7488945926..a1fe08f758 100644 --- a/src/runtime/map.go +++ b/src/runtime/map.go @@ -1365,13 +1365,13 @@ func reflect_mapaccess_faststr(t *maptype, h *hmap, key string) unsafe.Pointer { return elem } -//go:linkname reflect_mapassign reflect.mapassign +//go:linkname reflect_mapassign reflect.mapassign0 func reflect_mapassign(t *maptype, h *hmap, key unsafe.Pointer, elem unsafe.Pointer) { p := mapassign(t, h, key) typedmemmove(t.Elem, p, elem) } -//go:linkname reflect_mapassign_faststr reflect.mapassign_faststr +//go:linkname reflect_mapassign_faststr reflect.mapassign_faststr0 func reflect_mapassign_faststr(t *maptype, h *hmap, key string, elem unsafe.Pointer) { p := mapassign_faststr(t, h, key) typedmemmove(t.Elem, p, elem) -- cgit v1.3-5-g9baa