Repository navigation
[TrimmableTypeMap] Prefer non-generic aliases - #13749
Conversation
3edd91b to
1039399
Compare
Prefer non-generic peers in generated alias groups and when combining per-assembly universes, while retaining generic peers for typed lookups. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Move Release trimming coverage for duplicate generic bindings into the isolated TrimmingTests apps. Keep Debug coverage in MSBuildDeviceIntegration, where cross-universe proxy ordering is exercised. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
javac rejects the UTF-8 byte order mark emitted by the default project item encoding. Write the regression test source as UTF-8 without a BOM. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Share the peer sources between the TrimmingTests case and the Debug device test, create Java instances with JNIEnv.CreateInstance (), and build the generator test's peers with a local helper. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1039399 to
373b7d8
Compare
|
@dalexsoto review |
There was a problem hiding this comment.
🟡 Changes recommended
The activity-based test runs configuration cases in parallel, allowing them to interfere with activity startup and cause spurious logcat timeouts; it should be marked NonParallelizable or moved to instrumentation.
1 open issue
What changed in this PR
This PR makes untyped Java activation prefer non-generic bindings when multiple managed types bind the same Java class, addressing the activation failure reported in #13674 while retaining generic aliases for typed lookups.
Changes:
- Prioritizes non-generic aliases in generated type maps and Debug’s runtime cache.
- Adds ordering tests for the generator and cross-assembly runtime lookup.
- Adds a two-library regression case for trimming and NativeAOT, plus Debug device coverage with reversed reference order.
| File | Description |
|---|---|
| tests/TrimmingTests/Tests/JavaPeerActivationTests.cs | Registers the new activation regression case. |
| tests/TrimmingTests/Cases/GenericBindingAliases/ZNonGenericBinding/ZNonGenericBinding.csproj | Defines the non-generic binding library. |
| tests/TrimmingTests/Cases/GenericBindingAliases/ZNonGenericBinding/NonGenericPeer.cs | Provides the concrete Java peer binding. |
| tests/TrimmingTests/Cases/GenericBindingAliases/GenericBindingAliases.cs | Checks untyped activation and closed-generic lookup. |
| tests/TrimmingTests/Cases/GenericBindingAliases/Case.targets | Disables automatic binding for the Java fixture. |
| tests/TrimmingTests/Cases/GenericBindingAliases/AliasPeer.java | Supplies the Java class shared by both bindings. |
| tests/TrimmingTests/Cases/GenericBindingAliases/AGenericBinding/GenericPeer.cs | Provides the generic Java peer binding. |
| tests/TrimmingTests/Cases/GenericBindingAliases/AGenericBinding/AGenericBinding.csproj | Defines the generic binding library. |
| tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs | Adds Debug coverage with both project-reference orders. |
| tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/TrimmableTypeMapTypeManagerTests.cs | Tests non-generic preference across type-map universes. |
| src/Mono.Android/Microsoft.Android.Runtime/TrimmableTypeMap.cs | Places a non-generic proxy first in the runtime cache. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/ModelBuilder.cs | Sorts non-generic aliases before generic definitions. |
| src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/GenerateTrimmableTypeMapTests.cs | Verifies alias ordering and generic-binding retention. |
Review effort: Balanced
|
In response to @simonrozsival's request: My static review is still in progress. Before a complete verdict I need to finish the InstallAndRunTests and binding-project/Java patches, trace AggregateTypeMap/SingleUniverseTypeMap proxy insertion and TrimmableTypeMap peer creation/TargetTypeMatches, and check the removed native alias[0] alignment requirement. These are unfinished reviewer-coverage items within this tick, not defects established in the PR. The separate final whole-PR blocker pass is also still pending; the next scheduled tick will resume from the retained reads rather than restart. |
dalexsoto
left a comment
There was a problem hiding this comment.
The new activity-based trimming test needs serialization. In tests/TrimmingTests/JavaPeerActivationTests.cs:21-26, the new test inherits [Parallelizable(ParallelScope.Children)] but runs GenericBindingAliases, which is a [Activity(MainLauncher = true)] case. TrimmingTestBase.cs:69-72 explicitly requires activity cases to be [NonParallelizable]: otherwise concurrent cases can interfere with the foreground activity and make this test fail nondeterministically.
Please mark this test [NonParallelizable], or make the case use CaseInstrumentation and perform its checks in CallApplicationOnCreate(); it does not need an activity window. This is the single remaining blocker from the static review.
|
Reviewed as PeppersMuse. The one open concern — the new activity-based TrimmingTests case running under
|
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Run the alias checks without a launcher activity, so configuration cases can execute in parallel without competing for the foreground activity. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
@dalexsoto The activity-race concern is addressed in the pushed head: the trimming case now runs as instrumentation, so I removed |
|
In response to @simonrozsival's request: The instrumentation conversion addresses the activity-race concern from my previous review. I still need to trace the full |
dalexsoto
left a comment
There was a problem hiding this comment.
The activity-race blocker from my previous review is resolved: GenericBindingAliases now uses CaseInstrumentation.CallApplicationOnCreate, matching the harness contract without requiring NonParallelizable. The generator sorts non-generic aliases first after cross-assembly merging, and the runtime cache preserves that order while retaining generic proxies for closed-generic lookups. The added generator, runtime-cache and instrumentation cases cover both alias orders and assemblies. No remaining blocking issue found in the complete static review; no builds or device tests were executed.

Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
fed399804a93e3838a11deda38d3ce0f4c7909c0↑ Both Debug reference orders passed in the previous CI run.
↓ CI for the assessed revision is still running.
↓ The original report concerns SparseArray in Debug, not the two-library trimming reproduction.
Context: #13674
Context: #13658
When multiple libraries bind the same Java class, an open generic peer can sort before a concrete peer. Untyped Java activation then selects the open generic proxy, which cannot be instantiated. This is dependent on generated ordering; the current SparseArray ordering only masks the problem.
Order non-generic peers before generic definitions in generated alias groups, while retaining generic aliases for typed closed-generic lookups. Debug combines proxies from separate per-assembly universes, so the runtime cache builder applies the same preference there.
Add a two-library regression case to the isolated TrimmingTests app suite for Release full/partial trimming and NativeAOT. The case uses instrumentation rather than a launcher activity, so configurations do not compete for the foreground activity. Keep Debug coverage in MSBuildDeviceIntegration and vary project-reference order.
Validation
make leeroy CONFIGURATION=Debug MSBUILD_ARGS='-m:4'— passed after regenerating a stale localAssemblyInfo.cs; the initial build failed with IL3058 because that generated file lacked current AOT metadata.dotnet test src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Microsoft.Android.Build.Tasks.Tests.csproj --filter 'FullyQualifiedName~GenerateTrimmableTypeMapTests' -v:q -nologo— 68 passed on an earlier revision; the generator and its tests are unchanged since then../dotnet-local.sh build tests/TrimmingTests/TrimmingTests.csproj -v:q -nologo— passed.ADB_TARGET='-s emulator-5558' TEST_ANDROID_JDK_PATH="$HOME/android-toolchain/jdk-25" TEST_ANDROID_SDK_PATH="$HOME/android-toolchain/sdk" ./dotnet-local.sh test bin/TestDebug/TrimmingTests/net11.0/TrimmingTests.dll --filter 'Name~UntypedJavaActivationPrefersNonGenericBindingWithoutWarnings' --logger 'console;verbosity=normal'— 3 passed on an arm64 emulator: CoreCLR full trimming, CoreCLR partial trimming, and NativeAOT../dotnet-local.sh build tests/MSBuildDeviceIntegration/MSBuildDeviceIntegration.csproj -v:q -nologo— passed on an earlier revision.Z.NonGenericPeerat slot 0 and retainsA.GenericPeer<T>at slot 1.