Use Utf8Span for type system names#128969
Merged
MichalStrehovsky merged 2 commits intoJun 8, 2026
Merged
Conversation
Migrate type system name surfaces and related NativeAOT callers from ReadOnlySpan<byte> to Utf8StringRef, adding helper APIs to keep call sites explicit and avoid unnecessary span conversions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR migrates CoreCLR toolchain type-system “name” surfaces from ReadOnlySpan<byte> to a new Internal.Text.Utf8StringRef, updating call sites to use ==/!= comparisons and explicit .AsSpan() when span operations are required. It also wires the new type into multiple tool projects and adds small helper APIs to reduce call-site ambiguity and avoid repeated ad-hoc span conversions.
Changes:
- Introduce
Internal.Text.Utf8StringRefand extend existing UTF-8 helpers (Utf8String,Utf8StringBuilder,TypeSystemHelpers, hashing helpers). - Update
Internal.TypeSystem(and related compiler/tooling code) to expose names/namespaces asUtf8StringRef, and replace many.SequenceEqual("..."u8)patterns with==. - Update project files and tests to compile against the new shared source file and updated signatures.
Reviewed changes
Copilot reviewed 130 out of 130 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/tools/ILVerification/ILVerification.projitems | Link in Utf8StringRef to ILVerification build. |
| src/coreclr/tools/ILVerification/ILImporter.Verify.cs | Switch UTF-8 comparisons to == with new name types. |
| src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemType.cs | Move Name/Namespace/nested lookup APIs to Utf8StringRef. |
| src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemModule.cs | Update GetType API to Utf8StringRef and adjust decoding. |
| src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemMethod.cs | Change Name surface to Utf8StringRef. |
| src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemField.cs | Change Name surface to Utf8StringRef. |
| src/coreclr/tools/dotnet-pgo/TraceRuntimeDescToTypeSystemDesc.cs | Replace SequenceEqual name checks with ==. |
| src/coreclr/tools/Common/TypeSystem/RuntimeDetermined/RuntimeDeterminedType.cs | Update name/namespace/method lookup signatures to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/RuntimeDetermined/MethodForRuntimeDeterminedType.cs | Change Name surface to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/Interop/UnmanagedCallingConventions.cs | Replace namespace/name comparisons with ==. |
| src/coreclr/tools/Common/TypeSystem/Interop/InteropTypes.cs | Use == for core named-type checks. |
| src/coreclr/tools/Common/TypeSystem/Interop/IL/PInvokeDelegateWrapperConstructor.cs | Change Name surface to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/Interop/IL/PInvokeDelegateWrapper.cs | Change Name/Namespace and nested/method-impl APIs to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/Interop/IL/NativeStructType.cs | Change Name/Namespace and nested/method-impl APIs to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/Interop/IL/MarshalHelpers.cs | Update attribute checks and span operations for new name type. |
| src/coreclr/tools/Common/TypeSystem/Interop/IL/InlineArrayType.cs | Change Name/Namespace and mangling helpers to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/IL/Stubs/UnsafeIntrinsics.cs | Use == for intrinsic type name checks. |
| src/coreclr/tools/Common/TypeSystem/IL/Stubs/TypeGetTypeMethodThunk.cs | Change Name surface to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/IL/Stubs/StructMarshallingThunk.Mangling.cs | Adjust prefix mangling to return ReadOnlySpan<byte> from Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/IL/Stubs/StructMarshallingThunk.cs | Change Name and name-prefix plumbing to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/IL/Stubs/StreamIntrinsics.cs | Use == for intrinsic member checks. |
| src/coreclr/tools/Common/TypeSystem/IL/Stubs/RuntimeHelpersIntrinsics.cs | Use == for intrinsic member/type checks. |
| src/coreclr/tools/Common/TypeSystem/IL/Stubs/PInvokeTargetNativeMethod.cs | Change Name surface to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/IL/Stubs/PInvokeLazyFixupField.cs | Change Name surface to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/IL/Stubs/MethodBaseGetCurrentMethodThunk.cs | Change Name surface to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/IL/Stubs/InterlockedIntrinsics.cs | Use == for intrinsic member checks. |
| src/coreclr/tools/Common/TypeSystem/IL/Stubs/GetFieldHelperMethodOverride.cs | Change Name surface to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/IL/Stubs/ForwardDelegateCreationThunk.cs | Change Name surface to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs | Change Name surface to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateThunks.cs | Change multiple thunk Name surfaces to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateMethodILEmitter.cs | Use == for delegate method name checks. |
| src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateMarshallingMethodThunk.Mangling.cs | Adjust prefix mangling to return ReadOnlySpan<byte> from Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateMarshallingMethodThunk.cs | Change Name and name-prefix plumbing to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/IL/Stubs/CalliMarshallingMethodThunk.Mangling.cs | Update signature prefix building to use Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/IL/Stubs/CalliMarshallingMethodThunk.cs | Change Name surface to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/IL/Stubs/AsyncResumptionStub.cs | Change Name surface to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/IL/Stubs/AssemblyGetExecutingAssemblyMethodThunk.cs | Change Name surface to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/IL/NativeAotILProvider.cs | Replace span comparisons with Utf8StringRef comparisons and .AsSpan() where needed. |
| src/coreclr/tools/Common/TypeSystem/Ecma/MetadataExtensions.cs | Change StringEquals to accept Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.MethodImpls.cs | Update MethodImpl lookup signature to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.cs | Change Name/Namespace and lookup APIs to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/Ecma/EcmaModule.cs | Update type lookup plumbing to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/Ecma/EcmaMethod.cs | Change Name surface and constructor checks to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/Ecma/EcmaField.cs | Change Name surface to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/Ecma/EcmaAssembly.cs | Change assembly Name to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/Ecma/CustomAttributeTypeProvider.cs | Update well-known type checks to use ==. |
| src/coreclr/tools/Common/TypeSystem/Common/VersionResilientHashCode.TypeSystem.cs | Add Utf8StringRef overloads for name hashing. |
| src/coreclr/tools/Common/TypeSystem/Common/TypeWithRepeatedFields.cs | Update delegating type to expose Utf8StringRef surfaces. |
| src/coreclr/tools/Common/TypeSystem/Common/TypeSystemHelpers.cs | Add Utf8StringRef append helpers and update span conversions. |
| src/coreclr/tools/Common/TypeSystem/Common/TypeDesc.cs | Update GetMethod/GetField APIs to take Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/Common/ModuleDesc.cs | Update GetType APIs to take Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/Common/MethodForInstantiatedType.cs | Change Name surface to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/Common/MethodDesc.cs | Change Name surface to Utf8StringRef and update GetName() decoding. |
| src/coreclr/tools/Common/TypeSystem/Common/MethodDelegator.cs | Change Name surface to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/Common/MetadataVirtualMethodAlgorithm.cs | Update virtual method match to use Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/Common/MetadataTypeSystemContext.cs | Replace name/namespace checks with ==. |
| src/coreclr/tools/Common/TypeSystem/Common/MetadataType.MethodImpls.cs | Update MethodImpl lookup signature to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/Common/MetadataType.cs | Change Name/Namespace and nested-type API to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/Common/InstantiatedType.MethodImpls.cs | Update MethodImpl lookup signature to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/Common/InstantiatedType.Metadata.cs | Update nested type lookup signature to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/Common/InstantiatedType.cs | Update name/namespace and method/field lookup signatures. |
| src/coreclr/tools/Common/TypeSystem/Common/InstantiatedMethod.cs | Change Name surface to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/Common/ImpliedRepeatedFieldDesc.cs | Change Name surface to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/Common/IAssemblyDesc.cs | Change assembly Name to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/Common/FieldForInstantiatedType.cs | Change Name surface to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/Common/FieldDesc.cs | Change Name surface to Utf8StringRef and update decoding. |
| src/coreclr/tools/Common/TypeSystem/Common/DefType.cs | Change Name/Namespace surfaces to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/Common/CastingHelper.TypeEquivalence.cs | Use == for name/namespace equivalence. |
| src/coreclr/tools/Common/TypeSystem/Common/ArrayType.cs | Change Name surface to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/Canon/CanonTypes.Metadata.cs | Update nested/methodimpl signatures to Utf8StringRef. |
| src/coreclr/tools/Common/TypeSystem/Canon/CanonTypes.cs | Change canon type name/namespace surfaces to Utf8StringRef. |
| src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs | Update name comparisons and pinning helpers for Utf8StringRef. |
| src/coreclr/tools/Common/Internal/Text/Utf8StringRef.cs | Add new Utf8StringRef type. |
| src/coreclr/tools/Common/Internal/Text/Utf8StringBuilder.cs | Add Append(Utf8StringRef) overload. |
| src/coreclr/tools/Common/Internal/Text/Utf8String.cs | Add implicit conversion to Utf8StringRef. |
| src/coreclr/tools/Common/Internal/Runtime/EETypeBuilderHelpers.cs | Update type name/namespace checks to use ==. |
| src/coreclr/tools/Common/Compiler/VectorFieldLayoutAlgorithm.cs | Use == for vector type name checks. |
| src/coreclr/tools/Common/Compiler/TypeMapMetadata.cs | Update attribute checks and method Name surface to Utf8StringRef. |
| src/coreclr/tools/Common/Compiler/NativeAotNameMangler.cs | Adjust sanitization helpers to accept Utf8StringRef. |
| src/coreclr/tools/Common/Compiler/MethodExtensions.cs | Update Task/ValueTask return detection to use Utf8StringRef. |
| src/coreclr/tools/Common/Compiler/Int128FieldLayoutAlgorithm.cs | Use == for integer type checks. |
| src/coreclr/tools/Common/Compiler/InstructionSetSupport.cs | Update intrinsic-type checks to use Utf8StringRef. |
| src/coreclr/tools/Common/Compiler/Dataflow/TypeExtensions.cs | Remove UTF-8 span StringEquals helper (now on Utf8StringRef). |
| src/coreclr/tools/Common/Compiler/AsyncContinuationType.cs | Update Name/Namespace and nested/methodimpl signatures. |
| src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj | Link Utf8StringRef into ILCompiler.TypeSystem build. |
| src/coreclr/tools/aot/ILCompiler.TypeSystem.Tests/SyntheticVirtualOverrideTests.cs | Update test to compile against Utf8StringRef names. |
| src/coreclr/tools/aot/ILCompiler.Trimming.Tests/TestCasesRunner/MemberAssertionsCollector.cs | Update attribute namespace check to use != with UTF-8 names. |
| src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs | Update intrinsic name checks to ==. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/TypeSystem/Mutable/MutableModule.cs | Update GetType signature to Utf8StringRef. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs | Update delegate and intrinsic name checks to ==. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/IL/ReadyToRunILProvider.cs | Update intrinsic lookup checks to ==. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/IBC/MIbcProfileParser.cs | Update canon module Name and GetType signature to Utf8StringRef. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/IBC/IBCProfileParser.cs | Update method name matching to ==. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/RuntimeDeterminedTypeHelper.cs | Update field name equality to ==. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCompilerContext.cs | Update vector-of-T detection to use ==. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ProfileDataManager.cs | Update delegate invoke detection to use ==. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/TypeValidationChecker.cs | Update special-name filtering to Utf8StringRef operations. |
| src/coreclr/tools/aot/ILCompiler.MetadataTransform/ILCompiler/Metadata/Transform.CustomAttribute.cs | Update type checks to use !=/== with UTF-8 names. |
| src/coreclr/tools/aot/ILCompiler.Compiler/ILCompiler.Compiler.csproj | Link VersionResilientHashCode.TypeSystem.cs into build. |
| src/coreclr/tools/aot/ILCompiler.Compiler/IL/TypeEqualityPatternAnalyzer.cs | Update well-known type/method pattern checks to ==. |
| src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/StartupCodeMainMethod.cs | Update stub method Name surfaces to Utf8StringRef. |
| src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/NativeLibraryStartupMethod.cs | Update stub method Name surface to Utf8StringRef. |
| src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs | Update intrinsic/detection checks to == with Utf8StringRef. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/VectorOfTFieldLayoutAlgorithm.cs | Update vector-of-T detection to use ==. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UsageBasedInteropStubManager.cs | Update Marshal type check to ==. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/TypePreinit.cs | Update intrinsic pattern checks to == and adjust span slicing. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/SubstitutionProvider.cs | Update namespace checks and span slicing for new name type. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/SubstitutedILProvider.cs | Update resource accessor and intrinsic checks to ==. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ReachabilityInstrumentationProvider.cs | Update generated method Name to Utf8StringRef. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/NoMetadataBlockingPolicy.cs | Update name equality for metadata blocking. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/HardwareIntrinsicHelpers.Aot.cs | Update name equality check to ==. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ExternSymbolMappedField.cs | Update field Name to Utf8StringRef. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/VTableSliceNode.cs | Update finalizer name checks to ==. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/InlineableStringsResourceNode.cs | Update resource accessor matching to ==. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/EETypeNode.cs | Update special method checks to !=/==. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/CodeBasedDependencyAlgorithm.cs | Update comparer/equality-comparer checks to ==. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/MethodBodyScanner.cs | Pass Utf8StringRef.AsSpan() into compiler-generated name helpers. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/InterproceduralState.cs | Pass Utf8StringRef.AsSpan() into compiler-generated name helpers. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/FlowAnnotations.cs | Pass Utf8StringRef.AsSpan() into compiler-generated name helpers and update checks. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/CompilerGeneratedState.cs | Pass Utf8StringRef.AsSpan() into compiler-generated name helpers throughout. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/CompilerGeneratedCallGraph.cs | Pass Utf8StringRef.AsSpan() into compiler-generated name helpers. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.InterfaceThunks.cs | Update thunk Name surface to Utf8StringRef. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.GetFieldMethodOverrides.cs | Update ValueTuple check to use ==. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.GeneratedAssembly.cs | Update generated assembly name/type APIs to Utf8StringRef. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.BoxedTypes.cs | Update boxed type name surfaces and lookup signatures. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Compilation.cs | Update intrinsic expansion and invoke checks to ==. |
| src/coreclr/tools/aot/ILCompiler.Compiler.Tests/SwiftLoweringTests.cs | Update namespace checks to use ==. |
| src/coreclr/tools/aot/crossgen2/Program.cs | Update name matching to use != for Utf8StringRef. |
| src/coreclr/nativeaot/System.Private.TypeLoader/src/System.Private.TypeLoader.csproj | Link Utf8StringRef into TypeLoader build. |
| src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/TypeSystem/RuntimeMethodDesc.cs | Update method Name surface to Utf8StringRef. |
jkotas
reviewed
Jun 4, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jkotas
approved these changes
Jun 5, 2026
ladeak
reviewed
Jun 6, 2026
ladeak
reviewed
Jun 6, 2026
ladeak
reviewed
Jun 6, 2026
Member
Author
|
/ba-g the JIT issue was fixed |
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.
Contributes to #122363.
This addresses two issues with the current "the exchange type for UTF-8 strings is
ReadOnlySpan<byte>":ToStringis more meaningful than the one onReadOnlySpan<T>.==to compare strings, no morex.SequenceEqual("y"u8)Migrate type system name surfaces and related callers from
ReadOnlySpan<byte>toUtf8StringRef, adding helper APIs to keep call sites explicit and avoid unnecessary span conversions.