From d6fb9dd6781870b51e50b1734832300216786382 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Thu, 18 Jan 2024 09:06:06 +0100 Subject: [PATCH] Small cleanup in the cctor interpreter I was looking at the IsValueType handling here and decided to clean it up. --- .../ILCompiler.Compiler/Compiler/TypePreinit.cs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/TypePreinit.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/TypePreinit.cs index 5564907e4bc248..54ff6c6c544afe 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/TypePreinit.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/TypePreinit.cs @@ -1860,9 +1860,7 @@ private bool TryHandleIntrinsicCall(MethodDesc method, Value[] parameters, out V return spanRef.TryAccessElement(spanIndex.AsInt32(), out retVal); } return false; - case "GetTypeFromHandle" when method.OwningType is MetadataType typeType - && typeType.Name == "Type" && typeType.Namespace == "System" - && typeType.Module == typeType.Context.SystemModule + case "GetTypeFromHandle" when IsSystemType(method.OwningType) && parameters[0] is RuntimeTypeHandleValue typeHandle: { if (!_internedTypes.TryGetValue(typeHandle.Type, out RuntimeTypeValue runtimeType)) @@ -1872,17 +1870,13 @@ private bool TryHandleIntrinsicCall(MethodDesc method, Value[] parameters, out V retVal = runtimeType; return true; } - case "get_IsValueType" when method.OwningType is MetadataType typeType - && typeType.Name == "Type" && typeType.Namespace == "System" - && typeType.Module == typeType.Context.SystemModule + case "get_IsValueType" when IsSystemType(method.OwningType) && parameters[0] is RuntimeTypeValue typeToCheckForValueType: { retVal = ValueTypeValue.FromSByte(typeToCheckForValueType.TypeRepresented.IsValueType ? (sbyte)1 : (sbyte)0); return true; } - case "op_Equality" when method.OwningType is MetadataType typeType - && typeType.Name == "Type" && typeType.Namespace == "System" - && typeType.Module == typeType.Context.SystemModule + case "op_Equality" when IsSystemType(method.OwningType) && (parameters[0] is RuntimeTypeValue || parameters[1] is RuntimeTypeValue): { retVal = ValueTypeValue.FromSByte(parameters[0] == parameters[1] ? (sbyte)1 : (sbyte)0); @@ -1890,6 +1884,11 @@ private bool TryHandleIntrinsicCall(MethodDesc method, Value[] parameters, out V } } + static bool IsSystemType(TypeDesc type) + => type is MetadataType typeType + && typeType.Name == "Type" && typeType.Namespace == "System" + && typeType.Module == typeType.Context.SystemModule; + return false; }