[TrimmableTypeMap] Replace fixed value-type container allowlist with scalable NativeAOT rooting
- Dominant language
- C#
- Stars
- 2.1k
- Forks
- 579
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 252
Description
## Context
Follow-up to #12159.
The trimmable typemap currently uses `ValueTypeFactory.SupportedValueTypeFactories` as a fixed allowlist that statically roots the exact NativeAOT shapes needed for:
- managed value-type arrays;
- `JavaList` and `JavaCollection`;
- mixed reference/value `JavaDictionary` shapes;
- the full supported value/value dictionary cross-product.
#12159 extends the list with `DateTime`, `DateTimeOffset`, and `TimeSpan` (plus nullable forms), but arbitrary value types still cannot safely fall back to `MakeGenericType()` under NativeAOT.
## Problem
Growing a framework-owned allowlist does not scale:
- every supported type adds more statically rooted list, collection, and array shapes;
- value/value dictionaries currently root a Cartesian product, so cost grows quadratically;
- applications cannot opt in enums or their own structs;
- other common BCL candidates remain (`decimal`, `Guid`, `DateOnly`, `TimeOnly`, `Half`, unsigned/native-sized integers, `Int128`/`UInt128`, and enums);
- being AOT-rootable is distinct from having built-in JNI primitive marshaling semantics.
## Investigate
- Generate roots from the closed generic container shapes actually used by the application.
- Provide an opt-in registration or source-generation mechanism for additional value types.
- Root only used dictionary key/value pairs instead of the full allowlist cross-product.
- Define behavior for nullable types, enums, and user-defined structs.
- Keep diagnostics explicit when a value-type shape was not rooted.
- Measure NativeAOT build-time and binary-size impact against the fixed allowlist.
## Completion criteria
Produce and validate a design that supports app-specific value types without runtime reflection and without requiring an indefinitely growing, quadratic framework allowlist.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the current ValueTypeFactory.SupportedValueTypeFactories entry point and the design context in #12159. Investigate how NativeAOT roots the closed generic container shapes used by an application, including nullable types, enums, and user-defined structs. Done means a validated design with explicit diagnostics, app-specific opt-in support, and measured build-time and binary-size impact without runtime reflection.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- build-system, mobile-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100