-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x/tools/go/ssa: generate function bodies for parameterized functions #54984
Comments
CC @findleyr |
This proposal has been added to the active column of the proposals project |
Any objections to adopting this proposal? /cc @adonovan |
None at all! We should merge it as soon as we've verified that the new go/ssa builder is free of obvious bugs by running it over Google's internal Go code base. Thanks Tim and Zvonimir for your sustained efforts on this tricky problem. |
Based on the discussion above, this proposal seems like a likely accept. |
No change in consensus, so accepted. 🎉 |
There are no known bugs with go/ssa over Google's internal Go code base with BuilderMode(0). |
Implemented in https://go-review.googlesource.com/c/tools/+/425496. |
This proposal is to update the x/tools/go/ssa package to generate function bodies for parameterized functions. This enables analysis of generic functions and methods from incremental analysis tools (such as those built on
x/tools/go/analysis/passes/buildssa
) without instantiations from the same package.This is proposal is a continuation of the discussion in #48525. A full implementation of this proposal is available here https://go-review.googlesource.com/c/tools/+/425496 .
This will make several user visible changes to
x/tools
:TreeMap[K,V].Contains
may be partially instantiated to a wrapperTreeMap[string, V].Contains
whileTreeMap[string, int].Contains
is fully expanded and specialized.go/analysis/passes/buildssa builds
with the default build mode. (ssa.InstantiateGenerics is off.)Comparison to the current state of
ssa
andbuildssa
:This behavior is mostly an expansion of the existing behavior. Existing users of
ssa
may have incomplete type switches (no handling oftypes.TypeParam
) or other now incorrect assumptions that are now incorrect for parameterized Functions. This will only apply to analysis of code that uses generics. In practice, many existing drivers ofx/tools/go/analysis.Analyzers
will examine transitive dependencies. As of Go 1.19 standard library packages such assync/atomics.Pointer[T]
contain generics. So applyingssa
to parameterized functions is likely to occur in the analysis of non-toy packages.The current state of incremental analysis from
buildssa
is that ssa.InstantiateGenerics is on today. Genericssa.Function
s will be present inSrcFuncs
, havetypes.TypeParams
in theirSignatures
, and have empty bodies. Instantiations within the same package will be built with expanded function bodies. Instantiations of a generic function defined in another packages will not have a syntax tree available and will be built with an empty Function body. To analyze the contents of parameterized functions, a body must be made available without requiring [somewhat complete] instantiations from the same package. If this proposal is accepted, a body for parameterized functions will always be available.Users that want to skip over the bodies of generic functions (potentially temporarily while they add support) can use
fn.TypeParams() > 0 && len(fn.TypesArgs()) == 0
to detect when a function has a parameterized body.The text was updated successfully, but these errors were encountered: