Skip to content

Conversation

@jhump
Copy link
Member

@jhump jhump commented Feb 9, 2026

I was porting a lot of this code to a new stand-alone package (for now, in the bufbuild/extra repo) and when I was comparing test output in those ported tests to the original golden files in this package, there were some discrepancies. I was able to understand all of the discrepancies except ones related to weak imports in the "testdata/sourcecodeinfo" files. It turns out that there was a bug in the logic, that happened to manifest slightly differently between this original code and the ported code in extra.

So this fixes the logic. The issue is that it was using the "from" and "to" indexes in the dependencies field of FileDescriptorProto when updating source code info for the weak_dependencies field 😞. So this fixes that.

I also updated the "testdata/sourcecodeinfo" golden files to include the actual filtered sources, instead of only the source code info blob, in order to compare the filtered source code info to those filtered sources when debugging. I updated a handful of other small things, too, like fixing stale symbols in doc comments.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 9, 2026

The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedFeb 9, 2026, 6:04 PM

// Keep 2: comment on package
package foo.bar;
// Keep if NestedFoo: comment on import any.proto
import "google/protobuf/any.proto";
Copy link
Member Author

Choose a reason for hiding this comment

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

Annoyingly, this should be import weak. The actual filtered descriptor and source code info is correct. The issue turns out to be the way we package up the descriptor protos into protoreflect.FileDescriptor instances: those types no longer have any support for weak imports as of v1.36.5. 🤷

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, noticed that when we did the upgrade here :< #3653

Comment on lines +322 to +331
for i, indexFrom := range weakDependencies {
weakFrom := int32(i)
path := append(weakDependencyPath, weakFrom)
indexTo := dependencyChanges[indexFrom]
if indexTo == -1 {
sourcePathsRemap.markDeleted(path)
} else {
if indexTo != indexFrom {
sourcePathsRemap.markMoved(path, indexTo)
weakTo := int32(len(newWeakDependencies))
if weakTo != weakFrom {
sourcePathsRemap.markMoved(path, weakTo)
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the actual fix. Other stuff in this PR is incidental changes/improvement (trying to leave everything in better shape than when I arrived) and the updated test outputs.

@jhump jhump requested a review from emcfarlane February 9, 2026 18:04
Comment on lines +258 to +261
// TODO: Add support for option dependencies when buf CLI supports edition 2024.
if len(fileDescriptor.GetOptionDependency()) > 0 {
return nil, nil, nil, false, errors.New("edition 2024 not yet supported: cannot filter a file descriptor with option dependencies")
}
Copy link
Member

Choose a reason for hiding this comment

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

This is mostly a note for myself, I appreciate the TODO, I'm porting over the new compiler for edition 2024 support right now, so this is helpful for me when I rebase on this. Thank you!

@jhump jhump merged commit feaa2d8 into main Feb 10, 2026
10 checks passed
@jhump jhump deleted the jh/fix-rewrite-source-info-for-weak-deps branch February 10, 2026 16:50
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.

2 participants