forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only R2R public methods, methods that override public methods, and in…
…ternal methods that aren't always inlined (dotnet#75793)
- Loading branch information
1 parent
0f412b1
commit 55d3027
Showing
33 changed files
with
627 additions
and
84 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
95 changes: 95 additions & 0 deletions
95
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/EffectiveVisibility.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,95 @@ | ||
// 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 System.Diagnostics; | ||
using System.Reflection; | ||
using Internal.TypeSystem; | ||
using Internal.TypeSystem.Ecma; | ||
|
||
namespace ILCompiler | ||
{ | ||
public enum EffectiveVisibility | ||
{ | ||
Private, | ||
Public, | ||
Family, | ||
Assembly, | ||
FamilyAndAssembly, | ||
FamilyOrAssembly, | ||
} | ||
|
||
public static class EffectiveVisibilityExtensions | ||
{ | ||
private static EffectiveVisibility ToEffectiveVisibility(this TypeAttributes typeAttributes) | ||
{ | ||
return (typeAttributes & TypeAttributes.VisibilityMask) switch | ||
{ | ||
TypeAttributes.Public or TypeAttributes.NestedPublic => EffectiveVisibility.Public, | ||
TypeAttributes.NotPublic => EffectiveVisibility.Assembly, | ||
TypeAttributes.NestedPrivate => EffectiveVisibility.Private, | ||
TypeAttributes.NestedAssembly => EffectiveVisibility.Assembly, | ||
TypeAttributes.NestedFamily => EffectiveVisibility.Family, | ||
TypeAttributes.NestedFamANDAssem => EffectiveVisibility.FamilyAndAssembly, | ||
TypeAttributes.NestedFamORAssem => EffectiveVisibility.FamilyOrAssembly, | ||
_ => throw new UnreachableException() | ||
}; | ||
} | ||
private static EffectiveVisibility ToEffectiveVisibility(this MethodAttributes typeAttributes) | ||
{ | ||
return (typeAttributes & MethodAttributes.MemberAccessMask) switch | ||
{ | ||
// PrivateScope == Compiler-Controlled in the ECMA spec. A member with this accessibility | ||
// is only accessible through a MemberDef, not a MemberRef. | ||
// As a result, it's only accessible within the current assembly, which is effectively the same rules as | ||
// Family for our case. | ||
MethodAttributes.PrivateScope => EffectiveVisibility.Assembly, | ||
MethodAttributes.Public => EffectiveVisibility.Public, | ||
MethodAttributes.Private => EffectiveVisibility.Private, | ||
MethodAttributes.Assembly => EffectiveVisibility.Assembly, | ||
MethodAttributes.Family => EffectiveVisibility.Family, | ||
MethodAttributes.FamANDAssem => EffectiveVisibility.FamilyAndAssembly, | ||
MethodAttributes.FamORAssem => EffectiveVisibility.FamilyOrAssembly, | ||
_ => throw new UnreachableException() | ||
}; | ||
} | ||
|
||
private static EffectiveVisibility ConstrainToVisibility(this EffectiveVisibility visibility, EffectiveVisibility enclosingVisibility) | ||
{ | ||
return (visibility, enclosingVisibility) switch | ||
{ | ||
(_, _) when visibility == enclosingVisibility => visibility, | ||
(_, EffectiveVisibility.Private) => EffectiveVisibility.Private, | ||
(EffectiveVisibility.Private, _) => EffectiveVisibility.Private, | ||
(EffectiveVisibility.Public, _) => enclosingVisibility, | ||
(_, EffectiveVisibility.Public) => visibility, | ||
(EffectiveVisibility.FamilyOrAssembly, _) => enclosingVisibility, | ||
(_, EffectiveVisibility.FamilyOrAssembly) => visibility, | ||
(EffectiveVisibility.Family, EffectiveVisibility.Assembly) => EffectiveVisibility.FamilyAndAssembly, | ||
(EffectiveVisibility.Family, EffectiveVisibility.FamilyAndAssembly) => EffectiveVisibility.FamilyAndAssembly, | ||
(EffectiveVisibility.Assembly, EffectiveVisibility.Family) => EffectiveVisibility.FamilyAndAssembly, | ||
(EffectiveVisibility.Assembly, EffectiveVisibility.FamilyAndAssembly) => EffectiveVisibility.FamilyAndAssembly, | ||
(EffectiveVisibility.FamilyAndAssembly, EffectiveVisibility.Family) => EffectiveVisibility.FamilyAndAssembly, | ||
(EffectiveVisibility.FamilyAndAssembly, EffectiveVisibility.Assembly) => EffectiveVisibility.FamilyAndAssembly, | ||
_ => throw new UnreachableException(), | ||
}; | ||
} | ||
|
||
public static bool IsExposedOutsideOfThisAssembly(this EffectiveVisibility visibility, bool anyInternalsVisibleTo) | ||
{ | ||
return visibility is EffectiveVisibility.Public or EffectiveVisibility.Family | ||
|| (anyInternalsVisibleTo && visibility is EffectiveVisibility.Assembly or EffectiveVisibility.FamilyOrAssembly); | ||
} | ||
|
||
public static EffectiveVisibility GetEffectiveVisibility(this EcmaMethod method) | ||
{ | ||
EffectiveVisibility visibility = method.Attributes.ToEffectiveVisibility(); | ||
|
||
for (EcmaType type = (EcmaType)method.OwningType; type is not null; type = (EcmaType)type.ContainingType) | ||
{ | ||
visibility = visibility.ConstrainToVisibility(type.Attributes.ToEffectiveVisibility()); | ||
} | ||
return visibility; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.