Skip to content

x/tools/internal/refactor/inline: good starter projects #63352

Open

Description

@adonovan

Below is a list of starter projects for anyone who wants to get their hands dirty in the inliner logic. Before starting work on any item, please fork it off into a separate issue, briefly stating the approach you plan to take.

        //    x, y     = f()
        //    x, y    := f()
        //    var x, y = f()
  • use binding decls even with the literalization strategy: it's easier and more natural to read func() { var param=arg; ... } () than func(param) { ... } (arg). (Beware: binding decls cover params and named result vars; they may need to be teased apart.)
  • clean-up (?): unify pure, duplicable, and effects into a single pass.
  • use callee's FileSet (calleeFset) to format the new node (res.new), as it is mostly callee code. This should reduce comment loss. (Beware: it seems to introduce spurious newlines. Why?)

See also:

More challenging projects:

  • Translate if f(); cond { ... } to { fbody; if cond { ... } } when the inlining of f() is not a simple expression.- [ ] Add a control flow analysis that is more precise than the current "single assignment" predicate. Currently, a binding declaration is required if an argument is a variable that is not "single assignment". But if all the assignments can be proved to occur before or after the call (but not during it using lambdas) then a binding declaration may not be needed.
  • Add an alias analysis so that effects on memory by the callee can be localized to particular variables, allowing writes to commute with reads if they cannot alias.
  • Better handling of spread calls (f(g()) where g returns >1 result).

Activity

  1. added
    ToolsThis label describes issues relating to any tools in the x/tools repository.
    on Oct 3, 2023
  2. added this to the Unreleased milestone on Oct 3, 2023
  3. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    on Oct 3, 2023
  4. aimuz commented on Nov 7, 2023

    @aimuz
    Contributor

    Hello, what do I need to start with

  5. adonovan commented on Nov 7, 2023

    @adonovan
    MemberAuthor

    Hello, what do I need to start with

    Hi @aimuz, thanks for your interest! The task requires at least a little familiarity with the basic concepts of compilers, and with the APIs of Go's go/ast and go/types packages. Otherwise the learning curve will be steeper; you may find https://golang.org/s/types-tutorial helpful.

    Does any of the items listed above seem appealing? If there's one in particular that you want to start with, I suggest you create a separate issue for it, claim it for yourself, state briefly (a sentence or two is fine) what approach you plan to take, and ask any question you have about the approach. We can comment on the separate issue without confusing this one.

  6. aimuz commented on Nov 9, 2023

    @aimuz
    Contributor

    Thanks for the guide, have a nice day!

  7. vladvalkov commented on May 20, 2024

    @vladvalkov

    Hi @adonovan! Are these still relevant?
    Should the claimed issue follow any existing template? (or can it be just a blank issue referencing this one?)

  8. adonovan commented on May 21, 2024

    @adonovan
    MemberAuthor

    Hi @vladvalkov, yes they are still relevant. No particular template, just include the relevant information and link from here to the new issue.

    IMHO the best starter tasks are:

    • allow conversions (other than []byte(string), which observably allocates) to be considered duplicable.
    • improve precision of check of whether arg elimination removes last ref to a caller var...
    • choose better local names for renaming imports
  9. gopherbot commented on Oct 20, 2025

    @gopherbot
    Contributor

    Change https://go.dev/cl/712981 mentions this issue: internal/refactor/inline: preserve alias when choosing a local name for imported package

  10. gopherbot commented on Aug 13, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/814441 mentions this issue: internal/refactor/inline: use short binding decls when types are redundant

  11. gopherbot commented on Aug 13, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/814521 mentions this issue: internal/refactor/inline: reduce void calls in tail position

  12. gopherbot commented on Aug 13, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/814442 mentions this issue: internal/refactor/inline: reduce {stmts; return} calls in assign context

  13. gopherbot commented on Aug 13, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/814522 mentions this issue: internal/refactor/inline: prefer pathpkg-style local import names

  14. gopherbot commented on Aug 13, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/814620 mentions this issue: internal/refactor/inline: wrap void calls out of if/for/switch init

  15. gopherbot commented on Aug 13, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/814523 mentions this issue: internal/refactor/inline: discard go/defer of empty functions

  16. gopherbot commented on Aug 13, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/814401 mentions this issue: internal/refactor/inline: unwrap variadic literal in empty-body discard

  17. gopherbot commented on Oct 14, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/848906 mentions this issue: internal/refactor/inline: format res.new with callee FileSet

  18. gopherbot commented on Oct 14, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/849265 mentions this issue: internal/refactor/inline: unify pure, duplicable, and effects

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsFixThe path to resolution is known, but the work has not been done.RefactoringIssues related to refactoring toolsToolsThis label describes issues relating to any tools in the x/tools repository.help wanted

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions