]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: track reflect.Type.Method in deadcode
authorDavid Crawshaw <crawshaw@golang.org>
Thu, 10 Mar 2016 21:15:26 +0000 (16:15 -0500)
committerDavid Crawshaw <crawshaw@golang.org>
Fri, 11 Mar 2016 21:19:20 +0000 (21:19 +0000)
commitcc158403d618eafc476b0727f44e4468c61060f6
treeddcb20a36cb4ba84363302c59cc90ba71bfec8df
parent4112f0f7e68f1fa75965aa010f52aa64739912a8
cmd/compile: track reflect.Type.Method in deadcode

In addition to reflect.Value.Call, exported methods can be invoked
by the Func value in the reflect.Method struct. This CL has the
compiler track what functions get access to a legitimate reflect.Method
struct by looking for interface calls to either of:

Method(int) reflect.Method
MethodByName(string) (reflect.Method, bool)

This is a little overly conservative. If a user implements a type
with one of these methods without using the underlying calls on
reflect.Type, the linker will assume the worst and include all
exported methods. But it's cheap.

No change to any of the binary sizes reported in cl/20483.

For #14740

Change-Id: Ie17786395d0453ce0384d8b240ecb043b7726137
Reviewed-on: https://go-review.googlesource.com/20489
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
13 files changed:
src/cmd/compile/internal/gc/pgen.go
src/cmd/compile/internal/gc/syntax.go
src/cmd/compile/internal/gc/walk.go
src/cmd/internal/obj/link.go
src/cmd/internal/obj/objfile.go
src/cmd/internal/obj/textflag.go
src/cmd/link/internal/ld/deadcode.go
src/cmd/link/internal/ld/link.go
src/cmd/link/internal/ld/objfile.go
src/runtime/textflag.h
test/reflectmethod1.go [new file with mode: 0644]
test/reflectmethod2.go [new file with mode: 0644]
test/reflectmethod3.go [new file with mode: 0644]