-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
fcdb3fb
commit 3cc587e
Showing
8 changed files
with
219 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/R2RTypeExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using Internal.IL; | ||
using Internal.TypeSystem; | ||
using Internal.TypeSystem.Ecma; | ||
|
||
using Debug = System.Diagnostics.Debug; | ||
|
||
namespace ILCompiler | ||
{ | ||
public static class R2RTypeExtensions | ||
{ | ||
/// <summary> | ||
/// Return true when the type in question is marked with the NonVersionable attribute. Primitive types are implicitly NonVersionable | ||
/// </summary> | ||
/// <param name="type">Type to check</param> | ||
/// <returns>True when the type is marked with the non-versionable custom attribute and meets the criteria | ||
/// for a non-versionable type, false otherwise.</returns> | ||
public static bool IsNonVersionable(this MetadataType type) | ||
{ | ||
bool result = type.HasCustomAttribute("System.Runtime.Versioning", "NonVersionableAttribute"); | ||
|
||
if (!type.IsValueType) | ||
{ | ||
if (type.BaseType != type.Context.GetWellKnownType(WellKnownType.Object)) // Only types that derive directly from Object can be non-versionable | ||
result = false; | ||
|
||
// Only reference types defined in System.Private.CoreLib are eligible for the non-versionable processing | ||
// This allows for extremely careful vetting of said types | ||
if (type.Module != type.Context.SystemModule) | ||
result = false; | ||
} | ||
else if (type.IsPrimitive) | ||
{ | ||
// The primitive types are all NonVersionable | ||
result = true; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
/// <summary> | ||
/// Return true when the method is marked as non-versionable. Non-versionable methods | ||
/// may be freely inlined into ReadyToRun images even when they don't reside in the | ||
/// same version bubble as the module being compiled. | ||
/// </summary> | ||
/// <param name="method">Method to check</param> | ||
/// <returns>True when the method is marked as non-versionable, false otherwise.</returns> | ||
public static bool IsNonVersionable(this MethodDesc method) | ||
{ | ||
return method.HasCustomAttribute("System.Runtime.Versioning", "NonVersionableAttribute"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters