Repository navigation
Match assembly name whitespace quoting to the native grammar - #137332
Conversation
Replace the Unicode-wide Trim check in AssemblyNameFormatter.AppendQuoted with checks of the first and last characters. The native IsWhitespace helper and TextualIdentityParser::EscapeString in src\coreclr\binder\textualidentityparser.cpp require whitespace quoting only for space, horizontal tab, carriage return and line feed. The managed AssemblyNameParser.IsWhiteSpace uses the same four characters. Keep the existing quote and escape handling. Other Unicode whitespace no longer receives unnecessary quotes, while names continue to round-trip. This avoids retaining general Unicode whitespace classification solely for formatting an assembly identity. Standalone local HelloWorldSize probe, WASI NativeAOT Release, invariant globalization and size optimization: 722,933 -> 721,637 bytes, saving 1,296 bytes (0.18%) against the common base. Validated with clr.nativeaotlibs+libs.sfx and the HelloWorldSize build. HelloWorldSize ran under Wasmtime and exited 100. Co-authored-by: Copilot <[email protected]> Copilot-Session: 2e62c26c-6da8-442d-98ac-dcb988c2846a
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
|
Half of the saving is basically Char.IsWhiteSpace that includes a several unicode tables. |
There was a problem hiding this comment.
🟡 Changes recommended
The formatting change can cause Mono to load the wrong assembly name by stripping unquoted vertical tabs or form feeds, and regression coverage for whitespace quoting and round-tripping is missing.
2 open issues
What changed in this PR
This PR aligns shared assembly-name formatting with the CoreCLR native and managed parser whitespace grammar, avoiding general Unicode whitespace classification.
Changes:
- Replaces Unicode-wide trimming with first- and last-character checks for space, tab, carriage return, and line feed.
- Preserves existing quote detection and escaping while leaving other Unicode whitespace unquoted.
| File | Description |
|---|---|
| src/libraries/Common/src/System/Reflection/AssemblyNameFormatter.cs | Narrows whitespace-triggered quoting to the four parser-recognized characters. |
Review effort: Balanced
|
Tagging subscribers to this area: @steveisok, @dotnet/area-system-reflection |
Co-authored-by: Jan Kotas <[email protected]>
|
rt-sz now reports the promised 20 kB saving: MichalStrehovsky/rt-sz#287 (comment) Matching AssemblyNameParser.cs and the native parser in the VM is a bonus. |
Store LF line endings in Git to avoid phantom working-tree changes with text normalization enabled. Co-authored-by: Copilot <[email protected]> Copilot-Session: b05f9399-bf74-4ce7-9012-51b57fd3a54d
Apply the review suggestion to remove the obsolete duplicate comment. Co-authored-by: Copilot <[email protected]> Copilot-Session: b05f9399-bf74-4ce7-9012-51b57fd3a54d

Replace the Unicode-wide Trim check in AssemblyNameFormatter.AppendQuoted with checks of the first and last characters.
The native IsWhitespace helper and TextualIdentityParser::EscapeString in src\coreclr\binder\textualidentityparser.cpp require whitespace quoting only for space, horizontal tab, carriage return and line feed. The managed AssemblyNameParser.IsWhiteSpace uses the same four characters.
Keep the existing quote and escape handling. Other Unicode whitespace no longer receives unnecessary quotes, while names continue to round-trip. This avoids retaining general Unicode whitespace classification solely for formatting an assembly identity.
Standalone local HelloWorldSize probe, WASI NativeAOT Release, invariant globalization and size optimization: 722,933 -> 721,637 bytes, saving 1,296 bytes (0.18%) against the common base.
Validated with clr.nativeaotlibs+libs.sfx and the HelloWorldSize build. HelloWorldSize ran under Wasmtime and exited 100.