Inliner enhancement - choose better local names when renaming imports

66 views
Skip to first unread message

Gavin Lam

unread,
Aug 13, 2025, 1:49:08 PMAug 13
to golang-nuts
I noticed #63352 requests improvements to the inliner by choosing better local names when renaming imports.

I've opened #74965 outlining a proposal and potential strategies for generating more meaningful local names. I plan to work on implementing this enhancement and submit a PR.

What are your thoughts?

Potential strategies:
  1. Try PkgName (unchanged).
  2. Try the local alias of the callee. (There is a todo comment in inline.go#525)
  3. Try PkgName + "pkg". For example, path becomes pathpkg.
  4. Prepend the preceding path segment if available. For example, golang.org/x/tools/internal/astutil becomes internalastutil.
  5. Appending a numeric suffix (unchanged). For example, path becomes path1, path2, ...

These strategies follow common practices for package aliasing. Examples in OSS repositories:

Strategy 3
  1. path as pathpkg: 14 usages in golang/tools, 11 usages in golang/go
  2. urlpkg, tracepkg, errorspkg, stringspkg, logpkg, htmlpkg, etc. in golang/go and golang/tools
  3. nodepkg, volumepkg, auditpkg, controllerpkg, etc. in kubernetes/kubernetes

Reply all
Reply to author
Forward
0 new messages