Fix symbols re-exported via import public not being found - #4636
Open
bufdev wants to merge 1 commit into
Open
Conversation
Since v1.68.0, which switched to the new compiler, a symbol re-exported through `import public` was not always found by importers, while protoc and v1.67.0 accept the same files. The compiler classified each transitive import by looking only at whichever direct import happened to pull it in first, so a file reachable through several direct imports with differing public-ness could be misclassified. Fixed upstream in protocompile; bump the dependency and add a conformance test covering the two affected shapes. Fixes #4633.
Contributor
|
The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).
|
emcfarlane
approved these changes
Aug 5, 2026
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.
Fixes #4633.
Since v1.68.0, which switched
buf buildto the new compiler, a symbol re-exported throughimport publicis not always found by importers.protocand v1.67.0 accept the same files.From the reporter's repro:
Nothing to do with well-known types; swapping the order of
b.proto's two imports makes it compile.Root cause
In protocompile,
imports.Recurseclassified each transitive import by looking only at whichever direct import happened to pull it in first, so a file reachable through several direct imports with differing public-ness could be misclassified. Public direct imports are ordered first specifically so the public path wins, but that does not disambiguate when both direct imports are public:act.protois visited first, reachestimestamp.protonon-publicly, andtimestamp.protolands in the trailing non-public segment, sob.protostops re-exporting it.A second, related shape was also broken: a plain
importof a file that is also re-exported by a public import. That file has to stay in a direct segment, andTransitive()derived public-ness purely from the segment offsets, so it could not represent the case at all.Fixed in bufbuild/protocompile#754, which classifies every transitive import up front over all direct imports and records public-ness on the import rather than deriving it from segment offsets. This matches
protoc'sDescriptorBuilder::RecordPublicDependencies, which is a closure overpublic_dependencyedges and therefore order-independent.Testing
TestComparePublicImportsbuildstestdata/publicimportsand diffs the resultingFileDescriptorSetagainst realprotoc. It covers both shapes independently (each has its own consumer file, so one working mechanism cannot mask the other breaking), and both fail before the protocompile fix:Beyond that, the fix was validated by differential fuzzing against
protoc: 700 random import DAGs of up to 12 files, each file referencing every symbolprotoc's rule says is visible (zero rejections), plus 838 pairwise accept/reject probes agreeing withprotocin both directions. The same fuzzer flags the bug on an unpatched build within ~30 seeds.Note
go.modcurrently pins protocompile to the branch commit for bufbuild/protocompile#754. Needs a re-pin tomainonce that merges.