From 7c2083cecc5355d2f28b977ff9a402a46efa5341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Fri, 8 Aug 2025 14:45:34 +0200 Subject: [PATCH] Avoid considering types boxed in the scanner I'm not completely sure this is a fine assumption to make (we're assuming something that RyuJIT should do). Wanted to collect numbers if this is worth pursuing. Change salvaged out of #118479, rt-sz will decide if we want to pursue it. --- .../aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 92e8126b482dd1..c5713b5a322ee5 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs @@ -1143,10 +1143,8 @@ private void ImportBox(int token) { var type = (TypeDesc)_methodIL.GetObject(token); - // There are some sequences of box with ByRefLike types that are allowed - // per the extension to the ECMA-335 specification. - // Everything else is invalid. - if (!type.IsRuntimeDeterminedType && type.IsByRefLike) + // Some box operations will trivially be eliminated during import + if (!type.IsRuntimeDeterminedType) { ILReader reader = new ILReader(_ilBytes, _currentOffset); ILOpcode nextOpcode = reader.ReadILOpcode(); @@ -1180,7 +1178,9 @@ private void ImportBox(int token) } } - ThrowHelper.ThrowInvalidProgramException(); + // If this is a byref-like type, only the above operations are permitted. + if (type.IsByRefLike) + ThrowHelper.ThrowInvalidProgramException(); } AddBoxingDependencies(type, "Box");