Skip to content

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

Open
slachiewicz wants to merge 1 commit into
apache:masterfrom
slachiewicz:THRIFT-6391
Open

slachiewicz wants to merge 1 commit into
apache:masterfrom
slachiewicz:THRIFT-6391

Conversation

@slachiewicz

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 generator now reserves those names before rendering imports, so such a package is imported under an alias (for example client0) in every file of that program; nothing changes when -remote stubs are skipped. Programs that hit this also see generated temporaries renumbered, since allocating the alias uses the same counter. lib/go/test gains a service whose arguments come from packages named client and host.

Verified: make -C lib/go check, make -C test/go check and make dist pass; Apache Accumulo's generated Go, -remote stubs included, now builds (its hyphenated compaction-coordinator.thrift also needs #3968).

@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.

…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
generator now reserves those names before rendering imports, so such a package
is imported under an alias; nothing changes when -remote stubs are skipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@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.

"host", "httptrans", "iprot", "m", "oprot", "parsedUrl",
"parts", "port", "portStr", "protocol", "protocolFactory", "trans",
"urlString", "useHttp"}) {
package_identifiers_set_.insert(local);
"host", "httptrans", "iprot", "m", "oprot", "parsedUrl",
"parts", "port", "portStr", "protocol", "protocolFactory", "trans",
"urlString", "useHttp"}) {
package_identifiers_set_.insert(local);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

package_identifiers_set_ is actually global so this impacts more than the -remote code? do we have a way to only do this for the -remote part?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

also the hardcoded list here doesn't seem maintainable, like it's easy to get out of sync with the actual local variables used in main inside -remote, but that part haven't changed in a long time though.

This branch has not been deployed

No deployments
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