Increase precision and safety of the NonVersionableAttribute (#70327)
authorDavid Wrighton <davidwr@microsoft.com>
Wed, 8 Jun 2022 20:28:23 +0000 (13:28 -0700)
committerGitHub <noreply@github.com>
Wed, 8 Jun 2022 20:28:23 +0000 (13:28 -0700)
commit3cc587e1d037b054e785f1e758edec8490fa62ea
tree5d9a85d270afbc2f00512be9e93f782b09b8e127
parentfcdb3fb9ed9c8c340660012f602596588f2124a4
Increase precision and safety of the NonVersionableAttribute (#70327)

* Increase precision and safety of the NonVersionableAttribute
- NonVersionable now only unconditionally affects whether or not the IL is reported as inlined in the inlining data
- Primitive types are now implicitly considered to be NonVersionable
- Classes defined in CoreLib may now be considered to be NonVersionable
  - Classes now marked are String, RawData, and RawArrayData, which are all tied into intrinsics in crossgen2
- NFloat is now marked as NonVersionable so that some of its methods may actually be treated as NonVersionable
- There is now an additional predicate that the IL within the NonVersionable method must satisfy a series of tests to ensure that it can safely be inlined without adding additional tokens for the logic to depend on. See below for the details of the predicate

Collectively these changes make it so that even if we change our inlining rules, the NonVersionable marked methods will successfully pass through Crossgen, without generating requiring tokens from their original modules to be present in the final image.

The rules are:
                // 1. ldfld, ldflda, and stfld to instance fields of NonVersionable structs and NonVersionable classes
                // 2. cpobj, initobj, ldobj, stobj, ldelem, ldelema or sizeof, to NonVersionable structures, signature variables, pointers, function pointers, byrefs, classes, or arrays
                // 3. stelem, to NonVersionable structures
                // In addition, the method must not have any EH.
                // The method may only have locals which are NonVersionable structures, or classes

* Address code review feedback
src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs
src/coreclr/tools/Common/Compiler/TypeExtensions.cs
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/R2RTypeExtensions.cs [new file with mode: 0644]
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilation.cs
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCompilationModuleGroupBase.cs
src/coreclr/tools/aot/ILCompiler.ReadyToRun/ILCompiler.ReadyToRun.csproj
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NFloat.cs
src/libraries/System.Private.CoreLib/src/System/String.cs