21 — Who owns what: the ownership map of the corelib
Issue #191, child of the policy issue #187. The owner’s principle: csharpc owns the compiler (C#/IL to LLVM, the IL front-end, the driver, the toolchain), the C runtime (GC, exception dispatch, threads, the OS boundary) and a thin contract layer (the internal members of the few core types whose layout is tied to our runtime: String, Array, Object, Type, Exception, Thread, RuntimeHelpers, Unsafe, the span helpers). Everything else is upstream’s, taken from the pinned .NET version’s framework IL, including most of System.Private.CoreLib. Only the code that is necessary stays.
The tables below are the snapshot taken before the Regex flip (#206) and the System.Text.Json flip (#286): the Regex and Json shadows (the
RegexandJsonrows;Json/ArrayBufferWriter.cswent with System.Memory, #306) are deleted andownership.tsvno longer lists them, nor the Linq ones (Enumerable.cs,LinqIterators.cs: #267;LinqSpans.csis nowRuntimeSpans.cs), norNet/IPAddress.csandNet/IPNetwork.cs(System.Net.Primitives from IL, #326; the socket engine’s sockaddr shims are the newNet/SocketAddressPal.cs, GLUE). On Linux and macOS the socket files (Net/Sockets.cs,SocketEngine.cs,NetNative.cs,SocketAsyncEventArgs.cs,SocketAddressPal.cs,UnixDomainSocketEndPoint.cs; on Linux alsoNetworkInterfaces.cs,NetworkChange.cs) are Windows-only now: System.Net.Sockets, NameResolution and NetworkInformation come from IL over the libSystem.Native contractNet/SystemNative.Net.cs(GLUE, option (b) below; #423, docs/il-first/System.Net.Sockets.md). The totals are regenerated bytools/il-first/ownership.shon the next refresh. Later flips do not edit this note: each one’s shadows, and what replaced them, are in its own file underdocs/il-first/, andtools/il-first/ownership.shalways maps the corelib as it is.
This page is the map from today’s src/Csharpc/corelib (354 files, 169,705 lines, 8.1 MB) to that principle. The
per-file data is tools/il-first/ownership.tsv, generated on demand and not tracked (every flip deletes corelib files and
would rewrite it, so parallel flips conflicted there; ADR 0025, decision 6). Generate it, or print the tables below, with:
tools/il-first/ownership.sh # writes tools/il-first/ownership.tsv (git-ignored)
tools/il-first/ownership.sh --summary # the tables of this page, from the same data
tools/il-first/ownership.sh --contract # the runtime entry points of the framework assemblies (below)
The ADR 0023 per-library table (the A/B runs of #187/#188/#189) links here for the “lines removed” column; nothing here changes a default.
How the map is made
- What a file shadows. Every
[Shadows("...")]/[ShadowMembers("...")]attribute names a real type. Its defining assembly comes from the type definitions of the shared framework the compiler is pinned to (Microsoft.NETCore.AppandMicrosoft.AspNetCore.Appofglobal.json’s SDK; the same index idea asFrameworkIl). That part is exact: 743 targets in 243 files, 467 in System.Private.CoreLib, 276 in 28 other assemblies (Security.Cryptography 86, Text.Json 48, System.Collections 22, Regex 14, ComponentModel.TypeConverter 12, …). - Lines per target. The lines from one shadow attribute to the next belong to its target (a
ShadowMembersclass with several targets shares them); the header and helpers before the first attribute go to the first target (the one file with a large non-shadow preamble,Core.cs, is split by hand). 111 files hold no shadow attribute (support code of a family): they take the class of their directory or a per-file override in the tool. The attribution is approximate at the edges and exact in total. - Classes. (1) CORE-CONTRACT: runtime-coupled, stays; (2) CORELIB-PURE: a System.Private.CoreLib type that is plain managed code upstream; (3) FRAMEWORK-ABOVE: shadows a type of another framework assembly; (4) GLUE: csharpc-specific (libc/Win32/OpenSSL bindings, compiler hooks); (5) DATA: tables.
- Verdicts.
keep;shrink(a part is contract, the rest upstream’s);delete-when-IL-wins(a ceiling: the file goes when the real IL of its types passes the per-library A/B of ADR 0023, with the blockers listed). A verdict is not a decision to delete: security > speed > size still decides each case, and the Json and Regex rows belong to the A/B in #187/#188/#189. - Other columns.
origin(the header names dotnet/runtime:ported),data_lines(literal tables and lines over 300 characters),compiler_hooks(string literals naming the shadowed type inCodeGen/Frontend, i.e.Intrinsics.cs,BclValueTypes*.cs),fan_in(other corelib files that mention the main target’s name),basis(read: opened and checked against the code;rule: classified by the rules in the tool).
Totals
Framework 11.0.0-rc.2.26504.105. Lines attributed per shadow declaration:
| Class | Lines | % | Files (by dominant class) | Of those, ported from upstream |
|---|---|---|---|---|
| CORE-CONTRACT | 14,640 | 8.6 | 65 | 11 |
| CORELIB-PURE | 79,020 | 46.6 | 154 | 104 |
| FRAMEWORK-ABOVE | 65,597 | 38.7 | 110 | 84 |
| GLUE | 5,074 | 3.0 | 16 | 6 |
| DATA | 5,374 | 3.2 | 9 | 5 |
| Verdict (file level) | Files | Lines |
|---|---|---|
| delete-when-IL-wins (a ceiling) | 271 | 149,354 |
| keep | 67 | 13,505 |
| shrink | 16 | 6,846 |
What the numbers say:
- 85 % of the corelib sits in classes the principle gives to upstream (CORELIB-PURE and FRAMEWORK-ABOVE), and 210 of the 354 files already name dotnet/runtime as their source: most of the corelib is a port of the code the real IL contains. Deleting it is mostly a matter of the IL front-end and the contract, not of semantics.
- Globalization (38,376 lines) is not data. Only about 3,400 lines are tables (
IcuLocaleData.csis a verbatim port of upstream’s table, plus the generated Unicode/Bidi/Grapheme tables); the rest is upstream’s culture, calendar, collation, parsing and formatting code, ported. All DATA files together (adding the Regex tables and the Latin1 best-fit table) are 5,374 lines, 3.2 % of the corelib. - The contract is small by lines (8.6 %) but not by dependency. Task, CancellationTokenSource, wait events and
the async builders are runtime objects of the coroutine lowering (docs/10-async.md,
src/runtime/async.c); upstream’s Task cannot come as IL without changing the async lowering. Reflection (3.2k lines) sits on compiler metadata (ADR 0018). These two are most of the contract. - Not every shadow is a port.
List<T>,Dictionary<,>andHashSet<T>are csharpc’s own code mirroring upstream’s behaviour (the header says so), with internals the rest of the corelib touches (_items,_size, the Linq span fast paths,CollectionsMarshal) and compiler-coupled helpers (CoreIntrinsics.AreEqual/HashOf,LibraryFrames).Memory<T>is laid out without the array/MemoryManager/string object (stated inBuffers/ReadOnlySequence.cs), which realSystem.MemoryIL and everyMemory<byte>overload would need. The header ofNet/Tls.csstill calls TLS a stub (Net/SslStream.cshas grown since), so the Net rows are the least reliable. - String, Array and the primitives are member-level. The type stays ours (layout), but a good part of its members
(
String.Split/Join/Trim/Pad/Replace,Array.Sort/IndexOf/Resize,Double.*generic-math statics,Math.*that are plain C# upstream) are plain managed code. A mixed mode at type granularity cannot split them;ShadowMembersalready works per member on the compiler side,IsShadowedIlTypedoes not.
Class by area
| Area | Lines | CONTRACT | PURE | ABOVE | GLUE | DATA |
|---|---|---|---|---|---|---|
| (root) | 39,004 | 7,307 | 24,065 | 6,716 | 884 | 32 |
| Globalization | 38,376 | 172 | 33,729 | 0 | 1,085 | 3,390 |
| Regex | 16,830 | 0 | 0 | 15,797 | 0 | 1,033 |
| Json | 16,672 | 0 | 0 | 16,324 | 0 | 348 |
| Crypto | 8,581 | 0 | 0 | 7,859 | 722 | 0 |
| IO | 8,352 | 472 | 5,256 | 1,876 | 748 | 0 |
| Concurrent | 7,631 | 0 | 3,571 | 4,060 | 0 | 0 |
| Net | 7,450 | 0 | 85 | 5,949 | 1,416 | 0 |
| Tasks | 5,264 | 2,827 | 591 | 1,802 | 44 | 0 |
| Text | 4,904 | 0 | 4,294 | 39 | 0 | 571 |
| Reflection | 4,624 | 3,242 | 1,382 | 0 | 0 | 0 |
| Buffers | 2,989 | 0 | 58 | 2,931 | 0 | 0 |
| Threading | 2,568 | 620 | 1,948 | 0 | 0 | 0 |
| ComponentModel | 2,244 | 0 | 0 | 2,244 | 0 | 0 |
| Random | 1,614 | 0 | 1,551 | 0 | 63 | 0 |
| Tracing | 1,452 | 0 | 1,452 | 0 | 0 | 0 |
| Serialization | 623 | 0 | 623 | 0 | 0 | 0 |
| Numerics | 415 | 0 | 415 | 0 | 0 | 0 |
| Dynamic | 112 | 0 | 0 | 0 | 112 | 0 |
Readiness of the deletable files
The tier is the heaviest blocker of the file (blockers below); it is a prediction from reading, which Part B of #191 (the mixed-mode CoreLib spike) tests for collections, StringBuilder, number formatting and Guid.
| Tier | Meaning | Files | Lines |
|---|---|---|---|
| 1 | no blocker beyond the SIMD mapping, the default comparers and generic-math statics | 40 | 16,284 |
| 2 | a library decision by A/B (Json, Regex: #187/#188/#189) or a layout question (Memory<T>, AppContext switches) |
60 | 36,725 |
| 3 | needs members of the contract layer (threads, tasks, GC, reflection, exceptions, layout; ICU: the shim is already linked, the culture/thread contract is the work) | 120 | 68,879 |
| 4 | needs upstream’s native shims or a replacement (libSystem.Native, OpenSSL, console, EventPipe) | 51 | 27,466 |
First 20 files to delete (tier 1, by lines)
| File | Lines | Class | Family | Blockers |
|---|---|---|---|---|
| Concurrent/ConcurrentDictionary.cs | 2,649 | CORELIB-PURE | collections | EQCMP |
| Collections.cs | 1,436 | FRAMEWORK-ABOVE | collections-asm | EQCMP |
| Enumerable.cs | 1,164 | FRAMEWORK-ABOVE | linq | EQCMP, SIMD |
| Dictionary.cs | 1,105 | CORELIB-PURE | collections | EQCMP |
| Concurrent/ConcurrentQueue.cs | 922 | CORELIB-PURE | collections | EQCMP |
| BigIntegerOps.cs | 775 | FRAMEWORK-ABOVE | numerics | GENMATH |
| LinqIterators.cs | 711 | FRAMEWORK-ABOVE | linq | EQCMP, SIMD |
| List.cs | 595 | CORELIB-PURE | collections | EQCMP |
| Reflection/AssemblyName.cs | 575 | CORELIB-PURE | corelib-other | - |
| Text/Latin1BestFit.cs | 571 | DATA | encoding-data | - |
| Hashtable.cs | 523 | CORELIB-PURE | collections | EQCMP |
| HashSet.cs | 461 | CORELIB-PURE | collections | EQCMP |
| BitArray.cs | 435 | CORELIB-PURE | collections | EQCMP |
| OrderedDictionary.cs | 429 | FRAMEWORK-ABOVE | collections-asm | EQCMP |
| ObservableCollection.cs | 396 | FRAMEWORK-ABOVE | collections-asm | - |
| Globalization/InvariantModeCasing.cs | 355 | CORELIB-PURE | culture | - |
| ArrayList.cs | 334 | CORELIB-PURE | collections | EQCMP |
| Reflection/CompilerAttributes.cs | 299 | CORELIB-PURE | attributes | - |
| ValueBuilders.cs | 208 | GLUE | ports-glue | - |
| BigNum.cs | 190 | CORELIB-PURE | numbers | - |
Regex (flipped, #206) and Json (flipped, #286) were the biggest single deletions (15.8k and 16.6k lines); the Globalization cluster (33.7k lines of upstream ports) is the biggest CoreLib one and moves as one unit (CultureInfo, CultureData, CompareInfo, TextInfo, the calendars, DateTime parsing/formatting reach each other’s internals).
Top blockers (lines of deletable or shrinkable files each one gates)
| Blocker | Files | Lines | What it is |
|---|---|---|---|
| ICU | 58 | 41,325 | the culture cluster over libSystem.Globalization.Native; csharpc already links its port of the shim (src/runtime/globalization), and Interop.Globalization.cs is a port of the IL’s own imports |
| AB187 | 56 | 33,414 | Json/Regex A/B in progress, not decided here |
| SIMD | 75 | 32,388 | upstream’s Vector128/256/512 paths and SpanHelpers; today searches and sums go to src/runtime/span.c |
| SRCGEN | 51 | 31,224 | [GeneratedRegex] and JSON source generators must be the SDK’s, not csharpc’s own |
| LAYOUT | 54 | 23,906 | String/Array/Object internals (FastAllocateString, raw data, method table) the real code reads |
| REFLECT | 25 | 20,495 | reflection metadata (ADR 0018) against upstream’s RuntimeType family |
| EQCMP | 29 | 19,050 | EqualityComparer<T>.Default, Comparer<T>.Default, CoreIntrinsics.AreEqual/HashOf/Compare synthesized by codegen |
| SYSNATIVE | 38 | 17,919 | libSystem.Native imports (files, env, time, process, sockets, epoll) where csharpc calls libc through Posix.cs |
| NEWTYPES | 13 | 15,427 | .NET 11 CoreLib structs the JSON converters reach (Decimal32/64/128, BFloat16) |
| GENMATH | 25 | 13,771 | static abstract members on the primitives, mapped by the compiler |
| THREAD | 24 | 12,953 | Thread, Monitor, Interlocked, thread statics, ExecutionContext |
| OPENSSL | 13 | 10,655 | libSystem.Security.Cryptography.Native.OpenSsl imports |
| TASK | 12 | 4,082 | runtime tasks of the coroutine lowering |
| APPCTX | 9 | 3,434 | AppContext switches and ILLink substitutions |
| MEMORY | 3 | 3,106 | Memory<T> layout |
| GC | 8 | 2,432 | GCHandle, weak references, finalizers |
| EVENTPIPE | 4 | 1,452 | EventPipe QCalls |
| CONSOLE | 2 | 315 | console fast paths in Intrinsics.cs |
EXC (exception layout and stack traces) and RES (resource strings) are not in the table: EXC gates only keep
files, and RES applies to every flip alike (the IL front-end reads each assembly’s embedded resources), so it is not
a per-file blocker.
Largest files that stay (keep or shrink)
Globalization/IcuLocaleData.cs (3,316, a port; goes with the culture cluster), Reflection/Members.cs (1,473), StringExtras.cs (1,144), StringOps.cs (1,144), Tasks/TaskScheduling.cs (904), Interop.cs (838), Core.cs (833), Net/NetNative.cs (831), Reflection/Assembly.cs (613), Net/SocketEngine.cs (585), AsyncBuilders.cs (565), RuntimeMembers.cs (524), RuntimeServices.cs (501), ArrayExtras.cs (482), Crypto/AesNative.cs (440), Resources.cs (436).
What the contract has to stand in for: the framework’s runtime entry points
The shared framework’s System.Private.CoreLib is CoreCLR’s: its runtime-coupled surface is 200 InternalCall
(FCall) methods and 328 QCalls, plus 160 imports of libSystem.Native (123) and libSystem.Globalization.Native
(37), on 80 types (tools/il-first/ownership.sh --contract lists them). A type that reaches none of those is
plain managed code. The heaviest, by entry points: Interop+Sys (122 libSystem.Native imports), RuntimeTypeHandle
(16 + 32), Interop+Globalization (37), GC (13 + 19), RuntimeMethodHandle (18 + 11), RuntimeAssembly (4 + 23),
Math/MathF (25 + 25, libm), MetadataImport, Thread (3 + 15), RuntimeHelpers (5 + 11), String (10 + 2),
Marshal, Delegate, Exception, Array, Interlocked, ValueType, SpanHelpers (2 QCalls). That list is the
size of the thin contract layer the owner describes. The collections, StringBuilder, Convert, number formatting,
Guid and the culture logic are not among those types; they reach the list only through Array, String,
RuntimeHelpers, Unsafe, Interlocked and the default comparers.
Libraries above CoreLib that import natives (so are ineligible for IL until the shim question is decided, ADR 0013): System.Security.Cryptography (310 OpenSSL + 6), System.Net.Security (114 OpenSSL + 21 + 3), System.Net.Sockets (68), System.Diagnostics.Process (29), System.Console (24), System.IO.Pipes (17), System.IO.MemoryMappedFiles (15), System.Net.Primitives (13). System.Text.Json, System.Text.RegularExpressions, System.Linq and System.Collections import nothing native. That is the line between “an IL front-end question” and “a native shim question”.
A question for the owner that this map raises: csharpc already ports one shim (libSystem.Globalization.Native,
in src/runtime/globalization, linked into the program). The same could be done for libSystem.Native (and the
OpenSSL shim) by building upstream’s C sources in the runtime build, which would let CoreLib’s own IO, Process,
Console, Sockets and Cryptography IL bind to them, and would make IO/Posix.cs, Win32.cs, Net/NetNative.cs,
Net/SocketEngine.cs and the Crypto glue (about 2,900 lines of GLUE) deletable; the cost is that the OS boundary
then follows upstream’s shim API (and its size) instead of libc directly. Part B does not decide this.
libSystem.Native for the file system: option (b) is implemented; option (a) stays open (the owner’s decision).
The file-system flip (#315 part 2, il-first/System.IO.md) serves CoreLib’s File, Directory,
FileStream, Path, RandomAccess, SafeFileHandle and enumeration from the framework’s IL, Interop/Interop.Sys
included, and binds their 57 libSystem.Native entry points to a C# contract over csharpc’s libc layer
(corelib/IO/SystemNative.cs, 1 166 lines, pal_io.c’s behaviour function by function) — option (b). Option (a),
building upstream’s src/native/libs/System.Native C sources into the runtime and linking them as the globalization shim
is, has not been tried and is not decided here. Measured for (b) on x86-64 Linux (tools/il-first/bench/io_filesystem_throughput.cs):
947 808 B against NativeAOT’s 1 593 336 B; run 1 419 ms against NativeAOT’s 1 399 ms (1.01x, median of 9 interleaved runs,
the same system calls); compile cpu 20.5 s against NativeAOT’s 13.0 s publish. Against the deleted shadows (#438): 1.31x run time
(kernel time: .NET’s own system calls, which the shadows skipped) and 2.67x size (IConvertible slots of a boxed value type rooting
parsing code, a compiler-side cost). What (a) would change: the same entry points from upstream’s C (no C# copy to keep in
step with pal_io.c), more native code linked (the shim is one library), and the OS boundary following upstream’s shim API.
IO/Posix.cs (now only Process, Console, Environment, time, entropy, FileSystemWatcher’s and MemoryMappedFiles’ needs) and
IO/Win32.cs stay for the corelib code not yet from the IL.
Verification of the classification
46 files were opened and checked (header and the coupling to the contract: CoreIntrinsics, Unsafe,
RuntimeHelpers, runtime tasks and events, native imports); they carry basis = read in the TSV. 22 more headers
(Json, Crypto, Net, Reflection, Tasks, Threading, IO, Globalization) were read while refining the rules. Reading changed the rule-derived result for these, which are fixed in the tool:
Core.csis not one family (CoreIntrinsics and the throw helpers are GLUE, the default comparers are contract);ArrayExtras.csisshrink, notkeep(genericArraystatics are plain managed code);IcuLocaleData.csis a port of upstream’s table, not csharpc’s own;CancellationToken*,ManualResetEventSlim,Timer,TimeProvider,SynchronizationContextare runtime-backed (async.c / threads.c), not plain managed code;SpinLock,ReaderWriterLockSlim,SemaphoreSlim,Barrierare ports;- the calendars and
TimeSpanParsereach the culture cluster (ICU), not only resources; AssemblyNameis not an attribute type; small families inside a large file no longer decide its blockers.
Confidence: high (exact) for class FRAMEWORK-ABOVE versus System.Private.CoreLib (metadata) and for the line totals; about 85 % for the CONTRACT/PURE split per file (46 of 354 files read, 7 needed a rule change, none changed class by more than a family); medium for the verdicts of unread files and for every blocker, which are hypotheses from the code’s own headers and from what the CoreCLR CoreLib calls, to be replaced by measurements as each library goes through the A/B (Part B does this for collections, StringBuilder, number formatting and Guid).
Part B: the mixed-mode CoreLib spike (issue #191)
Under boundary A of ADR 0024 (our C runtime plus the contract layer, upstream above), can a type of System.Private.CoreLib drop its shadow and compile from the framework’s IL while the rest of the corelib stays? The spike answers it for List, Dictionary, HashSet, StringBuilder, Guid and number formatting, without changing a default.
Mechanism
- The slicer (
tools/il-first/slicer, Mono.Cecil from the ILLink tasks package the SDK restores) reads the shared framework’sSystem.Private.CoreLib.dlland cuts, from the root types, the methods they reach (calls, field accesses, type tokens, base types, interfaces, the virtual methods of every used type). A type the reference pack declares publicly is a stop type: references to it stay references to the reference-pack assembly, which csharpc serves from its shadows and intrinsics, so the slice binds like any framework IL assembly (ADR 0013). Every other CoreLib type reached joins the slice, underCsharpcCoreLib.Upstream.*so it never collides with the reference pack’s names. What the slice calls on a stop type that the reference pack does not declare is the contract; the extern methods it reaches (FCalls, QCalls, P/Invokes) are counted too (none for these six types). - The compiler hook (
CSHARPC_UPSTREAM_MAP=<slice>.map,Frontend/UpstreamSlice.cs, off by default): the shadows of the listed types and their nested types are dropped and the real types map to the slice’s, as they map to a shadow. Stack traces print the BCL names. Members the reference pack lacks resolve through the corelib’s shadows (PR #222, issue #220). - Reproduce:
tools/il-first/slicer/slice.sh out.dll 'System.Collections.Generic.List!1', thentools/il-first/slicer/compare.sh program.cs out.dll(shadow and slice builds: size, compile CPU, run CPU, output equality).
Per type (Linux x86-64, -O2, stripped; CPU times on a shared 4-core VPS under load, so sizes are exact and times are not)
| Type | Slice (types / methods / IL bytes) | Contract members (static) | Samples from the slice | Binary, shadow to slice | Run (CPU, best of 7 to 9) | Lines deletable | Verdict |
|---|---|---|---|---|---|---|---|
List<T> |
9 / 209 / 7.6 KB | 1 | 14 of 14 | 136.6 to 148.9 KB (+9 %) | 203 to 200 ms (=) | 556 (+ the Linq span fast path) | go |
HashSet<T> |
15 / 205 / 10.5 KB | 3 | 9 of 9 | 136.0 to 156.0 KB (+15 %) | 483 to 504 ms (+4 %, median +14 %) | 450 | partial: needs #223 |
Dictionary<K,V> |
21 / 283 / 13.2 KB | 3 | 14 of 14 | 125.5 to 179.6 KB (+43 %), string keys 129.7 to 203.6 KB (+57 %) | int keys 306 to 462 ms (+50 %), string keys 208 to 290 ms (+40 %) | 915 | no-go until #223 |
StringBuilder |
10 / 289 / 14.4 KB | 16 | 1 of 4 | 134.7 to 135.5 KB (+0.6 %) | 470 to 402 ms (= within noise) | 1 497 + about 100 of compiler hooks | partial: plain API yes; interpolation and AppendFormat need #221 |
Guid |
14 / 134 / 12.6 KB | 7 | blocked | n/a | n/a | 1 068 | blocked by #221 |
System.Number (formatting, parsing) |
58 / 672 / 89.6 KB | 33 | blocked | n/a | n/a | about 3 500 | blocked by #221 and by the culture cluster |
Compile CPU (the slice build against the shadow build, same program) rose from 10.6 to 15.2 s (List), 6.1 to 7.9 s (StringBuilder), 8.5 to 22.9 s (Dictionary) and 9.7 to 18.4 s (HashSet): the real IL is more code to lower (SR, ThrowHelper, the comparer and hashing helpers), most of it for Dictionary and HashSet.
What it found
- The contract is small, and it is the internals of a handful of types. List needs one member beyond the public surface;
Dictionary and HashSet three; StringBuilder sixteen (String 2, CompositeFormat 4, Buffer, ArrayPool, MemoryExtensions,
ArgumentNullException, Enum, DefaultInterpolatedStringHandler, Rune, the internal
Span<T>constructors). PR #222 adds the ones the six types call (12 members in the corelib) and the mechanism that resolves them. Number formatting is the exception: 33 members, 19 of themNumberFormatInfointernals, i.e. the culture cluster (CultureInfo, CultureData, ICU) comes with it. - Unsupported IL constructs: none of the IL opcodes.
localloc(54 sites in Number, 1 to 7 elsewhere) and theref-returning accessors lower. What stopped the slices were member resolution (fixed in #222), two missing capabilities of the primitives (#221: CoreLib-internal static abstract interfaces such asIUtfChar<T>, and interface dispatch on built-in types forISpanFormattable/IFormattable), and the default comparers (#223). #221 is closed by two general mechanisms. The slicer hosts, per built-in type, the methods that implement the static abstract members of the slice’s interfaces (implementers/internal-interfaceslist them:IUtfChar<T>on char and byte,IBinaryIntegerParseAndFormatInfo<T>on the 11 integers and char,IBinaryFloatParseAndFormatInfo<T>on float, double, Half, BFloat16) in a<Type>InterfaceMembersclass named in the map file (members:System.Char=...); the constrained-call resolution (FunctionCodeGen.BuiltinInterfaceMembers.cs) looks a member up there, and a member with no implementation is an explicit CSLLVM0001 naming the interface member and the constraint type, no longer invalid IR. Boxed built-in values dispatchISpanFormattable.TryFormat/IUtf8SpanFormattable.TryFormatthrough the corelib’sBoxedSpanFormattable, asIConvertiblegoes throughBoxedConvertible. Guid, StringBuilder (all 4 samples) and System.Number now compile from their slices;tests/slicer.shruns the samples against them. - Default comparers decide Dictionary and HashSet. Upstream calls
EqualityComparer<TKey>.Defaultper probe, which the shadows replace by inlineCoreIntrinsics.AreEqual/HashOf: +40 to 50 % run time and the larger code. Until the IL front-end lowers the default-comparer calls like the shadows do (#223), a Dictionary or HashSet flip fails the speed rule. #223 lowers them so (FunctionCodeGen.DefaultComparers.cs):EqualityComparer<T>.Default.Equals/GetHashCodeandComparer<T>.Default.Compareon a closed T are the same inline code asCoreIntrinsics.AreEqual/HashOf/Compare, in the IL and the source front-end, and the getter call that made the comparer is erased when nothing else uses it. Two other costs the framework’s collections showed came out with it:typeof(T).IsValueTypekept a deadcsrt_type_from_mtcall (the Type object is now erased when unused, which is most of Dictionary’s remaining gap), andx.GetHashCode()on a value-typeT(HashSet) boxed and dispatched virtually (nowHashOf). Callgrind instruction counts, same program, -O2, shadow / slice before / slice after: Dictionary<int,int> insert 146.4 M / 211.3 M / 151.3 M, lookup 97.4 M / 138.1 M / 93.3 M, remove 167.6 M / 275.8 M / 171.0 M (within 5 %); HashSetadd and contains 73.2 M / n/a / 74.6 M; Dictionary<string,int> +21 % and HashSet +31 % remain (the string-comparer family, out of scope of #223). The slice’s binary stays about 50 % larger. SRis a size decision. The CoreLib resource strings behind the exception messages (1 459 entries) cost 22 KB of strings plus the ResourceManager and culture code if embedded: List went from +132 KB to +12 KB by letting each reachedSRgetter carry its text as a literal (the slicer does what ILLink’s resource substitution does). A real flip needs that step in the IL front-end, not a slicer.- Reflection-based generic instantiation is the other hard dependency.
List<T>.SortreachesArraySortHelper<T>.CreateArraySortHelper, which creates its helper withRuntimeTypeHandle.CreateInstanceForAnotherGenericParameter; the spike redirects the helper to a corelib type (a copy of the span) and #224 asks for the compile-time intrinsic NativeAOT has. #224 adds it (FunctionCodeGen.IlGenericInstantiation.cs): a call withtypeofconstants becomesnewobj G<T>::.ctor(), anything else is an explicit diagnostic, andSystem.RuntimeTypein framework IL meansSystem.Type. Measured first: theArraySortHelper<T>call sits behindRuntimeFeature.IsDynamicCodeCompiled, which csharpc folds to false as NativeAOT does, soList<T>.SortandArray.Sortcompile from the framework’s own helper without the redirect (removed from the slicer, sample 1299) and never reach the intrinsic. The unguarded callers areComparerHelpers.CreateDefaultComparer/CreateDefaultEqualityComparer(the realEqualityComparer<T>.DefaultandComparer<T>.Default); they stop one step earlier, attypeof(IEquatable<>).MakeGenericType(type)(“csharpc compiles only the generic instantiations the program creates”), which is what a flip of the default comparers needs next. The intrinsic itself is tested with an IL library written with Cecil (tests/slicer.sh,tools/il-first/slicer/Synth.cs) because no C# program can call the internal member. - Deleting a shadow can mean deleting compiler hooks. StringBuilder’s interpolation handler and
DefaultInterpolatedStringHandlerare represented by the shadowStringBuilderinTypeMapperandFunctionCodeGen.Tuples.cs/Calls.cs(about 120 lines); with the real struct those paths must go, and they produced silent empty output when left in place (sb.Append($"...")appended nothing): the spike disables them when the slice serves StringBuilder. - Other code leans on the shadows’ layout. Only
LinqSpans.cs(theList<T>span fast path, throughCoreIntrinsics.IsExactClass<ListImpl<T>>) andCollectionsMarshal(inList.cs) nameListImpl; the Linq fast path silently falls back to the slow path once List is the real class, andCollectionsMarshal.AsSpan(list)must come from the IL too (root it with List) when a program uses it. - SIMD (#252).
Vector128<T>is now a<16 x i8>LLVM vector in both front-ends (FunctionCodeGen.Simd.cs): construction, loads and stores, comparisons and masks, bitwise and arithmetic operators, shifts,ConditionalSelect,ExtractMostSignificantBits, element access, theAs*views, and theISimdVector<TSelf,T>members the framework’s generic span code calls on it (TVector.Equals,IndexOfWhereAllBitsSet…).Vector128.IsHardwareAcceleratedis true on x86-64 and arm64 (wasm32 keeps the scalar paths); Vector64/256/512,Vector<T>and the ISA classes stay false, so the framework’s portable Vector128 branch runs. WithMemoryExtensionstaken from the framework IL (tests/slicer.sh), 130 518 searches of sample 1301 give the recorded answers. Instructions for 5 searches over 200 000 elements, shadow (the runtime’s C search) / framework IL on Vector128:IndexOfint 2.3 M / 3.8 M, byte 0.24 M / 1.0 M, short 1.0 M / 1.2 M,IndexOfAny0.66 M / 0.72 M,SequenceEqual0.03 M (libcmemcmp) / 0.44 M, andLastIndexOf15.0 M / 2.2 M (the shadow’s is scalar). The runtime’s search still winsIndexOfandSequenceEqualon x86-64 (libc uses 32-byte AVX2; the baseline here is 16 bytes), so those keep their runtime mapping untilMemoryExtensionsis flipped.List<T>.IndexOf/Containsdo not reach any of this: the realList<T>callsArray.IndexOf, which is the corelib’s scalarArrayExtras.IndexOf(the shadow’sListused its own bitwise search); the 5x regression measured for the List flip is that, not a missing Vector128.
Status (2026-11-09): Listsrc/Csharpc/upstream-types/, ADR 0023 “Types of System.Private.CoreLib”):
corelib/List.cs (595 lines) is gone, CollectionsMarshal’s List members reach the framework’s List<T> through [UnsafeAccessor]
(corelib/CollectionsMarshal.cs), and the build ships CsharpcUpstream.dll. The measured costs the owner accepted are in the ADR row (Add +33 %,
RemoveAll +14 %, about +5 % size; Insert/RemoveAt 20x faster); #259 tracks closing the Add gap in the compiler.
Status (2026-11-09): Dictionary<TKey,TValue>, HashSetcorelib/HashSet.cs,
corelib/CollectionsMarshal.cs and the DictionaryImpl half of corelib/Dictionary.cs are gone (about 1 250 lines). What the flip needed in the
compiler, beyond #221/#223/#269: boxed Index/Range method tables (the framework’s Dictionary<Range, V> boxes keys for its exception messages);
Int128 (and structs holding one) accessed 8-aligned, since a box keeps its payload at offset 8 (a Dictionary<Int128, V> enumerator boxed through
IEnumerable stored its KeyValuePair with a 16-byte-aligned move at an address that was only 8-aligned); Comparer<Int128>.Default (the corelib threw
InvalidOperationException); and the IL front-end folding typeof(A) == typeof(B) branches in generic methods (the if (typeof(T) == typeof(string)) ... else general-path shape is all over the framework; without it the general path was lowered for every instantiation). Contract members: the string
comparer family (UpstreamNonRandomizedStringEqualityComparer is what a Dictionary<string, V> with the default, Ordinal or OrdinalIgnoreCase comparer holds, as in .NET: alternate lookups work,
Comparer hands the original back, the default-comparer type guard recognizes the default one, and after more than 100 collisions the collection switches to
UpstreamRandomizedStringEqualityComparer, whose hash is string.GetHashCode(): Marvin, seeded per process from the OS random number generator, runtime/strings.c; hash flooding, #285), and the throw helpers whose message is string.Format(text, key):
for string, int, long, uint, ulong and char keys the text is built directly, so a program that reads a Dictionary does not carry composite
formatting, culture data and every number formatter for an exception message (that was +17 KB; the generic replacement is a slicer feature: a forwarded
method may be generic).
Status (2026-11-12): Queuecorelib/Queue.cs, corelib/Collection.cs, corelib/ObjectModel.cs and corelib/ReadOnlyDictionary.cs are gone (580 lines), with no compiler
change. Queue is 14 % fewer instructions than its shadow; the ObjectModel types are the same speed and size (docs/il-first/). The CoreLib
collections still shadowed: Hashtable (from IL it is correct but 30 % larger and 3 % slower, because Insert’s duplicate-key SR.Format brings in
composite formatting: #373), ArrayList (untyped Array.IndexOf/LastIndexOf/Sort(Array, int, int, IComparer)) and BitArray (Vector128/256
operators from IL): #372.
Status (2026-11-13): ConcurrentDictionary<TKey,TValue> and ConcurrentQueuecorelib/Concurrent/
is gone (3 571 lines). Two general compiler changes: the slicer copies the state-machine attributes, and the IL front-end folds
Type.GetTypeCode(typeof(X)). The dictionary program is the same size and the same instruction count as with the shadows, 0.90x NativeAOT’s
instructions (docs/il-first/System.Collections.Concurrent.md).
Proposed boundary, and the order
The numbers support boundary A for collections and text, with the contract growing by the internals listed above (12 members so
far, plus the spike’s own shims) and no change to the runtime. Order: List first (go; flip PR deletes ListImpl, its enumerator object and the Linq
hook), then the primitives’ interface work (#221) and the default comparers (#223) which unblock HashSet, StringBuilder,
Dictionary, Guid, then number formatting together with the culture cluster. Per #187’s rule each flip PR deletes its
shadow and reports the lines removed; none is part of this spike. If the owner would rather not keep the contract members in the
corelib, the alternative is member-level mixed mode for String and Array (their internals are the bulk of the contract), which
IsShadowedIlType does not support yet.
Legend of the blocker codes
LAYOUT, EQCMP, SIMD, ICU, SYSNATIVE, OPENSSL, THREAD, TASK, REFLECT, EXC, GC, GENMATH, SRCGEN, NEWTYPES, EVENTPIPE,
APPCTX, CONSOLE, MEMORY, AB187: defined in the comment block of Rules in tools/il-first/ownership.cs, next to the
rules that assign them.