[typemap] Match legacy JCW interface declarations - #12585
Open
simonrozsival wants to merge 1 commit into
Open
Conversation
Filter redundant parent interfaces and duplicate Java names from generated callable-wrapper declarations while retaining the complete ordered interface list for scanner and typemap semantics. Extend the shared semantic fixture and Android build matrix with the colliding-interface regression. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
Review tier: Lite
Findings: 1
New issues introduced by this change (1)
| Severity | Finding |
|---|---|
src/Microsoft.Android.Sdk.TrimmableTypeMap/Scanner/JavaPeerScanner.cs — interfaces.Any(...) inside the per-interface loop creates an O(n²) scan and… |
What changed in this PR
This PR updates the trimmable typemap Java peer scanning/generation pipeline so generated Java callable wrappers emit an interface implements list that matches legacy CecilImporter semantics (stable order, no redundant parent interfaces, no duplicate Java names), while still preserving the full ordered direct-interface list from managed metadata for other semantics.
Changes:
- Add
JavaCallableWrapperInterfaceJavaNamesonJavaPeerInfoand compute it in the scanner by filtering redundant parent interfaces and deduplicating Java names in first-seen order. - Update JCW Java source generation and Java-name validation to use the filtered interface list when available.
- Extend the shared semantic parity fixture + integration/build tests to cover parent/derived redundancy, colliding managed aliases, stable ordering, and compilation via
javac.
| File | Description |
|---|---|
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.IntegrationTests/JavaSourceSemanticParityTests.cs | Extends semantic parity coverage for redundant/colliding interfaces and adds Java stub types required for javac compilation. |
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.IntegrationTests/JavaSourceParityFixture/JavaSourceParityTypes.cs | Expands the managed fixture with interface hierarchy + alias collision scenarios used by both legacy and trimmable pipelines. |
| src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/TrimmableTypeMapBuildTests.cs | Extends build validation to ensure the semantic parity fixture compiles across llvm-ir/trimmable and CoreCLR/NativeAOT configurations. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/TrimmableTypeMapGenerator.cs | Validates interface names against the JCW-emitted interface list (when available) to match generated Java behavior. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/Scanner/JavaPeerScanner.cs | Computes both the full direct-interface list and the filtered JCW declaration list (dedupe + most-derived filtering). |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/Scanner/JavaPeerInfo.cs | Adds an internal property to carry the JCW-specific interface declaration list alongside the full direct-interface list. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/JcwJavaSourceGenerator.cs | Emits the JCW implements clause from the filtered interface list to avoid redundant/duplicate declarations. |
Comment on lines
+1673
to
+1677
| if (interfaces.Any (other => | ||
| !IsSameTypeDefinition (iface.Type, other.Type) && | ||
| IsInterfaceAssignableFrom (iface.Type, other.Type))) { | ||
| continue; | ||
| } |
27 tasks
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.

Summary
CecilImporterTDD evidence
Before the fix, the shared fixture's legacy/llvm-ir source compiled and its classfile declared
IGCUserPeer, Derived, Unrelated, OnClickListener, OnLongClickListener. Trimmable emittedIGCUserPeer, Root, Derived, Derived, Unrelated, OnClickListener, OnLongClickListener;javacrejected both CoreCLR and NativeAOT builds witherror: repeated interface.After the fix, the classfile semantic comparator and
javacpass, and all three build configurations compile the fixture: llvm-ir CoreCLR, trimmable CoreCLR, and trimmable NativeAOT. Because the pre-fix source did not compile and post-fix classfile parity proves the declaration semantics, no device runtime test is needed.Validation
Microsoft.Android.Sdk.TrimmableTypeMap.TeststestsMicrosoft.Android.Sdk.TrimmableTypeMap.IntegrationTeststestsGenerateOnlyMostDerivedInterfacesBuild_JavaSourceSemanticParityFixture_Compilesfor llvm-ir CoreCLR, trimmable CoreCLR, and trimmable NativeAOTgit diff --checkStacked on #12573. Tracks #12561.