Repository navigation
lib/go: Dedup include package - #16
Merged
Merged
Conversation
AlexisMontagne
approved these changes
Oct 27, 2026
tgallice
force-pushed
the
tg/go-plugin-dedup-includes
branch
from
October 28, 2026 08:51
95f4f23 to
94f5cf7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Dedup include package names in the Go plugin scope
plugin.BuildGoScopenamed each include after the last segment of its namespace, without checking for duplicates. When a program includes two packages with the same name, Go pluginsimport both under that one name, and the generated code does not compile.
Example:
influencer/apis/post/fetcher/v2/post_fetcher.thriftincludes bothbase.postandinfluencer.types.post.v2.post. In influencer v1.0.72, theunimplemented.goandfake.gofiles generated for it fail with
post redeclared in this block.media_fetcherv2 andindexerv2 hit the same issue withmedia. The C++ generator already handles this case.Changes
gocodegen.Scope.DedupIncludes(reserved...)gives each import path a distinctPkgName. An include keeps its own name when that name is free; otherwise it gets a numeric suffix(
post0). Names reserved in one call stay reserved in later calls, so a plugin can add its own.BuildGoScopereserves the thrift runtime package name and the Go predeclared identifiers (error,string...), so that an include cannot hide them.Include.BaseName()returns the package's real name, before any renaming.Include.ImportSpec()writes the import line, with an alias only when one is needed.Scope.Imports()returns a single entry per import path.GoTypestays consistent: a type from a renamed include is generated as*post0.Post.Compatibility
Includes are renamed only when there is a collision, and
ImportSpecadds no alias in other cases. Code generated without collisions is unchanged. To benefit from the fix, a plugintemplate must import with
{{.ImportSpec}}; this is done forgo-unimplemented-serverandgo-fake-serverin a follow-up PR on upfluence-if.[skip ci]anywhere in the commit message to free up build resources.