Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions docs/06-roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -550,10 +550,9 @@ before working on one (`tools/il-first/measure-aot.sh`), since earlier changes m
### Types still to serve from the framework's IL (was #475; ADR 0023/0024)
- Windows: System.Net.Sockets from IL needs IOCP (ThreadPoolBoundHandle) in the runtime (#441).
- System.Uri (System.Private.Uri behind System.Runtime) (#442).
- TimeSpan formatting through CoreLib's TimeSpanFormat instead of the corelib's formatter (#447).
- Vector2/3/4, Plane and Quaternion (#451); System.Half (#410).
- System.Diagnostics.Process (it would also give #102's other-process lookups).
- Done since the tracker opened: Guid (#416); ManualResetEventSlim and SpinWait from CoreLib, Barrier from System.Threading (#414);
- Done since the tracker opened: TimeSpan formatting through CoreLib's TimeSpanFormat (#447); Guid (#416); ManualResetEventSlim and SpinWait from CoreLib, Barrier from System.Threading (#414);
ArrayList and BitArray (#372); BFloat16 and Decimal32/64/128 (#405, docs/il-first/System.Numerics.IeeeTypes.md).

### Native hosting (after #294: #528, #532, #534)
Expand Down
3 changes: 2 additions & 1 deletion docs/il-first/System.Globalization.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ A library or CoreLib type served from the framework's IL: its row of the per-lib
| Library (switch) | Correctness (samples from IL) | Binary size, IL / shadow | Compile cpu, IL / shadow | Speed, IL / shadow (time) | Lines removed on a flip | Decision | NativeAOT on the same host, csharpc / NativeAOT (`tools/il-first/measure-aot.sh`: stripped size; compile cpu; run, median of 7; instructions) |
|---|---|---|---|---|---|---|---|
| Cultures and culture data (`CultureInfo`, `CultureData`, `RegionInfo`, `CultureNotFoundException`), `NumberFormatInfo`, casing (`TextInfo`), collation (`CompareInfo`, `SortKey`, `SortVersion`), `CharUnicodeInfo`, `StringInfo`/`TextElementEnumerator`, `IdnMapping`, `DateTimeFormatInfo`, every calendar (the lunisolar ones are new), and CoreLib's `DateTimeFormat`, `DateTimeParse`, `TimeSpanFormat` and `TimeSpanParse`; DateOnly's, TimeOnly's and TimeSpan's Parse/TryParse members hosted from their IL (`src/Csharpc/upstream-types/System.Globalization.txt`, #426) | 129 samples that use cultures, culture data, casing, collation, IDN, text elements, date and time formatting and parsing, number formatting, composite formatting and text writers byte-identical to real .NET at -O0 and -O2 (258 runs) and via IL (129), 12 of them on wasm32 (the others need ICU or threads); new samples 1381 (a constrained `IEquatable<T>.Equals` on `Vector128<T>`: an explicit diagnostic before) and 1382 (generic shifts on byte/sbyte/short/ushort: invalid IR before, from C# and from IL); `tests/slicer.sh` 10 of 10. 369/371/372/608 (the current culture flowing into threads, tasks and the thread pool) pass through the AsyncLocal contract below | a program that formats a number carries CoreLib's culture initialization (culture data over ICU, its locale tables, the culture caches): linux-x86_64 numbers 156 672 B budget to 236 328 B measured, collections 255 944, async 270 528, linq 341 288 (budgets raised with these numbers; hello, exceptions, typeinfo unchanged). `CultureInfo.GetFormat`'s DateTimeFormatInfo case through the runtime trigger and composite formatting without a type switch took about 470 KB of that back. The throughput program 230 216 to 265 648 B (NativeAOT 1 378 112) | throughput program 8.4 to 8.0 s (NativeAOT publish 12.9 s) | throughput program (`tools/il-first/bench/number_format_parse_throughput.cs`: int, long, double, decimal format and parse, invariant and de-DE, composite formatting), median of 7: **1 359 to 1 323 ms**; 12.48 G to 12.43 G instructions | 36 966 deleted (the 52 files of `corelib/Globalization` the slice replaces, `runtime/csrt.c`'s DateTimeFormatInfo trigger), 610 added (the ICU forwarding class, the DateTime/DateTimeOffset accessors, contract members) | **Flipped.** The ICU boundary stays the corelib's: the slicer's csharpc profile points CoreLib's 29 `Interop.Globalization` calls at `corelib/UpstreamGlobalization.cs`, which forwards each to the corelib's imports of the runtime's ICU shim (`src/runtime/globalization/pal_*.c`), and keeps `GlobalizationMode` (invariant mode compiled from the project, ICU loaded on first use, WASI always invariant), `CalendarId`, `CalendarDataType` and `TimeZoneInfoOptions` the corelib's. `Interop.CallStringMethod` (CalendarData's string helper) is hosted from IL. **Windows:** the Windows CoreLib carries the NLS back end next to ICU's; csharpc, like .NET by default, uses ICU, so the slicer folds `GlobalizationMode.UseNls` to false (the emitted IL loads the constant, the branches it rules out are not lowered, and the members and nested types only they use are not cut into the slice), and points the Win32 calls .NET still makes in ICU mode (`GetLocaleInfoEx` for the locale check, user overrides and code pages, `GetCalendarInfoEx`, `GetUserGeoID`/`GetGeoInfo`, `GetUserPreferredUILanguages`, `LCIDToLocaleName`, `MultiByteToWideChar`, and the Hijri calendar's `AddHijriDate` registry value) at the corelib's own imports (`corelib/UpstreamWindows.cs`). **WASI** (no ICU, invariant mode): linguistic comparisons with no option or IgnoreCase keep the runtime's approximation of ICU's root collation, as before the flip, through the 32-bit slice's replacement of `CompareInfo.Compare` over spans (`--wasi`, `corelib/UpstreamWasiCollation.cs`). **Security:** every buffer handed to the shim is bounded by the managed buffer it comes from: pointer arguments are CoreLib's own stackalloc or pinned buffers with their own lengths, and where a length travels next to an array or span (`GetLocales`, `GetCalendars`, `ToAscii`, `ToUnicode`) the forwarder clamps it to that array's or span's length, so a wrong length never lets native code write past it; strings go in NUL-terminated. The shim's `EnumCalendarInfo` callback is CoreLib's `[UnmanagedCallersOnly]` method (the slicer now copies that attribute). Compiler pieces it needed, all general: generic `[UnsafeAccessor]` static methods and accessors to internal types named by string; `[ShadowConstructor]` factories for internal value-type constructors (`DateTime(long, DateTimeKind, bool)`); constrained generic-math operator and `IEquatable<T>` calls on `Vector128<T>` (sample 1381); `m_value`, `_dateData` and `_ticks` as built-in private fields; hosted instance members of built-in value types (the slicer's `this.` host roots). | `number_format_parse_throughput`: 265 648 / 1 378 112 B; run 1 323 / 1 260 ms (1.05x; measure-aot.sh on the same host: 1 430 / 1 260 ms, 1.14x); 12.43 G / 10.54 G instructions. Number formatting itself is still the corelib's here (#426 continues with System.Number from IL) |
| Number formatting and parsing: CoreLib's `System.Number` with `NumberFormatInfo`, and the primitives' own `ToString`/`TryFormat`/`Parse`/`TryParse` (integers, `Int128`/`UInt128`, `Half`, `float`, `double`, `decimal`) hosted from their IL (`this.` roots in `src/Csharpc/upstream-types/System.Globalization.txt`, #426); `Enum.Parse` in C# over CoreLib's integer parser | 206 samples that format or parse numbers, enums, cultures and composite text byte-identical to real .NET at -O0 and -O2 (412 runs), 21 via IL (459, 642, 643 among them), 21 on wasm32; `tests/slicer.sh` 10 of 10; conformance formatting 5 of 5 and 7 of 7. New samples 1396 (constrained `ISpanFormattable`/`IUtf8SpanFormattable` calls on built-in numbers reached their boxed slot and recursed until the stack ran out; now they call the hosted member) and 1450 (`Enum.Parse` edges: NBSP trimming, overflow as `OverflowException`, names differing only by case) | the framework's formatter and parsers replace the corelib's smaller copies: linux-x86_64 numbers 236 024 to 254 088 B (+18 064), async 266 120 to 284 248, collections 255 640 to 269 608, linq 341 032 to 358 744, net 330 592 to 369 904, json 1 661 648 to 1 706 000, jsonwriter 832 112 to 861 464, regex 924 224 to 937 568, regexoptions 2 122 264 to 2 151 576; hello, exceptions, typeinfo unchanged (budgets raised with these numbers: a measured speed gain). The throughput program 269 832 to 337 968 B (NativeAOT 1 378 112) | throughput program 6.6 to 7.2 s wall (measure-aot.sh: 9.0 s cpu, 280 MB peak; NativeAOT publish 17.7 s cpu, 216 MB) | throughput program (`tools/il-first/bench/number_format_parse_throughput.cs`), median of 7 on the same host: **1 388 to 1 026 ms**; 12.53 G to 8.53 G instructions (-32 %) | 2 895 deleted, 299 added (`Number.Parsing.Culture.cs`, `NumberParsingMembers.cs` and most of `Number.Formatting.cs`, `Number.Parsing.cs`, `NumberTryFormat.cs`, `Int128Parsing.cs`; `runtime/parse.c`; the slicer's `NumberBridge` emitter) | **Flipped.** The corelib's `Number` class keeps only the compiler's entry points (concatenation, interpolation holes, boxed values, `Console.Write`), which call CoreLib's `System.Number` through `corelib/NumberUpstream.cs` (`[UnsafeAccessor]`, docs/12-corelib.md); the shortest-digits bridge is gone. Still the corelib's: `BigInteger`'s standard formats, decimal to and from double, `Math.Round(double, digits, mode)`, and TimeSpan's own formatter (remaining-flips.md). **Security:** parsing is CoreLib's span-based code, bounded by the input span's length, with overflow reported as `OverflowException` (Parse) or `false` (TryParse) and never wrapped; formatting writes through CoreLib's `ValueListBuilder`/span writers, so a `TryFormat` into a too-small destination returns false with nothing written past it (1396); NaN, infinity and sign texts come from the `NumberFormatInfo` in use. `Enum.Parse` no longer runs the C runtime's own string parser (`parse.c`, deleted): the name lookup and the integer fallback are bounds-checked C#. `decimal.GetBits`/`TryGetBits`/`new decimal(int[] or ReadOnlySpan<int>)` stay the representation's members (`corelib/DecimalBits.cs`) and validate length and scale as .NET does. Compiler pieces it needed, general: constrained interface calls on built-in value types reach the hosted IL member; ordinal comparison variants bind only non-private members (#443). | `number_format_parse_throughput`: 338 056 / 1 378 112 B; compile cpu 9.0 / 17.7 s; run **1 025 / 1 202 ms (0.85x)**, was 1 323 / 1 260 ms (1.05x) with the corelib's formatter; **8.53 G / 10.54 G instructions**, was 12.43 G / 10.54 G |
| Number formatting and parsing: CoreLib's `System.Number` with `NumberFormatInfo`, and the primitives' own `ToString`/`TryFormat`/`Parse`/`TryParse` (integers, `Int128`/`UInt128`, `Half`, `float`, `double`, `decimal`) hosted from their IL (`this.` roots in `src/Csharpc/upstream-types/System.Globalization.txt`, #426); `Enum.Parse` in C# over CoreLib's integer parser | 206 samples that format or parse numbers, enums, cultures and composite text byte-identical to real .NET at -O0 and -O2 (412 runs), 21 via IL (459, 642, 643 among them), 21 on wasm32; `tests/slicer.sh` 10 of 10; conformance formatting 5 of 5 and 7 of 7. New samples 1396 (constrained `ISpanFormattable`/`IUtf8SpanFormattable` calls on built-in numbers reached their boxed slot and recursed until the stack ran out; now they call the hosted member) and 1450 (`Enum.Parse` edges: NBSP trimming, overflow as `OverflowException`, names differing only by case) | the framework's formatter and parsers replace the corelib's smaller copies: linux-x86_64 numbers 236 024 to 254 088 B (+18 064), async 266 120 to 284 248, collections 255 640 to 269 608, linq 341 032 to 358 744, net 330 592 to 369 904, json 1 661 648 to 1 706 000, jsonwriter 832 112 to 861 464, regex 924 224 to 937 568, regexoptions 2 122 264 to 2 151 576; hello, exceptions, typeinfo unchanged (budgets raised with these numbers: a measured speed gain). The throughput program 269 832 to 337 968 B (NativeAOT 1 378 112) | throughput program 6.6 to 7.2 s wall (measure-aot.sh: 9.0 s cpu, 280 MB peak; NativeAOT publish 17.7 s cpu, 216 MB) | throughput program (`tools/il-first/bench/number_format_parse_throughput.cs`), median of 7 on the same host: **1 388 to 1 026 ms**; 12.53 G to 8.53 G instructions (-32 %) | 2 895 deleted, 299 added (`Number.Parsing.Culture.cs`, `NumberParsingMembers.cs` and most of `Number.Formatting.cs`, `Number.Parsing.cs`, `NumberTryFormat.cs`, `Int128Parsing.cs`; `runtime/parse.c`; the slicer's `NumberBridge` emitter) | **Flipped.** The corelib's `Number` class keeps only the compiler's entry points (concatenation, interpolation holes, boxed values, `Console.Write`), which call CoreLib's `System.Number` through `corelib/NumberUpstream.cs` (`[UnsafeAccessor]`, docs/12-corelib.md); the shortest-digits bridge is gone. Still the corelib's: `BigInteger`'s standard formats, decimal to and from double, `Math.Round(double, digits, mode)`, and, until #447, TimeSpan's own formatter. **Security:** parsing is CoreLib's span-based code, bounded by the input span's length, with overflow reported as `OverflowException` (Parse) or `false` (TryParse) and never wrapped; formatting writes through CoreLib's `ValueListBuilder`/span writers, so a `TryFormat` into a too-small destination returns false with nothing written past it (1396); NaN, infinity and sign texts come from the `NumberFormatInfo` in use. `Enum.Parse` no longer runs the C runtime's own string parser (`parse.c`, deleted): the name lookup and the integer fallback are bounds-checked C#. `decimal.GetBits`/`TryGetBits`/`new decimal(int[] or ReadOnlySpan<int>)` stay the representation's members (`corelib/DecimalBits.cs`) and validate length and scale as .NET does. Compiler pieces it needed, general: constrained interface calls on built-in value types reach the hosted IL member; ordinal comparison variants bind only non-private members (#443). | `number_format_parse_throughput`: 338 056 / 1 378 112 B; compile cpu 9.0 / 17.7 s; run **1 025 / 1 202 ms (0.85x)**, was 1 323 / 1 260 ms (1.05x) with the corelib's formatter; **8.53 G / 10.54 G instructions**, was 12.43 G / 10.54 G |
| TimeSpan formatting: TimeSpan's own `ToString()`, `ToString(string)`, `ToString(string, IFormatProvider)` and `TryFormat` (UTF-16 and UTF-8) hosted from their IL over CoreLib's `TimeSpanFormat` (`this.` roots in `src/Csharpc/upstream-types/System.Globalization.txt`, #447); the compiler's entry points (interpolation holes, boxed TimeSpans in composite formatting, `Stopwatch.ToString`) call `TimeSpanFormat.FormatC`/`Format` through `corelib/Globalization/DateTimeFormatting.cs` | the TimeSpan samples (82, 164, 186, 361, 376, 490, 509, 513, 542, 657, 864, 1224, 1252, 1545) and the two new ones byte-identical to real .NET at -O0 and -O2 (32 runs) and via IL (16); 1611 runs on wasm32 in CI (1610 needs ICU cultures); `tests/slicer.sh` 10 of 10. New samples, recorded from .NET: 1610 (every overload on negative values, `MinValue`/`MaxValue`, custom formats with quotes and escapes, "c"/"g"/"G" under six cultures, interpolation and composite holes with alignment, boxed and `ISpanFormattable` calls, `TryFormat` at every destination size in UTF-16 and UTF-8 with nothing written past the end, invalid formats through `TryFormat`, `Stopwatch`) and 1611 (invariant globalization mode: the decimal separator of "g"/"G" comes from the culture's data, not its `NumberFormat`; named cultures throw). The corelib's formatter gave the same text on all of them: no silent difference found | linux-x86_64, stripped -O2: `timespan_format_throughput` 362 976 to 411 536 B (+48 560: the framework's generic `TryFormatStandard`/`FormatCustomized` for char and byte), 1610 422 248 to 451 576, 186 346 608 to 366 112, 82 800 920 to 800 776; regex and regexoptions +4 416 each (both root the boxed-TimeSpan exports through the match timeout); hello, exceptions, typeinfo, async, collections, json, jsonwriter, linq, net, numbers, rsa unchanged; `tests/size.sh` 13 of 13 within budget, none raised | throughput program 9.4 s cpu (measure-aot.sh; NativeAOT publish 12.6 s) | `timespan_format_throughput` (`tools/il-first/bench/timespan_format_throughput.cs`: `ToString()`, "g"/"G" invariant and fr-FR, custom formats, `TryFormat` UTF-16 and UTF-8, interpolation), median of 7 on the same host: **384 to 269 ms (0.70x)**; 3 924 M to 2 080 M instructions (-47 %) | 170 deleted (`DateTimeOps`' standard and custom TimeSpan formatter and its helpers, the `TimeSpanTryFormat` shadow members, three `BclValueTypes` mappings), 33 added | **Flipped.** TimeSpan's representation and arithmetic stay the corelib's (built-in i64, `_ticks` a built-in private field). **Security:** the formatter writes through CoreLib's `ValueListBuilder` and span writers, so `TryFormat` into a too-small destination returns false with 0 written and nothing past the destination (1610 checks the two elements after it, UTF-16 and UTF-8); before, it formatted a whole string and copied it | `timespan_format_throughput`: 411 424 / 1 678 960 B; compile cpu 9.4 / 12.6 s; run **263 / 258 ms (1.02x)**; **2 080 M / 2 511 M instructions** |
2 changes: 1 addition & 1 deletion docs/il-first/remaining-flips.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ OS boundary) and the contract layer (reflection/type system, task/async glue, in
| Hashtable, ArrayList, BitArray | done: `docs/il-first/System.Collections.Hashtable.md`, `System.Collections.ArrayList.md` (SR.Format contract for every slice) | #372, #373 |
| Guid | done locally: from the framework; docs/il-first/System.Guid.md | #416 |
| Culture, number formatting and parsing (deletes the digits bridge) | done locally: cultures, culture data, casing, collation, `CharUnicodeInfo`, `IdnMapping`, `StringInfo`, and number formatting and parsing (`System.Number`, the primitives' ToString/TryFormat/Parse/TryParse hosted from IL; the digits bridge and `runtime/parse.c` deleted, `Enum.Parse` in C#) from the framework (docs/il-first/System.Globalization.md). BigInteger's standard formats, decimal to and from double and `Math.Round(double, digits, mode)` stay with the BigInteger and floating-point row | #426 |
| DateTime, calendars, TimeSpan parsing and formatting | done locally with culture: `DateTimeFormatInfo`, every calendar, `DateTimeFormat`, `DateTimeParse`, `TimeSpanFormat`/`TimeSpanParse`; DateOnly/TimeOnly/TimeSpan parsing hosted from IL; the corelib keeps those types' representation and their formatting members; TimeSpan's own formatter is still the corelib's (#447) | #426, #447 |
| DateTime, calendars, TimeSpan parsing and formatting | done locally with culture: `DateTimeFormatInfo`, every calendar, `DateTimeFormat`, `DateTimeParse`, `TimeSpanFormat`/`TimeSpanParse`; DateOnly/TimeOnly/TimeSpan parsing hosted from IL; the corelib keeps those types' representation and DateTime's/DateOnly's/TimeOnly's formatting members; TimeSpan's ToString/TryFormat hosted from IL over `TimeSpanFormat`, the corelib's TimeSpan formatter deleted (docs/il-first/System.Globalization.md, #447) | #426, #447 |
| Text and encoding, Convert, string helpers, hashing, BigInteger, floating-point math | done locally: Ascii, Base64, CompositeFormat, StandardFormat ([System.Text.Ascii.md](System.Text.Ascii.md)) the Encoding family with Utf8 ([System.Text.Encoding.md](System.Text.Encoding.md)) Convert ([System.Convert.md](System.Convert.md)) Rune ([System.Text.Rune.md](System.Text.Rune.md)) the string and char helpers ([System.String.md](System.String.md)) BigInteger ([System.Runtime.Numerics.md](System.Runtime.Numerics.md)) and the floating-point members of float, double, Math and MathF ([System.Math.md](System.Math.md)) done; hashing is all crypto (with the crypto row); Vector2/3/4 stay shadows (#451). Follow-ups #432, #433, #434, #435, #446, #448, #450, #453 | #423 |
| Tracing | done locally: EventSource, EventListener, the event counters and TraceLogging from the framework (docs/il-first/System.Diagnostics.Tracing.md: a disabled EventPipe contract, reflection over the event source, security review and measurements); follow-ups #454 (throughput vs NativeAOT), #455 (the runtime's own event sources) | #423 |
| IO above the libc boundary | done locally: part 1 (streams, readers, writers) and part 2 (`File`, `Directory`, `FileInfo`/`DirectoryInfo`, `FileStream`, `Path`, `RandomAccess`, `SafeFileHandle`, enumeration over the C# libSystem.Native contract `corelib/IO/SystemNative.cs`; security review and measurements in [System.IO.md](System.IO.md)); Windows (the Windows CoreLib slice over kernel32) waits for CI; linking the pack's libSystem.Native instead stays the owner's decision ([21-ownership.md](../21-ownership.md)) | #315 |
Expand Down
Loading
Loading