Skip to content

[typemap] Compare generated Java semantics - #12573

Open
simonrozsival wants to merge 5 commits into
simonrozsival-trimmable-typemap-parity-gapsfrom
simonrozsival-jcw-semantic-parity
Open

[typemap] Compare generated Java semantics#12573
simonrozsival wants to merge 5 commits into
simonrozsival-trimmable-typemap-parity-gapsfrom
simonrozsival-jcw-semantic-parity

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Aug 28, 2026

Copy link
Copy Markdown
Member

Summary

  • add a bounded managed fixture shared by legacy XAJavaInterop1 and the trimmable typemap
  • compile both generated Java source sets with javac and compare parsed classfile declarations
  • cover hierarchy, ordered interfaces, constructors, methods, export fields, visibility/modifiers, and checked throws
  • validate llvm-ir CoreCLR, trimmable CoreCLR, and trimmable NativeAOT builds

Stacked on #12564 so the fixture consumes its shared constructor/method throws formatting fix. This is semantic-comparison groundwork; managed annotation forwarding remains covered by #12549, and the broader generated-Java parity checklist remains open.

simonrozsival and others added 3 commits August 28, 2026 15:50
Compare legacy and trimmable JCW classfile declarations after compiling each generated source set with javac, and exercise the shared fixture through llvm-ir, CoreCLR, and NativeAOT builds.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Include all declaration-relevant classfile modifiers in semantic parity and wait for javac termination before cleaning up a timed-out compilation.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Reference Mono.Android.Export explicitly for legacy generation and preserve observable interface declaration order across two implemented Java interfaces.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings August 28, 2026 13:57

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

Review tier: Lite
Findings: 1 Medium severity · 1 Low severity

New issues introduced by this change (2)
Severity Finding
Low severity tests/​Microsoft.Android.Sdk.TrimmableTypeMap.IntegrationTests/​JavaSourceSemanticParityTests.cs⚠️ On Windows, spawning javac without CreateNoWindow/WindowStyle can flash a console window…
Medium severity tests/​Microsoft.Android.Sdk.TrimmableTypeMap.IntegrationTests/​JavaSourceSemanticParityTests.cs — 💡 Cleanup in the finally block can throw (e.g., file locks/AV scanners), which can mask the real…
What changed in this PR

This PR adds integration/build coverage to ensure the trimmable typemap Java source generator produces Java with the same declaration semantics as the legacy XAJavaInterop1 generator, by compiling both generated sources with javac and comparing the resulting classfile model.

Changes:

  • Add a new semantic parity integration test that generates legacy vs trimmable Java, compiles with javac, and compares parsed .class declarations (interfaces, ctors/methods/fields, modifiers, annotations, throws).
  • Introduce a shared managed fixture (JavaSourceParityFixture) used by both generators and test harness.
  • Add a build test matrix to ensure the semantic parity fixture compiles across llvm-ir/trimmable and CoreCLR/NativeAOT configurations.
File Description
tests/​Microsoft.Android.Sdk.TrimmableTypeMap.IntegrationTests/​Microsoft.Android.Sdk.TrimmableTypeMap.IntegrationTests.csproj Adds fixture project + bytecode reader dependency and embeds JavaCPath into assembly metadata for runtime javac invocation.
tests/​Microsoft.Android.Sdk.TrimmableTypeMap.IntegrationTests/​JavaSourceSemanticParityTests.cs New integration test that generates Java source for both pipelines, compiles via javac, reads classfile semantics, and asserts parity.
tests/​Microsoft.Android.Sdk.TrimmableTypeMap.IntegrationTests/​JavaSourceParityFixture/​JavaSourceParityTypes.cs Adds the bounded managed fixture type set used for semantic parity comparisons.
tests/​Microsoft.Android.Sdk.TrimmableTypeMap.IntegrationTests/​JavaSourceParityFixture/​JavaSourceParityFixture.csproj New fixture project that builds into the shared test output location and references ref assemblies as needed.
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.Android.Build.Tests/​TrimmableTypeMapBuildTests.cs Adds build-time validation that the semantic parity fixture’s generated Java compiles across typemap/runtime configurations.

Comment on lines +224 to +229
var startInfo = new ProcessStartInfo {
FileName = compilerPath,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
};
Comment on lines +151 to +153
} finally {
Directory.Delete (root, recursive: true);
}
Remove retained-annotation comparison until the separate managed annotation forwarding work is available beneath this stack.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Split long declaration expectations into readable Mono-style multiline assertions without changing coverage.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants