Delete more leftover UTF-16 code from compiler#128887
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates NativeAOT’s compiler name mangling to further move string-literal mangling onto Utf8String (removing more UTF-16-centric code paths), and adds a NativeAOT smoke test to validate correct handling of isolated UTF-16 surrogate literals.
Changes:
- Add a new NativeAOT smoke test (
MiscTests) that validates string literals containing isolated surrogates are preserved as singlecharcode units. - Change
NameMangler.GetMangledStringName(string)to returnUtf8Stringand update call sites (e.g.,NodeFactory.ConstantUtf8String) accordingly. - Adjust
NativeAotNameManglerstring-literal hashing to be primarily UTF-8-based, with a special-case for literals whose UTF-8 encoding contains U+FFFD replacement bytes.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/tests/nativeaot/SmokeTests/UnitTests/UnitTests.csproj | Adds the new MiscTests.cs compile item to the NativeAOT smoke tests project. |
| src/tests/nativeaot/SmokeTests/UnitTests/MiscTests.cs | New test validating isolated surrogate string literal preservation. |
| src/tests/nativeaot/SmokeTests/UnitTests/Main.cs | Wires MiscTests.Run into the smoke test runner. |
| src/coreclr/tools/Common/Compiler/NativeAotNameMangler.cs | Switches string-literal mangling cache/value to Utf8String, removes old UTF-16 helper, adds replacement-char detection + hashing adjustments. |
| src/coreclr/tools/Common/Compiler/NameMangler.cs | Updates the abstract API to return Utf8String for mangled string names. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs | Updates UTF-8 string symbol naming to use the new Utf8String-returning mangler API. |
Comments suppressed due to low confidence (1)
src/coreclr/tools/Common/Compiler/NativeAotNameMangler.cs:632
- The surrogate-special-case hash now uses
MemoryMarshal.AsBytes(literal.AsSpan()), which hashes the in-memory UTF-16 byte order. The removedGetBytesFromStringpreviously forced little-endian order, so this change can produce different mangled names on big-endian hosts. If big-endian builds are still supported, preserve a stable (little-endian) byte order when hashing UTF-16 data.
lock (this)
{
_mangledStringLiterals.TryAdd(literal, mangledName);
}
MihaZupan
approved these changes
Jun 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.