Skip to content

Commit e7da680

Browse files
Switch managed type system and compilers to utf-8 (#119385)
1 parent 8fd0afd commit e7da680

File tree

259 files changed

+2258
-2386
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

259 files changed

+2258
-2386
lines changed

src/coreclr/System.Private.CoreLib/src/Internal/VersionResilientHashCode.CoreCLR.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ internal static partial class VersionResilientHashCode
1919
public static int TypeHashCode(RuntimeType type)
2020
=> TypeHashCode(new QCallTypeHandle(ref type));
2121

22+
private static int NameHashCode(string s1, string s2)
23+
=> NameHashCode(System.Text.Encoding.UTF8.GetBytes(s1), System.Text.Encoding.UTF8.GetBytes(s2));
24+
2225
/// <summary>
2326
/// CoreCLR 1-parameter <a href="https://github.com/dotnet/runtime/blob/17154bd7b8f21d6d8d6fca71b89d7dcb705ec32b/src/coreclr/vm/versionresilienthashcode.cpp#L109">GetVersionResilientTypeHashCode</a>
2427
/// </summary>

src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/MethodNameAndSignature.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ public string GetName()
2626
return Reader.GetString(method.Name);
2727
}
2828

29+
public ReadOnlySpan<byte> Name
30+
{
31+
get
32+
{
33+
Method method = Reader.GetMethod(Handle);
34+
return Reader.ReadStringAsBytes(method.Name);
35+
}
36+
}
37+
2938
public override bool Equals(object? compare)
3039
{
3140
if (compare == null)

src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericMethodsLookup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public override int GetHashCode()
2828
{
2929
if (!_hashCode.HasValue)
3030
{
31-
_hashCode = _declaringTypeHandle.GetHashCode() ^ TypeHashingAlgorithms.ComputeGenericInstanceHashCode(TypeHashingAlgorithms.ComputeNameHashCode(_methodNameAndSignature.GetName()), _genericMethodArgumentHandles);
31+
_hashCode = _declaringTypeHandle.GetHashCode() ^ VersionResilientHashCode.GenericInstanceHashCode(VersionResilientHashCode.NameHashCode(_methodNameAndSignature.Name), _genericMethodArgumentHandles);
3232
}
3333
return _hashCode.Value;
3434
}

src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public override int GetHashCode()
3030
{
3131
if (!_hashCode.HasValue)
3232
{
33-
_hashCode = TypeHashingAlgorithms.ComputeGenericInstanceHashCode(_genericTypeDefinitionHandle.GetHashCode(), _genericTypeArgumentHandles);
33+
_hashCode = VersionResilientHashCode.GenericInstanceHashCode(_genericTypeDefinitionHandle.GetHashCode(), _genericTypeArgumentHandles);
3434
}
3535
return _hashCode.Value;
3636
}
@@ -114,7 +114,7 @@ internal GenericTypeLookupData(RuntimeTypeHandle genericTypeDefinitionHandle, Ru
114114

115115
internal int LookupHashCode()
116116
{
117-
return _typeToLookup != null ? _typeToLookup.GetHashCode() : TypeHashingAlgorithms.ComputeGenericInstanceHashCode(_genericTypeDefinitionHandle.GetHashCode(), _genericTypeArgumentHandles);
117+
return _typeToLookup != null ? _typeToLookup.GetHashCode() : VersionResilientHashCode.GenericInstanceHashCode(_genericTypeDefinitionHandle.GetHashCode(), _genericTypeArgumentHandles);
118118
}
119119

120120
internal bool MatchParsedEntry(RuntimeTypeHandle tentativeType)

src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.GVMResolution.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ internal static InstantiatedMethod GVMLookupForSlotWorker(DefType targetType, In
106106
sb.AppendLine();
107107
sb.AppendLine("Declaring type: " + GetTypeNameDebug(slotMethod.OwningType));
108108
sb.AppendLine("Target type: " + GetTypeNameDebug(targetType));
109-
sb.AppendLine("Method name: " + slotMethod.Name);
109+
sb.AppendLine("Method name: " + slotMethod.GetName());
110110
sb.AppendLine("Instantiation:");
111111
for (int i = 0; i < slotMethod.Instantiation.Length; i++)
112112
{
@@ -134,7 +134,7 @@ internal unsafe IntPtr ResolveGenericVirtualMethodTarget(RuntimeTypeHandle type,
134134
sb.AppendLine("Failed to create generic virtual method implementation");
135135
sb.AppendLine();
136136
sb.AppendLine("Declaring type: " + GetTypeNameDebug(result.OwningType));
137-
sb.AppendLine("Method name: " + result.Name);
137+
sb.AppendLine("Method name: " + result.GetName());
138138
sb.AppendLine("Instantiation:");
139139
for (int i = 0; i < result.Instantiation.Length; i++)
140140
{

src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.LdTokenResultLookup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public bool Equals(RuntimeMethodHandleKey other)
102102
public override int GetHashCode()
103103
=> _handle.GetHashCode() ^ (_genericArgs == null
104104
? _declaringType.GetHashCode()
105-
: TypeHashingAlgorithms.ComputeGenericInstanceHashCode(_declaringType.GetHashCode(), _genericArgs));
105+
: VersionResilientHashCode.GenericInstanceHashCode(_declaringType.GetHashCode(), _genericArgs));
106106
}
107107

108108
private LowLevelDictionary<RuntimeFieldHandleKey, RuntimeFieldHandle> _runtimeFieldHandles = new LowLevelDictionary<RuntimeFieldHandleKey, RuntimeFieldHandle>();

src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.Metadata.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public static unsafe bool TryGetArrayTypeForNonDynamicElementType(RuntimeTypeHan
202202
arrayTypeHandle = default(RuntimeTypeHandle);
203203

204204
Debug.Assert(isMdArray || rank == -1);
205-
int arrayHashcode = TypeHashingAlgorithms.ComputeArrayTypeHashCode(elementTypeHandle.GetHashCode(), rank);
205+
int arrayHashcode = VersionResilientHashCode.ArrayTypeHashCode(elementTypeHandle.GetHashCode(), rank == -1 ? 1 : rank);
206206

207207
// Note: ReflectionMapBlob.ArrayMap may not exist in the module that contains the element type.
208208
// So we must enumerate all loaded modules in order to find ArrayMap and the array type for
@@ -239,13 +239,13 @@ public static unsafe bool TryGetArrayTypeForNonDynamicElementType(RuntimeTypeHan
239239

240240
public static unsafe bool TryGetByRefTypeForNonDynamicElementType(RuntimeTypeHandle elementTypeHandle, out RuntimeTypeHandle pointerTypeHandle)
241241
{
242-
int byRefHashcode = TypeHashingAlgorithms.ComputeByrefTypeHashCode(elementTypeHandle.GetHashCode());
242+
int byRefHashcode = VersionResilientHashCode.ByrefTypeHashCode(elementTypeHandle.GetHashCode());
243243
return TryGetParameterizedTypeForNonDynamicElementType(elementTypeHandle, byRefHashcode, ReflectionMapBlob.ByRefTypeMap, out pointerTypeHandle);
244244
}
245245

246246
public static unsafe bool TryGetPointerTypeForNonDynamicElementType(RuntimeTypeHandle elementTypeHandle, out RuntimeTypeHandle pointerTypeHandle)
247247
{
248-
int pointerHashcode = TypeHashingAlgorithms.ComputePointerTypeHashCode(elementTypeHandle.GetHashCode());
248+
int pointerHashcode = VersionResilientHashCode.PointerTypeHashCode(elementTypeHandle.GetHashCode());
249249
return TryGetParameterizedTypeForNonDynamicElementType(elementTypeHandle, pointerHashcode, ReflectionMapBlob.PointerTypeMap, out pointerTypeHandle);
250250
}
251251

src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/TypeSystem/ExceptionTypeNameFormatter.Runtime.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ private static string GetTypeName(DefType type)
1010
if (type is NoMetadata.NoMetadataType)
1111
return ((NoMetadata.NoMetadataType)type).NameForDiagnostics;
1212

13-
return type.Name;
13+
return type.GetName();
1414
}
1515

1616
private static string GetTypeNamespace(DefType type)
1717
{
1818
if (type is NoMetadata.NoMetadataType)
1919
return ((NoMetadata.NoMetadataType)type).NamespaceForDiagnostics;
2020

21-
return type.Namespace;
21+
return type.GetNamespace();
2222
}
2323
}
2424
}

src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/TypeSystem/MethodForInstantiatedType.Runtime.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public override MethodNameAndSignature NameAndSignature
2121
#if DEBUG
2222
public override string ToString()
2323
{
24-
return OwningType.ToString() + "." + Name;
24+
return OwningType.ToString() + "." + GetName();
2525
}
2626
#endif
2727
}

src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/TypeSystem/RuntimeMethodDesc.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ public override MethodNameAndSignature NameAndSignature
8989
}
9090
}
9191

92-
public override string Name
92+
public override ReadOnlySpan<byte> Name
9393
{
9494
get
9595
{
96-
return NameAndSignature.GetName();
96+
return NameAndSignature.Name;
9797
}
9898
}
9999

@@ -163,7 +163,7 @@ public override bool HasCustomAttribute(string attributeNamespace, string attrib
163163

164164
public override string ToString()
165165
{
166-
string result = OwningType.ToString() + ".Method(" + Name + ")";
166+
string result = OwningType.ToString() + ".Method(" + GetName() + ")";
167167
return result;
168168
}
169169
#endif

0 commit comments

Comments
 (0)