1
0
mirror of https://github.com/golang/go synced 2024-09-30 22:48:32 -06:00
The Go programming language
Go to file
Alan Donovan 87ced824bd go.tools/ssa: fix computation of set of types requiring method sets.
Motivation:

Previously, we assumed that the set of types for which a
complete method set (containing all synthesized wrapper
functions) is required at runtime was the set of types
used as operands to some *ssa.MakeInterface instruction.

In fact, this is an underapproximation because types can
be derived from other ones via reflection, and some of
these may need methods.  The reflect.Type API allows *T to
be derived from T, and these may have different method
sets.  Reflection also allows almost any subcomponent of a
type to be accessed (with one exception: given T, defined
'type T struct{S}', you can reach S but not struct{S}).

As a result, the pointer analysis was unable to generate
all necessary constraints before running the solver,
causing a crash when reflection derives types whose
methods are unavailable.  (A similar problem would afflict
an ahead-of-time compiler based on ssa.  The ssa/interp
interpreter was immune only because it does not require
all wrapper methods to be created before execution
begins.)

Description:

This change causes the SSA builder to record, for each
package, the set of all types with non-empty method sets that
are referenced within that package.  This set is accessed via
Packages.TypesWithMethodSets().  Program.TypesWithMethodSets()
returns its union across all packages.

The set of references that matter are:
- types of operands to some MakeInterface instruction (as before)
- types of all exported package members
- all subcomponents of the above, recursively.
This is a conservative approximation to the set of types
whose methods may be called dynamically.

We define the owning package of a type as follows:
- the owner of a named type is the package in which it is defined;
- the owner of a pointer-to-named type is the owner of that named type;
- the owner of all other types is nil.

A package must include the method sets for all types that it
owns, and all subcomponents of that type that are not owned by
another package, recursively.  Types with an owner appear in
exactly one package; types with no owner (such as struct{T})
may appear within multiple packages.
(A typical Go compiler would emit multiple copies of these
methods as weak symbols; a typical linker would eliminate
duplicates.)

Also:
- go/types/typemap: implement hash function for *Tuple.
- pointer: generate nodes/constraints for all of
  ssa.Program.TypesWithMethodSets().
  Add rtti.go regression test.
- Add API test of Package.TypesWithMethodSets().
- Set Function.Pkg to nil (again) for wrapper functions,
  since these may be shared by many packages.
- Remove a redundant logging statement.
- Document that ssa CREATE phase is in fact sequential.

Fixes golang/go#6605

R=gri
CC=golang-dev
https://golang.org/cl/14920056
2013-10-23 17:07:52 -04:00
blog go.tools/blog: replace "\\" with "/" in path string to be compatible with windows platform 2013-10-08 16:55:56 +11:00
call go.tools/pointer: use new callgraph API. 2013-09-25 17:17:42 -04:00
cmd go.tools/cmd/godoc: search go.tools/cmd before $GOROOT/cmd 2013-10-18 10:42:41 +09:00
dashboard go.tools/dashboard: clone main repo from local path if it already exists locally. 2013-10-07 09:06:32 -07:00
go go.tools/ssa: fix computation of set of types requiring method sets. 2013-10-23 17:07:52 -04:00
godoc go.tools/godoc/static: fix & escape in codewalks 2013-10-13 22:22:48 -04:00
importer go.tools/ssa: implement correct control flow for recovered panic. 2013-10-14 15:38:56 -04:00
oracle go.tools/ssa: fix computation of set of types requiring method sets. 2013-10-23 17:07:52 -04:00
playground go.tools/present: add support for non Go code execution 2013-10-14 14:14:08 -07:00
pointer go.tools/ssa: fix computation of set of types requiring method sets. 2013-10-23 17:07:52 -04:00
present present/code.go: remove residual file from an hg merge. 2013-10-02 11:02:33 +10:00
ssa go.tools/ssa: fix computation of set of types requiring method sets. 2013-10-23 17:07:52 -04:00
.hgignore go.empty: prototype for new subrepository 2012-01-25 14:45:13 -05:00
AUTHORS go.empty: prototype for new subrepository 2012-01-25 14:45:13 -05:00
codereview.cfg go.empty: prototype for new subrepository 2012-01-25 14:45:13 -05:00
CONTRIBUTORS go.empty: prototype for new subrepository 2012-01-25 14:45:13 -05:00
LICENSE LICENSE: add 2012-03-17 15:20:58 +11:00
PATENTS go.empty: add PATENTS file to the subrepo. 2012-04-16 11:24:04 +10:00
README go.tools/README: update to make truthful 2013-10-09 11:47:05 -07:00

This subrepository holds the source for various packages and tools that support
the Go programming language.

Some of the tools, godoc and vet for example, are included in binary Go distributions.
Others, including the Go oracle and the test coverage tool, can be fetched with "go get".

Packages include a type-checker for Go and an implementation of the Single Static
Assignment (SSA) representation for Go programs.

To submit changes to this repository, see http://golang.org/doc/contribute.html.