Repository navigation
protobuf: infer dependencies on targets with more than one resolve-like field - #23743
Merged
tdyas merged 1 commit intoNov 5, 2026
Merged
Conversation
…ke field With Python and JVM codegen enabled together, protobuf_source carries both python_resolve and jvm_resolve, and inference raised NotImplementedError. Infer each import to the owner shared by every resolve the importing target is in, and stop falling back to the resolves-disabled partition for all targets when only one language has resolves disabled. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
tdyas
approved these changes
Nov 2, 2026
tdyas
left a comment
Contributor
There was a problem hiding this comment.
Looks good to me. Thanks for fixing!
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.
This PR was written primarily by Claude Code (Claude Opus 5.5). I reviewed the change and its tests before opening it.
Related: #21409, #21918.
Problem
Enabling Python and Java or Scala protobuf codegen together registers two resolve-like fields on
protobuf_source:python_resolveandjvm_resolve. Protobuf dependency inference then fails on every proto with:map_protobuf_filesalready handles this. A target with two resolve-like fields goes into one partition per field. Only the lookup side,get_resolve_key_from_target, gives up.A second bug sits in the same lookup. If any partition is the "resolves disabled" sentinel, every target uses the sentinel partition. With Python resolves disabled and JVM resolves enabled, inference ignores
jvm_resolveentirely, sojvm_resolve=parametrize("j1", "j2")makes every import ambiguous and infers nothing.Solution
get_resolve_keys_from_targetreturns one key per resolve-like field on the target, with the sentinel for a field whose resolves are disabled. For each import, inference takes the owners the import has in each of those resolves and intersects them:With one resolve-like field this is exactly today's behaviour. With two, it picks the owner that shares every one of the importing target's resolves. That is the only owner the target can build against in each language. For
protobuf_source(python_resolve=parametrize("a", "b"), jvm_resolve=parametrize("j1", "j2")), each import has two owners per resolve but exactly one in the intersection, the variant with the same parameters.The shortcut to the sentinel partition now applies only when the mapping has no other partitions, which is what it was for.
Design note
I considered inferring per language instead: the Python resolve when Python consumes the proto, the JVM resolve when Java or Scala does. That would be in the spirit of #23668's per-requesting-language dispatch. But dependency inference produces one dependency set per target, with no requesting language to consult, so the intersection is what that set can express. If the maintainers would rather discuss this in an issue first, I'm happy to move it there.
Testing
Three new tests in
protobuf_dependency_inference_test.pyuse the realPythonResolveFieldandPrefixedJvmResolveField, registered the way the Python, Java and Scala backends register them:NotImplementedErroronmain)NotImplementedErroronmain)jvm_resolveparametrized (silently inferred nothing onmain)The parametrized cases use per-file
protobuf_sourcetargets becausejvm_resolveis registered as a copied field onprotobuf_sources, so it can't be parametrized there yet. That is a separate one-line change.The existing protobuf and Python-protobuf inference tests pass unchanged.
🤖 Generated with Claude Code