Repository navigation
NativeAOT TODO list #9784
Copy link
Copy link
Open
Labels
Area: App+Library BuildIssues when building Library projects or Application projects.Issues when building Library projects or Application projects.Area: NativeAOTIssues that only occur when using NativeAOT.Issues that only occur when using NativeAOT.
Milestone
Description
What do we need to do for NativeAOT?
Current status for .NET 11 NativeAOT.
To investigate next:
- Re-test
dotnet publish; this was reported to fail whiledotnet buildworked during the original preview implementation - Re-test the current
dotnet new mauitemplate with NativeAOT
List of TODOs:
-
dotnet new android && dotnet publish -p:PublishAot=true -
dotnet new mauiruns - Parse Android system properties such as
debug.mono.log, including disablinglref/greflogging - Provide a printf-style alternative to
monodroid_log()for NativeAOT- [Native] Add printf-style native logging #12140
- Follow-up migrations: [NativeAOT] Migrate runtime utility logging to printf #12148, [CoreCLR/NativeAOT] Migrate JNI reference logging to printf #12150, [NativeAOT] Migrate shared GC logging to printf #12210, [NativeAOT] Migrate GC bridge logging to printf #12211, [NativeAOT] Add printf gref logging #12218
- MSBuild warning for non-Mono runtimes that says they are experimental
- Default
$(PublishAotUsingRuntimePack)=true - Get Mono.Android-Tests running on NativeAOT
- [nativeaot] run Mono.Android-Tests #9846
- Remaining exclusions are tracked by NativeAOT on-device tests #10079
- Finish runtime/startup behavior that differs from Mono
- System.Threading.Tasks synchronization context: [nativeaot] fix default
SynchronizationContext#9883 - NativeAOT coverage for timezone and Android uncaught-exception handling: Enable more tests to run on all 3 runtimes, part 14 #10644
-
AppDomain.CurrentDomain.UnhandledExceptionis still explicitly skipped under NativeAOT
- System.Threading.Tasks synchronization context: [nativeaot] fix default
- Address all NativeAOT trimming and AOT warnings
- Remove the
TrimmerRootAssemblyNativeAOT size deoptimization - Avoid dynamically linking
libc++_shared.so; NativeAOT currently linkslibc++_static.a - Remove the NativeAOT
libc++dependency entirely - Warn when code calls
JNINativeWrapper.CreateDelegate(...)- The API is annotated with
[RequiresDynamicCode], producing an AOT warning for callers - Framework usages were removed by [Mono.Android] Remove usages of
JNINativeWrapper.CreateDelegate. #9741
- The API is annotated with
- Decide whether NativeAOT should support FastDeploy/incremental deployment; it is currently explicitly unsupported by the test suite
- Enable
$(VerifyReferenceAotCompatibility)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Area: App+Library BuildIssues when building Library projects or Application projects.Issues when building Library projects or Application projects.Area: NativeAOTIssues that only occur when using NativeAOT.Issues that only occur when using NativeAOT.
Activity
jonpryor commentedon Feb 12, 2025
Alternate "MVP 1.1" typemap idea, for posterity: instead of a
Dictionary<string, Type>, have two fields:Dictionary<string, RuntimeTypeHandle>orstring[]+RuntimeTypeHandle[]pair, plusDictionary<string, Type>The linker step would populate (1), which might be faster because
RuntimeTypeHandleis a stuct.At runtime, consult (2) first, and if a type mapping doesn't exist, use (1) to lookup the
RuntimeTypeHandle+Type.GetTypeFromHandle(RuntimeTypeHandle), caching the result in (2).Questions:
jonathanpeppers commentedon Feb 12, 2025
There must be a way to use a
TypeHandlewith Mono.Cecil, as the IL "typemap MVP 1.0" is writing is doing this:android/src/Microsoft.Android.Sdk.ILLink/TypeMappingStep.cs
Lines 70 to 83 in 70bd636
filipnavara commentedon Feb 12, 2025
LdtokenreturnsRuntimeTypeHandleso you can use that in the dictionary. It's, however, not a pattern that can be represented in C# and ILSpy will not decode it correctly.simonrozsival commentedon Feb 21, 2025
I'm currently exploring this direction for the type map: https://gist.github.com/simonrozsival/8b3f2294d7fa1cf84ca32e8145984c98
What do you think?
jonathanpeppers commentedon Feb 21, 2025
@simonrozsival brought up a point that the
RuntimeTypeHandlevalues might not match up at runtime in NativeAOT:RuntimeTypeHandle...RuntimeTypeHandlesimonrozsival commentedon Feb 21, 2025
I don't think I expressed myself correctly. If we generate IL that builds the
Dictionary<string, RuntimeTypeHandle>usingil.Emit (Mono.Cecil.Cil.OpCodes.Ldtoken, module.ImportReference (typeDefinition));, then Native AOT will compile this correctly. That's not the problem.I was trying to say that we cannot serialize the raw numeric values of
RuntimeTypeHandlewhile we're processing the IL and use it for lookups viaType.GetTypeFromHandleat runtime.We can of course create an array of RTH, but it will need to be initialized at startup:
filipnavara commentedon Feb 21, 2025
ILC can interpret some static constructors at compile time and produce preinitialized data in the executable image. It would not work for the Dictionary but it can probably work for a simple array... (or can be tweaked to work if it doesn't at the moment)
am11 commentedon Apr 13, 2025
For zero-alloc string->Type dictionary known at build-time, we can generate a lookup method using stack-based
ReadOnlySpanand collection expressions like https://dotnetfiddle.net/1P6yNL (replaceseedDataDictionarywith your data). Similarly, for string->string https://dotnetfiddle.net/wFNdTh,string ->int https://dotnetfiddle.net/54v6CF and so on.Benchmark string->Type
With just array of 4 items, we start to see the difference.
Roslyn source generator: https://github.com/am11/GeneratedLookup
jonathanpeppers commentedon Apr 15, 2025
@am11 we have an implementation that doesn't use
Dictionaryat all now, so some of the comments above are out of date: