Open
Description
I would like to deprecate the AllFunctions helper function, because it's a poorly specified mess (my bad).
As its doc comment says:
// 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.
Before we can consider doing that (which will require a proposal), we should stop using it ourselves in x/tools and x/vuln. Its existing uses are:
// These test could use a simpler ad hoc algorithm, or an efficient CHA:
go/ssa/stdlib_test.go
go/ssa/builder_test.go
// both CHA and static do essentially the same reachability fixed point
// iteration and could do (the good bits of) AllFunctions themselves:
go/callgraph/cha/cha.go -- AllFunctions is not even correct here! see #66429
go/callgraph/static/static.go
--
// VTA uses AllFunctions to produce a set of entry points.
// I suspect it is both a massive overapproximation and yet still not always correct (see #66251)
// What exactly does vta.CallGraph need?
cmd/callgraph/main.go
go/callgraph/vta/vta_test.go
go/callgraph/vta/graph_test.go
go/callgraph/callgraph_test.go
x/vuln/internal/vulncheck/utils.go
// just for debugging; could easily be deleted.
go/callgraph/vta/helpers_test.go
I will tackle the first half. @zpavlinovic perhaps you could look at the VTA-related ones? What we need at this stage is just crisp descriptions of the exact requirements of each of these algorithms.
Metadata
Metadata
Assignees
Type
Projects
Relationships
Development
No branches or pull requests
Activity
gopherbot commentedon Sep 3, 2024
Change https://go.dev/cl/609280 mentions this issue:
go/callgraph/static: avoid ssautil.AllFunctions
go/callgraph/static: avoid ssautil.AllFunctions
gopherbot commentedon Sep 4, 2024
Change https://go.dev/cl/609281 mentions this issue:
go/callgraph/cha: make CHA, VTA faster and more precise
gopherbot commentedon Sep 5, 2024
Change https://go.dev/cl/611216 mentions this issue:
internal/vulncheck: remove use of ssautil.AllFunctions
gabyhelp commentedon Sep 5, 2024
Related Issues and Documentation
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
internal/vulncheck: remove use of ssautil.AllFunctions
zpavlinovic commentedon Sep 6, 2024
Regarding VTA:
_test files
need some set of functions for the test programs. We currently usessautil.AllFunctions
but we could in principle write a simple helper that collects functions for the test programs. These programs are rather simple. Also, we could use x/tools/go/ssa/ssautil: Reachable: conservative approximation to reachable functions, runtime types #69291.ssautil.AllFunctions
for some unnecessary pruning in vulncheck. However, we will have to reintroduce the use of this function soon for a different purpose, i.e., when we try to take advantage of some improvements in VTA. The set of functions passed to VTA will be a forward slice of roots computed using the (copy of)golang.org/x/tools/go/callgraph/internal/chautil.LazyCallees
. This function in turn expects a set of program functions. We have to usessautil.AllFunctions
for the time being and deprecate it when x/tools/go/ssa/ssautil: Reachable: conservative approximation to reachable functions, runtime types #69291 is done.gopherbot commentedon Sep 6, 2024
Change https://go.dev/cl/611535 mentions this issue:
internal/callgraph/chautil: add Reachable function
gopherbot commentedon Sep 6, 2024
Change https://go.dev/cl/611536 mentions this issue:
go/ssa: stop using ssautil.AllFunctions
adonovan commentedon Sep 6, 2024
With my https://go.dev/cl/609281 stack (the last CL needs some thought), there are no remaining uses of AllFunctions in x/tools. (Not even tests of it, alarmingly.)
I notice that AllFunctions returns uninstantiated generics whereas the new chautil.Reachable does not, and for this reason it's probably not safe for us ever to make AllFunctions a wrapper around Reachable; we'll just have to leave it there with a doc explaining what it does and why there are better solutions for most tasks, and what they are.
StevenACoffman commentedon Dec 6, 2024
@adonovan Reading through the current source code, I don't believe the second part of AllFunctions doc comment is available yet.
I was hoping for something like this:
This would be very convenient for some linters to have, so they don't need to waste time calling SrcFunctions in go/analysis/passes/buildssa if AllFunctions is no longer available.