go.tools/ssa: fix a package-level var initialization order bug.
buildDecl was visiting all decls in source order, but the spec
calls for visiting all vars and init() funcs in order, then
all remaining functions. These two passes are now called
buildInit(), buildFuncDecl().
+ Test.
Also:
- Added workaround to gcimporter for Func with pkg==nil.
- Prog.concreteMethods has been merged into Pkg.values.
- Prog.concreteMethod() renamed declaredFunc().
- s/mfunc/obj/ (name cleanup from recent gri CL)
R=gri
CC=golang-dev
https://golang.org/cl/12030044
diff --git a/ssa/ssa.go b/ssa/ssa.go
index 08300ae..78c5d0a 100644
--- a/ssa/ssa.go
+++ b/ssa/ssa.go
@@ -18,12 +18,11 @@
// A Program is a partial or complete Go program converted to SSA form.
//
type Program struct {
- Fset *token.FileSet // position information for the files of this Program
- PackagesByPath map[string]*Package // all loaded Packages, keyed by import path
- packages map[*types.Package]*Package // all loaded Packages, keyed by object
- builtins map[types.Object]*Builtin // all built-in functions, keyed by typechecker objects.
- concreteMethods map[*types.Func]*Function // maps declared concrete methods to their code
- mode BuilderMode // set of mode bits for SSA construction
+ Fset *token.FileSet // position information for the files of this Program
+ PackagesByPath map[string]*Package // all loaded Packages, keyed by import path
+ packages map[*types.Package]*Package // all loaded Packages, keyed by object
+ builtins map[types.Object]*Builtin // all built-in functions, keyed by typechecker objects.
+ mode BuilderMode // set of mode bits for SSA construction
methodsMu sync.Mutex // guards the following maps:
methodSets typemap.M // maps type to its concrete MethodSet
@@ -40,7 +39,7 @@
Prog *Program // the owning program
Object *types.Package // the type checker's package object for this package
Members map[string]Member // all package members keyed by name
- values map[types.Object]Value // package-level vars and funcs, keyed by object
+ values map[types.Object]Value // package-level vars & funcs (incl. methods), keyed by object
init *Function // Func("init"); the package's (concatenated) init function
// The following fields are set transiently, then cleared