Skip to content

Match assembly name whitespace quoting to the native grammar - #137332

Merged
jkotas merged 7 commits into
dotnet:mainfrom
MichalStrehovsky:size/assembly-name-whitespace
Nov 14, 2026
Merged

jkotas merged 7 commits into
dotnet:mainfrom
MichalStrehovsky:size/assembly-name-whitespace

Conversation

@MichalStrehovsky

Copy link
Copy Markdown
Member

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.

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

Copy link
Copy Markdown
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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.

@MichalStrehovsky

Copy link
Copy Markdown
Member Author

All three #137333, #137332, #137331 combined save 50 kB, which is a lot more then each individually. Maybe I should have made a single PR but I assumed we might need to iterate on some.

@MichalStrehovsky

Copy link
Copy Markdown
Member Author

Half of the saving is basically Char.IsWhiteSpace that includes a several unicode tables.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @steveisok, @dotnet/area-system-reflection
See info in area-owners.md if you want to be subscribed.

@MichalStrehovsky

Copy link
Copy Markdown
Member Author

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
@jkotas
jkotas merged commit 5dba5f7 into dotnet:main Nov 14, 2026
66 of 68 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants