Skip to content

x/tools/internal/refactor/inline: a read from a non-address-taken variable should commute with global effects #68948

@adonovan

Description

@adonovan

@lfolger reported a suboptimal inliner result of this form:

    var g = foo()

    func f(x, y any) { f2(x, y) }

    // before
    f(complicated(), g)

    // after
    var ( x = complicated(); y = g )
    f2(x, y)

In this case, the inliner's effects analysis assumed conservatively that the read from global var g would not commute with the call to complicated(). However, the variable g is not address-taken and is assigned only in its declaration.

The inliner's effects analysis should enumerate all non-address-taken variables (non-exported variables that appear in an lvalue position only in their own declaration) and allow reads of them to commute with global effects such as complicated(), resulting in this more optimal inlining: f2(g, complicated()).

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.RefactoringIssues related to refactoring toolsToolsThis label describes issues relating to any tools in the x/tools repository.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions