ADR 0016 — NativeAOT parity as the support target, csharpc as dotnet’s AOT backend as the end state
- Status: Accepted (2026-10-24). Direction for the roadmap; the end state is a plan, not code yet.
- Context: 06-roadmap.md (Standing goal, M4, M6, M7, M8, M9), 08-drop-in.md, ADR 0006, ADR 0010, ADR 0013.
Context
“Drop-in replacement for the .NET toolchain” needs a measurable definition. csharpc is an
ahead-of-time compiler for a closed world: it can’t do what only a JIT can (run-time code generation),
and nobody publishing a native executable today expects that either — the toolchain they compare
against is .NET’s own AOT path, dotnet publish -p:PublishAot=true (NativeAOT, the ILCompiler).
Decision
- Support target: 100 % parity with NativeAOT. Every program and library that works when
published with NativeAOT must compile with csharpc and behave identically (stdout, exit code,
exception types and messages). What NativeAOT can’t do is out of scope and stays an explicit
diagnostic, never a guess — decided by running NativeAOT, not by a fixed list:
Reflection.Emit,MakeGenericType/MakeGenericMethodover instantiations the compiler never saw, andAssembly.Load*of code outside the closed world fail there; expression trees (NativeAOT runs them through the expression interpreter) anddynamic(Microsoft.CSharp) do work under NativeAOT and are therefore in scope. - The JIT is the oracle and a benchmark baseline, not a support target. Tests keep recording
expectations with
dotnet run(where NativeAOT and the JIT agree, which is everywhere in scope); benchmarks compare against both the JIT and NativeAOT; compile time is compared againstdotnet publish -p:PublishAot=true. - The compatibility metric becomes NativeAOT parity (M4): the harness also publishes each corpus program with NativeAOT; programs NativeAOT can’t build or run identically leave the denominator, and the headline number is the share of NativeAOT-working programs csharpc matches.
- End state: csharpc as the AOT backend of a fork of dotnet. In the dotnet SDK,
PublishAot=truehands the IL assembliescscproduced (plus the framework’s) to ILCompiler throughMicrosoft.DotNet.ILCompiler’s MSBuild targets and an.ilc.rspresponse file. The end state is a dotnet fork in which that step runs csharpc instead — same inputs, same MSBuild properties, same outputs — so every existing project gets csharpc’s code by flipping the AOT backend, not by learning a new tool.
Consequences
- Parameter parity.
Csharpc.Sdk(and later the fork) must honour the properties that steer NativeAOT, with NativeAOT’s names and semantics:PublishAot,RuntimeIdentifier,OptimizationPreference/IlcOptimizationPreference(Speed/Size),IlcInstructionSet,InvariantGlobalization,UseSystemResourceKeys,StackTraceSupport/IlcGenerateStackTraceData,StripSymbols,NativeLib(Static/Shared libraries withUnmanagedCallersOnlyexports),DirectPInvoke/NativeLibraryitems,TrimMode, trimming descriptors (ILLinkXML,rd.xml,DynamicDependency,DynamicallyAccessedMembers) and the trim/AOT analysis warnings (IL2xxx/IL3xxx) — reported where csharpc’s closed-world analysis can prove the same thing,AutoreleasePoolSupport,EventSourceSupportand the other feature switches (runtimeconfigRuntimeHostConfigurationOptions, which csharpc already reads). A property csharpc doesn’t honour yet is a warning naming it, not silently ignored — or an error where ignoring it changes output:UseSystemResourceKeys=trueis refused (compile time, andAppContext.SetSwitchat run time) until the corelib’s and runtime’s messages give their .NET resource keys (sample 880). - The IL front-end becomes the primary path in the end state. Inside the dotnet pipeline the
input is IL from
csc, not sources. csharpc’s source front-end (Roslyn CFG) stays the best path forcsharpc file.csand for debug info today, but every feature must also work through the IL front-end (ADR 0010); the corelib already goes that way (ADR 0015). Gaps between the two front-ends are bugs. - Output parity. What NativeAOT produces next to the executable (the
.dbg/.pdbsymbol file split byStripSymbols,.mapwithIlcGenerateMapFile, static/shared libraries forNativeLib) becomes part of the drop-in contract. - Measured, not assumed. The compatibility corpus decides what is in scope by running NativeAOT
(docs/18-compatibility.md): its first runs found NativeAOT running expression-tree programs (through
the expression interpreter) and a
dynamicprogram exactly like the JIT, so those count against parity; what NativeAOT really can’t do (the reflection-basedSystem.Text.Jsonserializer, stack-trace file/line information) leaves the denominator. - Out-of-scope list is NativeAOT’s. The roadmap’s ❌ status means exactly “NativeAOT doesn’t support it either”; anything NativeAOT supports is ⬜/🟡/🚧 until it’s ✅.
- Acceptance gate for the fork: dotnet’s own tests pass. With NativeAOT removed and csharpc in its
place, the test suites dotnet uses to validate its AOT path must all pass: dotnet/runtime’s NativeAOT
runtime tests and the libraries’ tests in their NativeAOT configuration, and the SDK’s
PublishAottests. A test is only excluded where it tests ILCompiler internals rather than behaviour (each such exclusion listed with its reason). Tracked early: before the fork exists, the same suites are built with csharpc on CI and their pass rate is reported next to the compatibility numbers. - Definition of done (roadmap M9; renumbered 2026-10-30 — M7 is TechEmpower with the standalone csharpc CLI, M8 the fork and its acceptance gate, M9 TechEmpower through the fork): the fork, with NativeAOT’s code removed and csharpc in its place, is built and used to compile the ASP.NET Core TechEmpower Framework Benchmarks entries that .NET runs with NativeAOT; they run in the TechEmpower environment and beat the NativeAOT-compiled entries. That makes ASP.NET Core/Kestrel from IL and server-grade throughput (thread pool, sockets, epoll, GC under load) requirements, measured early by a local NativeAOT-vs-csharpc load harness.
- The fork is the last step, not the next one. It needs M5/M6 done (IL as the primary input,
csharpc compiling Roslyn and itself) and parity on the compatibility corpus; until then
Csharpc.Sdkis the integration point and must track the same property names.