Skip to content

cmd/compile: export inline method bodies for exported type aliases - #82477

Open
Capstan wants to merge 1 commit into
golang:masterfrom
Capstan:noder-inline-type-alias
Open

Capstan wants to merge 1 commit into
golang:masterfrom
Capstan:noder-inline-type-alias

Conversation

@Capstan

@Capstan Capstan commented Oct 23, 2026

Copy link
Copy Markdown

When package b declares an exported type alias "type T = a.T" for a
non-interface type a.T defined in an imported package a, the unified
IR linker does not export a.T's inline method bodies in b's export
data. relocObj only walks a type's methods when the object is not an
alias, and exportBody only re-exports an imported body if b itself
inlined a call to it (fn.Inl.HaveDcl). As a result, a package c that
imports b, but not a, cannot inline methods called through b.T.

Fix this by indexing imported static method bodies by their receiver
type symbol in readPackage (importTypeBodies). When relocObj relocates
a top-level, local, exported type alias to an imported non-interface
type, forward the aliased type's inline method bodies into b's export
data. While relocating a forwarded body, also forward the inline
bodies of imported functions and receiver types it references,
including entries that were already relocated. Packages without such
aliases export the same data as before.

Alias chains also work: if c instead declares "type T = b.T", c.T
resolves to a.T, so c forwards the bodies it read from b's export data
and a package d that imports only c can inline them.
TestInlineTypeAliasMethods covers this two-hop case.

Fixes #82474

When package b declares an exported type alias "type T = a.T" for a
non-interface type a.T defined in an imported package a, the unified
IR linker does not export a.T's inline method bodies in b's export
data. relocObj only walks a type's methods when the object is not an
alias, and exportBody only re-exports an imported body if b itself
inlined a call to it (fn.Inl.HaveDcl). As a result, a package c that
imports b, but not a, cannot inline methods called through b.T.

Fix this by indexing imported static method bodies by their receiver
type symbol in readPackage (importTypeBodies). When relocObj relocates
a top-level, local, exported type alias to an imported non-interface
type, forward the aliased type's inline method bodies into b's export
data. While relocating a forwarded body, also forward the inline
bodies of imported functions and receiver types it references,
including entries that were already relocated. Packages without such
aliases export the same data as before.

Alias chains also work: if c instead declares "type T = b.T", c.T
resolves to a.T, so c forwards the bodies it read from b's export data
and a package d that imports only c can inline them.
TestInlineTypeAliasMethods covers this two-hop case.
@Capstan
Capstan force-pushed the noder-inline-type-alias branch from 57ccd1c to 83ce276 Compare October 24, 2026 00:06
@gopherbot

Copy link
Copy Markdown
Contributor

This PR (HEAD: 83ce276) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/853585.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Gopher Robot:

Patch Set 1:

Congratulations on opening your first change. Thank you for your contribution!

Next steps:
A maintainer will review your change and provide feedback. See
https://go.dev/doc/contribute#review for more info and tips to get your
patch through code review.

Most changes in the Go project go through a few rounds of revision. This can be
surprising to people new to the project. The careful, iterative review process
is our way of helping mentor contributors and ensuring that their contributions
have a lasting impact.

During May-July and Nov-Jan the Go project is in a code freeze, during which
little code gets reviewed or merged. If a reviewer responds with a comment like
R=go1.11 or adds a tag like "wait-release", it means that this CL will be
reviewed as part of the next development cycle. See https://go.dev/s/release
for more details.


Please don’t reply on this GitHub thread. Visit golang.org/cl/853585.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from David Chase:

Patch Set 1: Auto-Submit+1 Commit-Queue+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/853585.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com:

Patch Set 1:

Dry run: CV is trying the patch.

Bot data: {"action":"start","triggered_at":"2026-10-26T00:24:59Z","revision":"b70ce5d8a6b6051e28a3031775f80c29c4936c92"}


Please don’t reply on this GitHub thread. Visit golang.org/cl/853585.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from David Chase:

Patch Set 1: -Commit-Queue

(Performed by <GERRIT_ACCOUNT_60063> on behalf of <GERRIT_ACCOUNT_7061>)


Please don’t reply on this GitHub thread. Visit golang.org/cl/853585.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com:

Patch Set 1:

This CL has passed the run


Please don’t reply on this GitHub thread. Visit golang.org/cl/853585.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com:

Patch Set 1: LUCI-TryBot-Result+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/853585.
After addressing review feedback, remember to publish your drafts!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cmd/compile: methods of an imported type are not inlined when reached through a type alias in another package

2 participants