golang/go

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

Open

#63,352 opened on Oct 3, 2023

View on GitHub
 (6 comments) (1 reaction) (0 assignees)Go (19,008 forks)batch import
NeedsFixRefactoringToolshelp wanted

Repository metrics

Stars
 (133,883 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

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.

  • allow conversions (other than []byte(string), which observably allocates) to be considered duplicable (#67589).
  • omit unnecessary interface conversions in argument passing (#68554).
  • simplify "binding decl" to use param := arg when it's not necessary to state the type.
  • improve precision of check of whether arg elimination removes last ref to a caller var... ...and instead of preventing elimination, blank out the var decl.
  • avoid imports.Process by reimplementing just the algorithm we need.
  • choose better local names for renaming imports
  • avoid unnecessarily renaming imports (may need additional inputs?) (#67281)
  • implement "void tail call" strategy (i.e. f() statement before return stmt). If the return stmt is pure, this is sound even if the callee uses defer.
  • implement parameterless call to { stmt; return expr } from one of these contexts:
        //    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).

Contributor guide