Skip to content

[TrimmableTypeMap] Keep array rank anchors private#11297

Open
simonrozsival wants to merge 4 commits intomainfrom
dev/simonrozsival/trimmable-private-array-typemap
Open

[TrimmableTypeMap] Keep array rank anchors private#11297
simonrozsival wants to merge 4 commits intomainfrom
dev/simonrozsival/trimmable-private-array-typemap

Conversation

@simonrozsival
Copy link
Copy Markdown
Member

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.

simonrozsival and others added 4 commits May 6, 2026 11:26
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>
Copilot AI review requested due to automatic review settings May 6, 2026 09:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 shared Mono.Android rank anchors.
  • Update the root typemap generator to emit per-assembly rank TypeMapAssemblyTargetAttribute<T> entries and to build arrayMapsByAssemblyAndRank for 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)
{
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