Skip to content

[typemap] Match legacy JCW interface declarations - #12585

Open
simonrozsival wants to merge 1 commit into
simonrozsival-jcw-semantic-parityfrom
simonrozsival-jcw-interface-parity
Open

[typemap] Match legacy JCW interface declarations#12585
simonrozsival wants to merge 1 commit into
simonrozsival-jcw-semantic-parityfrom
simonrozsival-jcw-interface-parity

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

Summary

  • preserve the scanner's complete ordered direct-interface list for typemap and alias semantics
  • add an internal JCW declaration list that filters redundant parent interfaces and deduplicates Java names in first-seen order, matching legacy CecilImporter
  • extend the shared semantic fixture and Android build test with parent/derived redundancy, colliding managed aliases, stable order, and an unrelated-interface control

TDD evidence

Before the fix, the shared fixture's legacy/llvm-ir source compiled and its classfile declared IGCUserPeer, Derived, Unrelated, OnClickListener, OnLongClickListener. Trimmable emitted IGCUserPeer, Root, Derived, Derived, Unrelated, OnClickListener, OnLongClickListener; javac rejected both CoreCLR and NativeAOT builds with error: repeated interface.

After the fix, the classfile semantic comparator and javac pass, 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

  • 771 Microsoft.Android.Sdk.TrimmableTypeMap.Tests tests
  • 25 Microsoft.Android.Sdk.TrimmableTypeMap.IntegrationTests tests
  • legacy GenerateOnlyMostDerivedInterfaces
  • Build_JavaSourceSemanticParityFixture_Compiles for llvm-ir CoreCLR, trimmable CoreCLR, and trimmable NativeAOT
  • git diff --check

Stacked on #12573. Tracks #12561.

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>
Copilot AI lite review requested due to automatic review settings August 29, 2026 03:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

Review tier: Lite
Findings: 1 Medium severity

New issues introduced by this change (1)
Severity Finding
Medium severity src/​Microsoft.Android.Sdk.TrimmableTypeMap/​Scanner/​JavaPeerScanner.cs⚠️ Performance — This 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 JavaCallableWrapperInterfaceJavaNames on JavaPeerInfo and 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;
}
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