]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: special-case MethodByName(string literal) to keep the DCE enabled.
authorDominique Lefevre <domingolefevre@gmail.com>
Thu, 24 Aug 2023 07:15:29 +0000 (10:15 +0300)
committerCherry Mui <cherryyz@google.com>
Fri, 1 Sep 2023 15:06:51 +0000 (15:06 +0000)
commite802f211b0d3f9dac5c4ca56c9f83df0cb745070
tree4e5c55d1abab256bad81ee7f958ec7287b1dbaae
parent660feea72f64d9d6d619529f10afd8c042299c65
cmd/compile: special-case MethodByName(string literal) to keep the DCE enabled.

Normally, a call to MethodByName() disables the DCE because the linker
assumes that any method can be accessed this way. This pessimises
the code generation for k8s.io/apimachinery which needs MethodByName()
to verify whether or not a struct implements DeepCopyInto(). It cannot
cast a struct to `interface { DeepCopyInto() Foo }` because the return
type may vary. Instead, it does the following:

  if m := reflect.ValueOf(obj).MethodByName("DeepCopyInto"); ... {

In this case there is no need to disable the DCE altogether. It
suffices to add a relocation to keep methods named DeepCopyInto().

Fixes #62257.

Change-Id: I583c2f04d8309a8807de75cd962c04151baeeb1b
Reviewed-on: https://go-review.googlesource.com/c/go/+/522436
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
src/cmd/compile/internal/walk/expr.go