Skip to content

THRIFT-6391: Import packages that collide with -remote stub locals under an alias - #3971

Merged
fishy merged 1 commit into
apache:masterfrom
slachiewicz:THRIFT-6391
Oct 11, 2026
Merged

fishy merged 1 commit into
apache:masterfrom
slachiewicz:THRIFT-6391

Conversation

@slachiewicz

@slachiewicz slachiewicz commented Sep 27, 2026 •

Copy link
Copy Markdown
Member

The Go -remote stub's main() declares locals such as client, cmd and host, which shadowed an imported package of the same name, so the stub did not compile. The stub now gets import identifiers of its own with those names reserved, so such a package is imported under an alias there; the program's other files are generated as before. An alias is also never a name another import already uses. lib/go/test gains a service whose arguments come from packages named client, host and client0.

Elsewhere in lib/go/test and test/v0.16, the generated code changes in one place: an alias in the conflict -remote stub is renumbered.

Verified: make -C lib/go/test check passes.

@mergeable mergeable Bot added golang Pull requests that update Go code compiler build and general CI cmake, automake and build system changes labels Sep 27, 2026
@slachiewicz

Copy link
Copy Markdown
Member Author

The lib-d job here timed out in lib/d/test/client_pool_test, which this PR doesn't touch. The cause is a hang in the D fastest client pool, fixed in #3972 (THRIFT-6392); lib-d should pass here once that is merged.

@slachiewicz
slachiewicz marked this pull request as ready for review October 7, 2026 21:22
@slachiewicz
slachiewicz requested a review from fishy as a code owner October 7, 2026 21:22
Copilot AI balanced review requested due to automatic review settings October 7, 2026 21:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Alias generation can select an identifier already assigned to another imported package.

1 open finding
What changed in this PR

Updates Go code generation to prevent -remote stub locals from shadowing imported Thrift packages.

Changes:

  • Reserves generated remote-stub local names before import allocation.
  • Adds compile-time regression fixtures for client and host package collisions.
  • Includes generated packages and remote executable in Go checks.
File Description
compiler/​cpp/​src/​thrift/​generate/​t_go_generator.cc Reserves remote-stub identifiers.
lib/​go/​test/​Makefile.am Generates, builds, and distributes regression fixtures.
lib/​go/​test/​RemoteShadowTest.thrift Defines the regression service.
lib/​go/​test/​RemoteShadowClient.thrift Adds the colliding client package.
lib/​go/​test/​RemoteShadowHost.thrift Adds the colliding host package.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread compiler/cpp/src/thrift/generate/t_go_generator.cc Outdated
Comment thread compiler/cpp/src/thrift/generate/t_go_generator.cc Outdated
Copilot AI balanced review requested due to automatic review settings October 11, 2026 14:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Dynamically generated indexed locals can still shadow imported packages, and the alias-retry path lacks effective coverage.

2 open findings
1 resolved since last review

🧠 Review effort: Balanced

Comment thread compiler/cpp/src/thrift/generate/t_go_generator.cc
Comment thread compiler/cpp/src/thrift/generate/t_go_generator.cc
…der an alias

Client: go

The Go -remote stub's main() declares locals such as client, cmd and host, which
shadowed an imported package of the same name, so the stub did not compile.
Apache Accumulo (client.thrift) and Apache Pegasus (package cmd) hit it. The stub
now gets import identifiers of its own, with those names reserved, so such a
package is imported under an alias there; the program's other files are
generated as before. An alias is also never one already taken by another import.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fishy
fishy merged commit a81db74 into apache:master Oct 11, 2026
86 of 87 checks passed
@slachiewicz
slachiewicz deleted the THRIFT-6391 branch October 11, 2026 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build and general CI cmake, automake and build system changes compiler golang Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants