Skip to content

proposal: x/tools/go/{ssa,cfg}: expose "no return" API #76161

@adonovan

Description

@adonovan

Background: The precision of analyses that use the golang.org/x/tools/go/ssa representation of Go programs is improved by exploiting information about which function calls can never return, such as log.Fatal or (*testing.T).Fatalf. This information is already computed interprocedurally by the ctrlflow analyzer, which uses the x/tools/go/cfg package, and is plumbed through to x/tools/go/ssa by using three backdoors. This is implemented in https://go.dev/cl/716920. We would like to add public API to obviate the need for such hacks.

Proposal: We propose to expose these three accessor methods:

package cfg // x/tools/go/cfg

// NoReturn reports whether the control flow graph cannot return normally.
func (*CFG) NoReturn() bool
package ctrlflow // x/tools/go/analysis/passes/ctrlflow

// NoReturn reports whether the specified control-flow graph cannot return normally.
func (*CFGs) NoReturn(*types.Func) bool
package ssa // x/tools/go/ssa

// SetNoReturn sets the predicate used by the SSA builder to decide whether a 
// call to the specified named function cannot return normally.
// This allows the builder to prune infeasible control flow edges,
// improving the precision of downstream analyses.
func (*Program) SetNoReturn(func (*types.Func) bool)

Metadata

Metadata

Assignees

Labels

AnalysisIssues related to static analysis (vet, x/tools/go/analysis)LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolProposalToolsThis label describes issues relating to any tools in the x/tools repository.

Type

No type

Projects

Status

Active

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions