[TrimmableTypeMap] Keep array rank anchors private#11297
Open
simonrozsival wants to merge 4 commits intomainfrom
Open
[TrimmableTypeMap] Keep array rank anchors private#11297simonrozsival wants to merge 4 commits intomainfrom
simonrozsival wants to merge 4 commits intomainfrom
Conversation
Include ArrayMapAnchors.cs in Mono.Android so generated per-rank array TypeMap entries can resolve their shared Microsoft.Android.Runtime.__ArrayMapRankN anchor types at NativeAOT compile time. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Keep the shared array typemap anchor types in an existing compiled Mono.Android runtime source file so the project does not need a separate Compile item for ArrayMapAnchors.cs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Rename the typemap abstraction to ITypeMap and move array lookup behind the unified runtime wrapper. Generated typemap assemblies now define private __ArrayMapRankN anchors, and the root loader builds per-assembly/per-rank array maps instead of referencing shared Mono.Android anchors. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Emit TypeMapAssemblyTargetAttribute entries for each per-assembly array rank anchor so NativeAOT TypeMapping sees the same private rank groups requested by TypeMapLoader.Initialize. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the TrimmableTypeMap pipeline so that __ArrayMapRank{N} anchors are emitted as internal types within each generated per-assembly typemap, instead of referencing shared anchors from Mono.Android. The root typemap generator is updated to emit matching TypeMapAssemblyTargetAttribute<T> metadata for these per-assembly rank anchors and to pass per-assembly/per-rank array dictionaries to the runtime initializer.
Changes:
- Emit
__ArrayMapRank{N}as internal TypeDefs inside each generated typemap assembly and stop referencing sharedMono.Androidrank anchors. - Update the root typemap generator to emit per-assembly rank
TypeMapAssemblyTargetAttribute<T>entries and to buildarrayMapsByAssemblyAndRankfor initialization. - Refactor runtime typemap abstractions (
ITypeMap) so array-type lookup goes through the typemap interface and supports per-universe/per-assembly rank maps.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/TypeMapModelBuilderTests.cs | Updates expectations so per-assembly typemaps define rank anchors and do not TypeRef Mono.Android for them. |
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/RootTypeMapAssemblyGeneratorTests.cs | Adds coverage ensuring root target attributes and TypeRefs point to per-assembly rank anchors, and updates IgnoresAccessChecksTo expectations. |
| src/Mono.Android/Mono.Android.csproj | Switches compile include from the old interface file to the new ITypeMap.cs. |
| src/Mono.Android/Microsoft.Android.Runtime/TrimmableTypeMap.cs | Refactors initialization and array lookup to use ITypeMap.TryGetArrayType, and adds per-assembly array-map initialization support. |
| src/Mono.Android/Microsoft.Android.Runtime/SingleUniverseTypeMap.cs | Implements ITypeMap and adds array-map lookup across provided per-universe/per-assembly rank dictionaries. |
| src/Mono.Android/Microsoft.Android.Runtime/ITypeMap.cs | Renames/redefines the typemap abstraction and adds TryGetArrayType. |
| src/Mono.Android/Microsoft.Android.Runtime/ArrayMapAnchors.cs | Removes shared rank-anchor types from Mono.Android. |
| src/Mono.Android/Microsoft.Android.Runtime/AggregateTypeMap.cs | Updates to ITypeMap and forwards array-type lookup across universes. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/TrimmableTypeMapGenerator.cs | Removes the hardcoded max-rank limit that was tied to shared Mono.Android anchor availability. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/TypeMapAssemblyEmitter.cs | Emits internal __ArrayMapRank{N} TypeDefs into each generated typemap assembly. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/RootTypeMapAssemblyGenerator.cs | Emits per-assembly rank target attributes and generates initialization IL that constructs arrayMapsByAssemblyAndRank. |
Comment on lines
+69
to
+73
| public static void Initialize ( | ||
| IReadOnlyDictionary<string, Type> typeMap, | ||
| IReadOnlyDictionary<Type, Type> proxyMap, | ||
| IReadOnlyDictionary<string, Type>?[][]? arrayMapsByUniverseAndRank) | ||
| { |
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.
Moves the generated array rank marker cleanup out of the NativeAOT PR.
This keeps array rank anchors private to each generated typemap assembly and emits matching root TypeMapAssemblyTargetAttribute metadata for the per-assembly rank groups.