Support type parameter substitution at call-sites during inlining. - #6039
Merged
Conversation
When inlining generic methods whose `@InlineMe` replacement contains type variables (e.g., `Client.<T>after()`, `new ArrayList<V>()`, `(T) obj`, `this.<T>after()`), Inliner now maps method type parameter names to the explicit type arguments passed at the call-site and substitutes them into the replacement expression. When explicit type arguments are omitted at the call-site: - In method invocations (e.g. `Client.<V>after()`), unsubstituted type arguments are stripped to allow standard compiler type inference (`Client.after()`). - In constructor invocations (e.g. `new ArrayList<V>()`), unsubstituted type arguments are converted to diamond syntax (`new ArrayList<>()`). - In casts (e.g. `(T) obj`), unresolvable type variable casts are stripped (`obj`), allowing compiler type inference when the cast is unnecessary. PiperOrigin-RevId: 966158769
copybara-service
Bot
force-pushed
the
test_964303865
branch
from
August 17, 2026 20:45
97e23b1 to
b41e2ba
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.
Support type parameter substitution at call-sites during inlining.
When inlining generic methods whose
@InlineMereplacement contains type variables(e.g.,
Client.<T>after(),new ArrayList<V>(),(T) obj,this.<T>after()),Inliner now maps method type parameter names to the explicit type arguments
passed at the call-site and substitutes them into the replacement expression.
When explicit type arguments are omitted at the call-site:
Client.<V>after()), unsubstituted type argumentsare stripped to allow standard compiler type inference (
Client.after()).new ArrayList<V>()), unsubstituted typearguments are converted to diamond syntax (
new ArrayList<>()).(T) obj), unresolvable type variable casts are stripped(
obj), allowing compiler type inference when the cast is unnecessary.