Skip to content

x/tools/go/analysis/passes/recursiveiter: publish Analyzer and include it in cmd/vet #77562

@adonovan

Description

@adonovan

Background: the recursiveiter analyzer reports subtly incorrect definitions of iterators over recursive data structures that lead to poor asymptotic performance. It has been included in gopls for over a year.

It does not trigger very often, but it does report a serious problem with high confidence, and is cheap to run. Here's a typical finding:

    78  func allYamlNodes(n *yaml.Node) iter.Seq[*yaml.Node] {
    79  	return func(yield func(*yaml.Node) bool) {
    80  		if !yield(n) {
    81  			return
    82  		}
    83  		for _, n2 := range n.Content {
    84  			for n3 := range allYamlNodes(n2) { // "inefficient recursion in iterator allYamlNodes"
    85  				if !yield(n3) {
    86  					return
    87  				}
    88  			}
    89  		}
    90  	}
    91  }

More:

Proposal: we propose to move this analyzer to a public package and include it in the cmd/vet suite.

Metadata

Metadata

Assignees

No one assigned

    Labels

    AnalysisIssues related to static analysis (vet, x/tools/go/analysis)NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolProposalIssues describing a requested change to a Go tool or command-line program.ToolsThis label describes issues relating to any tools in the x/tools repository.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions