Repository: dotnet/runtime
File: src/coreclr/tools/aot/crossgen2/Program.cs (C#)

Code before:
        {
            if (_outputFilePath == null && !_outNearInput)
                throw new CommandLineException(SR.MissingOutputFile);

            if (_singleFileCompilation && !_outNearInput)
                throw new CommandLineException(SR.MissingOutNearInput);

            var logger = new Logger(Console.Out, Get(_command.IsVerbose));

            // Crossgen2 is partial AOT and its pre-compiled methods can be
            // thrown away at runtime if they mismatch in required ISAs or
            // computed layouts of structs. Thus we want to ensure that usage
            // of Vector<T> is only optimistic and doesn't hard code a dependency
            // that would cause the entire image to be invalidated.
            bool isVectorTOptimistic = true;

            TargetArchitecture targetArchitecture = Get(_command.TargetArchitecture);
            TargetOS targetOS = Get(_command.TargetOS);
            InstructionSetSupport instructionSetSupport = Helpers.ConfigureInstructionSetSupport(Get(_command.InstructionSet), Get(_command.MaxVectorTBitWidth), isVectorTOptimistic, targetArchitecture, targetOS,
                SR.InstructionSetMustNotBe, SR.InstructionSetInvalidImplication, logger,
                optimizingForSize: _command.OptimizationMode == OptimizationMode.PreferSize,
                isReadyToRun: true);
            SharedGenericsMode genericsMode = SharedGenericsMode.CanonicalReferenceTypes;
            var targetDetails = new TargetDetails(targetArchitecture, targetOS, Crossgen2RootCommand.IsArmel ? TargetAbi.NativeAotArmel : TargetAbi.NativeAot, instructionSetSupport.GetVectorTSimdVector());

            ConfigureImageBase(targetDetails);

            bool versionBubbleIncludesCoreLib = false;
            Dictionary<string, string> inputFilePathsArg = _command.Result.GetValue(_command.InputFilePaths);
            Dictionary<string, string> unrootedInputFilePathsArg = Get(_command.UnrootedInputFilePaths);

            if (_inputBubble)
            {
                versionBubbleIncludesCoreLib = true;
            }
            else
            {
                if (!_singleFileCompilation)
                {
                    foreach (var inputFile in inputFilePathsArg)
                    {
                        if (String.Compare(inputFile.Key, "System.Private.CoreLib", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            versionBubbleIncludesCoreLib = true;
                            break;
                        }
                    }
                }
                if (!versionBubbleIncludesCoreLib)
                {
                    foreach (var inputFile in unrootedInputFilePathsArg)

Review comment (performance):
Is the consideration that `optimistic` for crossgen means the executable presumes support and the R2R image is thrown away if that isn't available?

So it will fallback to slower interpretation in such a case?

Are people even doing R2R targets for such scenarios rather than just straight NAOT (which handles optimistic differently)?

Code after:
        {
            if (_outputFilePath == null && !_outNearInput)
                throw new CommandLineException(SR.MissingOutputFile);

            if (_singleFileCompilation && !_outNearInput)
                throw new CommandLineException(SR.MissingOutNearInput);

            var logger = new Logger(Console.Out, Get(_command.IsVerbose));

            // Crossgen2 is partial AOT and its pre-compiled methods can be
            // thrown away at runtime if they mismatch in required ISAs or
            // computed layouts of structs. Thus we want to ensure that usage
            // of Vector<T> is only optimistic and doesn't hard code a dependency
            // that would cause the entire image to be invalidated.
            bool isVectorTOptimistic = true;

            TargetArchitecture targetArchitecture = Get(_command.TargetArchitecture);
            TargetOS targetOS = Get(_command.TargetOS);
            bool allowOptimistic = _command.OptimizationMode != OptimizationMode.PreferSize;

            if (targetOS is TargetOS.iOS or TargetOS.tvOS or TargetOS.iOSSimulator or TargetOS.tvOSSimulator or TargetOS.MacCatalyst)
            {
                // These platforms do not support jitted code, so we want to ensure that we don't
                // need to fall back to the interpreter for any hardware-intrinsic optimizations.
                // Disable optimistic instruction sets by default.
                allowOptimistic = false;
            }

            InstructionSetSupport instructionSetSupport = Helpers.ConfigureInstructionSetSupport(Get(_command.InstructionSet), Get(_command.MaxVectorTBitWidth), isVectorTOptimistic, targetArchitecture, targetOS,
                SR.InstructionSetMustNotBe, SR.InstructionSetInvalidImplication, logger,
                allowOptimistic: allowOptimistic,
                isReadyToRun: true);
            SharedGenericsMode genericsMode = SharedGenericsMode.CanonicalReferenceTypes;
            var targetDetails = new TargetDetails(targetArchitecture, targetOS, Crossgen2RootCommand.IsArmel ? TargetAbi.NativeAotArmel : TargetAbi.NativeAot, instructionSetSupport.GetVectorTSimdVector());

            ConfigureImageBase(targetDetails);

            bool versionBubbleIncludesCoreLib = false;
            Dictionary<string, string> inputFilePathsArg = _command.Result.GetValue(_command.InputFilePaths);
            Dictionary<string, string> unrootedInputFilePathsArg = Get(_command.UnrootedInputFilePaths);

            if (_inputBubble)
            {
                versionBubbleIncludesCoreLib = true;
            }
            else
            {
                if (!_singleFileCompilation)
                {
                    foreach (var inputFile in inputFilePathsArg)
                    {