// AllFunctions finds and returns the set of functions potentially // needed by program prog, as determined by a simple linker-style // reachability algorithm starting from the members and method-sets of // each package. The result may include anonymous functions and // synthetic wrappers. // // Precondition: all packages are built. // // TODO(adonovan): this function is underspecified. It doesn't // actually work like a linker, which computes reachability from main // using something like go/callgraph/cha (without materializing the // call graph). In fact, it treats all public functions and all // methods of public non-parameterized types as roots, even though // they may be unreachable--but only in packages created from syntax. // // I think we should deprecate AllFunctions function in favor of two // clearly defined ones: // // 1. The first would efficiently compute CHA reachability from a set // of main packages, making it suitable for a whole-program // analysis context with InstantiateGenerics, in conjunction with // Program.Build. // // 2. The second would return only the set of functions corresponding // to source Func{Decl,Lit} syntax, like SrcFunctions in // go/analysis/passes/buildssa; this is suitable for // package-at-a-time (or handful of packages) context. // ssa.Package could easily expose it as a field. // // We could add them unexported for now and use them via the linkname hack. func AllFunctions(prog *ssa.Program) map[*ssa.Function]bool { … } // MainPackages returns the subset of the specified packages // named "main" that define a main function. // The result may include synthetic "testmain" packages. func MainPackages(pkgs []*ssa.Package) []*ssa.Package { … } // TODO(adonovan): propose a principled API for this. One possibility // is a new field, Package.SrcFunctions []*Function, which would // contain the list of SrcFunctions described in point 2 of the // AllFunctions doc comment, or nil if the package is not from syntax. // But perhaps overloading nil vs empty slice is too subtle. // //go:linkname isSyntactic golang.org/x/tools/go/ssa.isSyntactic func isSyntactic(pkg *ssa.Package) bool