From 3fb55e72362e512abf80037568a894cb79055f4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Thu, 4 Jun 2026 12:50:12 +0900 Subject: [PATCH 1/2] Use Utf8StringRef for type system names Migrate type system name surfaces and related NativeAOT callers from ReadOnlySpan 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> --- .../Internal/TypeSystem/RuntimeMethodDesc.cs | 3 +- .../src/System.Private.TypeLoader.csproj | 3 + .../Common/Compiler/AsyncContinuationType.cs | 9 +-- .../Compiler/Dataflow/TypeExtensions.cs | 18 ----- .../Common/Compiler/InstructionSetSupport.cs | 6 +- .../Compiler/Int128FieldLayoutAlgorithm.cs | 4 +- .../tools/Common/Compiler/MethodExtensions.cs | 9 +-- .../Common/Compiler/NativeAotNameMangler.cs | 8 ++- .../tools/Common/Compiler/TypeMapMetadata.cs | 13 ++-- .../Compiler/VectorFieldLayoutAlgorithm.cs | 18 ++--- .../Internal/Runtime/EETypeBuilderHelpers.cs | 8 +-- .../tools/Common/Internal/Text/Utf8String.cs | 2 + .../Common/Internal/Text/Utf8StringBuilder.cs | 5 ++ .../Common/Internal/Text/Utf8StringRef.cs | 69 +++++++++++++++++++ .../tools/Common/JitInterface/CorInfoImpl.cs | 32 +++++---- .../TypeSystem/Canon/CanonTypes.Metadata.cs | 5 +- .../Common/TypeSystem/Canon/CanonTypes.cs | 9 +-- .../Common/TypeSystem/Common/ArrayType.cs | 4 +- .../Common/CastingHelper.TypeEquivalence.cs | 4 +- .../tools/Common/TypeSystem/Common/DefType.cs | 10 ++- .../Common/TypeSystem/Common/FieldDesc.cs | 8 +-- .../Common/FieldForInstantiatedType.cs | 6 +- .../Common/TypeSystem/Common/IAssemblyDesc.cs | 4 +- .../Common/ImpliedRepeatedFieldDesc.cs | 4 +- .../TypeSystem/Common/InstantiatedMethod.cs | 4 +- .../Common/InstantiatedType.Metadata.cs | 4 +- .../Common/InstantiatedType.MethodImpls.cs | 4 +- .../TypeSystem/Common/InstantiatedType.cs | 11 +-- .../Common/MetadataType.MethodImpls.cs | 4 +- .../Common/TypeSystem/Common/MetadataType.cs | 8 ++- .../Common/MetadataTypeSystemContext.cs | 4 +- .../Common/MetadataVirtualMethodAlgorithm.cs | 6 +- .../TypeSystem/Common/MethodDelegator.cs | 4 +- .../Common/TypeSystem/Common/MethodDesc.cs | 11 +-- .../Common/MethodForInstantiatedType.cs | 4 +- .../Common/TypeSystem/Common/ModuleDesc.cs | 6 +- .../Common/TypeSystem/Common/TypeDesc.cs | 16 +++-- .../TypeSystem/Common/TypeSystemHelpers.cs | 40 +++++++++-- .../Common/TypeWithRepeatedFields.cs | 10 +-- .../VersionResilientHashCode.TypeSystem.cs | 8 +++ .../Ecma/CustomAttributeTypeProvider.cs | 4 +- .../Common/TypeSystem/Ecma/EcmaAssembly.cs | 4 +- .../tools/Common/TypeSystem/Ecma/EcmaField.cs | 4 +- .../Common/TypeSystem/Ecma/EcmaMethod.cs | 8 ++- .../Common/TypeSystem/Ecma/EcmaModule.cs | 8 ++- .../TypeSystem/Ecma/EcmaType.MethodImpls.cs | 5 +- .../tools/Common/TypeSystem/Ecma/EcmaType.cs | 21 +++--- .../TypeSystem/Ecma/MetadataExtensions.cs | 6 +- .../TypeSystem/IL/NativeAotILProvider.cs | 56 +++++++-------- ...AssemblyGetExecutingAssemblyMethodThunk.cs | 4 +- .../IL/Stubs/AsyncResumptionStub.cs | 4 +- .../CalliMarshallingMethodThunk.Mangling.cs | 6 +- .../IL/Stubs/CalliMarshallingMethodThunk.cs | 4 +- ...DelegateMarshallingMethodThunk.Mangling.cs | 2 +- .../Stubs/DelegateMarshallingMethodThunk.cs | 11 +-- .../IL/Stubs/DelegateMethodILEmitter.cs | 6 +- .../TypeSystem/IL/Stubs/DelegateThunks.cs | 16 +++-- .../IL/Stubs/DynamicInvokeMethodThunk.cs | 4 +- .../IL/Stubs/ForwardDelegateCreationThunk.cs | 4 +- .../IL/Stubs/GetFieldHelperMethodOverride.cs | 3 +- .../IL/Stubs/InterlockedIntrinsics.cs | 4 +- .../Stubs/MethodBaseGetCurrentMethodThunk.cs | 4 +- .../IL/Stubs/PInvokeLazyFixupField.cs | 4 +- .../IL/Stubs/PInvokeTargetNativeMethod.cs | 4 +- .../IL/Stubs/RuntimeHelpersIntrinsics.cs | 8 +-- .../TypeSystem/IL/Stubs/StreamIntrinsics.cs | 6 +- .../Stubs/StructMarshallingThunk.Mangling.cs | 2 +- .../IL/Stubs/StructMarshallingThunk.cs | 10 ++- .../IL/Stubs/TypeGetTypeMethodThunk.cs | 4 +- .../TypeSystem/IL/Stubs/UnsafeIntrinsics.cs | 2 +- .../TypeSystem/Interop/IL/InlineArrayType.cs | 23 ++++--- .../TypeSystem/Interop/IL/MarshalHelpers.cs | 6 +- .../TypeSystem/Interop/IL/NativeStructType.cs | 14 ++-- .../Interop/IL/PInvokeDelegateWrapper.cs | 13 ++-- .../IL/PInvokeDelegateWrapperConstructor.cs | 4 +- .../Common/TypeSystem/Interop/InteropTypes.cs | 4 +- .../Interop/UnmanagedCallingConventions.cs | 16 ++--- .../MethodForRuntimeDeterminedType.cs | 4 +- .../RuntimeDeterminedType.cs | 12 ++-- .../tools/ILVerification/ILImporter.Verify.cs | 12 ++-- .../ILVerification/ILVerification.projitems | 3 + .../SwiftLoweringTests.cs | 2 +- .../Compiler/Compilation.cs | 16 ++--- .../CompilerTypeSystemContext.BoxedTypes.cs | 15 ++-- ...ilerTypeSystemContext.GeneratedAssembly.cs | 13 ++-- ...peSystemContext.GetFieldMethodOverrides.cs | 2 +- ...mpilerTypeSystemContext.InterfaceThunks.cs | 3 +- .../Dataflow/CompilerGeneratedCallGraph.cs | 8 +-- .../Dataflow/CompilerGeneratedState.cs | 38 +++++----- .../Compiler/Dataflow/FlowAnnotations.cs | 10 +-- .../Compiler/Dataflow/InterproceduralState.cs | 2 +- .../Compiler/Dataflow/MethodBodyScanner.cs | 2 +- .../CodeBasedDependencyAlgorithm.cs | 6 +- .../Compiler/DependencyAnalysis/EETypeNode.cs | 6 +- .../InlineableStringsResourceNode.cs | 4 +- .../DependencyAnalysis/VTableSliceNode.cs | 4 +- .../Compiler/ExternSymbolMappedField.cs | 3 +- .../Compiler/HardwareIntrinsicHelpers.Aot.cs | 2 +- .../Compiler/NoMetadataBlockingPolicy.cs | 2 +- .../ReachabilityInstrumentationProvider.cs | 2 +- .../Compiler/SubstitutedILProvider.cs | 10 +-- .../Compiler/SubstitutionProvider.cs | 4 +- .../Compiler/TypePreinit.cs | 34 ++++----- .../Compiler/UsageBasedInteropStubManager.cs | 2 +- .../Compiler/VectorOfTFieldLayoutAlgorithm.cs | 2 +- .../IL/ILImporter.Scanner.cs | 51 +++++++------- .../StartupCode/NativeLibraryStartupMethod.cs | 3 +- .../StartupCode/StartupCodeMainMethod.cs | 5 +- .../IL/TypeEqualityPatternAnalyzer.cs | 10 +-- .../ILCompiler.Compiler.csproj | 3 + .../Metadata/Transform.CustomAttribute.cs | 2 +- .../ReadyToRun/TypeValidationChecker.cs | 2 +- .../Compiler/ProfileDataManager.cs | 2 +- .../Compiler/ReadyToRunCompilerContext.cs | 2 +- .../Compiler/RuntimeDeterminedTypeHelper.cs | 2 +- .../IBC/IBCProfileParser.cs | 2 +- .../IBC/MIbcProfileParser.cs | 15 ++-- .../IL/ReadyToRunILProvider.cs | 24 +++---- .../JitInterface/CorInfoImpl.ReadyToRun.cs | 12 ++-- .../TypeSystem/Mutable/MutableModule.cs | 3 +- .../JitInterface/CorInfoImpl.RyuJit.cs | 2 +- .../MemberAssertionsCollector.cs | 2 +- .../SyntheticVirtualOverrideTests.cs | 11 +-- .../ILCompiler.TypeSystem.csproj | 3 + src/coreclr/tools/aot/crossgen2/Program.cs | 2 +- .../TraceRuntimeDescToTypeSystemDesc.cs | 2 +- .../TypeRefTypeSystemField.cs | 4 +- .../TypeRefTypeSystemMethod.cs | 4 +- .../TypeRefTypeSystemModule.cs | 10 +-- .../TypeRefTypeSystemType.cs | 16 +++-- 130 files changed, 680 insertions(+), 450 deletions(-) create mode 100644 src/coreclr/tools/Common/Internal/Text/Utf8StringRef.cs diff --git a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/TypeSystem/RuntimeMethodDesc.cs b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/TypeSystem/RuntimeMethodDesc.cs index d3a362efa88e65..40709a6c2b72eb 100644 --- a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/TypeSystem/RuntimeMethodDesc.cs +++ b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/TypeSystem/RuntimeMethodDesc.cs @@ -4,6 +4,7 @@ using System; +using Internal.Text; using Internal.Runtime.CompilerServices; using Internal.Runtime.TypeLoader; @@ -91,7 +92,7 @@ public override MethodNameAndSignature NameAndSignature } } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { diff --git a/src/coreclr/nativeaot/System.Private.TypeLoader/src/System.Private.TypeLoader.csproj b/src/coreclr/nativeaot/System.Private.TypeLoader/src/System.Private.TypeLoader.csproj index 67540af5894b7c..198b9448292e19 100644 --- a/src/coreclr/nativeaot/System.Private.TypeLoader/src/System.Private.TypeLoader.csproj +++ b/src/coreclr/nativeaot/System.Private.TypeLoader/src/System.Private.TypeLoader.csproj @@ -54,6 +54,9 @@ IntrinsicAttribute.cs + + Internal\Text\Utf8StringRef.cs + Internal\TypeSystem\ArrayType.Canon.cs diff --git a/src/coreclr/tools/Common/Compiler/AsyncContinuationType.cs b/src/coreclr/tools/Common/Compiler/AsyncContinuationType.cs index 2da1f72a9900bc..33bcc0b4deb29d 100644 --- a/src/coreclr/tools/Common/Compiler/AsyncContinuationType.cs +++ b/src/coreclr/tools/Common/Compiler/AsyncContinuationType.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using System.Text; +using Internal.Text; using Internal.TypeSystem; namespace ILCompiler @@ -21,8 +22,8 @@ public sealed partial class AsyncContinuationType : MetadataType public GCPointerMap PointerMap { get; } public override DefType[] ExplicitlyImplementedInterfaces => []; - public override ReadOnlySpan Name => Encoding.UTF8.GetBytes(DiagnosticName); - public override ReadOnlySpan Namespace => []; + public override Utf8StringRef Name => Encoding.UTF8.GetBytes(DiagnosticName); + public override Utf8StringRef Namespace => Array.Empty(); // We don't lay these out using MetadataType metadata. // Autolayout (which we'd get due to GC pointers) would likely not match what codegen expects. @@ -49,9 +50,9 @@ public AsyncContinuationType(MetadataType continuationBaseType, GCPointerMap poi public override bool HasCustomAttribute(string attributeNamespace, string attributeName) => false; public override IEnumerable GetNestedTypes() => []; - public override MetadataType GetNestedType(ReadOnlySpan name) => null; + public override MetadataType GetNestedType(Utf8StringRef name) => null; protected override MethodImplRecord[] ComputeVirtualMethodImplsForType() => []; - public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(ReadOnlySpan name) => []; + public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8StringRef name) => []; protected override int CompareToImpl(TypeDesc other, TypeSystemComparer comparer) { diff --git a/src/coreclr/tools/Common/Compiler/Dataflow/TypeExtensions.cs b/src/coreclr/tools/Common/Compiler/Dataflow/TypeExtensions.cs index a4f66b891f7c4d..312ea9880d0966 100644 --- a/src/coreclr/tools/Common/Compiler/Dataflow/TypeExtensions.cs +++ b/src/coreclr/tools/Common/Compiler/Dataflow/TypeExtensions.cs @@ -53,23 +53,5 @@ public static bool IsDeclaredOnType(this MethodDesc method, string fullTypeName) return method.OwningType.IsTypeOf(fullTypeName); } - public static bool StringEquals(this ReadOnlySpan utf8bytes, string value) - { - if (utf8bytes.Length < value.Length) - return false; - - for (int i = 0; i < value.Length; i++) - { - int ch = utf8bytes[i]; - if (ch > 0x7F) - return System.Text.Encoding.UTF8.GetString(utf8bytes) == value; - - // We are assuming here that valid UTF8 encoded byte > 0x7F cannot map to a character with code point <= 0x7F - if (ch != value[i]) - return false; - } - - return utf8bytes.Length == value.Length; // All char ANSI, all matching - } } } diff --git a/src/coreclr/tools/Common/Compiler/InstructionSetSupport.cs b/src/coreclr/tools/Common/Compiler/InstructionSetSupport.cs index 84019f16f8b88d..f04bdd184f3a75 100644 --- a/src/coreclr/tools/Common/Compiler/InstructionSetSupport.cs +++ b/src/coreclr/tools/Common/Compiler/InstructionSetSupport.cs @@ -61,7 +61,7 @@ public static string GetHardwareIntrinsicId(TargetArchitecture architecture, Typ return ""; // 64-bit ISA variants are not included in the mapping dictionary, so we use the containing type instead - if (potentialType.Name.SequenceEqual("X64"u8) || potentialType.Name.SequenceEqual("Arm64"u8)) + if (potentialType.Name == "X64"u8 || potentialType.Name == "Arm64"u8) { if (architecture is TargetArchitecture.X64 or TargetArchitecture.ARM64) potentialType = potentialType.ContainingType; @@ -79,12 +79,12 @@ public static string GetHardwareIntrinsicId(TargetArchitecture architecture, Typ if (architecture is TargetArchitecture.X64 or TargetArchitecture.X86) { - if (!potentialType.Namespace.SequenceEqual("System.Runtime.Intrinsics.X86"u8)) + if (potentialType.Namespace != "System.Runtime.Intrinsics.X86"u8) return ""; } else if (architecture is TargetArchitecture.ARM64 or TargetArchitecture.ARM) { - if (!potentialType.Namespace.SequenceEqual("System.Runtime.Intrinsics.Arm"u8)) + if (potentialType.Namespace != "System.Runtime.Intrinsics.Arm"u8) return ""; } else if (architecture is TargetArchitecture.LoongArch64) diff --git a/src/coreclr/tools/Common/Compiler/Int128FieldLayoutAlgorithm.cs b/src/coreclr/tools/Common/Compiler/Int128FieldLayoutAlgorithm.cs index 585d626353bd31..c38a7bdbead108 100644 --- a/src/coreclr/tools/Common/Compiler/Int128FieldLayoutAlgorithm.cs +++ b/src/coreclr/tools/Common/Compiler/Int128FieldLayoutAlgorithm.cs @@ -84,8 +84,8 @@ public override ValueTypeShapeCharacteristics ComputeValueTypeShapeCharacteristi public static bool IsIntegerType(DefType type) { return type.IsIntrinsic - && type.Namespace.SequenceEqual("System"u8) - && (type.Name.SequenceEqual("Int128"u8) || type.Name.SequenceEqual("UInt128"u8)); + && type.Namespace == "System"u8 + && (type.Name == "Int128"u8 || type.Name == "UInt128"u8); } } } diff --git a/src/coreclr/tools/Common/Compiler/MethodExtensions.cs b/src/coreclr/tools/Common/Compiler/MethodExtensions.cs index 954bb9c01d6a21..449c2448af3f4b 100644 --- a/src/coreclr/tools/Common/Compiler/MethodExtensions.cs +++ b/src/coreclr/tools/Common/Compiler/MethodExtensions.cs @@ -3,6 +3,7 @@ using System; using ILCompiler.DependencyAnalysis; +using Internal.Text; using Internal.TypeSystem; using Internal.TypeSystem.Ecma; @@ -142,11 +143,11 @@ public static bool ReturnsTaskOrValueTask(this MethodSignature method) if (ret is MetadataType md && md.Module == method.Context.SystemModule - && md.Namespace.SequenceEqual("System.Threading.Tasks"u8)) + && md.Namespace == "System.Threading.Tasks"u8) { - ReadOnlySpan name = md.Name; - if (name.SequenceEqual("Task"u8) || name.SequenceEqual("Task`1"u8) - || name.SequenceEqual("ValueTask"u8) || name.SequenceEqual("ValueTask`1"u8)) + Utf8StringRef name = md.Name; + if (name == "Task"u8 || name == "Task`1"u8 + || name == "ValueTask"u8 || name == "ValueTask`1"u8) { return true; } diff --git a/src/coreclr/tools/Common/Compiler/NativeAotNameMangler.cs b/src/coreclr/tools/Common/Compiler/NativeAotNameMangler.cs index 0dc458c42f6264..136a0c881a6ef1 100644 --- a/src/coreclr/tools/Common/Compiler/NativeAotNameMangler.cs +++ b/src/coreclr/tools/Common/Compiler/NativeAotNameMangler.cs @@ -40,8 +40,10 @@ public override Utf8String CompilationUnitPrefix public override Utf8String SanitizeName(Utf8String s) => SanitizeName(s.AsSpan()); - private static Utf8String SanitizeName(ReadOnlySpan s) + private static Utf8String SanitizeName(Utf8StringRef n) { + ReadOnlySpan s = n.AsSpan(); + Utf8StringBuilder sb = null; for (int i = 0; i < s.Length; i++) { @@ -98,7 +100,7 @@ private static bool ContainsUtf8ReplacementCharacter(ReadOnlySpan bytes) return bytes.IndexOf(replacementCharacter) >= 0; } - private Utf8String SanitizeNameWithHash(Utf8String literal, byte[] hash = null) + private static Utf8String SanitizeNameWithHash(Utf8String literal, byte[] hash = null) { Utf8String mangledName = SanitizeName(literal); @@ -242,7 +244,7 @@ static void AppendTypeName(Utf8StringBuilder sb, MetadataType t) } else { - ReadOnlySpan ns = t.Namespace; + Utf8StringRef ns = t.Namespace; if (ns.Length > 0) sb.Append(SanitizeName(ns)).Append('_'); } diff --git a/src/coreclr/tools/Common/Compiler/TypeMapMetadata.cs b/src/coreclr/tools/Common/Compiler/TypeMapMetadata.cs index e4455f8fd8e38d..1c4b6b117e15d4 100644 --- a/src/coreclr/tools/Common/Compiler/TypeMapMetadata.cs +++ b/src/coreclr/tools/Common/Compiler/TypeMapMetadata.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using System.Reflection.Metadata; using ILCompiler.DependencyAnalysis; +using Internal.Text; using Internal.IL; using Internal.IL.Stubs; using Internal.TypeSystem; @@ -26,13 +27,13 @@ private enum TypeMapAttributeKind private static TypeMapAttributeKind LookupTypeMapType(TypeDesc attrType) { var typeDef = attrType.GetTypeDefinition() as MetadataType; - if (typeDef != null && typeDef.Namespace.SequenceEqual("System.Runtime.InteropServices"u8)) + if (typeDef != null && typeDef.Namespace == "System.Runtime.InteropServices"u8) { - if (typeDef.Name.SequenceEqual("TypeMapAssemblyTargetAttribute`1"u8)) + if (typeDef.Name == "TypeMapAssemblyTargetAttribute`1"u8) return TypeMapAttributeKind.TypeMapAssemblyTarget; - else if (typeDef.Name.SequenceEqual("TypeMapAttribute`1"u8)) + else if (typeDef.Name == "TypeMapAttribute`1"u8) return TypeMapAttributeKind.TypeMap; - else if (typeDef.Name.SequenceEqual("TypeMapAssociationAttribute`1"u8)) + else if (typeDef.Name == "TypeMapAssociationAttribute`1"u8) return TypeMapAttributeKind.TypeMapAssociation; } return TypeMapAttributeKind.None; @@ -66,7 +67,7 @@ public ThrowingMethodStub(TypeDesc owningType, TypeDesc typeMapGroup, bool exter } public TypeSystemException Exception { get; } - public override ReadOnlySpan Name => _name; + public override Utf8StringRef Name => _name; public override MethodIL EmitIL() { #if READYTORUN @@ -78,7 +79,7 @@ public override MethodIL EmitIL() protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer) { - return Name.SequenceCompareTo(other.Name); + return Name.AsSpan().SequenceCompareTo(other.Name.AsSpan()); } public override bool IsPInvoke => false; diff --git a/src/coreclr/tools/Common/Compiler/VectorFieldLayoutAlgorithm.cs b/src/coreclr/tools/Common/Compiler/VectorFieldLayoutAlgorithm.cs index 7fbe585115dc3d..74481988dadf25 100644 --- a/src/coreclr/tools/Common/Compiler/VectorFieldLayoutAlgorithm.cs +++ b/src/coreclr/tools/Common/Compiler/VectorFieldLayoutAlgorithm.cs @@ -27,11 +27,11 @@ public override ComputedInstanceFieldLayout ComputeInstanceLayout(DefType defTyp LayoutInt alignment; - if (defType.Name.SequenceEqual("Vector64`1"u8)) + if (defType.Name == "Vector64`1"u8) { alignment = new LayoutInt(8); } - else if (defType.Name.SequenceEqual("Vector128`1"u8)) + else if (defType.Name == "Vector128`1"u8) { if (defType.Context.Target.Architecture == TargetArchitecture.ARM) { @@ -43,7 +43,7 @@ public override ComputedInstanceFieldLayout ComputeInstanceLayout(DefType defTyp alignment = new LayoutInt(16); } } - else if (defType.Name.SequenceEqual("Vector256`1"u8)) + else if (defType.Name == "Vector256`1"u8) { if (defType.Context.Target.Architecture == TargetArchitecture.ARM) { @@ -76,7 +76,7 @@ public override ComputedInstanceFieldLayout ComputeInstanceLayout(DefType defTyp } else { - Debug.Assert(defType.Name.SequenceEqual("Vector512`1"u8)); + Debug.Assert(defType.Name == "Vector512`1"u8); if (defType.Context.Target.Architecture == TargetArchitecture.ARM) { @@ -164,11 +164,11 @@ public override ValueTypeShapeCharacteristics ComputeValueTypeShapeCharacteristi public static bool IsVectorType(DefType type) { return type.IsIntrinsic && - type.Namespace.SequenceEqual("System.Runtime.Intrinsics"u8) && - (type.Name.SequenceEqual("Vector64`1"u8) || - type.Name.SequenceEqual("Vector128`1"u8) || - type.Name.SequenceEqual("Vector256`1"u8) || - type.Name.SequenceEqual("Vector512`1"u8)); + type.Namespace == "System.Runtime.Intrinsics"u8 && + (type.Name == "Vector64`1"u8 || + type.Name == "Vector128`1"u8 || + type.Name == "Vector256`1"u8 || + type.Name == "Vector512`1"u8); } } } diff --git a/src/coreclr/tools/Common/Internal/Runtime/EETypeBuilderHelpers.cs b/src/coreclr/tools/Common/Internal/Runtime/EETypeBuilderHelpers.cs index 1454df291cc4ae..7ae7bf404259d8 100644 --- a/src/coreclr/tools/Common/Internal/Runtime/EETypeBuilderHelpers.cs +++ b/src/coreclr/tools/Common/Internal/Runtime/EETypeBuilderHelpers.cs @@ -187,8 +187,8 @@ public static ushort ComputeFlagsEx(TypeDesc type) if (type is MetadataType mdType && mdType.Module == mdType.Context.SystemModule && - (mdType.Name.SequenceEqual("WeakReference"u8) || mdType.Name.SequenceEqual("WeakReference`1"u8)) && - mdType.Namespace.SequenceEqual("System"u8)) + (mdType.Name == "WeakReference"u8 || mdType.Name == "WeakReference`1"u8) && + mdType.Namespace == "System"u8) { flagsEx |= (ushort)EETypeFlagsEx.HasEagerFinalizerFlag; } @@ -273,8 +273,8 @@ private static bool HasCriticalFinalizer(TypeDesc type) if (type is MetadataType mdType && mdType.Module == mdType.Context.SystemModule && - mdType.Name.SequenceEqual("CriticalFinalizerObject"u8) && - mdType.Namespace.SequenceEqual("System.Runtime.ConstrainedExecution"u8)) + mdType.Name == "CriticalFinalizerObject"u8 && + mdType.Namespace == "System.Runtime.ConstrainedExecution"u8) return true; type = type.BaseType; diff --git a/src/coreclr/tools/Common/Internal/Text/Utf8String.cs b/src/coreclr/tools/Common/Internal/Text/Utf8String.cs index 0407c79e8ced9c..0419290c633df4 100644 --- a/src/coreclr/tools/Common/Internal/Text/Utf8String.cs +++ b/src/coreclr/tools/Common/Internal/Text/Utf8String.cs @@ -29,6 +29,8 @@ public Utf8String(string s) _value = Encoding.UTF8.GetBytes(s); } + public static implicit operator Utf8StringRef(Utf8String s) => s._value; + public int Length => _value.Length; public ReadOnlySpan AsSpan() => _value; diff --git a/src/coreclr/tools/Common/Internal/Text/Utf8StringBuilder.cs b/src/coreclr/tools/Common/Internal/Text/Utf8StringBuilder.cs index 468fdb46393876..2b292485a556c2 100644 --- a/src/coreclr/tools/Common/Internal/Text/Utf8StringBuilder.cs +++ b/src/coreclr/tools/Common/Internal/Text/Utf8StringBuilder.cs @@ -43,6 +43,11 @@ public Utf8StringBuilder Append(Utf8String value) return Append(value.AsSpan()); } + public Utf8StringBuilder Append(Utf8StringRef value) + { + return Append(value.AsSpan()); + } + public Utf8StringBuilder Append(ReadOnlySpan value) { Ensure(value.Length); diff --git a/src/coreclr/tools/Common/Internal/Text/Utf8StringRef.cs b/src/coreclr/tools/Common/Internal/Text/Utf8StringRef.cs new file mode 100644 index 00000000000000..9179e833a47637 --- /dev/null +++ b/src/coreclr/tools/Common/Internal/Text/Utf8StringRef.cs @@ -0,0 +1,69 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Diagnostics.CodeAnalysis; +using System.Numerics; +using System.Text; + +namespace Internal.Text +{ + public readonly ref struct Utf8StringRef + { + private readonly ReadOnlySpan _value; + + public Utf8StringRef(ReadOnlySpan value) => _value = value; + + public int Length => _value.Length; + + public bool IsEmpty => _value.IsEmpty; + + public ReadOnlySpan AsSpan() => _value; + + public byte[] ToArray() => _value.ToArray(); + + public bool StartsWith(Utf8StringRef value) => _value.StartsWith(value.AsSpan()); + + public bool EndsWith(Utf8StringRef value) => _value.EndsWith(value.AsSpan()); + + // This is deliberately not a == operator because we don't want to make it easy + // to accidentally do UTF-8 vs UTF-16 string comparisons. + public bool StringEquals(string value) + { + if (_value.Length < value.Length) + return false; + + for (int i = 0; i < value.Length; i++) + { + int ch = _value[i]; + if (ch > 0x7F) + return Encoding.UTF8.GetString(_value) == value; + + // We are assuming here that valid UTF8 encoded byte > 0x7F cannot map to a character with code point <= 0x7F + if (ch != value[i]) + return false; + } + + return _value.Length == value.Length; // All char ANSI, all matching + } + + public override bool Equals(object obj) => false; + + public override int GetHashCode() + { + HashCode h = default; + h.AddBytes(_value); + return h.ToHashCode(); + } + + public override string ToString() => Encoding.UTF8.GetString(_value); + + public static implicit operator Utf8StringRef(ReadOnlySpan s) => new Utf8StringRef(s); + + public static bool operator ==(Utf8StringRef left, Utf8StringRef right) + => left._value.SequenceEqual(right._value); + + public static bool operator !=(Utf8StringRef left, Utf8StringRef right) + => !left._value.SequenceEqual(right._value); + } +} diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index 5fc46db5a8978b..575a9ee0e847fb 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -12,6 +12,8 @@ using System.Runtime.InteropServices; using System.Text.Unicode; +using Internal.Text; + #if SUPPORT_JIT using Internal.Runtime.CompilerServices; #endif @@ -1155,7 +1157,7 @@ private uint getMethodAttribsInternal(MethodDesc method) result |= CorInfoFlag.CORINFO_FLG_FORCEINLINE; } - if (method.OwningType.IsDelegate && method.Name.SequenceEqual("Invoke"u8)) + if (method.OwningType.IsDelegate && method.Name == "Invoke"u8) { // This is now used to emit efficient invoke code for any delegate invoke, // including multicast. @@ -1769,7 +1771,7 @@ private static object ResolveTokenInScope(MethodILScope methodIL, object typeOrM Debug.Assert((methodContext.HasInstantiation && !owningMethod.HasInstantiation) || (!methodContext.HasInstantiation && !owningMethod.HasInstantiation) || methodContext.GetTypicalMethodDefinition() == owningMethod.GetTypicalMethodDefinition() || - (owningMethod.Name.SequenceEqual("CreateDefaultInstance"u8) && methodContext.Name.SequenceEqual("CreateInstance"u8))); + (owningMethod.Name == "CreateDefaultInstance"u8 && methodContext.Name == "CreateInstance"u8)); Debug.Assert(methodContext.OwningType.HasSameTypeDefinition(owningMethod.OwningType)); typeInst = methodContext.OwningType.Instantiation; methodInst = methodContext.Instantiation; @@ -2093,8 +2095,8 @@ private CorInfoType asCorInfoType(CORINFO_CLASS_STRUCT_* cls) else if (type is MetadataType mdType) { if (namespaceName != null) - *namespaceName = (byte*)GetPin(SpanToPinnableBytes(mdType.Namespace)); - return (byte*)GetPin(SpanToPinnableBytes(mdType.Name)); + *namespaceName = (byte*)GetPin(Utf8StringRefToPinnableBytes(mdType.Namespace)); + return (byte*)GetPin(Utf8StringRefToPinnableBytes(mdType.Name)); } if (namespaceName != null) @@ -2583,8 +2585,8 @@ private GetTypeLayoutResult GetTypeLayoutHelper(MetadataType type, uint parentIn // not care about since they are considered primitives by the JIT. if (type.IsIntrinsic) { - ReadOnlySpan ns = type.Namespace; - if (ns.SequenceEqual("System.Runtime.Intrinsics"u8) || ns.SequenceEqual("System.Numerics"u8)) + Utf8StringRef ns = type.Namespace; + if (ns == "System.Runtime.Intrinsics"u8 || ns == "System.Numerics"u8) { parNode->simdTypeHnd = ObjectToHandle(type); if (parentIndex != uint.MaxValue) @@ -3065,9 +3067,9 @@ private bool isExactType(CORINFO_CLASS_STRUCT_* cls) // non-candidates before we compare names. if (type.IsIntrinsic && type is MetadataType mdType) { - ReadOnlySpan name = mdType.Name; - if ((name.SequenceEqual("SZArrayHelper"u8) || name.SequenceEqual("Array`1"u8)) && - mdType.Namespace.SequenceEqual("System"u8)) + Utf8StringRef name = mdType.Name; + if ((name == "SZArrayHelper"u8 || name == "Array`1"u8) && + mdType.Namespace == "System"u8) { return false; } @@ -3265,16 +3267,16 @@ private static CORINFO_FIELD_ACCESSOR getFieldIntrinsic(FieldDesc field) var owningType = field.OwningType; if ((owningType.IsWellKnownType(WellKnownType.IntPtr) || owningType.IsWellKnownType(WellKnownType.UIntPtr)) && - field.Name.SequenceEqual("Zero"u8)) + field.Name == "Zero"u8) { return CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_INTRINSIC_ZERO; } - else if (owningType.IsString && field.Name.SequenceEqual("Empty"u8)) + else if (owningType.IsString && field.Name == "Empty"u8) { return CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_INTRINSIC_EMPTY_STRING; } - else if (owningType.Name.SequenceEqual("BitConverter"u8) && owningType.Namespace.SequenceEqual("System"u8) && - field.Name.SequenceEqual("IsLittleEndian"u8)) + else if (owningType.Name == "BitConverter"u8 && owningType.Namespace == "System"u8 && + field.Name == "IsLittleEndian"u8) { return CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_INTRINSIC_ISLITTLEENDIAN; } @@ -3536,10 +3538,10 @@ private static byte[] StringToUTF8(string s) return bytes; } - private static byte[] SpanToPinnableBytes(ReadOnlySpan s) + private static byte[] Utf8StringRefToPinnableBytes(Utf8StringRef s) { byte[] bytes = new byte[s.Length + 1]; - s.CopyTo(bytes); + s.AsSpan().CopyTo(bytes); return bytes; } diff --git a/src/coreclr/tools/Common/TypeSystem/Canon/CanonTypes.Metadata.cs b/src/coreclr/tools/Common/TypeSystem/Canon/CanonTypes.Metadata.cs index be5e7e49320116..814f88a112e08c 100644 --- a/src/coreclr/tools/Common/TypeSystem/Canon/CanonTypes.Metadata.cs +++ b/src/coreclr/tools/Common/TypeSystem/Canon/CanonTypes.Metadata.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using Internal.NativeFormat; +using Internal.Text; using Debug = System.Diagnostics.Debug; @@ -35,7 +36,7 @@ protected override MethodImplRecord[] ComputeVirtualMethodImplsForType() public override bool IsModuleType => false; - public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(ReadOnlySpan name) + public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8StringRef name) { return null; } @@ -45,7 +46,7 @@ public override ClassLayoutMetadata GetClassLayout() return default(ClassLayoutMetadata); } - public override MetadataType GetNestedType(ReadOnlySpan name) + public override MetadataType GetNestedType(Utf8StringRef name) { return null; } diff --git a/src/coreclr/tools/Common/TypeSystem/Canon/CanonTypes.cs b/src/coreclr/tools/Common/TypeSystem/Canon/CanonTypes.cs index c8b40489d24b99..d9c54a64bb0d96 100644 --- a/src/coreclr/tools/Common/TypeSystem/Canon/CanonTypes.cs +++ b/src/coreclr/tools/Common/TypeSystem/Canon/CanonTypes.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using Internal.NativeFormat; +using Internal.Text; using Debug = System.Diagnostics.Debug; @@ -65,7 +66,7 @@ internal sealed partial class CanonType : CanonBaseType { private int _hashcode; - public override ReadOnlySpan Namespace + public override Utf8StringRef Namespace { get { @@ -73,7 +74,7 @@ public override ReadOnlySpan Namespace } } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { @@ -149,7 +150,7 @@ internal sealed partial class UniversalCanonType : CanonBaseType { private int _hashcode; - public override ReadOnlySpan Namespace + public override Utf8StringRef Namespace { get { @@ -157,7 +158,7 @@ public override ReadOnlySpan Namespace } } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/Common/ArrayType.cs b/src/coreclr/tools/Common/TypeSystem/Common/ArrayType.cs index b861f3b1135af5..3541a3db81007a 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/ArrayType.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/ArrayType.cs @@ -5,6 +5,8 @@ using System.Collections.Generic; using System.Threading; +using Internal.Text; + namespace Internal.TypeSystem { /// @@ -299,7 +301,7 @@ public override MethodSignature Signature } } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/Common/CastingHelper.TypeEquivalence.cs b/src/coreclr/tools/Common/TypeSystem/Common/CastingHelper.TypeEquivalence.cs index bfc730f96f2b85..7d5df021462cb1 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/CastingHelper.TypeEquivalence.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/CastingHelper.TypeEquivalence.cs @@ -128,10 +128,10 @@ static bool IsEquivalentTo_TypeDefinition(MetadataType type1, MetadataType type2 if (!data1.Equals(data2)) return false; - if (!type1.Name.SequenceEqual(type2.Name)) + if (type1.Name != type2.Name) return false; - if (!type1.Namespace.SequenceEqual(type2.Namespace)) + if (type1.Namespace != type2.Namespace) return false; var containingType1 = (MetadataType)type1.ContainingType; diff --git a/src/coreclr/tools/Common/TypeSystem/Common/DefType.cs b/src/coreclr/tools/Common/TypeSystem/Common/DefType.cs index 71032d5409cab8..d17359d46f5d27 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/DefType.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/DefType.cs @@ -5,6 +5,8 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using Internal.Text; + namespace Internal.TypeSystem { /// @@ -16,22 +18,26 @@ public abstract partial class DefType : TypeDesc /// /// Gets the namespace of the type. /// - public virtual ReadOnlySpan Namespace => []; + public virtual Utf8StringRef Namespace => Array.Empty(); public string GetNamespace() => System.Text.Encoding.UTF8.GetString(Namespace #if NETSTANDARD .ToArray() +#else + .AsSpan() #endif ); /// /// Gets the name of the type as represented in the metadata. /// - public virtual ReadOnlySpan Name => []; + public virtual Utf8StringRef Name => Array.Empty(); public string GetName() => System.Text.Encoding.UTF8.GetString(Name #if NETSTANDARD .ToArray() +#else + .AsSpan() #endif ); diff --git a/src/coreclr/tools/Common/TypeSystem/Common/FieldDesc.cs b/src/coreclr/tools/Common/TypeSystem/Common/FieldDesc.cs index 4264363848e277..855d59c87561ad 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/FieldDesc.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/FieldDesc.cs @@ -3,7 +3,7 @@ using System; using System.Runtime.CompilerServices; - +using Internal.Text; using Debug = System.Diagnostics.Debug; #if TYPE_LOADER_IMPLEMENTATION @@ -31,18 +31,18 @@ public override bool Equals(object o) return ReferenceEquals(this, o); } - public virtual ReadOnlySpan Name + public virtual Utf8StringRef Name { get { - return []; + return Array.Empty(); } } public string GetName() { return System.Text.Encoding.UTF8.GetString( - Name + Name.AsSpan() #if NETSTANDARD .ToArray() #endif diff --git a/src/coreclr/tools/Common/TypeSystem/Common/FieldForInstantiatedType.cs b/src/coreclr/tools/Common/TypeSystem/Common/FieldForInstantiatedType.cs index b1345f1184b3a3..4deda1ec25312a 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/FieldForInstantiatedType.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/FieldForInstantiatedType.cs @@ -2,8 +2,10 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; -using Debug = System.Diagnostics.Debug; +using Internal.Text; + +using Debug = System.Diagnostics.Debug; #if TYPE_LOADER_IMPLEMENTATION using MetadataType = Internal.TypeSystem.DefType; #endif @@ -38,7 +40,7 @@ public override MetadataType OwningType } } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/Common/IAssemblyDesc.cs b/src/coreclr/tools/Common/TypeSystem/Common/IAssemblyDesc.cs index 4487411019e56f..902880de00f3cc 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/IAssemblyDesc.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/IAssemblyDesc.cs @@ -4,6 +4,8 @@ using System; using System.Reflection.Metadata; +using Internal.Text; + namespace Internal.TypeSystem { /// @@ -19,6 +21,6 @@ public interface IAssemblyDesc /// /// Gets the simple assembly name /// - ReadOnlySpan Name { get; } + Utf8StringRef Name { get; } } } diff --git a/src/coreclr/tools/Common/TypeSystem/Common/ImpliedRepeatedFieldDesc.cs b/src/coreclr/tools/Common/TypeSystem/Common/ImpliedRepeatedFieldDesc.cs index 411cef3264117d..3c2cdb349d8f6b 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/ImpliedRepeatedFieldDesc.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/ImpliedRepeatedFieldDesc.cs @@ -3,6 +3,8 @@ using System; +using Internal.Text; + namespace Internal.TypeSystem { public sealed partial class ImpliedRepeatedFieldDesc : FieldDesc @@ -42,6 +44,6 @@ public ImpliedRepeatedFieldDesc(MetadataType owningType, FieldDesc underlyingFie public override MarshalAsDescriptor GetMarshalAsDescriptor() => _underlyingFieldDesc.GetMarshalAsDescriptor(); - public override ReadOnlySpan Name => System.Text.Encoding.UTF8.GetBytes($"{_underlyingFieldDesc.GetName()}[{FieldIndex}]"); + public override Utf8StringRef Name => System.Text.Encoding.UTF8.GetBytes($"{_underlyingFieldDesc.GetName()}[{FieldIndex}]"); } } diff --git a/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedMethod.cs b/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedMethod.cs index 6024dcc6cc335d..6917d7ecd5ce5b 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedMethod.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedMethod.cs @@ -3,7 +3,9 @@ using System; using System.Diagnostics; + using Internal.NativeFormat; +using Internal.Text; namespace Internal.TypeSystem { @@ -166,7 +168,7 @@ public override MethodDesc GetTypicalMethodDefinition() return _methodDef.GetTypicalMethodDefinition(); } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedType.Metadata.cs b/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedType.Metadata.cs index 4f49f53e991a1c..7cb96019614280 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedType.Metadata.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedType.Metadata.cs @@ -5,6 +5,8 @@ using System.Collections.Generic; using System.Diagnostics; +using Internal.Text; + namespace Internal.TypeSystem { public sealed partial class InstantiatedType : MetadataType @@ -93,7 +95,7 @@ public override bool HasCustomAttribute(string attributeNamespace, string attrib return _typeDef.HasCustomAttribute(attributeNamespace, attributeName); } - public override MetadataType GetNestedType(ReadOnlySpan name) + public override MetadataType GetNestedType(Utf8StringRef name) { // Return the result from the typical type definition. return _typeDef.GetNestedType(name); diff --git a/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedType.MethodImpls.cs b/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedType.MethodImpls.cs index eddc665f515de5..b26f94d29ab896 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedType.MethodImpls.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedType.MethodImpls.cs @@ -3,6 +3,8 @@ using System; +using Internal.Text; + namespace Internal.TypeSystem { // Implementation of MethodImpl api surface implemented without metadata access. @@ -47,7 +49,7 @@ protected override MethodImplRecord[] ComputeVirtualMethodImplsForType() return InstantiateMethodImpls(uninstMethodImpls); } - public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(ReadOnlySpan name) + public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8StringRef name) { MethodImplRecord[] uninstMethodImpls = _typeDef.FindMethodsImplWithMatchingDeclName(name); return InstantiateMethodImpls(uninstMethodImpls); diff --git a/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedType.cs b/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedType.cs index 5e11675abcefb9..67fad00552af1e 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedType.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedType.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Diagnostics; +using Internal.Text; #if TYPE_LOADER_IMPLEMENTATION using MetadataType = Internal.TypeSystem.DefType; #endif @@ -127,7 +128,7 @@ protected override TypeFlags ComputeTypeFlags(TypeFlags mask) return flags; } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { @@ -135,7 +136,7 @@ public override ReadOnlySpan Name } } - public override ReadOnlySpan Namespace + public override Utf8StringRef Namespace { get { @@ -160,7 +161,7 @@ public override IEnumerable GetVirtualMethods() } // TODO: Substitutions, generics, modopts, ... - public override MethodDesc GetMethod(ReadOnlySpan name, MethodSignature signature, Instantiation substitution) + public override MethodDesc GetMethod(Utf8StringRef name, MethodSignature signature, Instantiation substitution) { MethodDesc typicalMethodDef = _typeDef.GetMethod(name, signature, substitution); if (typicalMethodDef == null) @@ -168,7 +169,7 @@ public override MethodDesc GetMethod(ReadOnlySpan name, MethodSignature si return _typeDef.Context.GetMethodForInstantiatedType(typicalMethodDef, this); } - public override MethodDesc GetMethodWithEquivalentSignature(ReadOnlySpan name, MethodSignature signature, Instantiation substitution) + public override MethodDesc GetMethodWithEquivalentSignature(Utf8StringRef name, MethodSignature signature, Instantiation substitution) { MethodDesc typicalMethodDef = _typeDef.GetMethodWithEquivalentSignature(name, signature, substitution); if (typicalMethodDef == null) @@ -230,7 +231,7 @@ public override IEnumerable GetFields() } // TODO: Substitutions, generics, modopts, ... - public override FieldDesc GetField(ReadOnlySpan name) + public override FieldDesc GetField(Utf8StringRef name) { FieldDesc fieldDef = _typeDef.GetField(name); if (fieldDef == null) diff --git a/src/coreclr/tools/Common/TypeSystem/Common/MetadataType.MethodImpls.cs b/src/coreclr/tools/Common/TypeSystem/Common/MetadataType.MethodImpls.cs index 466bb801f42c50..c363cdddf374a8 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/MetadataType.MethodImpls.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/MetadataType.MethodImpls.cs @@ -3,6 +3,8 @@ using System; +using Internal.Text; + namespace Internal.TypeSystem { public struct MethodImplRecord @@ -46,6 +48,6 @@ public MethodImplRecord[] VirtualMethodImplsForType /// /// /// - public abstract MethodImplRecord[] FindMethodsImplWithMatchingDeclName(ReadOnlySpan name); + public abstract MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8StringRef name); } } diff --git a/src/coreclr/tools/Common/TypeSystem/Common/MetadataType.cs b/src/coreclr/tools/Common/TypeSystem/Common/MetadataType.cs index 2e6d90b3d27c32..48586ad1bb8722 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/MetadataType.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/MetadataType.cs @@ -5,6 +5,8 @@ using System.Collections.Generic; using System.Diagnostics; +using Internal.Text; + namespace Internal.TypeSystem { /// @@ -13,9 +15,9 @@ namespace Internal.TypeSystem /// public abstract partial class MetadataType : DefType { - public abstract override ReadOnlySpan Name { get; } + public abstract override Utf8StringRef Name { get; } - public abstract override ReadOnlySpan Namespace { get; } + public abstract override Utf8StringRef Namespace { get; } /// /// Gets metadata that controls instance layout of this type. @@ -98,7 +100,7 @@ public virtual bool IsModuleType /// Get a specific type nested in this type. Returns null if the type /// doesn't exist. /// - public abstract MetadataType GetNestedType(ReadOnlySpan name); + public abstract MetadataType GetNestedType(Utf8StringRef name); /// /// Gets a value indicating whether this is an inline array type diff --git a/src/coreclr/tools/Common/TypeSystem/Common/MetadataTypeSystemContext.cs b/src/coreclr/tools/Common/TypeSystem/Common/MetadataTypeSystemContext.cs index bc6cff8b7a4f6c..83f66d562279b0 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/MetadataTypeSystemContext.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/MetadataTypeSystemContext.cs @@ -106,8 +106,8 @@ protected internal sealed override bool IsIDynamicInterfaceCastableInterface(Def { MetadataType t = (MetadataType)type; return t.Module == SystemModule - && t.Name.SequenceEqual("IDynamicInterfaceCastable"u8) - && t.Namespace.SequenceEqual("System.Runtime.InteropServices"u8); + && t.Name == "IDynamicInterfaceCastable"u8 + && t.Namespace == "System.Runtime.InteropServices"u8; } } } diff --git a/src/coreclr/tools/Common/TypeSystem/Common/MetadataVirtualMethodAlgorithm.cs b/src/coreclr/tools/Common/TypeSystem/Common/MetadataVirtualMethodAlgorithm.cs index 3034fd2fd69be5..8fedea03c70939 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/MetadataVirtualMethodAlgorithm.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/MetadataVirtualMethodAlgorithm.cs @@ -5,6 +5,8 @@ using System.Collections.Generic; using System.Diagnostics; +using Internal.Text; + namespace Internal.TypeSystem { public class MetadataVirtualMethodAlgorithm : VirtualMethodAlgorithm @@ -377,14 +379,14 @@ private static bool IsInterfaceExplicitlyImplementedOnType(MetadataType type, Me /// private static MethodDesc FindMatchingVirtualMethodOnTypeByNameAndSig(MethodDesc targetMethod, DefType currentType, bool reverseMethodSearch, Func nameSigMatchMethodIsValidCandidate) { - ReadOnlySpan name = targetMethod.Name; + Utf8StringRef name = targetMethod.Name; MethodSignature sig = targetMethod.Signature; MethodDesc implMethod = null; MethodDesc implMethodEquivalent = null; foreach (MethodDesc candidate in currentType.GetAllVirtualMethods()) { - if (candidate.Name.SequenceEqual(name)) + if (candidate.Name == name) { if (candidate.Signature.EquivalentTo(sig)) { diff --git a/src/coreclr/tools/Common/TypeSystem/Common/MethodDelegator.cs b/src/coreclr/tools/Common/TypeSystem/Common/MethodDelegator.cs index 55dba7ed9cead9..86fbab74d81f68 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/MethodDelegator.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/MethodDelegator.cs @@ -3,6 +3,8 @@ using System; +using Internal.Text; + namespace Internal.TypeSystem { /// @@ -28,7 +30,7 @@ public MethodDelegator(MethodDesc wrappedMethod) public override bool IsDefaultConstructor => _wrappedMethod.IsDefaultConstructor; public override bool IsStaticConstructor => _wrappedMethod.IsStaticConstructor; - public override ReadOnlySpan Name => _wrappedMethod.Name; + public override Utf8StringRef Name => _wrappedMethod.Name; public override bool IsVirtual => _wrappedMethod.IsVirtual; diff --git a/src/coreclr/tools/Common/TypeSystem/Common/MethodDesc.cs b/src/coreclr/tools/Common/TypeSystem/Common/MethodDesc.cs index 96d4c0b163507e..528005c7ec51cb 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/MethodDesc.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/MethodDesc.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using System.Runtime.CompilerServices; using Internal.NativeFormat; +using Internal.Text; namespace Internal.TypeSystem { @@ -557,7 +558,7 @@ public bool IsConstructor { // TODO: Precise check // TODO: Cache? - return this.Name.SequenceEqual(".ctor"u8); + return this.Name == ".ctor"u8; } } @@ -587,11 +588,11 @@ public virtual bool IsStaticConstructor /// /// Gets the name of the method as specified in the metadata. /// - public virtual ReadOnlySpan Name + public virtual Utf8StringRef Name { get { - return []; + return Array.Empty(); } } @@ -600,6 +601,8 @@ public string GetName() return System.Text.Encoding.UTF8.GetString(Name #if NETSTANDARD .ToArray() +#else + .AsSpan() #endif ); } @@ -727,7 +730,7 @@ public bool IsFinalizer get { TypeDesc owningType = OwningType; - return (owningType.IsObject && Name.SequenceEqual("Finalize"u8)) || (owningType.HasFinalizer && owningType.GetFinalizer() == this); + return (owningType.IsObject && Name == "Finalize"u8) || (owningType.HasFinalizer && owningType.GetFinalizer() == this); } } diff --git a/src/coreclr/tools/Common/TypeSystem/Common/MethodForInstantiatedType.cs b/src/coreclr/tools/Common/TypeSystem/Common/MethodForInstantiatedType.cs index b5c7195b483e14..f438a63312d53a 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/MethodForInstantiatedType.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/MethodForInstantiatedType.cs @@ -3,6 +3,8 @@ using System; +using Internal.Text; + using Debug = System.Diagnostics.Debug; namespace Internal.TypeSystem @@ -153,7 +155,7 @@ public override bool IsStaticConstructor } } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/Common/ModuleDesc.cs b/src/coreclr/tools/Common/TypeSystem/Common/ModuleDesc.cs index 200c26c0bb034d..621d66989ddbfa 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/ModuleDesc.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/ModuleDesc.cs @@ -4,6 +4,8 @@ using System; using System.Collections.Generic; +using Internal.Text; + #if TYPE_LOADER_IMPLEMENTATION using MetadataType = Internal.TypeSystem.DefType; #endif @@ -34,7 +36,7 @@ public ModuleDesc(TypeSystemContext context, IAssemblyDesc assembly) /// /// Gets a type in this module or null. /// - public MetadataType GetType(ReadOnlySpan nameSpace, ReadOnlySpan name, bool throwIfNotFound = true) + public MetadataType GetType(Utf8StringRef nameSpace, Utf8StringRef name, bool throwIfNotFound = true) { return (MetadataType)GetType(nameSpace, name, throwIfNotFound ? NotFoundBehavior.Throw : NotFoundBehavior.ReturnNull); } @@ -42,7 +44,7 @@ public MetadataType GetType(ReadOnlySpan nameSpace, ReadOnlySpan nam /// /// Gets a type in this module with the specified name, a resolution failure object, or null. /// - public abstract object GetType(ReadOnlySpan nameSpace, ReadOnlySpan name, NotFoundBehavior notFoundBehavior); + public abstract object GetType(Utf8StringRef nameSpace, Utf8StringRef name, NotFoundBehavior notFoundBehavior); /// /// Gets the global <Module> type. diff --git a/src/coreclr/tools/Common/TypeSystem/Common/TypeDesc.cs b/src/coreclr/tools/Common/TypeSystem/Common/TypeDesc.cs index c77106cac6ecb5..c370bc52ecee9b 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/TypeDesc.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/TypeDesc.cs @@ -6,6 +6,8 @@ using System.Diagnostics; using System.Runtime.CompilerServices; +using Internal.Text; + namespace Internal.TypeSystem { /// @@ -520,7 +522,7 @@ public virtual IEnumerable GetVirtualMethods() /// If signature is not specified and there are multiple matches, the first one /// is returned. Returns null if method not found. /// - public MethodDesc GetMethod(ReadOnlySpan name, MethodSignature signature) + public MethodDesc GetMethod(Utf8StringRef name, MethodSignature signature) { return GetMethod(name, signature, default(Instantiation)); } @@ -532,11 +534,11 @@ public MethodDesc GetMethod(ReadOnlySpan name, MethodSignature signature) /// is returned. If substitution is not null, then substitution will be applied to /// possible target methods before signature comparison. Returns null if method not found. /// - public virtual MethodDesc GetMethod(ReadOnlySpan name, MethodSignature signature, Instantiation substitution) + public virtual MethodDesc GetMethod(Utf8StringRef name, MethodSignature signature, Instantiation substitution) { foreach (var method in GetMethods()) { - if (method.Name.SequenceEqual(name)) + if (method.Name == name) { if (signature == null || signature.Equals(method.Signature.ApplySubstitution(substitution))) return method; @@ -545,11 +547,11 @@ public virtual MethodDesc GetMethod(ReadOnlySpan name, MethodSignature sig return null; } - public virtual MethodDesc GetMethodWithEquivalentSignature(ReadOnlySpan name, MethodSignature signature, Instantiation substitution) + public virtual MethodDesc GetMethodWithEquivalentSignature(Utf8StringRef name, MethodSignature signature, Instantiation substitution) { foreach (var method in GetMethods()) { - if (method.Name.SequenceEqual(name)) + if (method.Name == name) { if (signature == null || signature.EquivalentTo(method.Signature.ApplySubstitution(substitution))) return method; @@ -589,11 +591,11 @@ public virtual IEnumerable GetFields() /// // TODO: Substitutions, generics, modopts, ... // TODO: field signature - public virtual FieldDesc GetField(ReadOnlySpan name) + public virtual FieldDesc GetField(Utf8StringRef name) { foreach (var field in GetFields()) { - if (field.Name.SequenceEqual(name)) + if (field.Name == name) return field; } return null; diff --git a/src/coreclr/tools/Common/TypeSystem/Common/TypeSystemHelpers.cs b/src/coreclr/tools/Common/TypeSystem/Common/TypeSystemHelpers.cs index 931983a7245ae5..ef0ab602e10cc6 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/TypeSystemHelpers.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/TypeSystemHelpers.cs @@ -5,6 +5,8 @@ using System.Collections.Generic; using System.Diagnostics; +using Internal.Text; + namespace Internal.TypeSystem { public static class TypeSystemHelpers @@ -431,12 +433,22 @@ public static bool RequiresAlign8(this TypeDesc type) return false; } - public static ReadOnlySpan Append(this ReadOnlySpan s1, ReadOnlySpan s2) + public static ReadOnlySpan Append(this Utf8StringRef s1, Utf8StringRef s2) { - Span buffer = new T[s1.Length + s2.Length]; + Span buffer = new byte[s1.Length + s2.Length]; + + s1.AsSpan().CopyTo(buffer); + s2.AsSpan().CopyTo(buffer.Slice(s1.Length)); + + return buffer; + } + + public static ReadOnlySpan Append(this ReadOnlySpan s1, Utf8StringRef s2) + { + Span buffer = new byte[s1.Length + s2.Length]; s1.CopyTo(buffer); - s2.CopyTo(buffer.Slice(s1.Length)); + s2.AsSpan().CopyTo(buffer.Slice(s1.Length)); return buffer; } @@ -452,16 +464,30 @@ public static ReadOnlySpan Append(this ReadOnlySpan s1, ReadOnlySpan return buffer; } - public static ReadOnlySpan Append(this ReadOnlySpan s1, ReadOnlySpan s2, ReadOnlySpan s3, uint i) + public static ReadOnlySpan Append(this Utf8StringRef s1, Utf8StringRef s2, Utf8StringRef s3) + { + ReadOnlySpan s1Span = s1.AsSpan(); + ReadOnlySpan s2Span = s2.AsSpan(); + ReadOnlySpan s3Span = s3.AsSpan(); + Span buffer = new byte[s1Span.Length + s2Span.Length + s3Span.Length]; + + s1Span.CopyTo(buffer); + s2Span.CopyTo(buffer.Slice(s1Span.Length)); + s3Span.CopyTo(buffer.Slice(s1Span.Length + s2Span.Length)); + + return buffer; + } + + public static ReadOnlySpan Append(this Utf8StringRef s1, Utf8StringRef s2, Utf8StringRef s3, uint i) { Span s4 = stackalloc byte[16]; System.Buffers.Text.Utf8Formatter.TryFormat(i, s4, out int s4length); Span buffer = new byte[s1.Length + s2.Length + s3.Length + s4length]; - s1.CopyTo(buffer); - s2.CopyTo(buffer.Slice(s1.Length)); - s3.CopyTo(buffer.Slice(s1.Length + s2.Length)); + s1.AsSpan().CopyTo(buffer); + s2.AsSpan().CopyTo(buffer.Slice(s1.Length)); + s3.AsSpan().CopyTo(buffer.Slice(s1.Length + s2.Length)); s4.Slice(0, s4length).CopyTo(buffer.Slice(s1.Length + s2.Length + s3.Length)); return buffer; diff --git a/src/coreclr/tools/Common/TypeSystem/Common/TypeWithRepeatedFields.cs b/src/coreclr/tools/Common/TypeSystem/Common/TypeWithRepeatedFields.cs index cf9508b97ec154..fc42772760805c 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/TypeWithRepeatedFields.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/TypeWithRepeatedFields.cs @@ -6,6 +6,8 @@ using System.Diagnostics; using System.Threading; +using Internal.Text; + namespace Internal.TypeSystem { /// @@ -84,16 +86,16 @@ public override IEnumerable GetFields() public override ClassLayoutMetadata GetClassLayout() => MetadataType.GetClassLayout(); public override bool HasCustomAttribute(string attributeNamespace, string attributeName) => MetadataType.HasCustomAttribute(attributeNamespace, attributeName); public override IEnumerable GetNestedTypes() => (IEnumerable)EmptyTypes; - public override MetadataType GetNestedType(ReadOnlySpan name) => null; - public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(ReadOnlySpan name) => MetadataType.FindMethodsImplWithMatchingDeclName(name); + public override MetadataType GetNestedType(Utf8StringRef name) => null; + public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8StringRef name) => MetadataType.FindMethodsImplWithMatchingDeclName(name); public override int GetHashCode() => MetadataType.GetHashCode(); protected override MethodImplRecord[] ComputeVirtualMethodImplsForType() => Array.Empty(); protected override TypeFlags ComputeTypeFlags(TypeFlags mask) => MetadataType.GetTypeFlags(mask); - public override ReadOnlySpan Namespace => MetadataType.Namespace; + public override Utf8StringRef Namespace => MetadataType.Namespace; - public override ReadOnlySpan Name => MetadataType.Name; + public override Utf8StringRef Name => MetadataType.Name; public override DefType[] ExplicitlyImplementedInterfaces => Array.Empty(); diff --git a/src/coreclr/tools/Common/TypeSystem/Common/VersionResilientHashCode.TypeSystem.cs b/src/coreclr/tools/Common/TypeSystem/Common/VersionResilientHashCode.TypeSystem.cs index 259e3ee9b765d5..c8864f5222df4d 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/VersionResilientHashCode.TypeSystem.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/VersionResilientHashCode.TypeSystem.cs @@ -5,12 +5,20 @@ using System.Diagnostics; using System.Numerics; using System.Text; + using Internal.TypeSystem; +using Internal.Text; namespace Internal { internal static partial class VersionResilientHashCode { + public static int NameHashCode(Utf8StringRef src) + => NameHashCode(src.AsSpan()); + + public static int NameHashCode(Utf8StringRef namespacePart, Utf8StringRef namePart) + => NameHashCode(namespacePart.AsSpan(), namePart.AsSpan()); + /// /// CoreCLR ComputeGenericInstanceHashCode /// diff --git a/src/coreclr/tools/Common/TypeSystem/Ecma/CustomAttributeTypeProvider.cs b/src/coreclr/tools/Common/TypeSystem/Ecma/CustomAttributeTypeProvider.cs index 45a7a6944484be..952fe6db8af25f 100644 --- a/src/coreclr/tools/Common/TypeSystem/Ecma/CustomAttributeTypeProvider.cs +++ b/src/coreclr/tools/Common/TypeSystem/Ecma/CustomAttributeTypeProvider.cs @@ -88,9 +88,9 @@ public bool IsSystemType(TypeDesc type) { var metadataType = type as MetadataType; return metadataType != null - && metadataType.Name.SequenceEqual("Type"u8) + && metadataType.Name == "Type"u8 && metadataType.Module == _module.Context.SystemModule - && metadataType.Namespace.SequenceEqual("System"u8); + && metadataType.Namespace == "System"u8; } } } diff --git a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaAssembly.cs b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaAssembly.cs index c85861b5916818..b65549e44264d5 100644 --- a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaAssembly.cs +++ b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaAssembly.cs @@ -6,6 +6,8 @@ using System.Reflection.Metadata; using System.Reflection.PortableExecutable; +using Internal.Text; + namespace Internal.TypeSystem.Ecma { public sealed partial class EcmaAssembly : EcmaModule, IAssemblyDesc @@ -62,7 +64,7 @@ public AssemblyNameInfo GetName() return _assemblyName; } - public ReadOnlySpan Name + public Utf8StringRef Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaField.cs b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaField.cs index 470ac48552ffae..cce87727a5b8ba 100644 --- a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaField.cs +++ b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaField.cs @@ -9,6 +9,8 @@ using System.Runtime.CompilerServices; using System.Threading; +using Internal.Text; + namespace Internal.TypeSystem.Ecma { public sealed partial class EcmaField : FieldDesc, EcmaModule.IEntityHandleObject @@ -267,7 +269,7 @@ public unsafe ReadOnlySpan InitializeName() return new ReadOnlySpan(_namePointer, _nameLength); } - public override unsafe ReadOnlySpan Name + public override unsafe Utf8StringRef Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaMethod.cs b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaMethod.cs index a4b02943f9e746..7cc73a4485b8cf 100644 --- a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaMethod.cs +++ b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaMethod.cs @@ -9,6 +9,8 @@ using System.Runtime.CompilerServices; using System.Threading; +using Internal.Text; + namespace Internal.TypeSystem.Ecma { public sealed partial class EcmaMethod : MethodDesc, EcmaModule.IEntityHandleObject @@ -352,7 +354,7 @@ public override bool IsDefaultConstructor return attributes.IsRuntimeSpecialName() && attributes.IsPublic() && Signature.Length == 0 - && Name.SequenceEqual(".ctor"u8) + && Name == ".ctor"u8 && !_type.IsAbstract; } } @@ -369,7 +371,7 @@ public override bool IsStaticConstructor { get { - return Attributes.IsRuntimeSpecialName() && Name.SequenceEqual(".cctor"u8); + return Attributes.IsRuntimeSpecialName() && Name == ".cctor"u8; } } @@ -405,7 +407,7 @@ public unsafe ReadOnlySpan InitializeName() return new ReadOnlySpan(_namePointer, _nameLength); } - public override unsafe ReadOnlySpan Name + public override unsafe Utf8StringRef Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaModule.cs b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaModule.cs index 312d33f2fd5eb3..5c318f0ac6758f 100644 --- a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaModule.cs +++ b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaModule.cs @@ -9,6 +9,8 @@ using System.Reflection.PortableExecutable; using System.Text; +using Internal.Text; + using Debug = System.Diagnostics.Debug; namespace Internal.TypeSystem.Ecma @@ -315,7 +317,7 @@ private TypeDefinitionHandle[] InitializeTypeDefinitionBucketHeads() return bucketHeads; } - private TypeDefinitionHandle FindDefinedType(int hashCode, ReadOnlySpan nameSpace, ReadOnlySpan name) + private TypeDefinitionHandle FindDefinedType(int hashCode, Utf8StringRef nameSpace, Utf8StringRef name) { MetadataReader reader = _metadataReader; @@ -366,7 +368,7 @@ private ExportedTypeHandle[] InitializeExportedTypeBucketHeads() return bucketHeads; } - private ExportedTypeHandle FindExportedType(int hashCode, ReadOnlySpan nameSpace, ReadOnlySpan name) + private ExportedTypeHandle FindExportedType(int hashCode, Utf8StringRef nameSpace, Utf8StringRef name) { MetadataReader reader = _metadataReader; @@ -387,7 +389,7 @@ private ExportedTypeHandle FindExportedType(int hashCode, ReadOnlySpan nam return default; } - public sealed override object GetType(ReadOnlySpan nameSpace, ReadOnlySpan name, NotFoundBehavior notFoundBehavior) + public sealed override object GetType(Utf8StringRef nameSpace, Utf8StringRef name, NotFoundBehavior notFoundBehavior) { int hashCode = VersionResilientHashCode.NameHashCode(nameSpace, name); diff --git a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.MethodImpls.cs b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.MethodImpls.cs index 9d29e54464846d..4ff0f73f744f77 100644 --- a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.MethodImpls.cs +++ b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.MethodImpls.cs @@ -4,6 +4,9 @@ using System; using System.Collections.Generic; using System.Reflection.Metadata; + +using Internal.Text; + using Debug = System.Diagnostics.Debug; namespace Internal.TypeSystem.Ecma @@ -13,7 +16,7 @@ namespace Internal.TypeSystem.Ecma public sealed partial class EcmaType : MetadataType { // Virtual function related functionality - public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(ReadOnlySpan declName) + public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8StringRef declName) { MetadataReader metadataReader = _module.MetadataReader; ArrayBuilder foundRecords = default(ArrayBuilder); diff --git a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.cs b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.cs index b4491af580779b..3776de961c4bef 100644 --- a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.cs +++ b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.cs @@ -10,6 +10,7 @@ using System.Threading; using Internal.NativeFormat; +using Internal.Text; namespace Internal.TypeSystem.Ecma { @@ -246,7 +247,7 @@ protected override TypeFlags ComputeTypeFlags(TypeFlags mask) return flags; } - private unsafe ReadOnlySpan InitializeName() + private unsafe Utf8StringRef InitializeName() { StringHandle handle = _typeDefinition.Name; _nameLength = MetadataReader.GetStringBytes(handle).Length; @@ -254,7 +255,7 @@ private unsafe ReadOnlySpan InitializeName() return new ReadOnlySpan(_namePointer, _nameLength); } - public override unsafe ReadOnlySpan Name + public override unsafe Utf8StringRef Name { get { @@ -267,7 +268,7 @@ public override unsafe ReadOnlySpan Name } } - private unsafe ReadOnlySpan InitializeNamespace() + private unsafe Utf8StringRef InitializeNamespace() { StringHandle handle = _typeDefinition.Namespace; _namespaceLength = MetadataReader.GetStringBytes(handle).Length; @@ -275,7 +276,7 @@ private unsafe ReadOnlySpan InitializeNamespace() return new ReadOnlySpan(_namespacePointer, _namespaceLength); } - public override unsafe ReadOnlySpan Namespace + public override unsafe Utf8StringRef Namespace { get { @@ -313,12 +314,12 @@ public override IEnumerable GetVirtualMethods() /// If signature is not specified and there are multiple matches, the first one /// is returned. Returns null if method not found. /// - public new EcmaMethod GetMethod(ReadOnlySpan name, MethodSignature signature) + public new EcmaMethod GetMethod(Utf8StringRef name, MethodSignature signature) { return GetMethod(name, signature, default(Instantiation)); } - public override EcmaMethod GetMethod(ReadOnlySpan name, MethodSignature signature, Instantiation substitution) + public override EcmaMethod GetMethod(Utf8StringRef name, MethodSignature signature, Instantiation substitution) { var metadataReader = this.MetadataReader; @@ -335,7 +336,7 @@ public override EcmaMethod GetMethod(ReadOnlySpan name, MethodSignature si return null; } - public override EcmaMethod GetMethodWithEquivalentSignature(ReadOnlySpan name, MethodSignature signature, Instantiation substitution) + public override EcmaMethod GetMethodWithEquivalentSignature(Utf8StringRef name, MethodSignature signature, Instantiation substitution) { var metadataReader = this.MetadataReader; @@ -461,7 +462,7 @@ public override TypeDesc UnderlyingType } } - public override EcmaField GetField(ReadOnlySpan name) + public override EcmaField GetField(Utf8StringRef name) { var metadataReader = this.MetadataReader; @@ -485,7 +486,7 @@ public override IEnumerable GetNestedTypes() } } - public override EcmaType GetNestedType(ReadOnlySpan name) + public override EcmaType GetNestedType(Utf8StringRef name) { var metadataReader = this.MetadataReader; @@ -501,7 +502,7 @@ public override EcmaType GetNestedType(ReadOnlySpan name) { ReadOnlySpan typeName = metadataReader.GetStringBytes(type.Name); typeName = metadataReader.GetStringBytes(type.Namespace).Append("."u8, typeName); - nameMatched = typeName.SequenceEqual(name); + nameMatched = typeName.SequenceEqual(name.AsSpan()); } if (nameMatched) diff --git a/src/coreclr/tools/Common/TypeSystem/Ecma/MetadataExtensions.cs b/src/coreclr/tools/Common/TypeSystem/Ecma/MetadataExtensions.cs index 1db988cd2aaa66..e8a50d264492a1 100644 --- a/src/coreclr/tools/Common/TypeSystem/Ecma/MetadataExtensions.cs +++ b/src/coreclr/tools/Common/TypeSystem/Ecma/MetadataExtensions.cs @@ -7,6 +7,7 @@ using System.Reflection.Metadata; using System.Reflection.Metadata.Ecma335; using System.Runtime.InteropServices; +using Internal.Text; namespace Internal.TypeSystem.Ecma { @@ -319,7 +320,7 @@ public static unsafe ReadOnlySpan GetStringBytes(this MetadataReader reade return new ReadOnlySpan(blobReader.CurrentPointer, blobReader.Length); } - public static unsafe bool StringEquals(this MetadataReader reader, StringHandle handle, ReadOnlySpan otherString) + public static unsafe bool StringEquals(this MetadataReader reader, StringHandle handle, Utf8StringRef otherString) { int stringOffset = reader.GetHeapOffset(handle); @@ -333,9 +334,10 @@ public static unsafe bool StringEquals(this MetadataReader reader, StringHandle return false; // Compare characters + ReadOnlySpan otherSpan = otherString.AsSpan(); for (int i = 0; i < otherString.Length; i++) { - if (otherString[i] != *(currentChar++)) + if (otherSpan[i] != *(currentChar++)) return false; } diff --git a/src/coreclr/tools/Common/TypeSystem/IL/NativeAotILProvider.cs b/src/coreclr/tools/Common/TypeSystem/IL/NativeAotILProvider.cs index 84b4daec9d8c99..0a26773578045f 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/NativeAotILProvider.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/NativeAotILProvider.cs @@ -51,33 +51,33 @@ private static MethodIL TryGetIntrinsicMethodIL(MethodDesc method) if (owningType == null) return null; - if (owningType.Name.SequenceEqual("Unsafe"u8)) + if (owningType.Name == "Unsafe"u8) { - if (owningType.Namespace.SequenceEqual("System.Runtime.CompilerServices"u8)) + if (owningType.Namespace == "System.Runtime.CompilerServices"u8) return UnsafeIntrinsics.EmitIL(method); } - else if (owningType.Name.SequenceEqual("Debug"u8)) + else if (owningType.Name == "Debug"u8) { - if (owningType.Namespace.SequenceEqual("System.Diagnostics"u8) && method.Name.SequenceEqual("DebugBreak"u8)) + if (owningType.Namespace == "System.Diagnostics"u8 && method.Name == "DebugBreak"u8) return new ILStubMethodIL(method, new byte[] { (byte)ILOpcode.break_, (byte)ILOpcode.ret }, Array.Empty(), null); } - else if (owningType.Name.SequenceEqual("RuntimeAugments"u8)) + else if (owningType.Name == "RuntimeAugments"u8) { - if (owningType.Namespace.SequenceEqual("Internal.Runtime.Augments"u8) && method.Name.SequenceEqual("GetCanonType"u8)) + if (owningType.Namespace == "Internal.Runtime.Augments"u8 && method.Name == "GetCanonType"u8) return GetCanonTypeIntrinsic.EmitIL(method); } - else if (owningType.Name.SequenceEqual("MethodTable"u8)) + else if (owningType.Name == "MethodTable"u8) { - if (owningType.Namespace.SequenceEqual("Internal.Runtime"u8) && method.Name.SequenceEqual("get_SupportsRelativePointers"u8)) + if (owningType.Namespace == "Internal.Runtime"u8 && method.Name == "get_SupportsRelativePointers"u8) { ILOpcode value = method.Context.Target.SupportsRelativePointers ? ILOpcode.ldc_i4_1 : ILOpcode.ldc_i4_0; return new ILStubMethodIL(method, new byte[] { (byte)value, (byte)ILOpcode.ret }, Array.Empty(), null); } } - else if (owningType.Name.SequenceEqual("Stream"u8)) + else if (owningType.Name == "Stream"u8) { - if (owningType.Namespace.SequenceEqual("System.IO"u8)) + if (owningType.Namespace == "System.IO"u8) return StreamIntrinsics.EmitIL(method); } @@ -97,15 +97,15 @@ private static MethodIL TryGetPerInstantiationIntrinsicMethodIL(MethodDesc metho if (owningType == null) return null; - if (owningType.Name.SequenceEqual("Interlocked"u8)) + if (owningType.Name == "Interlocked"u8) { - if (owningType.Namespace.SequenceEqual("System.Threading"u8)) + if (owningType.Namespace == "System.Threading"u8) return InterlockedIntrinsics.EmitIL(method); } - else if (owningType.Name.SequenceEqual("Activator"u8)) + else if (owningType.Name == "Activator"u8) { TypeSystemContext context = owningType.Context; - if (method.Name.SequenceEqual("CreateInstance"u8) && method.Signature.Length == 0 && method.HasInstantiation + if (method.Name == "CreateInstance"u8 && method.Signature.Length == 0 && method.HasInstantiation && method.Instantiation[0] is TypeDesc activatedType && activatedType != context.UniversalCanonType && activatedType.IsValueType @@ -123,27 +123,27 @@ private static MethodIL TryGetPerInstantiationIntrinsicMethodIL(MethodDesc metho return new InstantiatedMethodIL(method, emit.Link(method.GetMethodDefinition())); } } - else if (owningType.Name.SequenceEqual("RuntimeHelpers"u8)) + else if (owningType.Name == "RuntimeHelpers"u8) { - if (owningType.Namespace.SequenceEqual("System.Runtime.CompilerServices"u8)) + if (owningType.Namespace == "System.Runtime.CompilerServices"u8) return RuntimeHelpersIntrinsics.EmitIL(method); } - else if (owningType.Name.SequenceEqual("Comparer`1"u8)) + else if (owningType.Name == "Comparer`1"u8) { - if (method.Name.SequenceEqual("Create"u8) && owningType.Namespace.SequenceEqual("System.Collections.Generic"u8)) + if (method.Name == "Create"u8 && owningType.Namespace == "System.Collections.Generic"u8) return ComparerIntrinsics.EmitComparerCreate(method); } - else if (owningType.Name.SequenceEqual("EqualityComparer`1"u8)) + else if (owningType.Name == "EqualityComparer`1"u8) { - if (method.Name.SequenceEqual("Create"u8) && owningType.Namespace.SequenceEqual("System.Collections.Generic"u8)) + if (method.Name == "Create"u8 && owningType.Namespace == "System.Collections.Generic"u8) return ComparerIntrinsics.EmitEqualityComparerCreate(method); } - else if (owningType.Name.SequenceEqual("ComparerHelpers"u8)) + else if (owningType.Name == "ComparerHelpers"u8) { - if (!owningType.Namespace.SequenceEqual("Internal.IntrinsicSupport"u8)) + if (owningType.Namespace != "Internal.IntrinsicSupport"u8) return null; - if (method.Name.SequenceEqual("EnumOnlyCompare"u8)) + if (method.Name == "EnumOnlyCompare"u8) { //calls CompareTo for underlyingType to avoid boxing @@ -171,12 +171,12 @@ private static MethodIL TryGetPerInstantiationIntrinsicMethodIL(MethodDesc metho return emitter.Link(method); } } - else if (owningType.Name.SequenceEqual("EqualityComparerHelpers"u8)) + else if (owningType.Name == "EqualityComparerHelpers"u8) { - if (!owningType.Namespace.SequenceEqual("Internal.IntrinsicSupport"u8)) + if (owningType.Namespace != "Internal.IntrinsicSupport"u8) return null; - if (method.Name.SequenceEqual("EnumOnlyEquals"u8)) + if (method.Name == "EnumOnlyEquals"u8) { // EnumOnlyEquals would basically like to do this: // static bool EnumOnlyEquals(T x, T y) where T: struct => x == y; @@ -211,7 +211,7 @@ private static MethodIL TryGetPerInstantiationIntrinsicMethodIL(MethodDesc metho }, Array.Empty(), null); } - else if (method.Name.SequenceEqual("GetComparerForReferenceTypesOnly"u8)) + else if (method.Name == "GetComparerForReferenceTypesOnly"u8) { TypeDesc elementType = method.Instantiation[0]; if (!elementType.IsRuntimeDeterminedSubtype @@ -225,7 +225,7 @@ private static MethodIL TryGetPerInstantiationIntrinsicMethodIL(MethodDesc metho Array.Empty(), null); } } - else if (method.Name.SequenceEqual("StructOnlyEquals"u8)) + else if (method.Name == "StructOnlyEquals"u8) { TypeDesc elementType = method.Instantiation[0]; if (!elementType.IsRuntimeDeterminedSubtype diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/AssemblyGetExecutingAssemblyMethodThunk.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/AssemblyGetExecutingAssemblyMethodThunk.cs index e9542585b9ef90..facdaf3b8e37f6 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/AssemblyGetExecutingAssemblyMethodThunk.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/AssemblyGetExecutingAssemblyMethodThunk.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; + +using Internal.Text; using Internal.TypeSystem; namespace Internal.IL.Stubs @@ -37,7 +39,7 @@ public IAssemblyDesc ExecutingAssembly get; } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/AsyncResumptionStub.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/AsyncResumptionStub.cs index dbff48e25c7f44..64f1cee10a10b2 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/AsyncResumptionStub.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/AsyncResumptionStub.cs @@ -2,8 +2,10 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; + using Internal.IL; using Internal.IL.Stubs; +using Internal.Text; using Internal.TypeSystem; using Debug = System.Diagnostics.Debug; @@ -24,7 +26,7 @@ public AsyncResumptionStub(MethodDesc targetMethod, TypeDesc owningType) _owningType = owningType; } - public override ReadOnlySpan Name => _targetMethod.Name; + public override Utf8StringRef Name => _targetMethod.Name; public override string DiagnosticName => "RESUME_" + _targetMethod.DiagnosticName; public override TypeDesc OwningType => _owningType; diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/CalliMarshallingMethodThunk.Mangling.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/CalliMarshallingMethodThunk.Mangling.cs index 0c629ae69247e9..637019ea90de56 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/CalliMarshallingMethodThunk.Mangling.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/CalliMarshallingMethodThunk.Mangling.cs @@ -3,7 +3,7 @@ using System; using System.Diagnostics; - +using Internal.Text; using Internal.TypeSystem; namespace Internal.IL.Stubs @@ -22,7 +22,7 @@ ReadOnlySpan IPrefixMangledSignature.Prefix { get { - ReadOnlySpan prefix = RuntimeMarshallingEnabled ? "CalliWithRuntimeMarshalling"u8 : "Calli"u8; + Utf8StringRef prefix = RuntimeMarshallingEnabled ? "CalliWithRuntimeMarshalling"u8 : "Calli"u8; // The target signature is expected to be normalized as MethodSignatureFlags.UnmanagedCallingConvention Debug.Assert((_targetSignature.Flags & MethodSignatureFlags.UnmanagedCallingConventionMask) == MethodSignatureFlags.UnmanagedCallingConvention); @@ -31,7 +31,7 @@ ReadOnlySpan IPrefixMangledSignature.Prefix if (_targetSignature.HasEmbeddedSignatureData) prefix = prefix.Append(System.Text.Encoding.ASCII.GetBytes(_targetSignature.GetStandaloneMethodSignatureCallingConventions().ToString("x"))); - return prefix; + return prefix.AsSpan(); } } } diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/CalliMarshallingMethodThunk.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/CalliMarshallingMethodThunk.cs index 25cfcb4a96b02d..6c6106f7c4ef90 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/CalliMarshallingMethodThunk.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/CalliMarshallingMethodThunk.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; + +using Internal.Text; using Internal.TypeSystem; namespace Internal.IL.Stubs @@ -70,7 +72,7 @@ public override MethodSignature Signature } } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateMarshallingMethodThunk.Mangling.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateMarshallingMethodThunk.Mangling.cs index f98f90c21df37d..b40f9ceba4558e 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateMarshallingMethodThunk.Mangling.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateMarshallingMethodThunk.Mangling.cs @@ -20,7 +20,7 @@ ReadOnlySpan IPrefixMangledType.Prefix { get { - return NamePrefix; + return NamePrefix.AsSpan(); } } } diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateMarshallingMethodThunk.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateMarshallingMethodThunk.cs index 834eb90e0eeae9..ed357892d79f69 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateMarshallingMethodThunk.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateMarshallingMethodThunk.cs @@ -3,10 +3,13 @@ using System; using System.Runtime.InteropServices; + +using Internal.Text; using Internal.TypeSystem; +using Internal.TypeSystem.Ecma; using Internal.TypeSystem.Interop; + using Debug = System.Diagnostics.Debug; -using Internal.TypeSystem.Ecma; namespace Internal.IL.Stubs { @@ -218,7 +221,7 @@ public MethodSignature DelegateSignature } } - private ReadOnlySpan NamePrefix + private Utf8StringRef NamePrefix { get { @@ -232,12 +235,12 @@ private ReadOnlySpan NamePrefix return "ForwardNativeFunctionWrapper"u8; default: Debug.Fail("Unexpected DelegateMarshallingMethodThunkKind."); - return []; + return Array.Empty(); } } } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateMethodILEmitter.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateMethodILEmitter.cs index 21cde1f4b10b0d..075bd1da26ac2c 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateMethodILEmitter.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateMethodILEmitter.cs @@ -17,7 +17,7 @@ public static MethodIL EmitIL(MethodDesc method) Debug.Assert(method.OwningType.IsTypeDefinition); Debug.Assert(method.IsRuntimeImplemented); - if (method.Name.SequenceEqual("BeginInvoke"u8) || method.Name.SequenceEqual("EndInvoke"u8)) + if (method.Name == "BeginInvoke"u8 || method.Name == "EndInvoke"u8) { // BeginInvoke and EndInvoke are not supported on .NET Core ILEmitter emit = new ILEmitter(); @@ -27,7 +27,7 @@ public static MethodIL EmitIL(MethodDesc method) return emit.Link(method); } - if (method.Name.SequenceEqual(".ctor"u8)) + if (method.Name == ".ctor"u8) { // We only support delegate creation if the IL follows the delegate creation verifiability requirements // described in ECMA-335 III.4.21 (newobj - create a new object). The codegen is expected to @@ -42,7 +42,7 @@ public static MethodIL EmitIL(MethodDesc method) return emit.Link(method); } - if (method.Name.SequenceEqual("Invoke"u8)) + if (method.Name == "Invoke"u8) { TypeSystemContext context = method.Context; diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateThunks.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateThunks.cs index 96cdef6151ac28..52063d043dfa24 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateThunks.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateThunks.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; + +using Internal.Text; using Internal.TypeSystem; using Debug = System.Diagnostics.Debug; @@ -128,7 +130,7 @@ public override MethodIL EmitIL() return emitter.Link(this); } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { @@ -221,7 +223,7 @@ public override MethodIL EmitIL() return emitter.Link(this); } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { @@ -281,7 +283,7 @@ public override MethodIL EmitIL() return emitter.Link(this); } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { @@ -416,7 +418,7 @@ public override MethodIL EmitIL() return emitter.Link(this); } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { @@ -464,7 +466,7 @@ public override MethodIL EmitIL() return emitter.Link(this); } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { @@ -641,7 +643,7 @@ public override MethodIL EmitIL() return emitter.Link(this); } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { @@ -758,7 +760,7 @@ public override bool IsVirtual } } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs index fd1dd35bd75d7c..076c71450afcbf 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; + +using Internal.Text; using Internal.TypeSystem; using Debug = System.Diagnostics.Debug; @@ -120,7 +122,7 @@ protected override int ComputeHashCode() return base.ComputeHashCode() ^ _targetSignature.GetHashCode(); } - public override ReadOnlySpan Name => "DynamicInvoke"u8; + public override Utf8StringRef Name => "DynamicInvoke"u8; public override string DiagnosticName => "DynamicInvoke"; diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/ForwardDelegateCreationThunk.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/ForwardDelegateCreationThunk.cs index 9d4ef6cbb517bb..dc31aacdded91b 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/ForwardDelegateCreationThunk.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/ForwardDelegateCreationThunk.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; + +using Internal.Text; using Internal.TypeSystem; using Internal.TypeSystem.Interop; @@ -62,7 +64,7 @@ public override MethodSignature Signature } } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/GetFieldHelperMethodOverride.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/GetFieldHelperMethodOverride.cs index 37a3ed8eb25cb2..f353247fe24a72 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/GetFieldHelperMethodOverride.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/GetFieldHelperMethodOverride.cs @@ -6,6 +6,7 @@ using ILCompiler; +using Internal.Text; using Internal.TypeSystem; using Debug = System.Diagnostics.Debug; @@ -217,7 +218,7 @@ public override bool IsVirtual internal static ReadOnlySpan MetadataName => "__GetFieldHelper"u8; - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/InterlockedIntrinsics.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/InterlockedIntrinsics.cs index 30f5fca3d9521c..d35fc7b9dc54f8 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/InterlockedIntrinsics.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/InterlockedIntrinsics.cs @@ -20,10 +20,10 @@ public static MethodIL EmitIL( #endif // READYTORUN MethodDesc method) { - Debug.Assert(((MetadataType)method.OwningType).Name.SequenceEqual("Interlocked"u8)); + Debug.Assert(((MetadataType)method.OwningType).Name == "Interlocked"u8); Debug.Assert(!method.IsGenericMethodDefinition); - if (method.HasInstantiation && method.Name.SequenceEqual("CompareExchange"u8)) + if (method.HasInstantiation && method.Name == "CompareExchange"u8) { #if READYTORUN // Check to see if the tokens needed to describe the CompareExchange are naturally present within diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/MethodBaseGetCurrentMethodThunk.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/MethodBaseGetCurrentMethodThunk.cs index 856b356c20922c..05a3ca3a759395 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/MethodBaseGetCurrentMethodThunk.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/MethodBaseGetCurrentMethodThunk.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; + +using Internal.Text; using Internal.TypeSystem; using Debug = System.Diagnostics.Debug; @@ -37,7 +39,7 @@ public MethodDesc Method get; } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/PInvokeLazyFixupField.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/PInvokeLazyFixupField.cs index 4ac119e4fb0d4d..323a977c3ff70e 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/PInvokeLazyFixupField.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/PInvokeLazyFixupField.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; + +using Internal.Text; using Internal.TypeSystem; using Debug = System.Diagnostics.Debug; @@ -124,7 +126,7 @@ public override bool HasCustomAttribute(string attributeNamespace, string attrib return false; } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/PInvokeTargetNativeMethod.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/PInvokeTargetNativeMethod.cs index 10520bf0266c70..b8618953402f8e 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/PInvokeTargetNativeMethod.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/PInvokeTargetNativeMethod.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; + +using Internal.Text; using Internal.TypeSystem; namespace Internal.IL.Stubs @@ -54,7 +56,7 @@ public override MethodSignature Signature } } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/RuntimeHelpersIntrinsics.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/RuntimeHelpersIntrinsics.cs index ae97ccd4c597d8..0ce9a5267bb92b 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/RuntimeHelpersIntrinsics.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/RuntimeHelpersIntrinsics.cs @@ -16,7 +16,7 @@ public static class RuntimeHelpersIntrinsics { public static MethodIL EmitIL(MethodDesc method) { - Debug.Assert(((MetadataType)method.OwningType).Name.SequenceEqual("RuntimeHelpers"u8)); + Debug.Assert(((MetadataType)method.OwningType).Name == "RuntimeHelpers"u8); // All the methods handled below are per-instantiation generic methods if (method.Instantiation.Length != 1 || method.IsTypicalMethodDefinition) @@ -29,7 +29,7 @@ public static MethodIL EmitIL(MethodDesc method) return null; bool result; - if (method.Name.SequenceEqual("IsBitwiseEquatable"u8)) + if (method.Name == "IsBitwiseEquatable"u8) { // Ideally we could detect automatically whether a type is trivially equatable // (i.e., its operator == could be implemented via memcmp). But for now we'll @@ -57,8 +57,8 @@ public static MethodIL EmitIL(MethodDesc method) if (elementType is MetadataType mdType) { if (mdType.Module == mdType.Context.SystemModule && - mdType.Namespace.SequenceEqual("System.Text"u8) && - mdType.Name.SequenceEqual("Rune"u8)) + mdType.Namespace == "System.Text"u8 && + mdType.Name == "Rune"u8) { result = true; } diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/StreamIntrinsics.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/StreamIntrinsics.cs index f678bfe9bd74e5..b6f34f9a3315dc 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/StreamIntrinsics.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/StreamIntrinsics.cs @@ -16,10 +16,10 @@ public static class StreamIntrinsics { public static MethodIL EmitIL(MethodDesc method) { - Debug.Assert(((MetadataType)method.OwningType).Name.SequenceEqual("Stream"u8)); + Debug.Assert(((MetadataType)method.OwningType).Name == "Stream"u8); - bool isRead = method.Name.SequenceEqual("HasOverriddenBeginEndRead"u8); - if (!isRead && !method.Name.SequenceEqual("HasOverriddenBeginEndWrite"u8)) + bool isRead = method.Name == "HasOverriddenBeginEndRead"u8; + if (!isRead && method.Name != "HasOverriddenBeginEndWrite"u8) return null; TypeDesc streamClass = method.OwningType; diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/StructMarshallingThunk.Mangling.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/StructMarshallingThunk.Mangling.cs index 8fc5840f49cba8..0512732f540249 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/StructMarshallingThunk.Mangling.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/StructMarshallingThunk.Mangling.cs @@ -20,7 +20,7 @@ ReadOnlySpan IPrefixMangledType.Prefix { get { - return NamePrefix; + return NamePrefix.AsSpan(); } } } diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/StructMarshallingThunk.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/StructMarshallingThunk.cs index 1d0263ef3cc52e..2e08a1e6f6292e 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/StructMarshallingThunk.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/StructMarshallingThunk.cs @@ -4,9 +4,13 @@ using System; using System.Collections.Generic; using System.Runtime.InteropServices; + using ILCompiler; + +using Internal.Text; using Internal.TypeSystem; using Internal.TypeSystem.Interop; + using Debug = System.Diagnostics.Debug; namespace Internal.IL.Stubs @@ -102,7 +106,7 @@ public override MethodSignature Signature } } - private ReadOnlySpan NamePrefix + private Utf8StringRef NamePrefix { get { @@ -116,12 +120,12 @@ private ReadOnlySpan NamePrefix return "Cleanup"u8; default: Debug.Fail("Unexpected Struct marshalling thunk type"); - return []; + return Array.Empty(); } } } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/TypeGetTypeMethodThunk.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/TypeGetTypeMethodThunk.cs index 1db9b1c2f4231f..16076905bd3c75 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/TypeGetTypeMethodThunk.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/TypeGetTypeMethodThunk.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; + +using Internal.Text; using Internal.TypeSystem; using Debug = System.Diagnostics.Debug; @@ -34,7 +36,7 @@ public override TypeSystemContext Context } } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/UnsafeIntrinsics.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/UnsafeIntrinsics.cs index 65b26afcf46f57..fd2cb914144679 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/UnsafeIntrinsics.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/UnsafeIntrinsics.cs @@ -16,7 +16,7 @@ public static class UnsafeIntrinsics { public static MethodIL EmitIL(MethodDesc method) { - Debug.Assert(((MetadataType)method.OwningType).Name.SequenceEqual("Unsafe"u8)); + Debug.Assert(((MetadataType)method.OwningType).Name == "Unsafe"u8); switch (method.GetName()) { diff --git a/src/coreclr/tools/Common/TypeSystem/Interop/IL/InlineArrayType.cs b/src/coreclr/tools/Common/TypeSystem/Interop/IL/InlineArrayType.cs index ce780a92a9509d..ba361fc3c1fc8b 100644 --- a/src/coreclr/tools/Common/TypeSystem/Interop/IL/InlineArrayType.cs +++ b/src/coreclr/tools/Common/TypeSystem/Interop/IL/InlineArrayType.cs @@ -3,11 +3,14 @@ using System; using System.Collections.Generic; -using Debug = System.Diagnostics.Debug; -using Internal.IL.Stubs; -using Internal.IL; using System.Threading; +using Internal.IL; +using Internal.IL.Stubs; +using Internal.Text; + +using Debug = System.Diagnostics.Debug; + namespace Internal.TypeSystem.Interop { internal sealed partial class InlineArrayType : MetadataType @@ -27,11 +30,11 @@ public override ModuleDesc Module get; } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { - return "_InlineArray__"u8.Append(ElementType.Name, "__"u8, Length); + return new Utf8StringRef("_InlineArray__"u8).Append(ElementType.Name, "__"u8, Length); } } @@ -43,7 +46,7 @@ public override string DiagnosticName } } - public override ReadOnlySpan Namespace + public override Utf8StringRef Namespace { get { @@ -199,7 +202,7 @@ public override IEnumerable GetNestedTypes() return Array.Empty(); } - public override MetadataType GetNestedType(ReadOnlySpan name) + public override MetadataType GetNestedType(Utf8StringRef name) { return null; } @@ -209,7 +212,7 @@ protected override MethodImplRecord[] ComputeVirtualMethodImplsForType() return Array.Empty(); } - public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(ReadOnlySpan name) + public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8StringRef name) { return Array.Empty(); } @@ -323,7 +326,7 @@ public override TypeSystemContext Context } } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { @@ -493,7 +496,7 @@ public override bool HasCustomAttribute(string attributeNamespace, string attrib return false; } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/Interop/IL/MarshalHelpers.cs b/src/coreclr/tools/Common/TypeSystem/Interop/IL/MarshalHelpers.cs index ec516afcd25265..6efabaefe10f22 100644 --- a/src/coreclr/tools/Common/TypeSystem/Interop/IL/MarshalHelpers.cs +++ b/src/coreclr/tools/Common/TypeSystem/Interop/IL/MarshalHelpers.cs @@ -202,8 +202,8 @@ private static bool HasCopyConstructorCustomModifier(int? parameterIndex, if (customModifierType == null) continue; - if ((customModifierType.Namespace.SequenceEqual("System.Runtime.CompilerServices"u8) && customModifierType.Name.SequenceEqual("IsCopyConstructed"u8)) || - (customModifierType.Namespace.SequenceEqual("Microsoft.VisualC"u8) && customModifierType.Name.SequenceEqual("NeedsCopyConstructorModifier"u8))) + if ((customModifierType.Namespace == "System.Runtime.CompilerServices"u8 && customModifierType.Name == "IsCopyConstructed"u8) || + (customModifierType.Namespace == "Microsoft.VisualC"u8 && customModifierType.Name == "NeedsCopyConstructorModifier"u8)) { return true; } @@ -946,7 +946,7 @@ internal static bool ShouldCheckForPendingException(TargetDetails target, PInvok // objc_msgSendSuper // objc_msgSendSuper_stret return metadata.Module.Equals(ObjectiveCLibrary) - && metadata.Name.StartsWith(ObjectiveCMsgSend); + && metadata.Name.AsSpan().StartsWith(ObjectiveCMsgSend); } internal static uint? GetObjectiveCMessageSendFunction(TargetDetails target, string pinvokeModule, string pinvokeFunction) diff --git a/src/coreclr/tools/Common/TypeSystem/Interop/IL/NativeStructType.cs b/src/coreclr/tools/Common/TypeSystem/Interop/IL/NativeStructType.cs index e70857e89aefee..c3a44322bcf600 100644 --- a/src/coreclr/tools/Common/TypeSystem/Interop/IL/NativeStructType.cs +++ b/src/coreclr/tools/Common/TypeSystem/Interop/IL/NativeStructType.cs @@ -3,7 +3,11 @@ using System; using System.Collections.Generic; + using ILCompiler; + +using Internal.Text; + using Debug = System.Diagnostics.Debug; namespace Internal.TypeSystem.Interop @@ -21,7 +25,7 @@ public override ModuleDesc Module get; } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { @@ -37,7 +41,7 @@ public override string DiagnosticName } } - public override ReadOnlySpan Namespace + public override Utf8StringRef Namespace { get { @@ -255,7 +259,7 @@ public override IEnumerable GetNestedTypes() return Array.Empty(); } - public override MetadataType GetNestedType(ReadOnlySpan name) + public override MetadataType GetNestedType(Utf8StringRef name) { return null; } @@ -265,7 +269,7 @@ protected override MethodImplRecord[] ComputeVirtualMethodImplsForType() return Array.Empty(); } - public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(ReadOnlySpan name) + public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8StringRef name) { return Array.Empty(); } @@ -394,7 +398,7 @@ public override bool HasCustomAttribute(string attributeNamespace, string attrib return false; } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/Interop/IL/PInvokeDelegateWrapper.cs b/src/coreclr/tools/Common/TypeSystem/Interop/IL/PInvokeDelegateWrapper.cs index 6f03cbcca43373..8b35bedad394ab 100644 --- a/src/coreclr/tools/Common/TypeSystem/Interop/IL/PInvokeDelegateWrapper.cs +++ b/src/coreclr/tools/Common/TypeSystem/Interop/IL/PInvokeDelegateWrapper.cs @@ -3,9 +3,12 @@ using System; using System.Collections.Generic; +using System.Threading; + using Internal.IL.Stubs; +using Internal.Text; + using Debug = System.Diagnostics.Debug; -using System.Threading; namespace Internal.TypeSystem.Interop { @@ -26,7 +29,7 @@ public override ModuleDesc Module get; } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { @@ -42,7 +45,7 @@ public override string DiagnosticName } } - public override ReadOnlySpan Namespace + public override Utf8StringRef Namespace { get { @@ -180,7 +183,7 @@ public override IEnumerable GetNestedTypes() return Array.Empty(); } - public override MetadataType GetNestedType(ReadOnlySpan name) + public override MetadataType GetNestedType(Utf8StringRef name) { return null; } @@ -190,7 +193,7 @@ protected override MethodImplRecord[] ComputeVirtualMethodImplsForType() return Array.Empty(); } - public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(ReadOnlySpan name) + public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8StringRef name) { return Array.Empty(); } diff --git a/src/coreclr/tools/Common/TypeSystem/Interop/IL/PInvokeDelegateWrapperConstructor.cs b/src/coreclr/tools/Common/TypeSystem/Interop/IL/PInvokeDelegateWrapperConstructor.cs index af6817d57d09e6..6c288c93909ae2 100644 --- a/src/coreclr/tools/Common/TypeSystem/Interop/IL/PInvokeDelegateWrapperConstructor.cs +++ b/src/coreclr/tools/Common/TypeSystem/Interop/IL/PInvokeDelegateWrapperConstructor.cs @@ -2,8 +2,10 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; + using Internal.IL; using Internal.IL.Stubs; +using Internal.Text; namespace Internal.TypeSystem.Interop { @@ -22,7 +24,7 @@ public override TypeDesc OwningType get; } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/Interop/InteropTypes.cs b/src/coreclr/tools/Common/TypeSystem/Interop/InteropTypes.cs index 09822e13f8b4de..d855b663049bc2 100644 --- a/src/coreclr/tools/Common/TypeSystem/Interop/InteropTypes.cs +++ b/src/coreclr/tools/Common/TypeSystem/Interop/InteropTypes.cs @@ -82,8 +82,8 @@ public static bool IsCriticalHandle(TypeSystemContext context, TypeDesc type) private static bool IsCoreNamedType(TypeSystemContext context, TypeDesc type, ReadOnlySpan @namespace, ReadOnlySpan name) { return type is MetadataType mdType && - mdType.Name.SequenceEqual(name) && - mdType.Namespace.SequenceEqual(@namespace) && + mdType.Name == name && + mdType.Namespace == @namespace && mdType.Module == context.SystemModule; } diff --git a/src/coreclr/tools/Common/TypeSystem/Interop/UnmanagedCallingConventions.cs b/src/coreclr/tools/Common/TypeSystem/Interop/UnmanagedCallingConventions.cs index 1d65930250df93..ed3c39d24f6545 100644 --- a/src/coreclr/tools/Common/TypeSystem/Interop/UnmanagedCallingConventions.cs +++ b/src/coreclr/tools/Common/TypeSystem/Interop/UnmanagedCallingConventions.cs @@ -189,24 +189,24 @@ private static UnmanagedCallingConventions GetUnmanagedCallingConventionFromAttr private static UnmanagedCallingConventions AccumulateCallingConventions(UnmanagedCallingConventions existing, MetadataType newConvention) { - if (!newConvention.Namespace.SequenceEqual("System.Runtime.CompilerServices"u8)) + if (newConvention.Namespace != "System.Runtime.CompilerServices"u8) return existing; UnmanagedCallingConventions? addedCallConv = null; - if (newConvention.Name.SequenceEqual("CallConvCdecl"u8)) + if (newConvention.Name == "CallConvCdecl"u8) addedCallConv = UnmanagedCallingConventions.Cdecl; - else if (newConvention.Name.SequenceEqual("CallConvStdcall"u8)) + else if (newConvention.Name == "CallConvStdcall"u8) addedCallConv = UnmanagedCallingConventions.Stdcall; - else if (newConvention.Name.SequenceEqual("CallConvFastcall"u8)) + else if (newConvention.Name == "CallConvFastcall"u8) addedCallConv = UnmanagedCallingConventions.Fastcall; - else if (newConvention.Name.SequenceEqual("CallConvThiscall"u8)) + else if (newConvention.Name == "CallConvThiscall"u8) addedCallConv = UnmanagedCallingConventions.Thiscall; - else if (newConvention.Name.SequenceEqual("CallConvSuppressGCTransition"u8)) + else if (newConvention.Name == "CallConvSuppressGCTransition"u8) addedCallConv = UnmanagedCallingConventions.IsSuppressGcTransition; - else if (newConvention.Name.SequenceEqual("CallConvMemberFunction"u8)) + else if (newConvention.Name == "CallConvMemberFunction"u8) addedCallConv = UnmanagedCallingConventions.IsMemberFunction; - else if (newConvention.Name.SequenceEqual("CallConvSwift"u8)) + else if (newConvention.Name == "CallConvSwift"u8) addedCallConv = UnmanagedCallingConventions.Swift; if (addedCallConv == null) diff --git a/src/coreclr/tools/Common/TypeSystem/RuntimeDetermined/MethodForRuntimeDeterminedType.cs b/src/coreclr/tools/Common/TypeSystem/RuntimeDetermined/MethodForRuntimeDeterminedType.cs index 9e6e2b974bd909..cb1d972bbd748d 100644 --- a/src/coreclr/tools/Common/TypeSystem/RuntimeDetermined/MethodForRuntimeDeterminedType.cs +++ b/src/coreclr/tools/Common/TypeSystem/RuntimeDetermined/MethodForRuntimeDeterminedType.cs @@ -4,6 +4,8 @@ using System; using System.Diagnostics; +using Internal.Text; + namespace Internal.TypeSystem { public sealed partial class MethodForRuntimeDeterminedType : MethodDesc @@ -36,7 +38,7 @@ internal MethodForRuntimeDeterminedType(MethodDesc typicalMethodDef, RuntimeDete public override bool IsAbstract => _typicalMethodDef.IsAbstract; public override bool IsFinal => _typicalMethodDef.IsFinal; public override bool IsDefaultConstructor => _typicalMethodDef.IsDefaultConstructor; - public override ReadOnlySpan Name => _typicalMethodDef.Name; + public override Utf8StringRef Name => _typicalMethodDef.Name; public override MethodDesc GetTypicalMethodDefinition() => _typicalMethodDef; public override Instantiation Instantiation => _typicalMethodDef.Instantiation; public override bool IsAsync => _typicalMethodDef.IsAsync; diff --git a/src/coreclr/tools/Common/TypeSystem/RuntimeDetermined/RuntimeDeterminedType.cs b/src/coreclr/tools/Common/TypeSystem/RuntimeDetermined/RuntimeDeterminedType.cs index 1834c19f5339e8..59d97fb730e9cc 100644 --- a/src/coreclr/tools/Common/TypeSystem/RuntimeDetermined/RuntimeDeterminedType.cs +++ b/src/coreclr/tools/Common/TypeSystem/RuntimeDetermined/RuntimeDeterminedType.cs @@ -4,6 +4,8 @@ using System; using System.Collections.Generic; +using Internal.Text; + using Debug = System.Diagnostics.Debug; namespace Internal.TypeSystem @@ -90,7 +92,7 @@ public override Instantiation Instantiation } } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { @@ -98,11 +100,11 @@ public override ReadOnlySpan Name } } - public override ReadOnlySpan Namespace + public override Utf8StringRef Namespace { get { - return System.Text.Encoding.UTF8.GetBytes(_runtimeDeterminedDetailsType.Name) + return new Utf8StringRef(System.Text.Encoding.UTF8.GetBytes(_runtimeDeterminedDetailsType.Name)) .Append("_"u8, _rawCanonType.Namespace); } } @@ -123,7 +125,7 @@ public override IEnumerable GetVirtualMethods() } } - public override MethodDesc GetMethod(ReadOnlySpan name, MethodSignature signature, Instantiation substitution) + public override MethodDesc GetMethod(Utf8StringRef name, MethodSignature signature, Instantiation substitution) { MethodDesc method = _rawCanonType.GetMethod(name, signature, substitution); if (method == null) @@ -131,7 +133,7 @@ public override MethodDesc GetMethod(ReadOnlySpan name, MethodSignature si return Context.GetMethodForRuntimeDeterminedType(method.GetTypicalMethodDefinition(), this); } - public override MethodDesc GetMethodWithEquivalentSignature(ReadOnlySpan name, MethodSignature signature, Instantiation substitution) + public override MethodDesc GetMethodWithEquivalentSignature(Utf8StringRef name, MethodSignature signature, Instantiation substitution) { MethodDesc method = _rawCanonType.GetMethodWithEquivalentSignature(name, signature, substitution); if (method == null) diff --git a/src/coreclr/tools/ILVerification/ILImporter.Verify.cs b/src/coreclr/tools/ILVerification/ILImporter.Verify.cs index 135f7f3b1d1825..ceed4747cbfcd5 100644 --- a/src/coreclr/tools/ILVerification/ILImporter.Verify.cs +++ b/src/coreclr/tools/ILVerification/ILImporter.Verify.cs @@ -1921,18 +1921,18 @@ bool IsTaskOrValueTaskType(TypeDesc type, out TypeDesc unwrappedType) if (type is not MetadataType metadataType) return false; - if (!metadataType.Namespace.SequenceEqual("System.Threading.Tasks"u8)) + if (metadataType.Namespace != "System.Threading.Tasks"u8) return false; // Check for Task (non-generic) - if (metadataType.Name.SequenceEqual("Task"u8) && !metadataType.HasInstantiation) + if (metadataType.Name == "Task"u8 && !metadataType.HasInstantiation) { unwrappedType = _typeSystemContext.GetWellKnownType(WellKnownType.Void); return true; } // Check for ValueTask (non-generic) - if (metadataType.Name.SequenceEqual("ValueTask"u8) && !metadataType.HasInstantiation) + if (metadataType.Name == "ValueTask"u8 && !metadataType.HasInstantiation) { unwrappedType = _typeSystemContext.GetWellKnownType(WellKnownType.Void); return true; @@ -1941,8 +1941,8 @@ bool IsTaskOrValueTaskType(TypeDesc type, out TypeDesc unwrappedType) // Check for Task and ValueTask if (metadataType.HasInstantiation && metadataType.Instantiation.Length == 1) { - if (metadataType.Name.SequenceEqual("Task`1"u8) || - metadataType.Name.SequenceEqual("ValueTask`1"u8)) + if (metadataType.Name == "Task`1"u8 || + metadataType.Name == "ValueTask`1"u8) { unwrappedType = metadataType.Instantiation[0]; return true; @@ -2784,7 +2784,7 @@ static bool HasIsExternalInit(MethodSignature signature) { foreach (var data in signature.GetEmbeddedSignatureData()) { - if (data.type is MetadataType mdType && mdType.Namespace.SequenceEqual("System.Runtime.CompilerServices"u8) && mdType.Name.SequenceEqual("IsExternalInit"u8) && + if (data.type is MetadataType mdType && mdType.Namespace == "System.Runtime.CompilerServices"u8 && mdType.Name == "IsExternalInit"u8 && data.index == MethodSignature.IndexOfCustomModifiersOnReturnType) return true; } diff --git a/src/coreclr/tools/ILVerification/ILVerification.projitems b/src/coreclr/tools/ILVerification/ILVerification.projitems index c301f2da1d298e..0fc325d210d7b9 100644 --- a/src/coreclr/tools/ILVerification/ILVerification.projitems +++ b/src/coreclr/tools/ILVerification/ILVerification.projitems @@ -27,6 +27,9 @@ TypeSystem\Common\VersionResilientHashCode.cs + + Common\Utf8StringRef.cs + TypeSystem\CodeGen\MethodDesc.CodeGen.cs diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler.Tests/SwiftLoweringTests.cs b/src/coreclr/tools/aot/ILCompiler.Compiler.Tests/SwiftLoweringTests.cs index 4b1c830eaee392..67b8c9c5d1d2e7 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler.Tests/SwiftLoweringTests.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler.Tests/SwiftLoweringTests.cs @@ -46,7 +46,7 @@ public static IEnumerable DiscoverSwiftTypes() foreach (var type in testModule.GetAllTypes()) { if (type is EcmaType { IsValueType: true } ecmaType - && ecmaType.Namespace.SequenceEqual("ILCompiler.Compiler.Tests.Assets.SwiftTypes"u8) + && ecmaType.Namespace == "ILCompiler.Compiler.Tests.Assets.SwiftTypes"u8 && ecmaType.GetDecodedCustomAttribute("ILCompiler.Compiler.Tests.Assets.SwiftTypes", "ExpectedLoweringAttribute") is { } expectedLoweringAttribute) { // By default, we assume that our lowered representation is meant to be naturally aligned. diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Compilation.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Compilation.cs index ed19f9406271ea..97c8c91e633e6b 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Compilation.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Compilation.cs @@ -176,9 +176,9 @@ public MethodDesc ExpandIntrinsicForCallsite(MethodDesc intrinsicMethod, MethodD if (intrinsicOwningType.Module != TypeSystemContext.SystemModule) return intrinsicMethod; - if (intrinsicOwningType.Name.SequenceEqual("Type"u8) && intrinsicOwningType.Namespace.SequenceEqual("System"u8)) + if (intrinsicOwningType.Name == "Type"u8 && intrinsicOwningType.Namespace == "System"u8) { - if (intrinsicMethod.Signature.IsStatic && intrinsicMethod.Name.SequenceEqual("GetType"u8)) + if (intrinsicMethod.Signature.IsStatic && intrinsicMethod.Name == "GetType"u8) { ModuleDesc callsiteModule = (callsiteMethod.OwningType as MetadataType)?.Module; if (callsiteModule != null) @@ -188,9 +188,9 @@ public MethodDesc ExpandIntrinsicForCallsite(MethodDesc intrinsicMethod, MethodD } } } - else if (intrinsicOwningType.Name.SequenceEqual("Assembly"u8) && intrinsicOwningType.Namespace.SequenceEqual("System.Reflection"u8)) + else if (intrinsicOwningType.Name == "Assembly"u8 && intrinsicOwningType.Namespace == "System.Reflection"u8) { - if (intrinsicMethod.Signature.IsStatic && intrinsicMethod.Name.SequenceEqual("GetExecutingAssembly"u8)) + if (intrinsicMethod.Signature.IsStatic && intrinsicMethod.Name == "GetExecutingAssembly"u8) { ModuleDesc callsiteModule = (callsiteMethod.OwningType as MetadataType)?.Module; if (callsiteModule != null) @@ -200,9 +200,9 @@ public MethodDesc ExpandIntrinsicForCallsite(MethodDesc intrinsicMethod, MethodD } } } - else if (intrinsicOwningType.Name.SequenceEqual("MethodBase"u8) && intrinsicOwningType.Namespace.SequenceEqual("System.Reflection"u8)) + else if (intrinsicOwningType.Name == "MethodBase"u8 && intrinsicOwningType.Namespace == "System.Reflection"u8) { - if (intrinsicMethod.Signature.IsStatic && intrinsicMethod.Name.SequenceEqual("GetCurrentMethod"u8)) + if (intrinsicMethod.Signature.IsStatic && intrinsicMethod.Name == "GetCurrentMethod"u8) { if (callsiteMethod.IsAsyncVariant()) { @@ -457,11 +457,11 @@ public bool IsFatPointerCandidate(MethodDesc containingMethod, MethodSignature s if (containingMethod.OwningType is MetadataType owningType) { // RawCalliHelper is a way for the class library to opt out of fat calls - if (owningType.Name.SequenceEqual("RawCalliHelper"u8)) + if (owningType.Name == "RawCalliHelper"u8) return false; // Delegate invocation never needs fat calls - if (owningType.IsDelegate && containingMethod.Name.SequenceEqual("Invoke"u8)) + if (owningType.IsDelegate && containingMethod.Name == "Invoke"u8) return false; } diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.BoxedTypes.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.BoxedTypes.cs index 993bc094ed7756..fd9b05f43a4ef0 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.BoxedTypes.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.BoxedTypes.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using Internal; +using Internal.Text; using Internal.TypeSystem; using Internal.IL; using Internal.IL.Stubs; @@ -231,8 +232,8 @@ private sealed partial class BoxedValueType : MetadataType, INonEmittableType public override ModuleDesc Module { get; } - public override ReadOnlySpan Name => "Boxed_"u8.Append(ValueTypeRepresented.Name); - public override ReadOnlySpan Namespace => ValueTypeRepresented.Namespace; + public override Utf8StringRef Name => "Boxed_"u8.Append(ValueTypeRepresented.Name); + public override Utf8StringRef Namespace => ValueTypeRepresented.Namespace; public override string DiagnosticName => "Boxed_" + ValueTypeRepresented.DiagnosticName; public override string DiagnosticNamespace => ValueTypeRepresented.DiagnosticNamespace; public override Instantiation Instantiation => ValueTypeRepresented.Instantiation; @@ -273,9 +274,9 @@ public BoxedValueType(ModuleDesc owningModule, MetadataType valuetype) public override ClassLayoutMetadata GetClassLayout() => default(ClassLayoutMetadata); public override bool HasCustomAttribute(string attributeNamespace, string attributeName) => false; public override IEnumerable GetNestedTypes() => Array.Empty(); - public override MetadataType GetNestedType(ReadOnlySpan name) => null; + public override MetadataType GetNestedType(Utf8StringRef name) => null; protected override MethodImplRecord[] ComputeVirtualMethodImplsForType() => Array.Empty(); - public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(ReadOnlySpan name) => Array.Empty(); + public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8StringRef name) => Array.Empty(); public override int GetHashCode() => VersionResilientHashCode.NameHashCode(Namespace, Name); @@ -299,7 +300,7 @@ protected override TypeFlags ComputeTypeFlags(TypeFlags mask) return flags; } - public override FieldDesc GetField(ReadOnlySpan name) + public override FieldDesc GetField(Utf8StringRef name) { return null; } @@ -369,7 +370,7 @@ public GenericUnboxingThunk(BoxedValueType owningType, MethodDesc targetMethod) public MethodDesc TargetMethod => _targetMethod; - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { @@ -458,7 +459,7 @@ public UnboxingThunk(BoxedValueType owningType, MethodDesc targetMethod) public MethodDesc TargetMethod => _targetMethod; - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.GeneratedAssembly.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.GeneratedAssembly.cs index d501cf40586c21..a0ccd041faf310 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.GeneratedAssembly.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.GeneratedAssembly.cs @@ -6,6 +6,7 @@ using System.Reflection.Metadata; using Internal; +using Internal.Text; using Internal.TypeSystem; using TypeHashingAlgorithms = Internal.NativeFormat.TypeHashingAlgorithms; @@ -37,7 +38,7 @@ private sealed class CompilerGeneratedAssembly : ModuleDesc, IAssemblyDesc public override IAssemblyDesc Assembly => this; - public ReadOnlySpan Name => "System.Private.CompilerGenerated"u8; + public Utf8StringRef Name => "System.Private.CompilerGenerated"u8; public CompilerGeneratedAssembly(TypeSystemContext context) : base(context, null) @@ -60,7 +61,7 @@ public AssemblyNameInfo GetName() return new AssemblyNameInfo("System.Private.CompilerGenerated"); } - public override object GetType(ReadOnlySpan nameSpace, ReadOnlySpan name, NotFoundBehavior notFoundBehavior) + public override object GetType(Utf8StringRef nameSpace, Utf8StringRef name, NotFoundBehavior notFoundBehavior) { Debug.Fail("Resolving a TypeRef in the compiler generated assembly?"); throw new NotImplementedException(); @@ -88,7 +89,7 @@ public override TypeSystemContext Context } } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { @@ -104,7 +105,7 @@ public override string DiagnosticName } } - public override ReadOnlySpan Namespace + public override Utf8StringRef Namespace { get { @@ -162,7 +163,7 @@ public override IEnumerable GetNestedTypes() return Array.Empty(); } - public override MetadataType GetNestedType(ReadOnlySpan name) + public override MetadataType GetNestedType(Utf8StringRef name) { return null; } @@ -172,7 +173,7 @@ protected override MethodImplRecord[] ComputeVirtualMethodImplsForType() return Array.Empty(); } - public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(ReadOnlySpan name) + public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8StringRef name) { return Array.Empty(); } diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.GetFieldMethodOverrides.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.GetFieldMethodOverrides.cs index 305960c8fb31e9..730d9f0182c94d 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.GetFieldMethodOverrides.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.GetFieldMethodOverrides.cs @@ -103,7 +103,7 @@ private bool RequiresValueTypeGetFieldHelperMethod(MetadataType valueType) return false; // ValueTuples override Equals/GetHashCode and don't have a `base.GetHashCode` call. So avoid the infrastructure. - if (valueType.Module == SystemModule && valueType.Name.StartsWith("ValueTuple`"u8) && valueType.Namespace.SequenceEqual("System"u8)) + if (valueType.Module == SystemModule && valueType.Name.StartsWith("ValueTuple`"u8) && valueType.Namespace == "System"u8) return false; return !_typeStateHashtable.GetOrCreateValue(valueType).CanCompareValueTypeBits; diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.InterfaceThunks.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.InterfaceThunks.cs index b1f08effb7135b..9790ec47f389b2 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.InterfaceThunks.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.InterfaceThunks.cs @@ -3,6 +3,7 @@ using System; +using Internal.Text; using Internal.TypeSystem; using Internal.IL; using Internal.IL.Stubs; @@ -196,7 +197,7 @@ public DefaultInterfaceMethodImplementationInstantiationThunk(TypeDesc owningTyp public MethodDesc TargetMethod => _targetMethod; - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/CompilerGeneratedCallGraph.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/CompilerGeneratedCallGraph.cs index 365ed545d7791c..fee8b208565cdc 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/CompilerGeneratedCallGraph.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/CompilerGeneratedCallGraph.cs @@ -30,7 +30,7 @@ public void TrackCall(MethodDesc fromMethod, MethodDesc toMethod) { Debug.Assert(fromMethod.IsTypicalMethodDefinition); Debug.Assert(toMethod.IsTypicalMethodDefinition); - Debug.Assert(CompilerGeneratedNames.IsLambdaOrLocalFunction(toMethod.Name)); + Debug.Assert(CompilerGeneratedNames.IsLambdaOrLocalFunction(toMethod.Name.AsSpan())); TrackCallInternal(fromMethod, toMethod); } @@ -38,7 +38,7 @@ public void TrackCall(MethodDesc fromMethod, DefType toType) { Debug.Assert(fromMethod.IsTypicalMethodDefinition); Debug.Assert(toType.IsTypeDefinition); - Debug.Assert(CompilerGeneratedNames.IsStateMachineType(toType.Name)); + Debug.Assert(CompilerGeneratedNames.IsStateMachineType(toType.Name.AsSpan())); TrackCallInternal(fromMethod, toType); } @@ -46,8 +46,8 @@ public void TrackCall(DefType fromType, MethodDesc toMethod) { Debug.Assert(fromType.IsTypeDefinition); Debug.Assert(toMethod.IsTypicalMethodDefinition); - Debug.Assert(CompilerGeneratedNames.IsStateMachineType(fromType.Name)); - Debug.Assert(CompilerGeneratedNames.IsLambdaOrLocalFunction(toMethod.Name)); + Debug.Assert(CompilerGeneratedNames.IsStateMachineType(fromType.Name.AsSpan())); + Debug.Assert(CompilerGeneratedNames.IsLambdaOrLocalFunction(toMethod.Name.AsSpan())); TrackCallInternal(fromType, toMethod); } diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/CompilerGeneratedState.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/CompilerGeneratedState.cs index 4314f9f6a2a2ee..fd6a96b50a1b35 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/CompilerGeneratedState.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/CompilerGeneratedState.cs @@ -117,7 +117,7 @@ internal void LogWarnings(Logger? logger) internal TypeCache(MetadataType type, ILProvider ilProvider) { Debug.Assert(type == type.GetTypeDefinition()); - Debug.Assert(!CompilerGeneratedNames.IsStateMachineOrDisplayClass(type.Name)); + Debug.Assert(!CompilerGeneratedNames.IsStateMachineOrDisplayClass(type.Name.AsSpan())); Type = type; @@ -138,8 +138,8 @@ void ProcessMethod(MethodDesc method) { Debug.Assert(method == method.GetTypicalMethodDefinition()); - bool isStateMachineMember = CompilerGeneratedNames.IsStateMachineType(((MetadataType)method.OwningType).Name); - if (!CompilerGeneratedNames.IsLambdaOrLocalFunction(method.Name)) + bool isStateMachineMember = CompilerGeneratedNames.IsStateMachineType(((MetadataType)method.OwningType).Name.AsSpan()); + if (!CompilerGeneratedNames.IsLambdaOrLocalFunction(method.Name.AsSpan())) { if (!isStateMachineMember) { @@ -183,7 +183,7 @@ void ProcessMethod(MethodDesc method) referencedMethod.OwningType is MetadataType generatedType && // Don't consider calls in the same/nested type, like inside a static constructor !IsSameOrNestedType(method.OwningType, generatedType) && - CompilerGeneratedNames.IsLambdaDisplayClass(generatedType.Name)) + CompilerGeneratedNames.IsLambdaDisplayClass(generatedType.Name.AsSpan())) { Debug.Assert(generatedType.IsTypeDefinition); @@ -196,7 +196,7 @@ referencedMethod.OwningType is MetadataType generatedType && continue; } - if (!CompilerGeneratedNames.IsLambdaOrLocalFunction(referencedMethod.Name)) + if (!CompilerGeneratedNames.IsLambdaOrLocalFunction(referencedMethod.Name.AsSpan())) continue; if (isStateMachineMember) @@ -224,7 +224,7 @@ referencedMethod.OwningType is MetadataType generatedType && if (field.OwningType is MetadataType generatedType && // Don't consider field accesses in the same/nested type, like inside a static constructor !IsSameOrNestedType(method.OwningType, generatedType) && - CompilerGeneratedNames.IsLambdaDisplayClass(generatedType.Name)) + CompilerGeneratedNames.IsLambdaDisplayClass(generatedType.Name.AsSpan())) { Debug.Assert(generatedType.IsTypeDefinition); @@ -249,7 +249,7 @@ referencedMethod.OwningType is MetadataType generatedType && if (TryGetStateMachineType(method, out MetadataType? stateMachineType)) { Debug.Assert(stateMachineType.ContainingType == type || - (CompilerGeneratedNames.IsStateMachineOrDisplayClass(stateMachineType.ContainingType.Name) && + (CompilerGeneratedNames.IsStateMachineOrDisplayClass(stateMachineType.ContainingType.Name.AsSpan()) && stateMachineType.ContainingType.ContainingType == type)); Debug.Assert(stateMachineType == stateMachineType.GetTypeDefinition()); @@ -325,7 +325,7 @@ static bool IsSameOrNestedType(TypeDesc type, TypeDesc potentialOuterType) switch (compilerGeneratedMember) { case MethodDesc nestedFunction: - Debug.Assert(CompilerGeneratedNames.IsLambdaOrLocalFunction(nestedFunction.Name)); + Debug.Assert(CompilerGeneratedNames.IsLambdaOrLocalFunction(nestedFunction.Name.AsSpan())); // Nested functions get suppressions from the user method only. _compilerGeneratedMethodToUserCodeMethod ??= new Dictionary(); if (!_compilerGeneratedMethodToUserCodeMethod.TryAdd(nestedFunction, userDefinedMethod)) @@ -340,7 +340,7 @@ static bool IsSameOrNestedType(TypeDesc type, TypeDesc potentialOuterType) // are represented by the state machine type itself. // We are already tracking the association of the state machine type to the user code method // above, so no need to track it here. - Debug.Assert(CompilerGeneratedNames.IsStateMachineType(stateMachineType.Name)); + Debug.Assert(CompilerGeneratedNames.IsStateMachineType(stateMachineType.Name.AsSpan())); break; default: throw new InvalidOperationException(); @@ -392,7 +392,7 @@ void MapGeneratedTypeTypeParameters( MetadataType generatedType, Dictionary generatedTypeToTypeArgs) { - Debug.Assert(CompilerGeneratedNames.IsStateMachineOrDisplayClass(generatedType.Name)); + Debug.Assert(CompilerGeneratedNames.IsStateMachineOrDisplayClass(generatedType.Name.AsSpan())); Debug.Assert(generatedType == generatedType.GetTypeDefinition()); var typeInfo = generatedTypeToTypeArgs[generatedType]; @@ -432,7 +432,7 @@ void MapGeneratedTypeTypeParameters( else { // Must be a type ref - if (method.OwningType is not MetadataType owningType || !CompilerGeneratedNames.IsStateMachineOrDisplayClass(owningType.Name)) + if (method.OwningType is not MetadataType owningType || !CompilerGeneratedNames.IsStateMachineOrDisplayClass(owningType.Name.AsSpan())) { userAttrs = param; } @@ -573,7 +573,7 @@ private static IEnumerable GetCompilerGeneratedNestedTypes(Metadat { foreach (var nestedType in type.GetNestedTypes()) { - if (!CompilerGeneratedNames.IsStateMachineOrDisplayClass(nestedType.Name)) + if (!CompilerGeneratedNames.IsStateMachineOrDisplayClass(nestedType.Name.AsSpan())) continue; yield return nestedType; @@ -585,14 +585,14 @@ private static IEnumerable GetCompilerGeneratedNestedTypes(Metadat public static bool IsHoistedLocal(FieldDesc field) { - if (CompilerGeneratedNames.IsLambdaDisplayClass(field.OwningType.Name)) + if (CompilerGeneratedNames.IsLambdaDisplayClass(field.OwningType.Name.AsSpan())) return true; - if (CompilerGeneratedNames.IsStateMachineType(field.OwningType.Name)) + if (CompilerGeneratedNames.IsStateMachineType(field.OwningType.Name.AsSpan())) { // Don't track the "current" field which is used for state machine return values, // because this can be expensive to track. - return !CompilerGeneratedNames.IsStateMachineCurrentField(field.Name); + return !CompilerGeneratedNames.IsStateMachineCurrentField(field.Name.AsSpan()); } return false; @@ -601,13 +601,13 @@ public static bool IsHoistedLocal(FieldDesc field) // "Nested function" refers to lambdas and local functions. public static bool IsNestedFunctionOrStateMachineMember(TypeSystemEntity member) { - if (member is MethodDesc method && CompilerGeneratedNames.IsLambdaOrLocalFunction(method.Name)) + if (member is MethodDesc method && CompilerGeneratedNames.IsLambdaOrLocalFunction(method.Name.AsSpan())) return true; if (member.GetOwningType() is not MetadataType declaringType) return false; - return CompilerGeneratedNames.IsStateMachineType(declaringType.Name); + return CompilerGeneratedNames.IsStateMachineType(declaringType.Name.AsSpan()); } public static bool TryGetStateMachineType(MethodDesc method, [NotNullWhen(true)] out MetadataType? stateMachineType) @@ -637,7 +637,7 @@ public static bool TryGetStateMachineType(MethodDesc method, [NotNullWhen(true)] // State machines can be emitted into display classes, so we may also need to go one more level up. // To avoid depending on implementation details, we go up until we see a non-compiler-generated type. // This is the counterpart to GetCompilerGeneratedNestedTypes. - while (userType != null && CompilerGeneratedNames.IsStateMachineOrDisplayClass(userType.Name)) + while (userType != null && CompilerGeneratedNames.IsStateMachineOrDisplayClass(userType.Name.AsSpan())) userType = userType.ContainingType as MetadataType; if (userType is null) @@ -682,7 +682,7 @@ public bool TryGetCompilerGeneratedCalleesForUserMethod(MethodDesc method, [NotN public IReadOnlyList? GetGeneratedTypeAttributes(MetadataType type) { MetadataType generatedType = (MetadataType)type.GetTypeDefinition(); - Debug.Assert(CompilerGeneratedNames.IsStateMachineOrDisplayClass(generatedType.Name)); + Debug.Assert(CompilerGeneratedNames.IsStateMachineOrDisplayClass(generatedType.Name.AsSpan())); // Avoid the heuristics for .NET10+, where DynamicallyAccessedMembers flows to generated code // because it is annotated with CompilerLoweringPreserveAttribute. diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/FlowAnnotations.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/FlowAnnotations.cs index dc1361c280b51e..3d2f5db67f0696 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/FlowAnnotations.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/FlowAnnotations.cs @@ -275,16 +275,16 @@ public static bool IsTypeInterestingForDataflow(TypeDesc type) foreach (var intf in type.RuntimeInterfaces) { - if (intf.Name.SequenceEqual("IReflect"u8) && intf.Namespace.SequenceEqual("System.Reflection"u8)) + if (intf.Name == "IReflect"u8 && intf.Namespace == "System.Reflection"u8) return true; } - if (metadataType.Name.SequenceEqual("IReflect"u8) && metadataType.Namespace.SequenceEqual("System.Reflection"u8)) + if (metadataType.Name == "IReflect"u8 && metadataType.Namespace == "System.Reflection"u8) return true; do { - if (metadataType.Name.SequenceEqual("Type"u8) && metadataType.Namespace.SequenceEqual("System"u8)) + if (metadataType.Name == "Type"u8 && metadataType.Namespace == "System"u8) return true; } while ((metadataType = metadataType.BaseType) != null); @@ -509,7 +509,7 @@ protected override TypeAnnotations CreateValueFromKey(TypeDesc key) PropertyPseudoDesc property = new PropertyPseudoDesc(ecmaType, propertyHandle); - if (CompilerGeneratedNames.IsExtensionType(ecmaType.Name)) + if (CompilerGeneratedNames.IsExtensionType(ecmaType.Name.AsSpan())) { // Annotations on extension properties are not supported. _logger.LogWarning(property, DiagnosticId.DynamicallyAccessedMembersIsNotAllowedOnExtensionProperties, property.GetDisplayName()); @@ -649,7 +649,7 @@ protected override TypeAnnotations CreateValueFromKey(TypeDesc key) private IReadOnlyList? GetGeneratedTypeAttributes(EcmaType typeDef) { - if (!CompilerGeneratedNames.IsStateMachineOrDisplayClass(typeDef.Name)) + if (!CompilerGeneratedNames.IsStateMachineOrDisplayClass(typeDef.Name.AsSpan())) { return null; } diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/InterproceduralState.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/InterproceduralState.cs index 71e3518a42bd81..748fe22d356b01 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/InterproceduralState.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/InterproceduralState.cs @@ -78,7 +78,7 @@ public void TrackMethod(MethodIL methodBody) { foreach (var stateMachineMethod in stateMachineType.GetMethods()) { - Debug.Assert(!CompilerGeneratedNames.IsLambdaOrLocalFunction(stateMachineMethod.Name)); + Debug.Assert(!CompilerGeneratedNames.IsLambdaOrLocalFunction(stateMachineMethod.Name.AsSpan())); if (TryGetMethodBody(stateMachineMethod, out MethodIL? stateMachineMethodBody)) { stateMachineMethodBody = GetInstantiatedMethodIL(stateMachineMethodBody); diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/MethodBodyScanner.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/MethodBodyScanner.cs index 5b7d9c50eeda91..13222425d52255 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/MethodBodyScanner.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/MethodBodyScanner.cs @@ -335,7 +335,7 @@ private static void TrackNestedFunctionReference(MethodDesc referencedMethod, re { MethodDesc method = referencedMethod.GetTypicalMethodDefinition(); - if (!CompilerGeneratedNames.IsLambdaOrLocalFunction(method.Name)) + if (!CompilerGeneratedNames.IsLambdaOrLocalFunction(method.Name.AsSpan())) return; interproceduralState.TrackMethod(method); diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/CodeBasedDependencyAlgorithm.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/CodeBasedDependencyAlgorithm.cs index d09c6646c7c96a..ea42f9e654c3e1 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/CodeBasedDependencyAlgorithm.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/CodeBasedDependencyAlgorithm.cs @@ -36,16 +36,16 @@ public static void AddDependenciesDueToMethodCodePresence(ref DependencyList dep case "Create": if (method.IsSharedByGenericInstantiations && owningType.Module == factory.TypeSystemContext.SystemModule - && owningType.Namespace.SequenceEqual("System.Collections.Generic"u8)) + && owningType.Namespace == "System.Collections.Generic"u8) { TypeDesc[] templateDependencies = null; - if (owningType.Name.SequenceEqual("Comparer`1"u8)) + if (owningType.Name == "Comparer`1"u8) { templateDependencies = Internal.IL.Stubs.ComparerIntrinsics.GetPotentialComparersForType( owningType.Instantiation[0]); } - else if (owningType.Name.SequenceEqual("EqualityComparer`1"u8)) + else if (owningType.Name == "EqualityComparer`1"u8) { templateDependencies = Internal.IL.Stubs.ComparerIntrinsics.GetPotentialEqualityComparersForType( owningType.Instantiation[0]); diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/EETypeNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/EETypeNode.cs index 8ecdb7b7c0d5c3..da95fde9335dc1 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/EETypeNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/EETypeNode.cs @@ -972,7 +972,7 @@ private void OutputVirtualSlots(NodeFactory factory, ref ObjectDataBuilder objDa // Object.Finalize shouldn't get a virtual slot. Finalizer is stored in an optional field // instead: most MethodTable don't have a finalizer, but all EETypes contain Object's vtable. // This lets us save a pointer (+reloc) on most EETypes. - Debug.Assert(!declType.IsObject || !declMethod.Name.SequenceEqual("Finalize"u8)); + Debug.Assert(!declType.IsObject || declMethod.Name != "Finalize"u8); // No generic virtual methods can appear in the vtable! Debug.Assert(!declMethod.HasInstantiation); @@ -997,8 +997,8 @@ private void OutputVirtualSlots(NodeFactory factory, ref ObjectDataBuilder objDa // We also null out Equals/GetHashCode - that's just a marginal size/startup optimization. if (isAsyncStateMachineValueType) { - if ((declType.IsObject && (declMethod.Name.SequenceEqual("Equals"u8) || declMethod.Name.SequenceEqual("GetHashCode"u8)) && implMethod.OwningType.IsWellKnownType(WellKnownType.ValueType)) - || (declType.IsWellKnownType(WellKnownType.ValueType) && declMethod.Name.SequenceEqual(GetFieldHelperMethodOverride.MetadataName))) + if ((declType.IsObject && (declMethod.Name == "Equals"u8 || declMethod.Name == "GetHashCode"u8) && implMethod.OwningType.IsWellKnownType(WellKnownType.ValueType)) + || (declType.IsWellKnownType(WellKnownType.ValueType) && declMethod.Name == GetFieldHelperMethodOverride.MetadataName)) { shouldEmitImpl = false; } diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/InlineableStringsResourceNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/InlineableStringsResourceNode.cs index fcda5e674b8f4f..26d4100aed666c 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/InlineableStringsResourceNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/InlineableStringsResourceNode.cs @@ -60,8 +60,8 @@ public static bool IsInlineableStringsResource(EcmaModule module, string resourc public static void AddDependenciesDueToResourceStringUse(ref DependencyList dependencies, NodeFactory factory, MethodDesc method) { - if (method.Name.SequenceEqual(ResourceAccessorGetStringMethodName) && method.OwningType is MetadataType mdType - && mdType.Name.SequenceEqual(ResourceAccessorTypeName) && mdType.Namespace.SequenceEqual(ResourceAccessorTypeNamespace)) + if (method.Name == ResourceAccessorGetStringMethodName && method.OwningType is MetadataType mdType + && mdType.Name == ResourceAccessorTypeName && mdType.Namespace == ResourceAccessorTypeNamespace) { dependencies ??= new DependencyList(); dependencies.Add(factory.InlineableStringResource((EcmaModule)mdType.Module), "Using the System.SR class"); diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/VTableSliceNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/VTableSliceNode.cs index 4d0e0785e15117..c5b22842c46669 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/VTableSliceNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/VTableSliceNode.cs @@ -42,7 +42,7 @@ protected static MethodDesc[] ComputeSlots(TypeDesc type) continue; // Finalizers are called via a field on the MethodTable, not through the VTable - if (isObjectType && method.Name.SequenceEqual("Finalize"u8)) + if (isObjectType && method.Name == "Finalize"u8) continue; // Current type doesn't define this slot. @@ -203,7 +203,7 @@ public void AddEntry(MethodDesc virtualMethod) #endif // Finalizers are called via a field on the MethodTable, not through the VTable - if (_type.IsObject && virtualMethod.Name.SequenceEqual("Finalize"u8)) + if (_type.IsObject && virtualMethod.Name == "Finalize"u8) return; _usedMethods.Add(virtualMethod); diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ExternSymbolMappedField.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ExternSymbolMappedField.cs index 7e560963522de2..b6471bc4e2dc1b 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ExternSymbolMappedField.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ExternSymbolMappedField.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using Internal.Text; using Internal.TypeSystem; namespace ILCompiler @@ -20,7 +21,7 @@ public ExternSymbolMappedField(TypeDesc fieldType, string symbolName) _symbolName = symbolName; } - public override ReadOnlySpan Name => System.Text.Encoding.UTF8.GetBytes(_symbolName); + public override Utf8StringRef Name => System.Text.Encoding.UTF8.GetBytes(_symbolName); public string SymbolName => _symbolName; diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/HardwareIntrinsicHelpers.Aot.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/HardwareIntrinsicHelpers.Aot.cs index e02ed8a0e597cd..0a66f169fbc978 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/HardwareIntrinsicHelpers.Aot.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/HardwareIntrinsicHelpers.Aot.cs @@ -16,7 +16,7 @@ public static partial class HardwareIntrinsicHelpers { public static bool IsIsSupportedMethod(MethodDesc method) { - return method.Name.SequenceEqual("get_IsSupported"u8); + return method.Name == "get_IsSupported"u8; } /// diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/NoMetadataBlockingPolicy.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/NoMetadataBlockingPolicy.cs index c1b9fbe4e7b1b7..946a2fa1533361 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/NoMetadataBlockingPolicy.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/NoMetadataBlockingPolicy.cs @@ -54,7 +54,7 @@ public override bool IsBlocked(MethodDesc method) return true; // Also don't expose the ValueType.__GetFieldOverride method. - if (ecmaMethod.Name.SequenceEqual(Internal.IL.Stubs.GetFieldHelperMethodOverride.MetadataName) + if (ecmaMethod.Name == Internal.IL.Stubs.GetFieldHelperMethodOverride.MetadataName && ecmaMethod.OwningType.IsWellKnownType(WellKnownType.ValueType)) return true; diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ReachabilityInstrumentationProvider.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ReachabilityInstrumentationProvider.cs index 609fc2be0fb9f6..ef89fda1a8f113 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ReachabilityInstrumentationProvider.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ReachabilityInstrumentationProvider.cs @@ -240,7 +240,7 @@ public InitializeMethod(CompilerTypeSystemContext context) public override TypeSystemContext Context => _context; public override TypeDesc OwningType => _context.GeneratedAssembly.GetGlobalModuleType(); - public override ReadOnlySpan Name => "InitializeReachabilityInfo"u8; + public override Utf8StringRef Name => "InitializeReachabilityInfo"u8; public override string DiagnosticName => "InitializeReachabilityInfo"; public override MethodIL EmitIL() diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/SubstitutedILProvider.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/SubstitutedILProvider.cs index dc4e1c91a49cf9..4c15e385bb0a9e 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/SubstitutedILProvider.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/SubstitutedILProvider.cs @@ -414,8 +414,8 @@ public MethodIL GetMethodILWithInlinedSubstitutions(MethodIL method) { var callee = method.GetObject(reader.ReadILToken(), NotFoundBehavior.ReturnNull) as EcmaMethod; if (callee != null && callee.IsSpecialName && callee.OwningType is EcmaType calleeType - && calleeType.Name.SequenceEqual(InlineableStringsResourceNode.ResourceAccessorTypeName) - && calleeType.Namespace.SequenceEqual(InlineableStringsResourceNode.ResourceAccessorTypeNamespace) + && calleeType.Name == InlineableStringsResourceNode.ResourceAccessorTypeName + && calleeType.Namespace == InlineableStringsResourceNode.ResourceAccessorTypeNamespace && callee.Signature is { Length: 0, IsStatic: true } && callee.Name.StartsWith("get_"u8)) { @@ -822,9 +822,9 @@ private bool TryGetConstantArgument(MethodIL methodIL, byte[] body, OpcodeFlags[ { return true; } - else if (method.IsIntrinsic && (method.Name.SequenceEqual("get_IsValueType"u8) || method.Name.SequenceEqual("get_IsEnum"u8)) + else if (method.IsIntrinsic && (method.Name == "get_IsValueType"u8 || method.Name == "get_IsEnum"u8) && method.OwningType is MetadataType mdt - && mdt.Name.SequenceEqual("Type"u8) && mdt.Namespace.SequenceEqual("System"u8) && mdt.Module == mdt.Context.SystemModule + && mdt.Name == "Type"u8 && mdt.Namespace == "System"u8 && mdt.Module == mdt.Context.SystemModule && TryExpandTypeIs(methodIL, body, flags, currentOffset, method.GetName(), out constant)) { return true; @@ -1133,7 +1133,7 @@ private static bool ReadGetTypeFromHandle(ref ILReader reader, MethodIL methodIL MethodDesc method = (MethodDesc)methodIL.GetObject(reader.ReadILToken()); - if (!method.IsIntrinsic || !method.Name.SequenceEqual("GetTypeFromHandle"u8)) + if (!method.IsIntrinsic || method.Name != "GetTypeFromHandle"u8) return false; if ((flags[reader.Offset] & OpcodeFlags.BasicBlockStart) != 0) diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/SubstitutionProvider.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/SubstitutionProvider.cs index 4b686bcb2528dc..47ff492d2ad94f 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/SubstitutionProvider.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/SubstitutionProvider.cs @@ -73,7 +73,7 @@ private bool TryGetFeatureCheckValue(EcmaMethod method, out bool value) if (featureGuardAttribute.FixedArguments is not [CustomAttributeTypedArgument { Value: EcmaType featureType }]) continue; - if (featureType.Namespace.SequenceEqual("System.Diagnostics.CodeAnalysis"u8)) + if (featureType.Namespace == "System.Diagnostics.CodeAnalysis"u8) { switch (featureType.GetName()) { @@ -135,7 +135,7 @@ public bool HasSubstitutedValue(FieldDesc field) internal string GetResourceStringForAccessor(EcmaMethod method) { Debug.Assert(method.Name.StartsWith("get_"u8)); - string resourceStringName = System.Text.Encoding.UTF8.GetString(method.Name.Slice(4)); + string resourceStringName = System.Text.Encoding.UTF8.GetString(method.Name.AsSpan().Slice(4)); Dictionary dict = _hashtable.GetOrCreateValue(method.Module).InlineableResourceStrings; if (dict != null diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/TypePreinit.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/TypePreinit.cs index 758aa20d33b46f..85a6c845c9a451 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/TypePreinit.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/TypePreinit.cs @@ -1837,8 +1837,8 @@ private static bool TryGetSpanElementType(TypeDesc type, bool isReadOnlySpan, ou if (type.IsByRefLike && type is MetadataType maybeSpan && maybeSpan.Module == type.Context.SystemModule - && ((isReadOnlySpan && maybeSpan.Name.SequenceEqual("ReadOnlySpan`1"u8)) || (!isReadOnlySpan && maybeSpan.Name.SequenceEqual("Span`1"u8))) - && maybeSpan.Namespace.SequenceEqual("System"u8) + && ((isReadOnlySpan && maybeSpan.Name == "ReadOnlySpan`1"u8) || (!isReadOnlySpan && maybeSpan.Name == "Span`1"u8)) + && maybeSpan.Namespace == "System"u8 && maybeSpan.Instantiation[0] is MetadataType readOnlySpanElementType) { elementType = readOnlySpanElementType; @@ -1885,7 +1885,7 @@ private bool TryHandleIntrinsicCall(MethodDesc method, Value[] parameters, out V { case "InitializeArray": if (method.OwningType is MetadataType mdType - && mdType.Name.SequenceEqual("RuntimeHelpers"u8) && mdType.Namespace.SequenceEqual("System.Runtime.CompilerServices"u8) + && mdType.Name == "RuntimeHelpers"u8 && mdType.Namespace == "System.Runtime.CompilerServices"u8 && mdType.Module == mdType.Context.SystemModule && parameters[0] is ArrayInstance array && parameters[1] is RuntimeFieldHandleValue fieldHandle @@ -1898,7 +1898,7 @@ private bool TryHandleIntrinsicCall(MethodDesc method, Value[] parameters, out V return false; case "CreateSpan": if (method.OwningType is MetadataType createSpanType - && createSpanType.Name.SequenceEqual("RuntimeHelpers"u8) && createSpanType.Namespace.SequenceEqual("System.Runtime.CompilerServices"u8) + && createSpanType.Name == "RuntimeHelpers"u8 && createSpanType.Namespace == "System.Runtime.CompilerServices"u8 && createSpanType.Module == createSpanType.Context.SystemModule && parameters[0] is RuntimeFieldHandleValue createSpanFieldHandle && createSpanFieldHandle.Field.IsStatic && createSpanFieldHandle.Field.HasRva @@ -1938,7 +1938,7 @@ private bool TryHandleIntrinsicCall(MethodDesc method, Value[] parameters, out V } case "IsReferenceOrContainsReferences" when method.Instantiation.Length == 1 && method.OwningType is MetadataType isReferenceOrContainsReferencesType - && isReferenceOrContainsReferencesType.Name.SequenceEqual("RuntimeHelpers"u8) && isReferenceOrContainsReferencesType.Namespace.SequenceEqual("System.Runtime.CompilerServices"u8) + && isReferenceOrContainsReferencesType.Name == "RuntimeHelpers"u8 && isReferenceOrContainsReferencesType.Namespace == "System.Runtime.CompilerServices"u8 && isReferenceOrContainsReferencesType.Module == method.Context.SystemModule: { bool result = method.Instantiation[0].IsGCPointer || (method.Instantiation[0] is DefType defType && defType.ContainsGCPointers); @@ -1947,7 +1947,7 @@ private bool TryHandleIntrinsicCall(MethodDesc method, Value[] parameters, out V } case "GetArrayDataReference" when method.Instantiation.Length == 1 && method.OwningType is MetadataType getArrayDataReferenceType - && getArrayDataReferenceType.Name.SequenceEqual("MemoryMarshal"u8) && getArrayDataReferenceType.Namespace.SequenceEqual("System.Runtime.InteropServices"u8) + && getArrayDataReferenceType.Name == "MemoryMarshal"u8 && getArrayDataReferenceType.Namespace == "System.Runtime.InteropServices"u8 && getArrayDataReferenceType.Module == method.Context.SystemModule && parameters[0] is ArrayInstance arrayData && ((ArrayType)arrayData.Type).ElementType == method.Instantiation[0]: @@ -1959,7 +1959,7 @@ private bool TryHandleIntrinsicCall(MethodDesc method, Value[] parameters, out V static bool IsSystemType(TypeDesc type) => type is MetadataType typeType - && typeType.Name.SequenceEqual("Type"u8) && typeType.Namespace.SequenceEqual("System"u8) + && typeType.Name == "Type"u8 && typeType.Namespace == "System"u8 && typeType.Module == typeType.Context.SystemModule; return false; @@ -2434,9 +2434,9 @@ public ComInterfaceEntryArrayValue(TypeDesc type, TypeDesc entryType) private static bool IsComInterfaceEntryType(TypeDesc type) => type is MetadataType mdType - && mdType.Name.SequenceEqual("ComInterfaceEntry"u8) + && mdType.Name == "ComInterfaceEntry"u8 && mdType.ContainingType is MetadataType comWrappersType - && comWrappersType.Name.SequenceEqual("ComWrappers"u8) && comWrappersType.Namespace.SequenceEqual("System.Runtime.InteropServices"u8) + && comWrappersType.Name == "ComWrappers"u8 && comWrappersType.Namespace == "System.Runtime.InteropServices"u8 && comWrappersType.Module == comWrappersType.Context.SystemModule; public static bool IsCompatible(TypeDesc type, out TypeDesc entryType) @@ -2536,14 +2536,14 @@ bool IHasInstanceFields.TrySetField(FieldDesc field, Value value) if (field.OwningType != _parent._entryType) return false; - if (field.Name.SequenceEqual("IID"u8) + if (field.Name == "IID"u8 && value is ValueTypeValue guidValue && guidValue.Size == _parent._guidBytes[_index].Length) { Array.Copy(guidValue.InstanceBytes, _parent._guidBytes[_index], _parent._guidBytes[_index].Length); return true; } - else if (field.Name.SequenceEqual("Vtable"u8) + else if (field.Name == "Vtable"u8 && value is ByRefValueBase byrefValue && byrefValue.BackingField != null) { @@ -2982,7 +2982,7 @@ public bool TrySetField(FieldDesc field, Value value) if (elementType != _value._elementType) return false; - if (field.Name.SequenceEqual("_length"u8)) + if (field.Name == "_length"u8) { _value._length = value.AsInt32() * _value._elementType.InstanceFieldSize.AsInt; return true; @@ -2990,7 +2990,7 @@ public bool TrySetField(FieldDesc field, Value value) if (value is ByRefValue byref) { - Debug.Assert(field.Name.SequenceEqual("_reference"u8)); + Debug.Assert(field.Name == "_reference"u8); _value._bytes = byref.PointedToBytes; _value._index = byref.PointedToOffset; return true; @@ -3009,10 +3009,10 @@ public Value GetField(FieldDesc field) if (elementType != _value._elementType) ThrowHelper.ThrowInvalidProgramException(); - if (field.Name.SequenceEqual("_length"u8)) + if (field.Name == "_length"u8) return ValueTypeValue.FromInt32(_value._length / elementType.InstanceFieldSize.AsInt); - Debug.Assert(field.Name.SequenceEqual("_reference"u8)); + Debug.Assert(field.Name == "_reference"u8); return new ByRefValue(_value._bytes, _value._index); } @@ -3272,7 +3272,7 @@ public void WriteContent(ref ObjectDataBuilder builder, ISymbolNode thisNode, No if (_methodPointed.Signature.IsStatic) { - Debug.Assert(creationInfo.Constructor.Method.Name.SequenceEqual("InitializeOpenStaticThunk"u8)); + Debug.Assert(creationInfo.Constructor.Method.Name == "InitializeOpenStaticThunk"u8); // _firstParameter builder.EmitPointerReloc(thisNode); @@ -3289,7 +3289,7 @@ public void WriteContent(ref ObjectDataBuilder builder, ISymbolNode thisNode, No } else { - Debug.Assert(creationInfo.Constructor.Method.Name.SequenceEqual("InitializeClosedInstance"u8)); + Debug.Assert(creationInfo.Constructor.Method.Name == "InitializeClosedInstance"u8); // _firstParameter _firstParameter.WriteFieldData(ref builder, factory); diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UsageBasedInteropStubManager.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UsageBasedInteropStubManager.cs index 01834179b1f9d3..edae137c83b403 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UsageBasedInteropStubManager.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UsageBasedInteropStubManager.cs @@ -60,7 +60,7 @@ public override void AddMarshalAPIsGenericDependencies(ref DependencyList depend MetadataType metadataType = owningType as MetadataType; if (metadataType != null && metadataType.Module == factory.TypeSystemContext.SystemModule) { - if (metadataType.Name.SequenceEqual("Marshal"u8) && metadataType.Namespace.SequenceEqual("System.Runtime.InteropServices"u8)) + if (metadataType.Name == "Marshal"u8 && metadataType.Namespace == "System.Runtime.InteropServices"u8) { string methodName = method.GetName(); if (methodName == "GetFunctionPointerForDelegate" || diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/VectorOfTFieldLayoutAlgorithm.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/VectorOfTFieldLayoutAlgorithm.cs index e4694484a7bf35..0bb36a84800e56 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/VectorOfTFieldLayoutAlgorithm.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/VectorOfTFieldLayoutAlgorithm.cs @@ -98,7 +98,7 @@ public override bool ComputeIsUnsafeValueType(DefType type) public static bool IsVectorOfTType(DefType type) { - return type.IsIntrinsic && type.Namespace.SequenceEqual("System.Numerics"u8) && type.Name.SequenceEqual("Vector`1"u8); + return type.IsIntrinsic && type.Namespace == "System.Numerics"u8 && type.Name == "Vector`1"u8; } } } diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs index 1ad99261d73798..b1566c75d843e1 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs @@ -3,6 +3,7 @@ using System; +using Internal.Text; using Internal.TypeSystem; using Internal.ReadyToRunConstants; @@ -535,7 +536,7 @@ private void ImportCall(ILOpcode opcode, MethodDesc method, MethodDesc runtimeDe } } - if (method.OwningType.IsDelegate && method.Name.SequenceEqual("Invoke"u8) && + if (method.OwningType.IsDelegate && method.Name == "Invoke"u8 && opcode != ILOpcode.ldftn && opcode != ILOpcode.ldvirtftn) { // This call is expanded as an intrinsic; it's not an actual function call. @@ -630,7 +631,7 @@ private void ImportCall(ILOpcode opcode, MethodDesc method, MethodDesc runtimeDe // null since the virtual method resolves to System.Enum's implementation and that's a reference type. // We can't do this for any other method since ToString and Equals have different semantics for enums // and their underlying type. - if (method.OwningType.IsObject && method.Name.SequenceEqual("GetHashCode"u8)) + if (method.OwningType.IsObject && method.Name == "GetHashCode"u8) { constrained = constrained.UnderlyingType; } @@ -1154,7 +1155,7 @@ private void ImportLdToken(int token) { if (type.IsCanonicalDefinitionType(CanonicalFormKind.Any)) { - Debug.Assert(_methodIL.OwningMethod.Name.SequenceEqual("GetCanonType"u8)); + Debug.Assert(_methodIL.OwningMethod.Name == "GetCanonType"u8); helperId = ReadyToRunHelperId.NecessaryTypeHandle; } @@ -1630,12 +1631,12 @@ private static void ReportInvalidExceptionRegion() private static bool IsTypeGetTypeFromHandle(MethodDesc method) { - if (method.IsIntrinsic && method.Name.SequenceEqual("GetTypeFromHandle"u8)) + if (method.IsIntrinsic && method.Name == "GetTypeFromHandle"u8) { MetadataType owningType = method.OwningType as MetadataType; if (owningType != null) { - return owningType.Name.SequenceEqual("Type"u8) && owningType.Namespace.SequenceEqual("System"u8); + return owningType.Name == "Type"u8 && owningType.Namespace == "System"u8; } } @@ -1644,12 +1645,12 @@ private static bool IsTypeGetTypeFromHandle(MethodDesc method) private static bool IsActivatorDefaultConstructorOf(MethodDesc method) { - if (method.IsIntrinsic && method.Name.SequenceEqual("DefaultConstructorOf"u8) && method.Instantiation.Length == 1) + if (method.IsIntrinsic && method.Name == "DefaultConstructorOf"u8 && method.Instantiation.Length == 1) { MetadataType owningType = method.OwningType as MetadataType; if (owningType != null) { - return owningType.Name.SequenceEqual("Activator"u8) && owningType.Namespace.SequenceEqual("System"u8); + return owningType.Name == "Activator"u8 && owningType.Namespace == "System"u8; } } @@ -1658,12 +1659,12 @@ private static bool IsActivatorDefaultConstructorOf(MethodDesc method) private static bool IsActivatorAllocatorOf(MethodDesc method) { - if (method.IsIntrinsic && method.Name.SequenceEqual("AllocatorOf"u8) && method.Instantiation.Length == 1) + if (method.IsIntrinsic && method.Name == "AllocatorOf"u8 && method.Instantiation.Length == 1) { MetadataType owningType = method.OwningType as MetadataType; if (owningType != null) { - return owningType.Name.SequenceEqual("Activator"u8) && owningType.Namespace.SequenceEqual("System"u8); + return owningType.Name == "Activator"u8 && owningType.Namespace == "System"u8; } } @@ -1672,12 +1673,12 @@ private static bool IsActivatorAllocatorOf(MethodDesc method) private static bool IsEETypePtrOf(MethodDesc method) { - if (method.IsIntrinsic && method.Name.SequenceEqual("Of"u8) && method.Instantiation.Length == 1) + if (method.IsIntrinsic && method.Name == "Of"u8 && method.Instantiation.Length == 1) { MetadataType owningType = method.OwningType as MetadataType; if (owningType != null) { - return owningType.Name.SequenceEqual("MethodTable"u8) && owningType.Namespace.SequenceEqual("Internal.Runtime"u8); + return owningType.Name == "MethodTable"u8 && owningType.Namespace == "Internal.Runtime"u8; } } @@ -1686,12 +1687,12 @@ private static bool IsEETypePtrOf(MethodDesc method) private static bool IsRuntimeHelpersIsReferenceOrContainsReferences(MethodDesc method) { - if (method.IsIntrinsic && method.Name.SequenceEqual("IsReferenceOrContainsReferences"u8) && method.Instantiation.Length == 1) + if (method.IsIntrinsic && method.Name == "IsReferenceOrContainsReferences"u8 && method.Instantiation.Length == 1) { MetadataType owningType = method.OwningType as MetadataType; if (owningType != null) { - return owningType.Name.SequenceEqual("RuntimeHelpers"u8) && owningType.Namespace.SequenceEqual("System.Runtime.CompilerServices"u8); + return owningType.Name == "RuntimeHelpers"u8 && owningType.Namespace == "System.Runtime.CompilerServices"u8; } } @@ -1700,12 +1701,12 @@ private static bool IsRuntimeHelpersIsReferenceOrContainsReferences(MethodDesc m private static bool IsMemoryMarshalGetArrayDataReference(MethodDesc method) { - if (method.IsIntrinsic && method.Name.SequenceEqual("GetArrayDataReference"u8) && method.Instantiation.Length == 1) + if (method.IsIntrinsic && method.Name == "GetArrayDataReference"u8 && method.Instantiation.Length == 1) { MetadataType owningType = method.OwningType as MetadataType; if (owningType != null) { - return owningType.Name.SequenceEqual("MemoryMarshal"u8) && owningType.Namespace.SequenceEqual("System.Runtime.InteropServices"u8); + return owningType.Name == "MemoryMarshal"u8 && owningType.Namespace == "System.Runtime.InteropServices"u8; } } @@ -1714,14 +1715,14 @@ private static bool IsMemoryMarshalGetArrayDataReference(MethodDesc method) private static bool IsAsyncHelpersAwait(MethodDesc method) { - if (method.IsIntrinsic && method.Name.SequenceEqual("Await"u8)) + if (method.IsIntrinsic && method.Name == "Await"u8) { MetadataType owningType = method.OwningType as MetadataType; if (owningType != null) { return owningType.Module == method.Context.SystemModule - && owningType.Name.SequenceEqual("AsyncHelpers"u8) - && owningType.Namespace.SequenceEqual("System.Runtime.CompilerServices"u8); + && owningType.Name == "AsyncHelpers"u8 + && owningType.Namespace == "System.Runtime.CompilerServices"u8; } } @@ -1730,18 +1731,18 @@ private static bool IsAsyncHelpersAwait(MethodDesc method) private static bool IsTaskConfigureAwait(MethodDesc method) { - if (method.IsIntrinsic && method.Name.SequenceEqual("ConfigureAwait"u8)) + if (method.IsIntrinsic && method.Name == "ConfigureAwait"u8) { MetadataType owningType = method.OwningType as MetadataType; if (owningType != null) { - ReadOnlySpan typeName = owningType.Name; + Utf8StringRef typeName = owningType.Name; return owningType.Module == method.Context.SystemModule - && owningType.Namespace.SequenceEqual("System.Threading.Tasks"u8) - && (typeName.SequenceEqual("Task"u8) - || typeName.SequenceEqual("Task`1"u8) - || typeName.SequenceEqual("ValueTask"u8) - || typeName.SequenceEqual("ValueTask`1"u8)); + && owningType.Namespace == "System.Threading.Tasks"u8 + && (typeName == "Task"u8 + || typeName == "Task`1"u8 + || typeName == "ValueTask"u8 + || typeName == "ValueTask`1"u8); } } diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/NativeLibraryStartupMethod.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/NativeLibraryStartupMethod.cs index 949ce0597b8ec6..5c47b2f98a226e 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/NativeLibraryStartupMethod.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/NativeLibraryStartupMethod.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; +using Internal.Text; using Internal.TypeSystem; namespace Internal.IL.Stubs.StartupCode @@ -40,7 +41,7 @@ public override TypeDesc OwningType } } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/StartupCodeMainMethod.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/StartupCodeMainMethod.cs index b74ec0b0814e5b..ba89f9fd47ba7d 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/StartupCodeMainMethod.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/StartupCodeMainMethod.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; +using Internal.Text; using Internal.TypeSystem; using Debug = System.Diagnostics.Debug; @@ -45,7 +46,7 @@ public override TypeDesc OwningType } } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { @@ -230,7 +231,7 @@ public override TypeDesc OwningType get; } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/TypeEqualityPatternAnalyzer.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/TypeEqualityPatternAnalyzer.cs index 31580e6e80ee9c..436a8a746ff613 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/TypeEqualityPatternAnalyzer.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/TypeEqualityPatternAnalyzer.cs @@ -141,26 +141,26 @@ public void Advance(ILOpcode opcode, in ILReader reader, MethodIL methodIL) } static bool IsSystemType(TypeDesc t) - => t is MetadataType mdType && mdType.Name.SequenceEqual("Type"u8) && mdType.Namespace.SequenceEqual("System"u8); + => t is MetadataType mdType && mdType.Name == "Type"u8 && mdType.Namespace == "System"u8; static bool IsTypeGetTypeFromHandle(ILOpcode opcode, in ILReader reader, MethodIL methodIL) => opcode == ILOpcode.call && methodIL.GetObject(reader.PeekILToken()) is MethodDesc method - && method.IsIntrinsic && method.Name.SequenceEqual("GetTypeFromHandle"u8) + && method.IsIntrinsic && method.Name == "GetTypeFromHandle"u8 && IsSystemType(method.OwningType); static bool IsTypeEquals(ILOpcode opcode, in ILReader reader, MethodIL methodIL) => opcode == ILOpcode.call && methodIL.GetObject(reader.PeekILToken()) is MethodDesc method - && method.IsIntrinsic && method.Name.SequenceEqual("op_Equality"u8) + && method.IsIntrinsic && method.Name == "op_Equality"u8 && IsSystemType(method.OwningType); static bool IsTypeInequals(ILOpcode opcode, in ILReader reader, MethodIL methodIL) => opcode == ILOpcode.call && methodIL.GetObject(reader.PeekILToken()) is MethodDesc method - && method.IsIntrinsic && method.Name.SequenceEqual("op_Inequality"u8) + && method.IsIntrinsic && method.Name == "op_Inequality"u8 && IsSystemType(method.OwningType); static bool IsObjectGetType(ILOpcode opcode, in ILReader reader, MethodIL methodIL) => opcode is ILOpcode.call or ILOpcode.callvirt && methodIL.GetObject(reader.PeekILToken()) is MethodDesc method - && method.IsIntrinsic && method.Name.SequenceEqual("GetType"u8) && method.OwningType.IsObject; + && method.IsIntrinsic && method.Name == "GetType"u8 && method.OwningType.IsObject; static bool IsArgumentOrLocalLoad(ILOpcode opcode) => opcode is (>= ILOpcode.ldloc_0 and <= ILOpcode.ldloc_3) or (>= ILOpcode.ldarg_0 and <= ILOpcode.ldarg_3) diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/ILCompiler.Compiler.csproj b/src/coreclr/tools/aot/ILCompiler.Compiler/ILCompiler.Compiler.csproj index ed7c03a4d32171..6e9d8b30c17f8d 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/ILCompiler.Compiler.csproj +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/ILCompiler.Compiler.csproj @@ -84,6 +84,9 @@ TypeSystem\Common\VersionResilientHashCode.cs + + TypeSystem\Common\VersionResilientHashCode.TypeSystem.cs + diff --git a/src/coreclr/tools/aot/ILCompiler.MetadataTransform/ILCompiler/Metadata/Transform.CustomAttribute.cs b/src/coreclr/tools/aot/ILCompiler.MetadataTransform/ILCompiler/Metadata/Transform.CustomAttribute.cs index 1469a42950de64..ee7e303ef41b7a 100644 --- a/src/coreclr/tools/aot/ILCompiler.MetadataTransform/ILCompiler/Metadata/Transform.CustomAttribute.cs +++ b/src/coreclr/tools/aot/ILCompiler.MetadataTransform/ILCompiler/Metadata/Transform.CustomAttribute.cs @@ -99,7 +99,7 @@ private static Ecma.SerializationTypeCode TypeDescToSerializationTypeCode(Cts.Ty return Ecma.SerializationTypeCode.String; if (type is not Cts.MetadataType mdType - || !mdType.Name.SequenceEqual("Type"u8) || !mdType.Namespace.SequenceEqual("System"u8)) + || mdType.Name != "Type"u8 || mdType.Namespace != "System"u8) throw new UnreachableException(); return Ecma.SerializationTypeCode.Type; diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/TypeValidationChecker.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/TypeValidationChecker.cs index 649c1e48f6c893..0962855a091fee 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/TypeValidationChecker.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/TypeValidationChecker.cs @@ -228,7 +228,7 @@ Task ValidateTypeWorkerHelper(TypeDesc typeToCheckForSkipValidation) { if (methodDef.Attributes.HasFlag(MethodAttributes.RTSpecialName)) { - if (!method.Name.SequenceEqual(".cctor"u8) && !method.Name.StartsWith("_VtblGap"u8)) + if (method.Name != ".cctor"u8 && !method.Name.StartsWith("_VtblGap"u8)) { AddTypeValidationError(type, $"Special name method {method} defined on interface"); return false; diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ProfileDataManager.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ProfileDataManager.cs index 492ef797360ded..cf1d8b49582057 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ProfileDataManager.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ProfileDataManager.cs @@ -202,7 +202,7 @@ private PgoSchemaElem[] SynthesizeSchema(Compilation comp, MethodDesc method) if (targetMeth.Signature.IsStatic || !targetMeth.IsTypicalMethodDefinition) continue; - bool isDelegateInvoke = targetMeth.OwningType.IsDelegate && targetMeth.Name.SequenceEqual("Invoke"u8); + bool isDelegateInvoke = targetMeth.OwningType.IsDelegate && targetMeth.Name == "Invoke"u8; if (opcode != ILOpcode.callvirt && !isDelegateInvoke) continue; diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCompilerContext.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCompilerContext.cs index 0a882fadd65ffa..568488eda1f9ec 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCompilerContext.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCompilerContext.cs @@ -342,7 +342,7 @@ public override ValueTypeShapeCharacteristics ComputeValueTypeShapeCharacteristi public static bool IsVectorOfTType(DefType type) { - return type.IsIntrinsic && type.Namespace.SequenceEqual("System.Numerics"u8) && type.Name.SequenceEqual("Vector`1"u8); + return type.IsIntrinsic && type.Namespace == "System.Numerics"u8 && type.Name == "Vector`1"u8; } } } diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/RuntimeDeterminedTypeHelper.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/RuntimeDeterminedTypeHelper.cs index b13a190754d917..4a0714bf1e5e82 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/RuntimeDeterminedTypeHelper.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/RuntimeDeterminedTypeHelper.cs @@ -142,7 +142,7 @@ public static bool Equals(FieldDesc field1, FieldDesc field2) { return field1 == null && field2 == null; } - return field1.Name.SequenceEqual(field2.Name) && + return field1.Name == field2.Name && RuntimeDeterminedTypeHelper.Equals(field1.OwningType, field2.OwningType) && RuntimeDeterminedTypeHelper.Equals(field1.FieldType, field2.FieldType); } diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/IBC/IBCProfileParser.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/IBC/IBCProfileParser.cs index 3962a9ef3f3d35..292ba153cc4a5d 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/IBC/IBCProfileParser.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/IBC/IBCProfileParser.cs @@ -410,7 +410,7 @@ private uint LookupIbcMethodToken(MetadataType methodMetadataType, uint ibcToken foreach (MethodDesc method in ecmaType.GetMethods()) { - if (method.Name.SequenceEqual(methodName)) + if (method.Name == methodName) { EcmaMethod ecmaCandidateMethod = method as EcmaMethod; if (ecmaCandidateMethod == null) diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/IBC/MIbcProfileParser.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/IBC/MIbcProfileParser.cs index 2f186d3ebaa19b..a6da7e323eee8e 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/IBC/MIbcProfileParser.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/IBC/MIbcProfileParser.cs @@ -7,10 +7,11 @@ using System.Reflection.Metadata; using System.Text; -using Internal.TypeSystem; -using Internal.TypeSystem.Ecma; using Internal.IL; using Internal.Pgo; +using Internal.Text; +using Internal.TypeSystem; +using Internal.TypeSystem.Ecma; using System.Linq; using System.IO; @@ -621,7 +622,7 @@ private sealed class CustomCanonResolver : IModuleResolver { private sealed class CanonModule : ModuleDesc, IAssemblyDesc { - public ReadOnlySpan Name => "System.Private.Canon"u8; + public Utf8StringRef Name => "System.Private.Canon"u8; public CanonModule(TypeSystemContext wrappedContext) : base(wrappedContext, null) { @@ -637,19 +638,19 @@ public override MetadataType GetGlobalModuleType() throw new NotImplementedException(); } - public override object GetType(ReadOnlySpan nameSpace, ReadOnlySpan name, NotFoundBehavior notFoundBehavior) + public override object GetType(Utf8StringRef nameSpace, Utf8StringRef name, NotFoundBehavior notFoundBehavior) { TypeSystemContext context = Context; - if (context.SupportsCanon && nameSpace.SequenceEqual(context.CanonType.Namespace) && name.SequenceEqual(context.CanonType.Name)) + if (context.SupportsCanon && nameSpace == context.CanonType.Namespace && name == context.CanonType.Name) return Context.CanonType; - if (context.SupportsUniversalCanon && nameSpace.SequenceEqual(context.UniversalCanonType.Namespace) && name.SequenceEqual(context.UniversalCanonType.Name)) + if (context.SupportsUniversalCanon && nameSpace == context.UniversalCanonType.Namespace && name == context.UniversalCanonType.Name) return Context.UniversalCanonType; else { if (notFoundBehavior != NotFoundBehavior.ReturnNull) { - var failure = ResolutionFailure.GetTypeLoadResolutionFailure(Encoding.UTF8.GetString(nameSpace), Encoding.UTF8.GetString(name), "System.Private.Canon"); + var failure = ResolutionFailure.GetTypeLoadResolutionFailure(Encoding.UTF8.GetString(nameSpace.AsSpan()), Encoding.UTF8.GetString(name.AsSpan()), "System.Private.Canon"); if (notFoundBehavior == NotFoundBehavior.Throw) failure.Throw(); diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/IL/ReadyToRunILProvider.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/IL/ReadyToRunILProvider.cs index 961c634100caa5..126e44cebafb3f 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/IL/ReadyToRunILProvider.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/IL/ReadyToRunILProvider.cs @@ -52,7 +52,7 @@ private MethodIL TryGetIntrinsicMethodILForActivator(MethodDesc method) { if (method.Instantiation.Length == 1 && method.Signature.Length == 0 - && method.Name.SequenceEqual("CreateInstance"u8)) + && method.Name == "CreateInstance"u8) { TypeDesc type = method.Instantiation[0]; if (type.IsValueType && type.GetParameterlessConstructor() == null) @@ -77,17 +77,17 @@ private MethodIL TryGetIntrinsicMethodIL(MethodDesc method) if (mdType == null) return null; - if (mdType.Name.SequenceEqual("RuntimeHelpers"u8) && mdType.Namespace.SequenceEqual("System.Runtime.CompilerServices"u8)) + if (mdType.Name == "RuntimeHelpers"u8 && mdType.Namespace == "System.Runtime.CompilerServices"u8) { return RuntimeHelpersIntrinsics.EmitIL(method); } - if (mdType.Name.SequenceEqual("Unsafe"u8) && mdType.Namespace.SequenceEqual("System.Runtime.CompilerServices"u8)) + if (mdType.Name == "Unsafe"u8 && mdType.Namespace == "System.Runtime.CompilerServices"u8) { return UnsafeIntrinsics.EmitIL(method); } - if (mdType.Name.SequenceEqual("InstanceCalliHelper"u8) && mdType.Namespace.SequenceEqual("System.Reflection"u8)) + if (mdType.Name == "InstanceCalliHelper"u8 && mdType.Namespace == "System.Reflection"u8) { return InstanceCalliHelperIntrinsics.EmitIL(method); } @@ -106,31 +106,31 @@ private MethodIL TryGetPerInstantiationIntrinsicMethodIL(MethodDesc method) if (mdType == null) return null; - if (mdType.Name.SequenceEqual("RuntimeHelpers"u8) && mdType.Namespace.SequenceEqual("System.Runtime.CompilerServices"u8)) + if (mdType.Name == "RuntimeHelpers"u8 && mdType.Namespace == "System.Runtime.CompilerServices"u8) { return RuntimeHelpersIntrinsics.EmitIL(method); } - if (mdType.Name.SequenceEqual("Activator"u8) && mdType.Namespace.SequenceEqual("System"u8)) + if (mdType.Name == "Activator"u8 && mdType.Namespace == "System"u8) { return TryGetIntrinsicMethodILForActivator(method); } - if (mdType.Name.SequenceEqual("Interlocked"u8) && mdType.Namespace.SequenceEqual("System.Threading"u8)) + if (mdType.Name == "Interlocked"u8 && mdType.Namespace == "System.Threading"u8) { return InterlockedIntrinsics.EmitIL(_compilationModuleGroup, method); } - if (mdType.Namespace.SequenceEqual("System.Collections.Generic"u8)) + if (mdType.Namespace == "System.Collections.Generic"u8) { - if (mdType.Name.SequenceEqual("Comparer`1"u8)) + if (mdType.Name == "Comparer`1"u8) { - if (method.Name.SequenceEqual("Create"u8)) + if (method.Name == "Create"u8) return ComparerIntrinsics.EmitComparerCreate(method); } - else if (mdType.Name.SequenceEqual("EqualityComparer`1"u8)) + else if (mdType.Name == "EqualityComparer`1"u8) { - if (method.Name.SequenceEqual("Create"u8)) + if (method.Name == "Create"u8) return ComparerIntrinsics.EmitEqualityComparerCreate(method); } } diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs index 8c4af968d66747..83a77be52ebb62 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs @@ -576,9 +576,9 @@ public static bool ShouldSkipCompilation(InstructionSetSupport instructionSetSup } if (methodNeedingCode.OwningType.IsDelegate && ( methodNeedingCode.IsConstructor || - methodNeedingCode.Name.SequenceEqual("BeginInvoke"u8) || - methodNeedingCode.Name.SequenceEqual("Invoke"u8) || - methodNeedingCode.Name.SequenceEqual("EndInvoke"u8))) + methodNeedingCode.Name == "BeginInvoke"u8 || + methodNeedingCode.Name == "Invoke"u8 || + methodNeedingCode.Name == "EndInvoke"u8)) { // Special methods on delegate types return true; @@ -2041,7 +2041,7 @@ private void ceeInfoGetCallInfo( // JIT compilation, and require a runtime lookup for the actual code pointer // to call. - if (constrainedType.IsEnum && originalMethod.Name.SequenceEqual("GetHashCode"u8)) + if (constrainedType.IsEnum && originalMethod.Name == "GetHashCode"u8) { MethodDesc methodOnUnderlyingType = constrainedType.UnderlyingType.FindVirtualFunctionTargetMethodOnObjectType(originalMethod); Debug.Assert(methodOnUnderlyingType != null); @@ -2209,8 +2209,8 @@ private void ceeInfoGetCallInfo( // 2) Delegate.Invoke() - since a Delegate is a sealed class as per ECMA spec // 3) JIT intrinsics - since they have pre-defined behavior devirt = targetMethod.OwningType.IsValueType || - (targetMethod.OwningType.IsDelegate && targetMethod.Name.SequenceEqual("Invoke"u8)) || - (targetMethod.OwningType.IsObject && targetMethod.Name.SequenceEqual("GetType"u8)); + (targetMethod.OwningType.IsDelegate && targetMethod.Name == "Invoke"u8) || + (targetMethod.OwningType.IsObject && targetMethod.Name == "GetType"u8); callVirtCrossingVersionBubble = true; } diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/TypeSystem/Mutable/MutableModule.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/TypeSystem/Mutable/MutableModule.cs index e571ed1d8b3ddc..db33d058a4c98a 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/TypeSystem/Mutable/MutableModule.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/TypeSystem/Mutable/MutableModule.cs @@ -11,6 +11,7 @@ using System.IO; using ILCompiler; +using Internal.Text; using System.Runtime.CompilerServices; namespace Internal.TypeSystem.Ecma @@ -403,7 +404,7 @@ public string GetUserString(UserStringHandle handle) } throw new ArgumentException("Invalid UserStringHandle passed to MutableModule.GetObject"); } - public override object GetType(ReadOnlySpan nameSpace, ReadOnlySpan name, NotFoundBehavior notFoundBehavior) => throw new NotImplementedException(); + public override object GetType(Utf8StringRef nameSpace, Utf8StringRef name, NotFoundBehavior notFoundBehavior) => throw new NotImplementedException(); public TypeDesc GetType(EntityHandle handle) { TypeDesc type = GetObject(handle, NotFoundBehavior.Throw) as TypeDesc; diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs index 6c22da04d78a90..86a63a64bce39a 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs @@ -1259,7 +1259,7 @@ private void getCallInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_RESO // null since the virtual method resolves to System.Enum's implementation and that's a reference type. // We can't do this for any other method since ToString and Equals have different semantics for enums // and their underlying type. - if (method.OwningType.IsObject && method.Name.SequenceEqual("GetHashCode"u8)) + if (method.OwningType.IsObject && method.Name == "GetHashCode"u8) { constrainedType = constrainedType.UnderlyingType; } diff --git a/src/coreclr/tools/aot/ILCompiler.Trimming.Tests/TestCasesRunner/MemberAssertionsCollector.cs b/src/coreclr/tools/aot/ILCompiler.Trimming.Tests/TestCasesRunner/MemberAssertionsCollector.cs index 7716fbf5674bed..fc610efaab1e0c 100644 --- a/src/coreclr/tools/aot/ILCompiler.Trimming.Tests/TestCasesRunner/MemberAssertionsCollector.cs +++ b/src/coreclr/tools/aot/ILCompiler.Trimming.Tests/TestCasesRunner/MemberAssertionsCollector.cs @@ -80,7 +80,7 @@ private static bool IsMemberAssertion(MetadataType attributeType) if (attributeType == null) return false; - if (!attributeType.Namespace.SequenceEqual("Mono.Linker.Tests.Cases.Expectations.Assertions"u8)) + if (attributeType.Namespace != "Mono.Linker.Tests.Cases.Expectations.Assertions"u8) return false; MetadataType t = attributeType; diff --git a/src/coreclr/tools/aot/ILCompiler.TypeSystem.Tests/SyntheticVirtualOverrideTests.cs b/src/coreclr/tools/aot/ILCompiler.TypeSystem.Tests/SyntheticVirtualOverrideTests.cs index 1880bbcd6606d3..f42f5998e2fe7a 100644 --- a/src/coreclr/tools/aot/ILCompiler.TypeSystem.Tests/SyntheticVirtualOverrideTests.cs +++ b/src/coreclr/tools/aot/ILCompiler.TypeSystem.Tests/SyntheticVirtualOverrideTests.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; +using Internal.Text; using Internal.TypeSystem; using Xunit; @@ -143,8 +144,8 @@ protected override IEnumerable GetAllMethods(TypeDesc type) { MetadataType mdType = type as MetadataType; - if (mdType.Name.SequenceEqual("StructWithNoEqualsAndGetHashCode"u8) - || mdType.Name.SequenceEqual("ClassWithInjectedEqualsAndGetHashCode"u8)) + if (mdType.Name == "StructWithNoEqualsAndGetHashCode"u8 + || mdType.Name == "ClassWithInjectedEqualsAndGetHashCode"u8) { yield return GetEqualsMethod(type); yield return GetGetHashCodeMethod(type); @@ -158,8 +159,8 @@ protected override IEnumerable GetAllVirtualMethods(TypeDesc type) { MetadataType mdType = type as MetadataType; - if (mdType.Name.SequenceEqual("StructWithNoEqualsAndGetHashCode"u8) - || mdType.Name.SequenceEqual("ClassWithInjectedEqualsAndGetHashCode"u8)) + if (mdType.Name == "StructWithNoEqualsAndGetHashCode"u8 + || mdType.Name == "ClassWithInjectedEqualsAndGetHashCode"u8) { yield return GetEqualsMethod(type); yield return GetGetHashCodeMethod(type); @@ -212,7 +213,7 @@ public override TypeSystemContext Context } } - public override ReadOnlySpan Name + public override Utf8StringRef Name { get { diff --git a/src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj b/src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj index 279b463b2c7594..d13348936719f0 100644 --- a/src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj +++ b/src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj @@ -35,6 +35,9 @@ TypeSystem\Common\VersionResilientHashCode.cs + + Common\Utf8StringRef.cs + TypeSystem\Common\ArrayMethod.Diagnostic.cs diff --git a/src/coreclr/tools/aot/crossgen2/Program.cs b/src/coreclr/tools/aot/crossgen2/Program.cs index c3e794dc8dfeeb..45a094d1e1da7d 100644 --- a/src/coreclr/tools/aot/crossgen2/Program.cs +++ b/src/coreclr/tools/aot/crossgen2/Program.cs @@ -818,7 +818,7 @@ internal static string CreateReproArgumentString(MethodDesc method) int curIndex = 0; foreach (var searchMethod in method.OwningType.GetMethods()) { - if (!searchMethod.Name.SequenceEqual(method.Name)) + if (searchMethod.Name != method.Name) continue; curIndex++; diff --git a/src/coreclr/tools/dotnet-pgo/TraceRuntimeDescToTypeSystemDesc.cs b/src/coreclr/tools/dotnet-pgo/TraceRuntimeDescToTypeSystemDesc.cs index c1a0e142e8c8d0..dfd3b27a887960 100644 --- a/src/coreclr/tools/dotnet-pgo/TraceRuntimeDescToTypeSystemDesc.cs +++ b/src/coreclr/tools/dotnet-pgo/TraceRuntimeDescToTypeSystemDesc.cs @@ -437,7 +437,7 @@ public TypeDesc ResolveTypeHandle(long handle, ref bool dependsOnKnownNonLoadabl } else { - if ((uninstantiatedType.Name.SequenceEqual("__Canon"u8)) && uninstantiatedType.Namespace.SequenceEqual("System"u8) && (uninstantiatedType.Module == uninstantiatedType.Context.SystemModule)) + if ((uninstantiatedType.Name == "__Canon"u8) && uninstantiatedType.Namespace == "System"u8 && (uninstantiatedType.Module == uninstantiatedType.Context.SystemModule)) { tinfo.Type = uninstantiatedType.Context.CanonType; } diff --git a/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemField.cs b/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemField.cs index d551c1eafcc2ed..9dc7d987bbc1e8 100644 --- a/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemField.cs +++ b/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemField.cs @@ -6,6 +6,8 @@ using System.Linq; using System.Text; using System.Threading.Tasks; + +using Internal.Text; using Internal.TypeSystem; namespace Microsoft.Diagnostics.Tools.Pgo.TypeRefTypeSystem @@ -25,7 +27,7 @@ public TypeRefTypeSystemField(TypeRefTypeSystemType type, ReadOnlySpan nam _embeddedSignatureData = embeddedSigData; } - public override ReadOnlySpan Name => _name; + public override Utf8StringRef Name => _name; public override MetadataType OwningType => _type; public override TypeDesc FieldType => _fieldType; diff --git a/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemMethod.cs b/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemMethod.cs index 7812746900155c..1f84ca41dfe7d5 100644 --- a/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemMethod.cs +++ b/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemMethod.cs @@ -6,6 +6,8 @@ using System.Linq; using System.Text; using System.Threading.Tasks; + +using Internal.Text; using Internal.TypeSystem; namespace Microsoft.Diagnostics.Tools.Pgo.TypeRefTypeSystem @@ -37,7 +39,7 @@ public TypeRefTypeSystemMethod(TypeRefTypeSystemType type, ReadOnlySpan na } } - public override ReadOnlySpan Name => _name; + public override Utf8StringRef Name => _name; public override Instantiation Instantiation => _instantiation; diff --git a/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemModule.cs b/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemModule.cs index 33cd22881c6bc6..959bb9110518ce 100644 --- a/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemModule.cs +++ b/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemModule.cs @@ -7,6 +7,8 @@ using System.Reflection.Metadata; using System.Text; using System.Threading.Tasks; + +using Internal.Text; using Internal.TypeSystem; namespace Microsoft.Diagnostics.Tools.Pgo.TypeRefTypeSystem @@ -49,7 +51,7 @@ public TypeRefTypeSystemType GetOrAddType(string nameSpace, string name) public override IAssemblyDesc Assembly => this; - public ReadOnlySpan Name => System.Text.Encoding.UTF8.GetBytes(_name.Name); + public Utf8StringRef Name => System.Text.Encoding.UTF8.GetBytes(_name.Name); public override IEnumerable GetAllTypes() => _types; public override MetadataType GetGlobalModuleType() => throw new NotImplementedException(); @@ -73,10 +75,10 @@ private TypeRefTypeSystemType GetTypeInternal(string nameSpace, string name) return type; } - public override object GetType(ReadOnlySpan nameSpace, ReadOnlySpan name, NotFoundBehavior notFoundBehavior) + public override object GetType(Utf8StringRef nameSpace, Utf8StringRef name, NotFoundBehavior notFoundBehavior) { - string strns = Encoding.UTF8.GetString(nameSpace); - string strname = Encoding.UTF8.GetString(name); + string strns = Encoding.UTF8.GetString(nameSpace.AsSpan()); + string strname = Encoding.UTF8.GetString(name.AsSpan()); MetadataType type = GetTypeInternal(strns, strname); if ((type == null) && notFoundBehavior != NotFoundBehavior.ReturnNull) { diff --git a/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemType.cs b/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemType.cs index 1ba1bf0762923f..c4c4b3b216e237 100644 --- a/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemType.cs +++ b/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemType.cs @@ -7,6 +7,8 @@ using System.Linq; using System.Text; using System.Threading.Tasks; + +using Internal.Text; using Internal.TypeSystem; namespace Microsoft.Diagnostics.Tools.Pgo.TypeRefTypeSystem @@ -140,9 +142,9 @@ public FieldDesc GetOrAddField(ReadOnlySpan name, TypeDesc fieldType, Embe public override PInvokeStringFormat PInvokeStringFormat => throw new NotImplementedException(); - public override ReadOnlySpan Name => _name; + public override Utf8StringRef Name => _name; - public override ReadOnlySpan Namespace => _namespace; + public override Utf8StringRef Namespace => _namespace; public override bool IsExplicitLayout => throw new NotImplementedException(); @@ -184,23 +186,23 @@ public override MetadataType BaseType protected override int ClassCode => throw new NotImplementedException(); - public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(ReadOnlySpan name) => throw new NotImplementedException(); + public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8StringRef name) => throw new NotImplementedException(); public override ClassLayoutMetadata GetClassLayout() => throw new NotImplementedException(); public override int GetHashCode() { var hash = new HashCode(); - hash.AddBytes(Namespace); - hash.AddBytes(Name); + hash.AddBytes(Namespace.AsSpan()); + hash.AddBytes(Name.AsSpan()); hash.Add(Module); return hash.ToHashCode(); } - public override MetadataType GetNestedType(ReadOnlySpan name) + public override MetadataType GetNestedType(Utf8StringRef name) { TypeRefTypeSystemType type = null; if (_nestedType != null) { - _nestedType.TryGetValue(Encoding.UTF8.GetString(name), out type); + _nestedType.TryGetValue(Encoding.UTF8.GetString(name.AsSpan()), out type); } return type; } From 2261b4cfd5ed1386bf7050ef158faeef8f2d0668 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Fri, 5 Jun 2026 14:37:00 +0900 Subject: [PATCH 2/2] Rename Utf8StringRef to Utf8Span Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Internal/TypeSystem/RuntimeMethodDesc.cs | 2 +- .../src/System.Private.TypeLoader.csproj | 4 ++-- .../Common/Compiler/AsyncContinuationType.cs | 8 ++++---- .../tools/Common/Compiler/MethodExtensions.cs | 2 +- .../Common/Compiler/NativeAotNameMangler.cs | 4 ++-- .../tools/Common/Compiler/TypeMapMetadata.cs | 2 +- .../Text/{Utf8StringRef.cs => Utf8Span.cs} | 14 +++++++------- .../tools/Common/Internal/Text/Utf8String.cs | 2 +- .../Common/Internal/Text/Utf8StringBuilder.cs | 2 +- .../tools/Common/JitInterface/CorInfoImpl.cs | 10 +++++----- .../TypeSystem/Canon/CanonTypes.Metadata.cs | 4 ++-- .../Common/TypeSystem/Canon/CanonTypes.cs | 8 ++++---- .../Common/TypeSystem/Common/ArrayType.cs | 2 +- .../tools/Common/TypeSystem/Common/DefType.cs | 4 ++-- .../Common/TypeSystem/Common/FieldDesc.cs | 2 +- .../Common/FieldForInstantiatedType.cs | 2 +- .../Common/TypeSystem/Common/IAssemblyDesc.cs | 2 +- .../Common/ImpliedRepeatedFieldDesc.cs | 2 +- .../TypeSystem/Common/InstantiatedMethod.cs | 2 +- .../Common/InstantiatedType.Metadata.cs | 2 +- .../Common/InstantiatedType.MethodImpls.cs | 2 +- .../TypeSystem/Common/InstantiatedType.cs | 10 +++++----- .../Common/MetadataType.MethodImpls.cs | 2 +- .../Common/TypeSystem/Common/MetadataType.cs | 6 +++--- .../Common/MetadataVirtualMethodAlgorithm.cs | 2 +- .../TypeSystem/Common/MethodDelegator.cs | 2 +- .../Common/TypeSystem/Common/MethodDesc.cs | 2 +- .../Common/MethodForInstantiatedType.cs | 2 +- .../Common/TypeSystem/Common/ModuleDesc.cs | 4 ++-- .../tools/Common/TypeSystem/Common/TypeDesc.cs | 8 ++++---- .../TypeSystem/Common/TypeSystemHelpers.cs | 8 ++++---- .../Common/TypeWithRepeatedFields.cs | 8 ++++---- .../VersionResilientHashCode.TypeSystem.cs | 4 ++-- .../Common/TypeSystem/Ecma/EcmaAssembly.cs | 2 +- .../tools/Common/TypeSystem/Ecma/EcmaField.cs | 2 +- .../tools/Common/TypeSystem/Ecma/EcmaMethod.cs | 2 +- .../tools/Common/TypeSystem/Ecma/EcmaModule.cs | 6 +++--- .../TypeSystem/Ecma/EcmaType.MethodImpls.cs | 2 +- .../tools/Common/TypeSystem/Ecma/EcmaType.cs | 18 +++++++++--------- .../TypeSystem/Ecma/MetadataExtensions.cs | 2 +- .../AssemblyGetExecutingAssemblyMethodThunk.cs | 2 +- .../TypeSystem/IL/Stubs/AsyncResumptionStub.cs | 2 +- .../CalliMarshallingMethodThunk.Mangling.cs | 2 +- .../IL/Stubs/CalliMarshallingMethodThunk.cs | 2 +- .../IL/Stubs/DelegateMarshallingMethodThunk.cs | 4 ++-- .../TypeSystem/IL/Stubs/DelegateThunks.cs | 14 +++++++------- .../IL/Stubs/DynamicInvokeMethodThunk.cs | 2 +- .../IL/Stubs/ForwardDelegateCreationThunk.cs | 2 +- .../IL/Stubs/GetFieldHelperMethodOverride.cs | 2 +- .../Stubs/MethodBaseGetCurrentMethodThunk.cs | 2 +- .../IL/Stubs/PInvokeLazyFixupField.cs | 2 +- .../IL/Stubs/PInvokeTargetNativeMethod.cs | 2 +- .../IL/Stubs/StructMarshallingThunk.cs | 4 ++-- .../IL/Stubs/TypeGetTypeMethodThunk.cs | 2 +- .../TypeSystem/Interop/IL/InlineArrayType.cs | 14 +++++++------- .../TypeSystem/Interop/IL/NativeStructType.cs | 10 +++++----- .../Interop/IL/PInvokeDelegateWrapper.cs | 8 ++++---- .../IL/PInvokeDelegateWrapperConstructor.cs | 2 +- .../MethodForRuntimeDeterminedType.cs | 2 +- .../RuntimeDetermined/RuntimeDeterminedType.cs | 10 +++++----- .../ILVerification/ILVerification.projitems | 4 ++-- .../CompilerTypeSystemContext.BoxedTypes.cs | 14 +++++++------- ...pilerTypeSystemContext.GeneratedAssembly.cs | 12 ++++++------ ...ompilerTypeSystemContext.InterfaceThunks.cs | 2 +- .../Compiler/ExternSymbolMappedField.cs | 2 +- .../ReachabilityInstrumentationProvider.cs | 2 +- .../IL/ILImporter.Scanner.cs | 2 +- .../StartupCode/NativeLibraryStartupMethod.cs | 2 +- .../Stubs/StartupCode/StartupCodeMainMethod.cs | 4 ++-- .../IBC/MIbcProfileParser.cs | 4 ++-- .../TypeSystem/Mutable/MutableModule.cs | 2 +- .../SyntheticVirtualOverrideTests.cs | 2 +- .../ILCompiler.TypeSystem.csproj | 4 ++-- .../TypeRefTypeSystemField.cs | 2 +- .../TypeRefTypeSystemMethod.cs | 2 +- .../TypeRefTypeSystemModule.cs | 4 ++-- .../TypeRefTypeSystem/TypeRefTypeSystemType.cs | 8 ++++---- 77 files changed, 168 insertions(+), 168 deletions(-) rename src/coreclr/tools/Common/Internal/Text/{Utf8StringRef.cs => Utf8Span.cs} (75%) diff --git a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/TypeSystem/RuntimeMethodDesc.cs b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/TypeSystem/RuntimeMethodDesc.cs index 40709a6c2b72eb..29ea55ec5aa039 100644 --- a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/TypeSystem/RuntimeMethodDesc.cs +++ b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/TypeSystem/RuntimeMethodDesc.cs @@ -92,7 +92,7 @@ public override MethodNameAndSignature NameAndSignature } } - public override Utf8StringRef Name + public override Utf8Span Name { get { diff --git a/src/coreclr/nativeaot/System.Private.TypeLoader/src/System.Private.TypeLoader.csproj b/src/coreclr/nativeaot/System.Private.TypeLoader/src/System.Private.TypeLoader.csproj index 198b9448292e19..6158a89613fec4 100644 --- a/src/coreclr/nativeaot/System.Private.TypeLoader/src/System.Private.TypeLoader.csproj +++ b/src/coreclr/nativeaot/System.Private.TypeLoader/src/System.Private.TypeLoader.csproj @@ -54,8 +54,8 @@ IntrinsicAttribute.cs - - Internal\Text\Utf8StringRef.cs + + Internal\Text\Utf8Span.cs Internal\TypeSystem\ArrayType.Canon.cs diff --git a/src/coreclr/tools/Common/Compiler/AsyncContinuationType.cs b/src/coreclr/tools/Common/Compiler/AsyncContinuationType.cs index 33bcc0b4deb29d..4e19c264d98447 100644 --- a/src/coreclr/tools/Common/Compiler/AsyncContinuationType.cs +++ b/src/coreclr/tools/Common/Compiler/AsyncContinuationType.cs @@ -22,8 +22,8 @@ public sealed partial class AsyncContinuationType : MetadataType public GCPointerMap PointerMap { get; } public override DefType[] ExplicitlyImplementedInterfaces => []; - public override Utf8StringRef Name => Encoding.UTF8.GetBytes(DiagnosticName); - public override Utf8StringRef Namespace => Array.Empty(); + public override Utf8Span Name => Encoding.UTF8.GetBytes(DiagnosticName); + public override Utf8Span Namespace => Array.Empty(); // We don't lay these out using MetadataType metadata. // Autolayout (which we'd get due to GC pointers) would likely not match what codegen expects. @@ -50,9 +50,9 @@ public AsyncContinuationType(MetadataType continuationBaseType, GCPointerMap poi public override bool HasCustomAttribute(string attributeNamespace, string attributeName) => false; public override IEnumerable GetNestedTypes() => []; - public override MetadataType GetNestedType(Utf8StringRef name) => null; + public override MetadataType GetNestedType(Utf8Span name) => null; protected override MethodImplRecord[] ComputeVirtualMethodImplsForType() => []; - public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8StringRef name) => []; + public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8Span name) => []; protected override int CompareToImpl(TypeDesc other, TypeSystemComparer comparer) { diff --git a/src/coreclr/tools/Common/Compiler/MethodExtensions.cs b/src/coreclr/tools/Common/Compiler/MethodExtensions.cs index 449c2448af3f4b..20510d67784c40 100644 --- a/src/coreclr/tools/Common/Compiler/MethodExtensions.cs +++ b/src/coreclr/tools/Common/Compiler/MethodExtensions.cs @@ -145,7 +145,7 @@ public static bool ReturnsTaskOrValueTask(this MethodSignature method) && md.Module == method.Context.SystemModule && md.Namespace == "System.Threading.Tasks"u8) { - Utf8StringRef name = md.Name; + Utf8Span name = md.Name; if (name == "Task"u8 || name == "Task`1"u8 || name == "ValueTask"u8 || name == "ValueTask`1"u8) { diff --git a/src/coreclr/tools/Common/Compiler/NativeAotNameMangler.cs b/src/coreclr/tools/Common/Compiler/NativeAotNameMangler.cs index 136a0c881a6ef1..7066af715b31bf 100644 --- a/src/coreclr/tools/Common/Compiler/NativeAotNameMangler.cs +++ b/src/coreclr/tools/Common/Compiler/NativeAotNameMangler.cs @@ -40,7 +40,7 @@ public override Utf8String CompilationUnitPrefix public override Utf8String SanitizeName(Utf8String s) => SanitizeName(s.AsSpan()); - private static Utf8String SanitizeName(Utf8StringRef n) + private static Utf8String SanitizeName(Utf8Span n) { ReadOnlySpan s = n.AsSpan(); @@ -244,7 +244,7 @@ static void AppendTypeName(Utf8StringBuilder sb, MetadataType t) } else { - Utf8StringRef ns = t.Namespace; + Utf8Span ns = t.Namespace; if (ns.Length > 0) sb.Append(SanitizeName(ns)).Append('_'); } diff --git a/src/coreclr/tools/Common/Compiler/TypeMapMetadata.cs b/src/coreclr/tools/Common/Compiler/TypeMapMetadata.cs index 1c4b6b117e15d4..d929eab6a773f4 100644 --- a/src/coreclr/tools/Common/Compiler/TypeMapMetadata.cs +++ b/src/coreclr/tools/Common/Compiler/TypeMapMetadata.cs @@ -67,7 +67,7 @@ public ThrowingMethodStub(TypeDesc owningType, TypeDesc typeMapGroup, bool exter } public TypeSystemException Exception { get; } - public override Utf8StringRef Name => _name; + public override Utf8Span Name => _name; public override MethodIL EmitIL() { #if READYTORUN diff --git a/src/coreclr/tools/Common/Internal/Text/Utf8StringRef.cs b/src/coreclr/tools/Common/Internal/Text/Utf8Span.cs similarity index 75% rename from src/coreclr/tools/Common/Internal/Text/Utf8StringRef.cs rename to src/coreclr/tools/Common/Internal/Text/Utf8Span.cs index 9179e833a47637..5bb3d8491ad522 100644 --- a/src/coreclr/tools/Common/Internal/Text/Utf8StringRef.cs +++ b/src/coreclr/tools/Common/Internal/Text/Utf8Span.cs @@ -8,11 +8,11 @@ namespace Internal.Text { - public readonly ref struct Utf8StringRef + public readonly ref struct Utf8Span { private readonly ReadOnlySpan _value; - public Utf8StringRef(ReadOnlySpan value) => _value = value; + public Utf8Span(ReadOnlySpan value) => _value = value; public int Length => _value.Length; @@ -22,9 +22,9 @@ public readonly ref struct Utf8StringRef public byte[] ToArray() => _value.ToArray(); - public bool StartsWith(Utf8StringRef value) => _value.StartsWith(value.AsSpan()); + public bool StartsWith(Utf8Span value) => _value.StartsWith(value.AsSpan()); - public bool EndsWith(Utf8StringRef value) => _value.EndsWith(value.AsSpan()); + public bool EndsWith(Utf8Span value) => _value.EndsWith(value.AsSpan()); // This is deliberately not a == operator because we don't want to make it easy // to accidentally do UTF-8 vs UTF-16 string comparisons. @@ -58,12 +58,12 @@ public override int GetHashCode() public override string ToString() => Encoding.UTF8.GetString(_value); - public static implicit operator Utf8StringRef(ReadOnlySpan s) => new Utf8StringRef(s); + public static implicit operator Utf8Span(ReadOnlySpan s) => new Utf8Span(s); - public static bool operator ==(Utf8StringRef left, Utf8StringRef right) + public static bool operator ==(Utf8Span left, Utf8Span right) => left._value.SequenceEqual(right._value); - public static bool operator !=(Utf8StringRef left, Utf8StringRef right) + public static bool operator !=(Utf8Span left, Utf8Span right) => !left._value.SequenceEqual(right._value); } } diff --git a/src/coreclr/tools/Common/Internal/Text/Utf8String.cs b/src/coreclr/tools/Common/Internal/Text/Utf8String.cs index 0419290c633df4..52efab1b84b5f1 100644 --- a/src/coreclr/tools/Common/Internal/Text/Utf8String.cs +++ b/src/coreclr/tools/Common/Internal/Text/Utf8String.cs @@ -29,7 +29,7 @@ public Utf8String(string s) _value = Encoding.UTF8.GetBytes(s); } - public static implicit operator Utf8StringRef(Utf8String s) => s._value; + public static implicit operator Utf8Span(Utf8String s) => s._value; public int Length => _value.Length; diff --git a/src/coreclr/tools/Common/Internal/Text/Utf8StringBuilder.cs b/src/coreclr/tools/Common/Internal/Text/Utf8StringBuilder.cs index 2b292485a556c2..e8df7d7d70b34f 100644 --- a/src/coreclr/tools/Common/Internal/Text/Utf8StringBuilder.cs +++ b/src/coreclr/tools/Common/Internal/Text/Utf8StringBuilder.cs @@ -43,7 +43,7 @@ public Utf8StringBuilder Append(Utf8String value) return Append(value.AsSpan()); } - public Utf8StringBuilder Append(Utf8StringRef value) + public Utf8StringBuilder Append(Utf8Span value) { return Append(value.AsSpan()); } diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index 575a9ee0e847fb..5638e885771ee5 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -2095,8 +2095,8 @@ private CorInfoType asCorInfoType(CORINFO_CLASS_STRUCT_* cls) else if (type is MetadataType mdType) { if (namespaceName != null) - *namespaceName = (byte*)GetPin(Utf8StringRefToPinnableBytes(mdType.Namespace)); - return (byte*)GetPin(Utf8StringRefToPinnableBytes(mdType.Name)); + *namespaceName = (byte*)GetPin(Utf8SpanToPinnableBytes(mdType.Namespace)); + return (byte*)GetPin(Utf8SpanToPinnableBytes(mdType.Name)); } if (namespaceName != null) @@ -2585,7 +2585,7 @@ private GetTypeLayoutResult GetTypeLayoutHelper(MetadataType type, uint parentIn // not care about since they are considered primitives by the JIT. if (type.IsIntrinsic) { - Utf8StringRef ns = type.Namespace; + Utf8Span ns = type.Namespace; if (ns == "System.Runtime.Intrinsics"u8 || ns == "System.Numerics"u8) { parNode->simdTypeHnd = ObjectToHandle(type); @@ -3067,7 +3067,7 @@ private bool isExactType(CORINFO_CLASS_STRUCT_* cls) // non-candidates before we compare names. if (type.IsIntrinsic && type is MetadataType mdType) { - Utf8StringRef name = mdType.Name; + Utf8Span name = mdType.Name; if ((name == "SZArrayHelper"u8 || name == "Array`1"u8) && mdType.Namespace == "System"u8) { @@ -3538,7 +3538,7 @@ private static byte[] StringToUTF8(string s) return bytes; } - private static byte[] Utf8StringRefToPinnableBytes(Utf8StringRef s) + private static byte[] Utf8SpanToPinnableBytes(Utf8Span s) { byte[] bytes = new byte[s.Length + 1]; s.AsSpan().CopyTo(bytes); diff --git a/src/coreclr/tools/Common/TypeSystem/Canon/CanonTypes.Metadata.cs b/src/coreclr/tools/Common/TypeSystem/Canon/CanonTypes.Metadata.cs index 814f88a112e08c..f09dc231dda89b 100644 --- a/src/coreclr/tools/Common/TypeSystem/Canon/CanonTypes.Metadata.cs +++ b/src/coreclr/tools/Common/TypeSystem/Canon/CanonTypes.Metadata.cs @@ -36,7 +36,7 @@ protected override MethodImplRecord[] ComputeVirtualMethodImplsForType() public override bool IsModuleType => false; - public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8StringRef name) + public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8Span name) { return null; } @@ -46,7 +46,7 @@ public override ClassLayoutMetadata GetClassLayout() return default(ClassLayoutMetadata); } - public override MetadataType GetNestedType(Utf8StringRef name) + public override MetadataType GetNestedType(Utf8Span name) { return null; } diff --git a/src/coreclr/tools/Common/TypeSystem/Canon/CanonTypes.cs b/src/coreclr/tools/Common/TypeSystem/Canon/CanonTypes.cs index d9c54a64bb0d96..4a18ed3ad134b9 100644 --- a/src/coreclr/tools/Common/TypeSystem/Canon/CanonTypes.cs +++ b/src/coreclr/tools/Common/TypeSystem/Canon/CanonTypes.cs @@ -66,7 +66,7 @@ internal sealed partial class CanonType : CanonBaseType { private int _hashcode; - public override Utf8StringRef Namespace + public override Utf8Span Namespace { get { @@ -74,7 +74,7 @@ public override Utf8StringRef Namespace } } - public override Utf8StringRef Name + public override Utf8Span Name { get { @@ -150,7 +150,7 @@ internal sealed partial class UniversalCanonType : CanonBaseType { private int _hashcode; - public override Utf8StringRef Namespace + public override Utf8Span Namespace { get { @@ -158,7 +158,7 @@ public override Utf8StringRef Namespace } } - public override Utf8StringRef Name + public override Utf8Span Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/Common/ArrayType.cs b/src/coreclr/tools/Common/TypeSystem/Common/ArrayType.cs index 3541a3db81007a..2162fc76c39569 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/ArrayType.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/ArrayType.cs @@ -301,7 +301,7 @@ public override MethodSignature Signature } } - public override Utf8StringRef Name + public override Utf8Span Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/Common/DefType.cs b/src/coreclr/tools/Common/TypeSystem/Common/DefType.cs index d17359d46f5d27..6d4e37f5a7d20b 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/DefType.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/DefType.cs @@ -18,7 +18,7 @@ public abstract partial class DefType : TypeDesc /// /// Gets the namespace of the type. /// - public virtual Utf8StringRef Namespace => Array.Empty(); + public virtual Utf8Span Namespace => Array.Empty(); public string GetNamespace() => System.Text.Encoding.UTF8.GetString(Namespace #if NETSTANDARD @@ -31,7 +31,7 @@ public string GetNamespace() => System.Text.Encoding.UTF8.GetString(Namespace /// /// Gets the name of the type as represented in the metadata. /// - public virtual Utf8StringRef Name => Array.Empty(); + public virtual Utf8Span Name => Array.Empty(); public string GetName() => System.Text.Encoding.UTF8.GetString(Name #if NETSTANDARD diff --git a/src/coreclr/tools/Common/TypeSystem/Common/FieldDesc.cs b/src/coreclr/tools/Common/TypeSystem/Common/FieldDesc.cs index 855d59c87561ad..7f930f81353cc1 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/FieldDesc.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/FieldDesc.cs @@ -31,7 +31,7 @@ public override bool Equals(object o) return ReferenceEquals(this, o); } - public virtual Utf8StringRef Name + public virtual Utf8Span Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/Common/FieldForInstantiatedType.cs b/src/coreclr/tools/Common/TypeSystem/Common/FieldForInstantiatedType.cs index 4deda1ec25312a..44a089037952fa 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/FieldForInstantiatedType.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/FieldForInstantiatedType.cs @@ -40,7 +40,7 @@ public override MetadataType OwningType } } - public override Utf8StringRef Name + public override Utf8Span Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/Common/IAssemblyDesc.cs b/src/coreclr/tools/Common/TypeSystem/Common/IAssemblyDesc.cs index 902880de00f3cc..a5a22f463a480f 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/IAssemblyDesc.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/IAssemblyDesc.cs @@ -21,6 +21,6 @@ public interface IAssemblyDesc /// /// Gets the simple assembly name /// - Utf8StringRef Name { get; } + Utf8Span Name { get; } } } diff --git a/src/coreclr/tools/Common/TypeSystem/Common/ImpliedRepeatedFieldDesc.cs b/src/coreclr/tools/Common/TypeSystem/Common/ImpliedRepeatedFieldDesc.cs index 3c2cdb349d8f6b..5330c51bb1dc4d 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/ImpliedRepeatedFieldDesc.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/ImpliedRepeatedFieldDesc.cs @@ -44,6 +44,6 @@ public ImpliedRepeatedFieldDesc(MetadataType owningType, FieldDesc underlyingFie public override MarshalAsDescriptor GetMarshalAsDescriptor() => _underlyingFieldDesc.GetMarshalAsDescriptor(); - public override Utf8StringRef Name => System.Text.Encoding.UTF8.GetBytes($"{_underlyingFieldDesc.GetName()}[{FieldIndex}]"); + public override Utf8Span Name => System.Text.Encoding.UTF8.GetBytes($"{_underlyingFieldDesc.GetName()}[{FieldIndex}]"); } } diff --git a/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedMethod.cs b/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedMethod.cs index 6917d7ecd5ce5b..7fb20e485be777 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedMethod.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedMethod.cs @@ -168,7 +168,7 @@ public override MethodDesc GetTypicalMethodDefinition() return _methodDef.GetTypicalMethodDefinition(); } - public override Utf8StringRef Name + public override Utf8Span Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedType.Metadata.cs b/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedType.Metadata.cs index 7cb96019614280..127da7edbf5762 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedType.Metadata.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedType.Metadata.cs @@ -95,7 +95,7 @@ public override bool HasCustomAttribute(string attributeNamespace, string attrib return _typeDef.HasCustomAttribute(attributeNamespace, attributeName); } - public override MetadataType GetNestedType(Utf8StringRef name) + public override MetadataType GetNestedType(Utf8Span name) { // Return the result from the typical type definition. return _typeDef.GetNestedType(name); diff --git a/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedType.MethodImpls.cs b/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedType.MethodImpls.cs index b26f94d29ab896..2d2e9e7679f634 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedType.MethodImpls.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedType.MethodImpls.cs @@ -49,7 +49,7 @@ protected override MethodImplRecord[] ComputeVirtualMethodImplsForType() return InstantiateMethodImpls(uninstMethodImpls); } - public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8StringRef name) + public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8Span name) { MethodImplRecord[] uninstMethodImpls = _typeDef.FindMethodsImplWithMatchingDeclName(name); return InstantiateMethodImpls(uninstMethodImpls); diff --git a/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedType.cs b/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedType.cs index 67fad00552af1e..fd0ee365905e00 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedType.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/InstantiatedType.cs @@ -128,7 +128,7 @@ protected override TypeFlags ComputeTypeFlags(TypeFlags mask) return flags; } - public override Utf8StringRef Name + public override Utf8Span Name { get { @@ -136,7 +136,7 @@ public override Utf8StringRef Name } } - public override Utf8StringRef Namespace + public override Utf8Span Namespace { get { @@ -161,7 +161,7 @@ public override IEnumerable GetVirtualMethods() } // TODO: Substitutions, generics, modopts, ... - public override MethodDesc GetMethod(Utf8StringRef name, MethodSignature signature, Instantiation substitution) + public override MethodDesc GetMethod(Utf8Span name, MethodSignature signature, Instantiation substitution) { MethodDesc typicalMethodDef = _typeDef.GetMethod(name, signature, substitution); if (typicalMethodDef == null) @@ -169,7 +169,7 @@ public override MethodDesc GetMethod(Utf8StringRef name, MethodSignature signatu return _typeDef.Context.GetMethodForInstantiatedType(typicalMethodDef, this); } - public override MethodDesc GetMethodWithEquivalentSignature(Utf8StringRef name, MethodSignature signature, Instantiation substitution) + public override MethodDesc GetMethodWithEquivalentSignature(Utf8Span name, MethodSignature signature, Instantiation substitution) { MethodDesc typicalMethodDef = _typeDef.GetMethodWithEquivalentSignature(name, signature, substitution); if (typicalMethodDef == null) @@ -231,7 +231,7 @@ public override IEnumerable GetFields() } // TODO: Substitutions, generics, modopts, ... - public override FieldDesc GetField(Utf8StringRef name) + public override FieldDesc GetField(Utf8Span name) { FieldDesc fieldDef = _typeDef.GetField(name); if (fieldDef == null) diff --git a/src/coreclr/tools/Common/TypeSystem/Common/MetadataType.MethodImpls.cs b/src/coreclr/tools/Common/TypeSystem/Common/MetadataType.MethodImpls.cs index c363cdddf374a8..23f05ec6a14a57 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/MetadataType.MethodImpls.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/MetadataType.MethodImpls.cs @@ -48,6 +48,6 @@ public MethodImplRecord[] VirtualMethodImplsForType /// /// /// - public abstract MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8StringRef name); + public abstract MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8Span name); } } diff --git a/src/coreclr/tools/Common/TypeSystem/Common/MetadataType.cs b/src/coreclr/tools/Common/TypeSystem/Common/MetadataType.cs index 48586ad1bb8722..db2c03f3ef753d 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/MetadataType.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/MetadataType.cs @@ -15,9 +15,9 @@ namespace Internal.TypeSystem /// public abstract partial class MetadataType : DefType { - public abstract override Utf8StringRef Name { get; } + public abstract override Utf8Span Name { get; } - public abstract override Utf8StringRef Namespace { get; } + public abstract override Utf8Span Namespace { get; } /// /// Gets metadata that controls instance layout of this type. @@ -100,7 +100,7 @@ public virtual bool IsModuleType /// Get a specific type nested in this type. Returns null if the type /// doesn't exist. /// - public abstract MetadataType GetNestedType(Utf8StringRef name); + public abstract MetadataType GetNestedType(Utf8Span name); /// /// Gets a value indicating whether this is an inline array type diff --git a/src/coreclr/tools/Common/TypeSystem/Common/MetadataVirtualMethodAlgorithm.cs b/src/coreclr/tools/Common/TypeSystem/Common/MetadataVirtualMethodAlgorithm.cs index 8fedea03c70939..b1444f1afe5077 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/MetadataVirtualMethodAlgorithm.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/MetadataVirtualMethodAlgorithm.cs @@ -379,7 +379,7 @@ private static bool IsInterfaceExplicitlyImplementedOnType(MetadataType type, Me /// private static MethodDesc FindMatchingVirtualMethodOnTypeByNameAndSig(MethodDesc targetMethod, DefType currentType, bool reverseMethodSearch, Func nameSigMatchMethodIsValidCandidate) { - Utf8StringRef name = targetMethod.Name; + Utf8Span name = targetMethod.Name; MethodSignature sig = targetMethod.Signature; MethodDesc implMethod = null; diff --git a/src/coreclr/tools/Common/TypeSystem/Common/MethodDelegator.cs b/src/coreclr/tools/Common/TypeSystem/Common/MethodDelegator.cs index 86fbab74d81f68..d517c4ff63b599 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/MethodDelegator.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/MethodDelegator.cs @@ -30,7 +30,7 @@ public MethodDelegator(MethodDesc wrappedMethod) public override bool IsDefaultConstructor => _wrappedMethod.IsDefaultConstructor; public override bool IsStaticConstructor => _wrappedMethod.IsStaticConstructor; - public override Utf8StringRef Name => _wrappedMethod.Name; + public override Utf8Span Name => _wrappedMethod.Name; public override bool IsVirtual => _wrappedMethod.IsVirtual; diff --git a/src/coreclr/tools/Common/TypeSystem/Common/MethodDesc.cs b/src/coreclr/tools/Common/TypeSystem/Common/MethodDesc.cs index 528005c7ec51cb..79e3c5bbabcf60 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/MethodDesc.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/MethodDesc.cs @@ -588,7 +588,7 @@ public virtual bool IsStaticConstructor /// /// Gets the name of the method as specified in the metadata. /// - public virtual Utf8StringRef Name + public virtual Utf8Span Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/Common/MethodForInstantiatedType.cs b/src/coreclr/tools/Common/TypeSystem/Common/MethodForInstantiatedType.cs index f438a63312d53a..bcfea7c2b0bbab 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/MethodForInstantiatedType.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/MethodForInstantiatedType.cs @@ -155,7 +155,7 @@ public override bool IsStaticConstructor } } - public override Utf8StringRef Name + public override Utf8Span Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/Common/ModuleDesc.cs b/src/coreclr/tools/Common/TypeSystem/Common/ModuleDesc.cs index 621d66989ddbfa..e7ba89231f5a95 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/ModuleDesc.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/ModuleDesc.cs @@ -36,7 +36,7 @@ public ModuleDesc(TypeSystemContext context, IAssemblyDesc assembly) /// /// Gets a type in this module or null. /// - public MetadataType GetType(Utf8StringRef nameSpace, Utf8StringRef name, bool throwIfNotFound = true) + public MetadataType GetType(Utf8Span nameSpace, Utf8Span name, bool throwIfNotFound = true) { return (MetadataType)GetType(nameSpace, name, throwIfNotFound ? NotFoundBehavior.Throw : NotFoundBehavior.ReturnNull); } @@ -44,7 +44,7 @@ public MetadataType GetType(Utf8StringRef nameSpace, Utf8StringRef name, bool th /// /// Gets a type in this module with the specified name, a resolution failure object, or null. /// - public abstract object GetType(Utf8StringRef nameSpace, Utf8StringRef name, NotFoundBehavior notFoundBehavior); + public abstract object GetType(Utf8Span nameSpace, Utf8Span name, NotFoundBehavior notFoundBehavior); /// /// Gets the global <Module> type. diff --git a/src/coreclr/tools/Common/TypeSystem/Common/TypeDesc.cs b/src/coreclr/tools/Common/TypeSystem/Common/TypeDesc.cs index c370bc52ecee9b..e1845fbea31814 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/TypeDesc.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/TypeDesc.cs @@ -522,7 +522,7 @@ public virtual IEnumerable GetVirtualMethods() /// If signature is not specified and there are multiple matches, the first one /// is returned. Returns null if method not found. /// - public MethodDesc GetMethod(Utf8StringRef name, MethodSignature signature) + public MethodDesc GetMethod(Utf8Span name, MethodSignature signature) { return GetMethod(name, signature, default(Instantiation)); } @@ -534,7 +534,7 @@ public MethodDesc GetMethod(Utf8StringRef name, MethodSignature signature) /// is returned. If substitution is not null, then substitution will be applied to /// possible target methods before signature comparison. Returns null if method not found. /// - public virtual MethodDesc GetMethod(Utf8StringRef name, MethodSignature signature, Instantiation substitution) + public virtual MethodDesc GetMethod(Utf8Span name, MethodSignature signature, Instantiation substitution) { foreach (var method in GetMethods()) { @@ -547,7 +547,7 @@ public virtual MethodDesc GetMethod(Utf8StringRef name, MethodSignature signatur return null; } - public virtual MethodDesc GetMethodWithEquivalentSignature(Utf8StringRef name, MethodSignature signature, Instantiation substitution) + public virtual MethodDesc GetMethodWithEquivalentSignature(Utf8Span name, MethodSignature signature, Instantiation substitution) { foreach (var method in GetMethods()) { @@ -591,7 +591,7 @@ public virtual IEnumerable GetFields() /// // TODO: Substitutions, generics, modopts, ... // TODO: field signature - public virtual FieldDesc GetField(Utf8StringRef name) + public virtual FieldDesc GetField(Utf8Span name) { foreach (var field in GetFields()) { diff --git a/src/coreclr/tools/Common/TypeSystem/Common/TypeSystemHelpers.cs b/src/coreclr/tools/Common/TypeSystem/Common/TypeSystemHelpers.cs index ef0ab602e10cc6..d3aa34f8632e29 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/TypeSystemHelpers.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/TypeSystemHelpers.cs @@ -433,7 +433,7 @@ public static bool RequiresAlign8(this TypeDesc type) return false; } - public static ReadOnlySpan Append(this Utf8StringRef s1, Utf8StringRef s2) + public static ReadOnlySpan Append(this Utf8Span s1, Utf8Span s2) { Span buffer = new byte[s1.Length + s2.Length]; @@ -443,7 +443,7 @@ public static ReadOnlySpan Append(this Utf8StringRef s1, Utf8StringRef s2) return buffer; } - public static ReadOnlySpan Append(this ReadOnlySpan s1, Utf8StringRef s2) + public static ReadOnlySpan Append(this ReadOnlySpan s1, Utf8Span s2) { Span buffer = new byte[s1.Length + s2.Length]; @@ -464,7 +464,7 @@ public static ReadOnlySpan Append(this ReadOnlySpan s1, ReadOnlySpan return buffer; } - public static ReadOnlySpan Append(this Utf8StringRef s1, Utf8StringRef s2, Utf8StringRef s3) + public static ReadOnlySpan Append(this Utf8Span s1, Utf8Span s2, Utf8Span s3) { ReadOnlySpan s1Span = s1.AsSpan(); ReadOnlySpan s2Span = s2.AsSpan(); @@ -478,7 +478,7 @@ public static ReadOnlySpan Append(this Utf8StringRef s1, Utf8StringRef s2, return buffer; } - public static ReadOnlySpan Append(this Utf8StringRef s1, Utf8StringRef s2, Utf8StringRef s3, uint i) + public static ReadOnlySpan Append(this Utf8Span s1, Utf8Span s2, Utf8Span s3, uint i) { Span s4 = stackalloc byte[16]; System.Buffers.Text.Utf8Formatter.TryFormat(i, s4, out int s4length); diff --git a/src/coreclr/tools/Common/TypeSystem/Common/TypeWithRepeatedFields.cs b/src/coreclr/tools/Common/TypeSystem/Common/TypeWithRepeatedFields.cs index fc42772760805c..5dc513caea288f 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/TypeWithRepeatedFields.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/TypeWithRepeatedFields.cs @@ -86,16 +86,16 @@ public override IEnumerable GetFields() public override ClassLayoutMetadata GetClassLayout() => MetadataType.GetClassLayout(); public override bool HasCustomAttribute(string attributeNamespace, string attributeName) => MetadataType.HasCustomAttribute(attributeNamespace, attributeName); public override IEnumerable GetNestedTypes() => (IEnumerable)EmptyTypes; - public override MetadataType GetNestedType(Utf8StringRef name) => null; - public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8StringRef name) => MetadataType.FindMethodsImplWithMatchingDeclName(name); + public override MetadataType GetNestedType(Utf8Span name) => null; + public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8Span name) => MetadataType.FindMethodsImplWithMatchingDeclName(name); public override int GetHashCode() => MetadataType.GetHashCode(); protected override MethodImplRecord[] ComputeVirtualMethodImplsForType() => Array.Empty(); protected override TypeFlags ComputeTypeFlags(TypeFlags mask) => MetadataType.GetTypeFlags(mask); - public override Utf8StringRef Namespace => MetadataType.Namespace; + public override Utf8Span Namespace => MetadataType.Namespace; - public override Utf8StringRef Name => MetadataType.Name; + public override Utf8Span Name => MetadataType.Name; public override DefType[] ExplicitlyImplementedInterfaces => Array.Empty(); diff --git a/src/coreclr/tools/Common/TypeSystem/Common/VersionResilientHashCode.TypeSystem.cs b/src/coreclr/tools/Common/TypeSystem/Common/VersionResilientHashCode.TypeSystem.cs index c8864f5222df4d..82b9f0882be0f5 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/VersionResilientHashCode.TypeSystem.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/VersionResilientHashCode.TypeSystem.cs @@ -13,10 +13,10 @@ namespace Internal { internal static partial class VersionResilientHashCode { - public static int NameHashCode(Utf8StringRef src) + public static int NameHashCode(Utf8Span src) => NameHashCode(src.AsSpan()); - public static int NameHashCode(Utf8StringRef namespacePart, Utf8StringRef namePart) + public static int NameHashCode(Utf8Span namespacePart, Utf8Span namePart) => NameHashCode(namespacePart.AsSpan(), namePart.AsSpan()); /// diff --git a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaAssembly.cs b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaAssembly.cs index b65549e44264d5..c6083775f2321a 100644 --- a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaAssembly.cs +++ b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaAssembly.cs @@ -64,7 +64,7 @@ public AssemblyNameInfo GetName() return _assemblyName; } - public Utf8StringRef Name + public Utf8Span Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaField.cs b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaField.cs index cce87727a5b8ba..243635c8e0f381 100644 --- a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaField.cs +++ b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaField.cs @@ -269,7 +269,7 @@ public unsafe ReadOnlySpan InitializeName() return new ReadOnlySpan(_namePointer, _nameLength); } - public override unsafe Utf8StringRef Name + public override unsafe Utf8Span Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaMethod.cs b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaMethod.cs index 7cc73a4485b8cf..05ecffbe523d0f 100644 --- a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaMethod.cs +++ b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaMethod.cs @@ -407,7 +407,7 @@ public unsafe ReadOnlySpan InitializeName() return new ReadOnlySpan(_namePointer, _nameLength); } - public override unsafe Utf8StringRef Name + public override unsafe Utf8Span Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaModule.cs b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaModule.cs index 5c318f0ac6758f..4d0be6772890bb 100644 --- a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaModule.cs +++ b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaModule.cs @@ -317,7 +317,7 @@ private TypeDefinitionHandle[] InitializeTypeDefinitionBucketHeads() return bucketHeads; } - private TypeDefinitionHandle FindDefinedType(int hashCode, Utf8StringRef nameSpace, Utf8StringRef name) + private TypeDefinitionHandle FindDefinedType(int hashCode, Utf8Span nameSpace, Utf8Span name) { MetadataReader reader = _metadataReader; @@ -368,7 +368,7 @@ private ExportedTypeHandle[] InitializeExportedTypeBucketHeads() return bucketHeads; } - private ExportedTypeHandle FindExportedType(int hashCode, Utf8StringRef nameSpace, Utf8StringRef name) + private ExportedTypeHandle FindExportedType(int hashCode, Utf8Span nameSpace, Utf8Span name) { MetadataReader reader = _metadataReader; @@ -389,7 +389,7 @@ private ExportedTypeHandle FindExportedType(int hashCode, Utf8StringRef nameSpac return default; } - public sealed override object GetType(Utf8StringRef nameSpace, Utf8StringRef name, NotFoundBehavior notFoundBehavior) + public sealed override object GetType(Utf8Span nameSpace, Utf8Span name, NotFoundBehavior notFoundBehavior) { int hashCode = VersionResilientHashCode.NameHashCode(nameSpace, name); diff --git a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.MethodImpls.cs b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.MethodImpls.cs index 4ff0f73f744f77..3e219b6828bbbd 100644 --- a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.MethodImpls.cs +++ b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.MethodImpls.cs @@ -16,7 +16,7 @@ namespace Internal.TypeSystem.Ecma public sealed partial class EcmaType : MetadataType { // Virtual function related functionality - public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8StringRef declName) + public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8Span declName) { MetadataReader metadataReader = _module.MetadataReader; ArrayBuilder foundRecords = default(ArrayBuilder); diff --git a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.cs b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.cs index 3776de961c4bef..0cfdf0104648bb 100644 --- a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.cs +++ b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaType.cs @@ -247,7 +247,7 @@ protected override TypeFlags ComputeTypeFlags(TypeFlags mask) return flags; } - private unsafe Utf8StringRef InitializeName() + private unsafe Utf8Span InitializeName() { StringHandle handle = _typeDefinition.Name; _nameLength = MetadataReader.GetStringBytes(handle).Length; @@ -255,7 +255,7 @@ private unsafe Utf8StringRef InitializeName() return new ReadOnlySpan(_namePointer, _nameLength); } - public override unsafe Utf8StringRef Name + public override unsafe Utf8Span Name { get { @@ -268,7 +268,7 @@ public override unsafe Utf8StringRef Name } } - private unsafe Utf8StringRef InitializeNamespace() + private unsafe Utf8Span InitializeNamespace() { StringHandle handle = _typeDefinition.Namespace; _namespaceLength = MetadataReader.GetStringBytes(handle).Length; @@ -276,7 +276,7 @@ private unsafe Utf8StringRef InitializeNamespace() return new ReadOnlySpan(_namespacePointer, _namespaceLength); } - public override unsafe Utf8StringRef Namespace + public override unsafe Utf8Span Namespace { get { @@ -314,12 +314,12 @@ public override IEnumerable GetVirtualMethods() /// If signature is not specified and there are multiple matches, the first one /// is returned. Returns null if method not found. /// - public new EcmaMethod GetMethod(Utf8StringRef name, MethodSignature signature) + public new EcmaMethod GetMethod(Utf8Span name, MethodSignature signature) { return GetMethod(name, signature, default(Instantiation)); } - public override EcmaMethod GetMethod(Utf8StringRef name, MethodSignature signature, Instantiation substitution) + public override EcmaMethod GetMethod(Utf8Span name, MethodSignature signature, Instantiation substitution) { var metadataReader = this.MetadataReader; @@ -336,7 +336,7 @@ public override EcmaMethod GetMethod(Utf8StringRef name, MethodSignature signatu return null; } - public override EcmaMethod GetMethodWithEquivalentSignature(Utf8StringRef name, MethodSignature signature, Instantiation substitution) + public override EcmaMethod GetMethodWithEquivalentSignature(Utf8Span name, MethodSignature signature, Instantiation substitution) { var metadataReader = this.MetadataReader; @@ -462,7 +462,7 @@ public override TypeDesc UnderlyingType } } - public override EcmaField GetField(Utf8StringRef name) + public override EcmaField GetField(Utf8Span name) { var metadataReader = this.MetadataReader; @@ -486,7 +486,7 @@ public override IEnumerable GetNestedTypes() } } - public override EcmaType GetNestedType(Utf8StringRef name) + public override EcmaType GetNestedType(Utf8Span name) { var metadataReader = this.MetadataReader; diff --git a/src/coreclr/tools/Common/TypeSystem/Ecma/MetadataExtensions.cs b/src/coreclr/tools/Common/TypeSystem/Ecma/MetadataExtensions.cs index e8a50d264492a1..52010df2a63599 100644 --- a/src/coreclr/tools/Common/TypeSystem/Ecma/MetadataExtensions.cs +++ b/src/coreclr/tools/Common/TypeSystem/Ecma/MetadataExtensions.cs @@ -320,7 +320,7 @@ public static unsafe ReadOnlySpan GetStringBytes(this MetadataReader reade return new ReadOnlySpan(blobReader.CurrentPointer, blobReader.Length); } - public static unsafe bool StringEquals(this MetadataReader reader, StringHandle handle, Utf8StringRef otherString) + public static unsafe bool StringEquals(this MetadataReader reader, StringHandle handle, Utf8Span otherString) { int stringOffset = reader.GetHeapOffset(handle); diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/AssemblyGetExecutingAssemblyMethodThunk.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/AssemblyGetExecutingAssemblyMethodThunk.cs index facdaf3b8e37f6..491d9509d8aac4 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/AssemblyGetExecutingAssemblyMethodThunk.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/AssemblyGetExecutingAssemblyMethodThunk.cs @@ -39,7 +39,7 @@ public IAssemblyDesc ExecutingAssembly get; } - public override Utf8StringRef Name + public override Utf8Span Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/AsyncResumptionStub.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/AsyncResumptionStub.cs index 64f1cee10a10b2..c002140abff23b 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/AsyncResumptionStub.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/AsyncResumptionStub.cs @@ -26,7 +26,7 @@ public AsyncResumptionStub(MethodDesc targetMethod, TypeDesc owningType) _owningType = owningType; } - public override Utf8StringRef Name => _targetMethod.Name; + public override Utf8Span Name => _targetMethod.Name; public override string DiagnosticName => "RESUME_" + _targetMethod.DiagnosticName; public override TypeDesc OwningType => _owningType; diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/CalliMarshallingMethodThunk.Mangling.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/CalliMarshallingMethodThunk.Mangling.cs index 637019ea90de56..b5859374eb4872 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/CalliMarshallingMethodThunk.Mangling.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/CalliMarshallingMethodThunk.Mangling.cs @@ -22,7 +22,7 @@ ReadOnlySpan IPrefixMangledSignature.Prefix { get { - Utf8StringRef prefix = RuntimeMarshallingEnabled ? "CalliWithRuntimeMarshalling"u8 : "Calli"u8; + Utf8Span prefix = RuntimeMarshallingEnabled ? "CalliWithRuntimeMarshalling"u8 : "Calli"u8; // The target signature is expected to be normalized as MethodSignatureFlags.UnmanagedCallingConvention Debug.Assert((_targetSignature.Flags & MethodSignatureFlags.UnmanagedCallingConventionMask) == MethodSignatureFlags.UnmanagedCallingConvention); diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/CalliMarshallingMethodThunk.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/CalliMarshallingMethodThunk.cs index 6c6106f7c4ef90..bc946d803dd3ae 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/CalliMarshallingMethodThunk.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/CalliMarshallingMethodThunk.cs @@ -72,7 +72,7 @@ public override MethodSignature Signature } } - public override Utf8StringRef Name + public override Utf8Span Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateMarshallingMethodThunk.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateMarshallingMethodThunk.cs index ed357892d79f69..b3d8b984c352f8 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateMarshallingMethodThunk.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateMarshallingMethodThunk.cs @@ -221,7 +221,7 @@ public MethodSignature DelegateSignature } } - private Utf8StringRef NamePrefix + private Utf8Span NamePrefix { get { @@ -240,7 +240,7 @@ private Utf8StringRef NamePrefix } } - public override Utf8StringRef Name + public override Utf8Span Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateThunks.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateThunks.cs index 52063d043dfa24..40b267d9d2c19c 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateThunks.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateThunks.cs @@ -130,7 +130,7 @@ public override MethodIL EmitIL() return emitter.Link(this); } - public override Utf8StringRef Name + public override Utf8Span Name { get { @@ -223,7 +223,7 @@ public override MethodIL EmitIL() return emitter.Link(this); } - public override Utf8StringRef Name + public override Utf8Span Name { get { @@ -283,7 +283,7 @@ public override MethodIL EmitIL() return emitter.Link(this); } - public override Utf8StringRef Name + public override Utf8Span Name { get { @@ -418,7 +418,7 @@ public override MethodIL EmitIL() return emitter.Link(this); } - public override Utf8StringRef Name + public override Utf8Span Name { get { @@ -466,7 +466,7 @@ public override MethodIL EmitIL() return emitter.Link(this); } - public override Utf8StringRef Name + public override Utf8Span Name { get { @@ -643,7 +643,7 @@ public override MethodIL EmitIL() return emitter.Link(this); } - public override Utf8StringRef Name + public override Utf8Span Name { get { @@ -760,7 +760,7 @@ public override bool IsVirtual } } - public override Utf8StringRef Name + public override Utf8Span Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs index 076c71450afcbf..0e42567f860bb4 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs @@ -122,7 +122,7 @@ protected override int ComputeHashCode() return base.ComputeHashCode() ^ _targetSignature.GetHashCode(); } - public override Utf8StringRef Name => "DynamicInvoke"u8; + public override Utf8Span Name => "DynamicInvoke"u8; public override string DiagnosticName => "DynamicInvoke"; diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/ForwardDelegateCreationThunk.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/ForwardDelegateCreationThunk.cs index dc31aacdded91b..a886d77d378b30 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/ForwardDelegateCreationThunk.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/ForwardDelegateCreationThunk.cs @@ -64,7 +64,7 @@ public override MethodSignature Signature } } - public override Utf8StringRef Name + public override Utf8Span Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/GetFieldHelperMethodOverride.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/GetFieldHelperMethodOverride.cs index f353247fe24a72..0eb7ff14051dd8 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/GetFieldHelperMethodOverride.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/GetFieldHelperMethodOverride.cs @@ -218,7 +218,7 @@ public override bool IsVirtual internal static ReadOnlySpan MetadataName => "__GetFieldHelper"u8; - public override Utf8StringRef Name + public override Utf8Span Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/MethodBaseGetCurrentMethodThunk.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/MethodBaseGetCurrentMethodThunk.cs index 05a3ca3a759395..2b1dd5afcb36ef 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/MethodBaseGetCurrentMethodThunk.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/MethodBaseGetCurrentMethodThunk.cs @@ -39,7 +39,7 @@ public MethodDesc Method get; } - public override Utf8StringRef Name + public override Utf8Span Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/PInvokeLazyFixupField.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/PInvokeLazyFixupField.cs index 323a977c3ff70e..9f0a620dbeab03 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/PInvokeLazyFixupField.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/PInvokeLazyFixupField.cs @@ -126,7 +126,7 @@ public override bool HasCustomAttribute(string attributeNamespace, string attrib return false; } - public override Utf8StringRef Name + public override Utf8Span Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/PInvokeTargetNativeMethod.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/PInvokeTargetNativeMethod.cs index b8618953402f8e..f806da9e03b65a 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/PInvokeTargetNativeMethod.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/PInvokeTargetNativeMethod.cs @@ -56,7 +56,7 @@ public override MethodSignature Signature } } - public override Utf8StringRef Name + public override Utf8Span Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/StructMarshallingThunk.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/StructMarshallingThunk.cs index 2e08a1e6f6292e..6593394dc8a20e 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/StructMarshallingThunk.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/StructMarshallingThunk.cs @@ -106,7 +106,7 @@ public override MethodSignature Signature } } - private Utf8StringRef NamePrefix + private Utf8Span NamePrefix { get { @@ -125,7 +125,7 @@ private Utf8StringRef NamePrefix } } - public override Utf8StringRef Name + public override Utf8Span Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/TypeGetTypeMethodThunk.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/TypeGetTypeMethodThunk.cs index 16076905bd3c75..0b953e844682b9 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/TypeGetTypeMethodThunk.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/TypeGetTypeMethodThunk.cs @@ -36,7 +36,7 @@ public override TypeSystemContext Context } } - public override Utf8StringRef Name + public override Utf8Span Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/Interop/IL/InlineArrayType.cs b/src/coreclr/tools/Common/TypeSystem/Interop/IL/InlineArrayType.cs index ba361fc3c1fc8b..72d66aeabe2414 100644 --- a/src/coreclr/tools/Common/TypeSystem/Interop/IL/InlineArrayType.cs +++ b/src/coreclr/tools/Common/TypeSystem/Interop/IL/InlineArrayType.cs @@ -30,11 +30,11 @@ public override ModuleDesc Module get; } - public override Utf8StringRef Name + public override Utf8Span Name { get { - return new Utf8StringRef("_InlineArray__"u8).Append(ElementType.Name, "__"u8, Length); + return new Utf8Span("_InlineArray__"u8).Append(ElementType.Name, "__"u8, Length); } } @@ -46,7 +46,7 @@ public override string DiagnosticName } } - public override Utf8StringRef Namespace + public override Utf8Span Namespace { get { @@ -202,7 +202,7 @@ public override IEnumerable GetNestedTypes() return Array.Empty(); } - public override MetadataType GetNestedType(Utf8StringRef name) + public override MetadataType GetNestedType(Utf8Span name) { return null; } @@ -212,7 +212,7 @@ protected override MethodImplRecord[] ComputeVirtualMethodImplsForType() return Array.Empty(); } - public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8StringRef name) + public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8Span name) { return Array.Empty(); } @@ -326,7 +326,7 @@ public override TypeSystemContext Context } } - public override Utf8StringRef Name + public override Utf8Span Name { get { @@ -496,7 +496,7 @@ public override bool HasCustomAttribute(string attributeNamespace, string attrib return false; } - public override Utf8StringRef Name + public override Utf8Span Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/Interop/IL/NativeStructType.cs b/src/coreclr/tools/Common/TypeSystem/Interop/IL/NativeStructType.cs index c3a44322bcf600..0874faf446d713 100644 --- a/src/coreclr/tools/Common/TypeSystem/Interop/IL/NativeStructType.cs +++ b/src/coreclr/tools/Common/TypeSystem/Interop/IL/NativeStructType.cs @@ -25,7 +25,7 @@ public override ModuleDesc Module get; } - public override Utf8StringRef Name + public override Utf8Span Name { get { @@ -41,7 +41,7 @@ public override string DiagnosticName } } - public override Utf8StringRef Namespace + public override Utf8Span Namespace { get { @@ -259,7 +259,7 @@ public override IEnumerable GetNestedTypes() return Array.Empty(); } - public override MetadataType GetNestedType(Utf8StringRef name) + public override MetadataType GetNestedType(Utf8Span name) { return null; } @@ -269,7 +269,7 @@ protected override MethodImplRecord[] ComputeVirtualMethodImplsForType() return Array.Empty(); } - public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8StringRef name) + public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8Span name) { return Array.Empty(); } @@ -398,7 +398,7 @@ public override bool HasCustomAttribute(string attributeNamespace, string attrib return false; } - public override Utf8StringRef Name + public override Utf8Span Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/Interop/IL/PInvokeDelegateWrapper.cs b/src/coreclr/tools/Common/TypeSystem/Interop/IL/PInvokeDelegateWrapper.cs index 8b35bedad394ab..1358ea56f33429 100644 --- a/src/coreclr/tools/Common/TypeSystem/Interop/IL/PInvokeDelegateWrapper.cs +++ b/src/coreclr/tools/Common/TypeSystem/Interop/IL/PInvokeDelegateWrapper.cs @@ -29,7 +29,7 @@ public override ModuleDesc Module get; } - public override Utf8StringRef Name + public override Utf8Span Name { get { @@ -45,7 +45,7 @@ public override string DiagnosticName } } - public override Utf8StringRef Namespace + public override Utf8Span Namespace { get { @@ -183,7 +183,7 @@ public override IEnumerable GetNestedTypes() return Array.Empty(); } - public override MetadataType GetNestedType(Utf8StringRef name) + public override MetadataType GetNestedType(Utf8Span name) { return null; } @@ -193,7 +193,7 @@ protected override MethodImplRecord[] ComputeVirtualMethodImplsForType() return Array.Empty(); } - public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8StringRef name) + public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8Span name) { return Array.Empty(); } diff --git a/src/coreclr/tools/Common/TypeSystem/Interop/IL/PInvokeDelegateWrapperConstructor.cs b/src/coreclr/tools/Common/TypeSystem/Interop/IL/PInvokeDelegateWrapperConstructor.cs index 6c288c93909ae2..7909032e3cd691 100644 --- a/src/coreclr/tools/Common/TypeSystem/Interop/IL/PInvokeDelegateWrapperConstructor.cs +++ b/src/coreclr/tools/Common/TypeSystem/Interop/IL/PInvokeDelegateWrapperConstructor.cs @@ -24,7 +24,7 @@ public override TypeDesc OwningType get; } - public override Utf8StringRef Name + public override Utf8Span Name { get { diff --git a/src/coreclr/tools/Common/TypeSystem/RuntimeDetermined/MethodForRuntimeDeterminedType.cs b/src/coreclr/tools/Common/TypeSystem/RuntimeDetermined/MethodForRuntimeDeterminedType.cs index cb1d972bbd748d..f99137d974d3b7 100644 --- a/src/coreclr/tools/Common/TypeSystem/RuntimeDetermined/MethodForRuntimeDeterminedType.cs +++ b/src/coreclr/tools/Common/TypeSystem/RuntimeDetermined/MethodForRuntimeDeterminedType.cs @@ -38,7 +38,7 @@ internal MethodForRuntimeDeterminedType(MethodDesc typicalMethodDef, RuntimeDete public override bool IsAbstract => _typicalMethodDef.IsAbstract; public override bool IsFinal => _typicalMethodDef.IsFinal; public override bool IsDefaultConstructor => _typicalMethodDef.IsDefaultConstructor; - public override Utf8StringRef Name => _typicalMethodDef.Name; + public override Utf8Span Name => _typicalMethodDef.Name; public override MethodDesc GetTypicalMethodDefinition() => _typicalMethodDef; public override Instantiation Instantiation => _typicalMethodDef.Instantiation; public override bool IsAsync => _typicalMethodDef.IsAsync; diff --git a/src/coreclr/tools/Common/TypeSystem/RuntimeDetermined/RuntimeDeterminedType.cs b/src/coreclr/tools/Common/TypeSystem/RuntimeDetermined/RuntimeDeterminedType.cs index 59d97fb730e9cc..6b4ad0487942a7 100644 --- a/src/coreclr/tools/Common/TypeSystem/RuntimeDetermined/RuntimeDeterminedType.cs +++ b/src/coreclr/tools/Common/TypeSystem/RuntimeDetermined/RuntimeDeterminedType.cs @@ -92,7 +92,7 @@ public override Instantiation Instantiation } } - public override Utf8StringRef Name + public override Utf8Span Name { get { @@ -100,11 +100,11 @@ public override Utf8StringRef Name } } - public override Utf8StringRef Namespace + public override Utf8Span Namespace { get { - return new Utf8StringRef(System.Text.Encoding.UTF8.GetBytes(_runtimeDeterminedDetailsType.Name)) + return new Utf8Span(System.Text.Encoding.UTF8.GetBytes(_runtimeDeterminedDetailsType.Name)) .Append("_"u8, _rawCanonType.Namespace); } } @@ -125,7 +125,7 @@ public override IEnumerable GetVirtualMethods() } } - public override MethodDesc GetMethod(Utf8StringRef name, MethodSignature signature, Instantiation substitution) + public override MethodDesc GetMethod(Utf8Span name, MethodSignature signature, Instantiation substitution) { MethodDesc method = _rawCanonType.GetMethod(name, signature, substitution); if (method == null) @@ -133,7 +133,7 @@ public override MethodDesc GetMethod(Utf8StringRef name, MethodSignature signatu return Context.GetMethodForRuntimeDeterminedType(method.GetTypicalMethodDefinition(), this); } - public override MethodDesc GetMethodWithEquivalentSignature(Utf8StringRef name, MethodSignature signature, Instantiation substitution) + public override MethodDesc GetMethodWithEquivalentSignature(Utf8Span name, MethodSignature signature, Instantiation substitution) { MethodDesc method = _rawCanonType.GetMethodWithEquivalentSignature(name, signature, substitution); if (method == null) diff --git a/src/coreclr/tools/ILVerification/ILVerification.projitems b/src/coreclr/tools/ILVerification/ILVerification.projitems index 0fc325d210d7b9..ab41851c791f91 100644 --- a/src/coreclr/tools/ILVerification/ILVerification.projitems +++ b/src/coreclr/tools/ILVerification/ILVerification.projitems @@ -27,8 +27,8 @@ TypeSystem\Common\VersionResilientHashCode.cs - - Common\Utf8StringRef.cs + + Common\Utf8Span.cs TypeSystem\CodeGen\MethodDesc.CodeGen.cs diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.BoxedTypes.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.BoxedTypes.cs index fd9b05f43a4ef0..6d8fa81539b8be 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.BoxedTypes.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.BoxedTypes.cs @@ -232,8 +232,8 @@ private sealed partial class BoxedValueType : MetadataType, INonEmittableType public override ModuleDesc Module { get; } - public override Utf8StringRef Name => "Boxed_"u8.Append(ValueTypeRepresented.Name); - public override Utf8StringRef Namespace => ValueTypeRepresented.Namespace; + public override Utf8Span Name => "Boxed_"u8.Append(ValueTypeRepresented.Name); + public override Utf8Span Namespace => ValueTypeRepresented.Namespace; public override string DiagnosticName => "Boxed_" + ValueTypeRepresented.DiagnosticName; public override string DiagnosticNamespace => ValueTypeRepresented.DiagnosticNamespace; public override Instantiation Instantiation => ValueTypeRepresented.Instantiation; @@ -274,9 +274,9 @@ public BoxedValueType(ModuleDesc owningModule, MetadataType valuetype) public override ClassLayoutMetadata GetClassLayout() => default(ClassLayoutMetadata); public override bool HasCustomAttribute(string attributeNamespace, string attributeName) => false; public override IEnumerable GetNestedTypes() => Array.Empty(); - public override MetadataType GetNestedType(Utf8StringRef name) => null; + public override MetadataType GetNestedType(Utf8Span name) => null; protected override MethodImplRecord[] ComputeVirtualMethodImplsForType() => Array.Empty(); - public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8StringRef name) => Array.Empty(); + public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8Span name) => Array.Empty(); public override int GetHashCode() => VersionResilientHashCode.NameHashCode(Namespace, Name); @@ -300,7 +300,7 @@ protected override TypeFlags ComputeTypeFlags(TypeFlags mask) return flags; } - public override FieldDesc GetField(Utf8StringRef name) + public override FieldDesc GetField(Utf8Span name) { return null; } @@ -370,7 +370,7 @@ public GenericUnboxingThunk(BoxedValueType owningType, MethodDesc targetMethod) public MethodDesc TargetMethod => _targetMethod; - public override Utf8StringRef Name + public override Utf8Span Name { get { @@ -459,7 +459,7 @@ public UnboxingThunk(BoxedValueType owningType, MethodDesc targetMethod) public MethodDesc TargetMethod => _targetMethod; - public override Utf8StringRef Name + public override Utf8Span Name { get { diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.GeneratedAssembly.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.GeneratedAssembly.cs index a0ccd041faf310..8e236e90d5bd97 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.GeneratedAssembly.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.GeneratedAssembly.cs @@ -38,7 +38,7 @@ private sealed class CompilerGeneratedAssembly : ModuleDesc, IAssemblyDesc public override IAssemblyDesc Assembly => this; - public Utf8StringRef Name => "System.Private.CompilerGenerated"u8; + public Utf8Span Name => "System.Private.CompilerGenerated"u8; public CompilerGeneratedAssembly(TypeSystemContext context) : base(context, null) @@ -61,7 +61,7 @@ public AssemblyNameInfo GetName() return new AssemblyNameInfo("System.Private.CompilerGenerated"); } - public override object GetType(Utf8StringRef nameSpace, Utf8StringRef name, NotFoundBehavior notFoundBehavior) + public override object GetType(Utf8Span nameSpace, Utf8Span name, NotFoundBehavior notFoundBehavior) { Debug.Fail("Resolving a TypeRef in the compiler generated assembly?"); throw new NotImplementedException(); @@ -89,7 +89,7 @@ public override TypeSystemContext Context } } - public override Utf8StringRef Name + public override Utf8Span Name { get { @@ -105,7 +105,7 @@ public override string DiagnosticName } } - public override Utf8StringRef Namespace + public override Utf8Span Namespace { get { @@ -163,7 +163,7 @@ public override IEnumerable GetNestedTypes() return Array.Empty(); } - public override MetadataType GetNestedType(Utf8StringRef name) + public override MetadataType GetNestedType(Utf8Span name) { return null; } @@ -173,7 +173,7 @@ protected override MethodImplRecord[] ComputeVirtualMethodImplsForType() return Array.Empty(); } - public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8StringRef name) + public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8Span name) { return Array.Empty(); } diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.InterfaceThunks.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.InterfaceThunks.cs index 9790ec47f389b2..3b315aefa40f03 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.InterfaceThunks.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.InterfaceThunks.cs @@ -197,7 +197,7 @@ public DefaultInterfaceMethodImplementationInstantiationThunk(TypeDesc owningTyp public MethodDesc TargetMethod => _targetMethod; - public override Utf8StringRef Name + public override Utf8Span Name { get { diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ExternSymbolMappedField.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ExternSymbolMappedField.cs index b6471bc4e2dc1b..43bdfb790c2ad8 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ExternSymbolMappedField.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ExternSymbolMappedField.cs @@ -21,7 +21,7 @@ public ExternSymbolMappedField(TypeDesc fieldType, string symbolName) _symbolName = symbolName; } - public override Utf8StringRef Name => System.Text.Encoding.UTF8.GetBytes(_symbolName); + public override Utf8Span Name => System.Text.Encoding.UTF8.GetBytes(_symbolName); public string SymbolName => _symbolName; diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ReachabilityInstrumentationProvider.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ReachabilityInstrumentationProvider.cs index ef89fda1a8f113..199f92718e17cc 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ReachabilityInstrumentationProvider.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ReachabilityInstrumentationProvider.cs @@ -240,7 +240,7 @@ public InitializeMethod(CompilerTypeSystemContext context) public override TypeSystemContext Context => _context; public override TypeDesc OwningType => _context.GeneratedAssembly.GetGlobalModuleType(); - public override Utf8StringRef Name => "InitializeReachabilityInfo"u8; + public override Utf8Span Name => "InitializeReachabilityInfo"u8; public override string DiagnosticName => "InitializeReachabilityInfo"; public override MethodIL EmitIL() diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs index b1566c75d843e1..c61590199c91f9 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs @@ -1736,7 +1736,7 @@ private static bool IsTaskConfigureAwait(MethodDesc method) MetadataType owningType = method.OwningType as MetadataType; if (owningType != null) { - Utf8StringRef typeName = owningType.Name; + Utf8Span typeName = owningType.Name; return owningType.Module == method.Context.SystemModule && owningType.Namespace == "System.Threading.Tasks"u8 && (typeName == "Task"u8 diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/NativeLibraryStartupMethod.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/NativeLibraryStartupMethod.cs index 5c47b2f98a226e..528cff3893d526 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/NativeLibraryStartupMethod.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/NativeLibraryStartupMethod.cs @@ -41,7 +41,7 @@ public override TypeDesc OwningType } } - public override Utf8StringRef Name + public override Utf8Span Name { get { diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/StartupCodeMainMethod.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/StartupCodeMainMethod.cs index ba89f9fd47ba7d..e0d597cb0d62e2 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/StartupCodeMainMethod.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/StartupCodeMainMethod.cs @@ -46,7 +46,7 @@ public override TypeDesc OwningType } } - public override Utf8StringRef Name + public override Utf8Span Name { get { @@ -231,7 +231,7 @@ public override TypeDesc OwningType get; } - public override Utf8StringRef Name + public override Utf8Span Name { get { diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/IBC/MIbcProfileParser.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/IBC/MIbcProfileParser.cs index a6da7e323eee8e..a16b10060b4c54 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/IBC/MIbcProfileParser.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/IBC/MIbcProfileParser.cs @@ -622,7 +622,7 @@ private sealed class CustomCanonResolver : IModuleResolver { private sealed class CanonModule : ModuleDesc, IAssemblyDesc { - public Utf8StringRef Name => "System.Private.Canon"u8; + public Utf8Span Name => "System.Private.Canon"u8; public CanonModule(TypeSystemContext wrappedContext) : base(wrappedContext, null) { @@ -638,7 +638,7 @@ public override MetadataType GetGlobalModuleType() throw new NotImplementedException(); } - public override object GetType(Utf8StringRef nameSpace, Utf8StringRef name, NotFoundBehavior notFoundBehavior) + public override object GetType(Utf8Span nameSpace, Utf8Span name, NotFoundBehavior notFoundBehavior) { TypeSystemContext context = Context; diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/TypeSystem/Mutable/MutableModule.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/TypeSystem/Mutable/MutableModule.cs index db33d058a4c98a..116d6d71bc0bff 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/TypeSystem/Mutable/MutableModule.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/TypeSystem/Mutable/MutableModule.cs @@ -404,7 +404,7 @@ public string GetUserString(UserStringHandle handle) } throw new ArgumentException("Invalid UserStringHandle passed to MutableModule.GetObject"); } - public override object GetType(Utf8StringRef nameSpace, Utf8StringRef name, NotFoundBehavior notFoundBehavior) => throw new NotImplementedException(); + public override object GetType(Utf8Span nameSpace, Utf8Span name, NotFoundBehavior notFoundBehavior) => throw new NotImplementedException(); public TypeDesc GetType(EntityHandle handle) { TypeDesc type = GetObject(handle, NotFoundBehavior.Throw) as TypeDesc; diff --git a/src/coreclr/tools/aot/ILCompiler.TypeSystem.Tests/SyntheticVirtualOverrideTests.cs b/src/coreclr/tools/aot/ILCompiler.TypeSystem.Tests/SyntheticVirtualOverrideTests.cs index f42f5998e2fe7a..cb0941e63ffb7f 100644 --- a/src/coreclr/tools/aot/ILCompiler.TypeSystem.Tests/SyntheticVirtualOverrideTests.cs +++ b/src/coreclr/tools/aot/ILCompiler.TypeSystem.Tests/SyntheticVirtualOverrideTests.cs @@ -213,7 +213,7 @@ public override TypeSystemContext Context } } - public override Utf8StringRef Name + public override Utf8Span Name { get { diff --git a/src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj b/src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj index d13348936719f0..536b7ac549eba0 100644 --- a/src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj +++ b/src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj @@ -35,8 +35,8 @@ TypeSystem\Common\VersionResilientHashCode.cs - - Common\Utf8StringRef.cs + + Common\Utf8Span.cs TypeSystem\Common\ArrayMethod.Diagnostic.cs diff --git a/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemField.cs b/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemField.cs index 9dc7d987bbc1e8..2a0717a2849e53 100644 --- a/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemField.cs +++ b/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemField.cs @@ -27,7 +27,7 @@ public TypeRefTypeSystemField(TypeRefTypeSystemType type, ReadOnlySpan nam _embeddedSignatureData = embeddedSigData; } - public override Utf8StringRef Name => _name; + public override Utf8Span Name => _name; public override MetadataType OwningType => _type; public override TypeDesc FieldType => _fieldType; diff --git a/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemMethod.cs b/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemMethod.cs index 1f84ca41dfe7d5..6b434fcc0cb751 100644 --- a/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemMethod.cs +++ b/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemMethod.cs @@ -39,7 +39,7 @@ public TypeRefTypeSystemMethod(TypeRefTypeSystemType type, ReadOnlySpan na } } - public override Utf8StringRef Name => _name; + public override Utf8Span Name => _name; public override Instantiation Instantiation => _instantiation; diff --git a/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemModule.cs b/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemModule.cs index 959bb9110518ce..6442986571c20d 100644 --- a/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemModule.cs +++ b/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemModule.cs @@ -51,7 +51,7 @@ public TypeRefTypeSystemType GetOrAddType(string nameSpace, string name) public override IAssemblyDesc Assembly => this; - public Utf8StringRef Name => System.Text.Encoding.UTF8.GetBytes(_name.Name); + public Utf8Span Name => System.Text.Encoding.UTF8.GetBytes(_name.Name); public override IEnumerable GetAllTypes() => _types; public override MetadataType GetGlobalModuleType() => throw new NotImplementedException(); @@ -75,7 +75,7 @@ private TypeRefTypeSystemType GetTypeInternal(string nameSpace, string name) return type; } - public override object GetType(Utf8StringRef nameSpace, Utf8StringRef name, NotFoundBehavior notFoundBehavior) + public override object GetType(Utf8Span nameSpace, Utf8Span name, NotFoundBehavior notFoundBehavior) { string strns = Encoding.UTF8.GetString(nameSpace.AsSpan()); string strname = Encoding.UTF8.GetString(name.AsSpan()); diff --git a/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemType.cs b/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemType.cs index c4c4b3b216e237..d67a2315065fe9 100644 --- a/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemType.cs +++ b/src/coreclr/tools/dotnet-pgo/TypeRefTypeSystem/TypeRefTypeSystemType.cs @@ -142,9 +142,9 @@ public FieldDesc GetOrAddField(ReadOnlySpan name, TypeDesc fieldType, Embe public override PInvokeStringFormat PInvokeStringFormat => throw new NotImplementedException(); - public override Utf8StringRef Name => _name; + public override Utf8Span Name => _name; - public override Utf8StringRef Namespace => _namespace; + public override Utf8Span Namespace => _namespace; public override bool IsExplicitLayout => throw new NotImplementedException(); @@ -186,7 +186,7 @@ public override MetadataType BaseType protected override int ClassCode => throw new NotImplementedException(); - public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8StringRef name) => throw new NotImplementedException(); + public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(Utf8Span name) => throw new NotImplementedException(); public override ClassLayoutMetadata GetClassLayout() => throw new NotImplementedException(); public override int GetHashCode() { @@ -197,7 +197,7 @@ public override int GetHashCode() return hash.ToHashCode(); } - public override MetadataType GetNestedType(Utf8StringRef name) + public override MetadataType GetNestedType(Utf8Span name) { TypeRefTypeSystemType type = null; if (_nestedType != null)