From 89772126698ca6f126f17c5ad2c2e76233799415 Mon Sep 17 00:00:00 2001
From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com>
Date: Thu, 15 Feb 2024 07:57:41 -0800
Subject: [PATCH 1/8] Add correct ImplementingType to DIM cache in TypeMapInfo
---
src/tools/illink/src/linker/Linker/TypeMapInfo.cs | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/tools/illink/src/linker/Linker/TypeMapInfo.cs b/src/tools/illink/src/linker/Linker/TypeMapInfo.cs
index a2f118adf9fb7..8e19040baa348 100644
--- a/src/tools/illink/src/linker/Linker/TypeMapInfo.cs
+++ b/src/tools/illink/src/linker/Linker/TypeMapInfo.cs
@@ -181,7 +181,7 @@ void MapInterfaceMethodsInTypeHierarchy (TypeDefinition type)
}
// Look for a default implementation last.
- FindAndAddDefaultInterfaceImplementations (type, resolvedInterfaceMethod);
+ FindAndAddDefaultInterfaceImplementations (type, type, resolvedInterfaceMethod);
}
}
}
@@ -283,12 +283,12 @@ void AnnotateMethods (MethodDefinition @base, MethodDefinition @override, Interf
// Note that this returns a list to potentially cover the diamond case (more than one
// most specific implementation of the given interface methods). ILLink needs to preserve
// all the implementations so that the proper exception can be thrown at runtime.
- void FindAndAddDefaultInterfaceImplementations (TypeDefinition type, MethodDefinition interfaceMethod)
+ void FindAndAddDefaultInterfaceImplementations (TypeDefinition typeThatImplementsInterface, TypeDefinition typeThatMayHaveDIM, MethodDefinition interfaceMethodToBeImplemented)
{
// Go over all interfaces, trying to find a method that is an explicit MethodImpl of the
// interface method in question.
- foreach (var interfaceImpl in type.Interfaces) {
+ foreach (var interfaceImpl in typeThatMayHaveDIM.Interfaces) {
var potentialImplInterface = context.TryResolve (interfaceImpl.InterfaceType);
if (potentialImplInterface == null)
continue;
@@ -298,7 +298,7 @@ void FindAndAddDefaultInterfaceImplementations (TypeDefinition type, MethodDefin
foreach (var potentialImplMethod in potentialImplInterface.Methods) {
if (potentialImplMethod == interfaceMethod &&
!potentialImplMethod.IsAbstract) {
- AddDefaultInterfaceImplementation (interfaceMethod, type, (interfaceImpl, potentialImplMethod));
+ AddDefaultInterfaceImplementation (interfaceMethod, typeThatImplementsInterface, (interfaceImpl, potentialImplMethod));
foundImpl = true;
break;
}
@@ -309,7 +309,7 @@ void FindAndAddDefaultInterfaceImplementations (TypeDefinition type, MethodDefin
// This method is an override of something. Let's see if it's the method we are looking for.
foreach (var @override in potentialImplMethod.Overrides) {
if (context.TryResolve (@override) == interfaceMethod) {
- AddDefaultInterfaceImplementation (interfaceMethod, type, (interfaceImpl, @potentialImplMethod));
+ AddDefaultInterfaceImplementation (interfaceMethod, typeThatImplementsInterface, (interfaceImpl, @potentialImplMethod));
foundImpl = true;
break;
}
@@ -323,7 +323,7 @@ void FindAndAddDefaultInterfaceImplementations (TypeDefinition type, MethodDefin
// We haven't found a MethodImpl on the current interface, but one of the interfaces
// this interface requires could still provide it.
if (!foundImpl) {
- FindAndAddDefaultInterfaceImplementations (potentialImplInterface, interfaceMethod);
+ FindAndAddDefaultInterfaceImplementations (typeThatImplementsInterface, potentialImplInterface, interfaceMethod);
}
}
}
From 69e563adf532e8c213ba20af3e207b24cead9972 Mon Sep 17 00:00:00 2001
From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com>
Date: Thu, 15 Feb 2024 13:17:24 -0800
Subject: [PATCH 2/8] Deal with renames
---
src/tools/illink/src/linker/Linker/TypeMapInfo.cs | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/tools/illink/src/linker/Linker/TypeMapInfo.cs b/src/tools/illink/src/linker/Linker/TypeMapInfo.cs
index 8e19040baa348..3c0610837e1b8 100644
--- a/src/tools/illink/src/linker/Linker/TypeMapInfo.cs
+++ b/src/tools/illink/src/linker/Linker/TypeMapInfo.cs
@@ -296,9 +296,9 @@ void FindAndAddDefaultInterfaceImplementations (TypeDefinition typeThatImplement
bool foundImpl = false;
foreach (var potentialImplMethod in potentialImplInterface.Methods) {
- if (potentialImplMethod == interfaceMethod &&
+ if (potentialImplMethod == interfaceMethodToBeImplemented &&
!potentialImplMethod.IsAbstract) {
- AddDefaultInterfaceImplementation (interfaceMethod, typeThatImplementsInterface, (interfaceImpl, potentialImplMethod));
+ AddDefaultInterfaceImplementation (interfaceMethodToBeImplemented, typeThatImplementsInterface, (interfaceImpl, potentialImplMethod));
foundImpl = true;
break;
}
@@ -308,8 +308,8 @@ void FindAndAddDefaultInterfaceImplementations (TypeDefinition typeThatImplement
// This method is an override of something. Let's see if it's the method we are looking for.
foreach (var @override in potentialImplMethod.Overrides) {
- if (context.TryResolve (@override) == interfaceMethod) {
- AddDefaultInterfaceImplementation (interfaceMethod, typeThatImplementsInterface, (interfaceImpl, @potentialImplMethod));
+ if (context.TryResolve (@override) == interfaceMethodToBeImplemented) {
+ AddDefaultInterfaceImplementation (interfaceMethodToBeImplemented, typeThatImplementsInterface, (interfaceImpl, @potentialImplMethod));
foundImpl = true;
break;
}
@@ -323,7 +323,7 @@ void FindAndAddDefaultInterfaceImplementations (TypeDefinition typeThatImplement
// We haven't found a MethodImpl on the current interface, but one of the interfaces
// this interface requires could still provide it.
if (!foundImpl) {
- FindAndAddDefaultInterfaceImplementations (typeThatImplementsInterface, potentialImplInterface, interfaceMethod);
+ FindAndAddDefaultInterfaceImplementations (typeThatImplementsInterface, potentialImplInterface, interfaceMethodToBeImplemented);
}
}
}
From 18e9ea96711a8aab2a9a2e67cd6fab10314af1a0 Mon Sep 17 00:00:00 2001
From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com>
Date: Fri, 16 Feb 2024 12:47:10 -0800
Subject: [PATCH 3/8] Pass correct interfaceImpl for DIM cache
---
.../illink/src/linker/Linker/TypeMapInfo.cs | 23 ++++++++++++-------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/src/tools/illink/src/linker/Linker/TypeMapInfo.cs b/src/tools/illink/src/linker/Linker/TypeMapInfo.cs
index 3c0610837e1b8..cfc3abd208273 100644
--- a/src/tools/illink/src/linker/Linker/TypeMapInfo.cs
+++ b/src/tools/illink/src/linker/Linker/TypeMapInfo.cs
@@ -279,11 +279,18 @@ void AnnotateMethods (MethodDefinition @base, MethodDefinition @override, Interf
return context.TryResolve (type)?.BaseType;
}
- // Returns a list of default implementations of the given interface method on this type.
- // Note that this returns a list to potentially cover the diamond case (more than one
- // most specific implementation of the given interface methods). ILLink needs to preserve
- // all the implementations so that the proper exception can be thrown at runtime.
- void FindAndAddDefaultInterfaceImplementations (TypeDefinition typeThatImplementsInterface, TypeDefinition typeThatMayHaveDIM, MethodDefinition interfaceMethodToBeImplemented)
+ ///
+ /// Returns a list of default implementations of the given interface method on this type.
+ /// Note that this returns a list to potentially cover the diamond case (more than one
+ /// most specific implementation of the given interface methods). ILLink needs to preserve
+ /// all the implementations so that the proper exception can be thrown at runtime.
+ ///
+ /// The type that implements (directly or via a base interface) the declaring interface of
+ /// The method to find a default implementation for
+ ///
+ /// The InterfaceImplementation on that points to the DeclaringType of .
+ ///
+ void FindAndAddDefaultInterfaceImplementations (TypeDefinition typeThatImplementsInterface, TypeDefinition typeThatMayHaveDIM, MethodDefinition interfaceMethodToBeImplemented, IntefaceImplementation implOfInterface)
{
// Go over all interfaces, trying to find a method that is an explicit MethodImpl of the
// interface method in question.
@@ -298,7 +305,7 @@ void FindAndAddDefaultInterfaceImplementations (TypeDefinition typeThatImplement
foreach (var potentialImplMethod in potentialImplInterface.Methods) {
if (potentialImplMethod == interfaceMethodToBeImplemented &&
!potentialImplMethod.IsAbstract) {
- AddDefaultInterfaceImplementation (interfaceMethodToBeImplemented, typeThatImplementsInterface, (interfaceImpl, potentialImplMethod));
+ AddDefaultInterfaceImplementation (interfaceMethodToBeImplemented, typeThatImplementsInterface, (implOfInterface, potentialImplMethod));
foundImpl = true;
break;
}
@@ -309,7 +316,7 @@ void FindAndAddDefaultInterfaceImplementations (TypeDefinition typeThatImplement
// This method is an override of something. Let's see if it's the method we are looking for.
foreach (var @override in potentialImplMethod.Overrides) {
if (context.TryResolve (@override) == interfaceMethodToBeImplemented) {
- AddDefaultInterfaceImplementation (interfaceMethodToBeImplemented, typeThatImplementsInterface, (interfaceImpl, @potentialImplMethod));
+ AddDefaultInterfaceImplementation (interfaceMethodToBeImplemented, typeThatImplementsInterface, (implOfInterface, @potentialImplMethod));
foundImpl = true;
break;
}
@@ -323,7 +330,7 @@ void FindAndAddDefaultInterfaceImplementations (TypeDefinition typeThatImplement
// We haven't found a MethodImpl on the current interface, but one of the interfaces
// this interface requires could still provide it.
if (!foundImpl) {
- FindAndAddDefaultInterfaceImplementations (typeThatImplementsInterface, potentialImplInterface, interfaceMethodToBeImplemented);
+ FindAndAddDefaultInterfaceImplementations (typeThatImplementsInterface, potentialImplInterface, interfaceMethodToBeImplemented, implOfInterface);
}
}
}
From 5f86b88fcc5a7afe8eb2ba2e65155a01be24b312 Mon Sep 17 00:00:00 2001
From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com>
Date: Fri, 16 Feb 2024 13:29:38 -0800
Subject: [PATCH 4/8] Fix typo
---
src/tools/illink/src/linker/Linker/TypeMapInfo.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/tools/illink/src/linker/Linker/TypeMapInfo.cs b/src/tools/illink/src/linker/Linker/TypeMapInfo.cs
index cfc3abd208273..a6a185c6e6a80 100644
--- a/src/tools/illink/src/linker/Linker/TypeMapInfo.cs
+++ b/src/tools/illink/src/linker/Linker/TypeMapInfo.cs
@@ -181,7 +181,7 @@ void MapInterfaceMethodsInTypeHierarchy (TypeDefinition type)
}
// Look for a default implementation last.
- FindAndAddDefaultInterfaceImplementations (type, type, resolvedInterfaceMethod);
+ FindAndAddDefaultInterfaceImplementations (type, type, resolvedInterfaceMethod, interfaceImpl.OriginalImpl);
}
}
}
@@ -290,7 +290,7 @@ void AnnotateMethods (MethodDefinition @base, MethodDefinition @override, Interf
///
/// The InterfaceImplementation on that points to the DeclaringType of .
///
- void FindAndAddDefaultInterfaceImplementations (TypeDefinition typeThatImplementsInterface, TypeDefinition typeThatMayHaveDIM, MethodDefinition interfaceMethodToBeImplemented, IntefaceImplementation implOfInterface)
+ void FindAndAddDefaultInterfaceImplementations (TypeDefinition typeThatImplementsInterface, TypeDefinition typeThatMayHaveDIM, MethodDefinition interfaceMethodToBeImplemented, InterfaceImplementation implOfInterface)
{
// Go over all interfaces, trying to find a method that is an explicit MethodImpl of the
// interface method in question.
From 17929175e4567285a649a510ee7fb771f07750da Mon Sep 17 00:00:00 2001
From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com>
Date: Wed, 21 Feb 2024 15:06:21 -0800
Subject: [PATCH 5/8] Pass the interfaceImplementation to OverrideInformation
so it doesn't search for it
---
src/tools/illink/src/linker/Linker.Steps/MarkStep.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs b/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs
index c7eb071913f59..0d0543dcdcf56 100644
--- a/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs
+++ b/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs
@@ -703,7 +703,7 @@ void ProcessVirtualMethod (MethodDefinition method)
foreach (var dimInfo in defaultImplementations) {
ProcessDefaultImplementation (dimInfo.ImplementingType, dimInfo.InterfaceImpl, dimInfo.DefaultInterfaceMethod);
- var ov = new OverrideInformation (method, dimInfo.DefaultInterfaceMethod, Context);
+ var ov = new OverrideInformation (method, dimInfo.DefaultInterfaceMethod, Context, dimInfo.InterfaceImpl);
if (IsInterfaceImplementationMethodNeededByTypeDueToInterface (ov, dimInfo.ImplementingType))
MarkMethod (ov.Override, new DependencyInfo (DependencyKind.Override, ov.Base), ScopeStack.CurrentScope.Origin);
}
From 50c18a31a167b5abc994a007f144299298d9ff90 Mon Sep 17 00:00:00 2001
From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com>
Date: Wed, 21 Feb 2024 15:27:56 -0800
Subject: [PATCH 6/8] This should go in a separate PR
---
src/tools/illink/src/linker/Linker/TypeMapInfo.cs | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/tools/illink/src/linker/Linker/TypeMapInfo.cs b/src/tools/illink/src/linker/Linker/TypeMapInfo.cs
index a6a185c6e6a80..804b2ad93ec26 100644
--- a/src/tools/illink/src/linker/Linker/TypeMapInfo.cs
+++ b/src/tools/illink/src/linker/Linker/TypeMapInfo.cs
@@ -181,7 +181,7 @@ void MapInterfaceMethodsInTypeHierarchy (TypeDefinition type)
}
// Look for a default implementation last.
- FindAndAddDefaultInterfaceImplementations (type, type, resolvedInterfaceMethod, interfaceImpl.OriginalImpl);
+ FindAndAddDefaultInterfaceImplementations (type, type, resolvedInterfaceMethod);
}
}
}
@@ -290,7 +290,7 @@ void AnnotateMethods (MethodDefinition @base, MethodDefinition @override, Interf
///
/// The InterfaceImplementation on that points to the DeclaringType of .
///
- void FindAndAddDefaultInterfaceImplementations (TypeDefinition typeThatImplementsInterface, TypeDefinition typeThatMayHaveDIM, MethodDefinition interfaceMethodToBeImplemented, InterfaceImplementation implOfInterface)
+ void FindAndAddDefaultInterfaceImplementations (TypeDefinition typeThatImplementsInterface, TypeDefinition typeThatMayHaveDIM, MethodDefinition interfaceMethodToBeImplemented)
{
// Go over all interfaces, trying to find a method that is an explicit MethodImpl of the
// interface method in question.
@@ -305,7 +305,7 @@ void FindAndAddDefaultInterfaceImplementations (TypeDefinition typeThatImplement
foreach (var potentialImplMethod in potentialImplInterface.Methods) {
if (potentialImplMethod == interfaceMethodToBeImplemented &&
!potentialImplMethod.IsAbstract) {
- AddDefaultInterfaceImplementation (interfaceMethodToBeImplemented, typeThatImplementsInterface, (implOfInterface, potentialImplMethod));
+ AddDefaultInterfaceImplementation (interfaceMethodToBeImplemented, typeThatImplementsInterface, (interfaceImpl, potentialImplMethod));
foundImpl = true;
break;
}
@@ -316,7 +316,7 @@ void FindAndAddDefaultInterfaceImplementations (TypeDefinition typeThatImplement
// This method is an override of something. Let's see if it's the method we are looking for.
foreach (var @override in potentialImplMethod.Overrides) {
if (context.TryResolve (@override) == interfaceMethodToBeImplemented) {
- AddDefaultInterfaceImplementation (interfaceMethodToBeImplemented, typeThatImplementsInterface, (implOfInterface, @potentialImplMethod));
+ AddDefaultInterfaceImplementation (interfaceMethodToBeImplemented, typeThatImplementsInterface, (interfaceImpl, potentialImplMethod));
foundImpl = true;
break;
}
@@ -330,7 +330,7 @@ void FindAndAddDefaultInterfaceImplementations (TypeDefinition typeThatImplement
// We haven't found a MethodImpl on the current interface, but one of the interfaces
// this interface requires could still provide it.
if (!foundImpl) {
- FindAndAddDefaultInterfaceImplementations (typeThatImplementsInterface, potentialImplInterface, interfaceMethodToBeImplemented, implOfInterface);
+ FindAndAddDefaultInterfaceImplementations (typeThatImplementsInterface, potentialImplInterface, interfaceMethodToBeImplemented);
}
}
}
From 11e691385f114852df97ef599f9f68b7ca0c2570 Mon Sep 17 00:00:00 2001
From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com>
Date: Wed, 21 Feb 2024 15:40:41 -0800
Subject: [PATCH 7/8] Don't need to change this yet
---
.../src/linker/Linker.Steps/MarkStep.cs | 56 +++++++++----------
1 file changed, 28 insertions(+), 28 deletions(-)
diff --git a/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs b/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs
index 0d0543dcdcf56..bb5e95e0a38dd 100644
--- a/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs
+++ b/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs
@@ -297,7 +297,7 @@ bool ProcessInternalsVisibleAttributes ()
Debug.Assert (attr.Provider is ModuleDefinition or AssemblyDefinition);
var assembly = (provider is ModuleDefinition module) ? module.Assembly : provider as AssemblyDefinition;
- using var assemblyScope = ScopeStack.PushLocalScope (new MessageOrigin (assembly));
+ using var assemblyScope = ScopeStack.PushScope (new MessageOrigin (assembly));
if (!Annotations.IsMarked (attr.Attribute) && IsInternalsVisibleAttributeAssemblyMarked (attr.Attribute)) {
MarkCustomAttribute (attr.Attribute, new DependencyInfo (DependencyKind.AssemblyOrModuleAttribute, attr.Provider));
@@ -362,7 +362,7 @@ internal void MarkEntireType (TypeDefinition type, in DependencyInfo reason)
// Prevent cases where there's nothing on the stack (can happen when marking entire assemblies)
// In which case we would generate warnings with no source (hard to debug)
- using MarkScopeStack.LocalScope? _ = ScopeStack.CurrentScope.Origin.Provider == null ? ScopeStack.PushLocalScope (new MessageOrigin (type)) : null;
+ using var _ = ScopeStack.CurrentScope.Origin.Provider == null ? ScopeStack.PushScope (new MessageOrigin (type)) : null;
if (!_entireTypesMarked.Add (type))
return;
@@ -451,7 +451,7 @@ bool MarkFullyPreservedAssemblies ()
// Setup empty scope - there has to be some scope setup since we're doing marking below
// but there's no "origin" right now (command line is the origin really)
- using var localScope = ScopeStack.PushLocalScope (new MessageOrigin ((ICustomAttributeProvider?) null));
+ using var localScope = ScopeStack.PushScope (new MessageOrigin ((ICustomAttributeProvider?) null));
// Beware: this works on loaded assemblies, not marked assemblies, so it should not be tied to marking.
// We could further optimize this to only iterate through assemblies if the last mark iteration loaded
@@ -488,7 +488,7 @@ bool ProcessPrimaryQueue ()
bool ProcessMarkedPending ()
{
- using var emptyScope = ScopeStack.PushLocalScope (new MessageOrigin (null as ICustomAttributeProvider));
+ using var emptyScope = ScopeStack.PushScope (new MessageOrigin (null as ICustomAttributeProvider));
bool marked = false;
foreach (var pending in Annotations.GetMarkedPending ()) {
@@ -498,7 +498,7 @@ bool ProcessMarkedPending ()
if (Annotations.IsProcessed (pending.Key))
continue;
- using var localScope = ScopeStack.PushLocalScope (pending.Value);
+ using var localScope = ScopeStack.PushScope (pending.Value);
switch (pending.Key) {
case TypeDefinition type:
@@ -572,7 +572,7 @@ protected virtual void EnqueueMethod (MethodDefinition method, in DependencyInfo
void ProcessVirtualMethods ()
{
foreach ((var method, var scope) in _virtual_methods) {
- using (ScopeStack.PushLocalScope (scope)) {
+ using (ScopeStack.PushScope (scope)) {
ProcessVirtualMethod (method);
}
}
@@ -597,7 +597,7 @@ void ProcessMarkedTypesWithInterfaces ()
// UnusedInterfaces optimization is turned off mark all interface implementations
bool unusedInterfacesOptimizationEnabled = Context.IsOptimizationEnabled (CodeOptimizations.UnusedInterfaces, type);
- using (ScopeStack.PushLocalScope (scope)) {
+ using (ScopeStack.PushScope (scope)) {
if (Annotations.IsInstantiated (type) || Annotations.IsRelevantToVariantCasting (type) ||
!unusedInterfacesOptimizationEnabled) {
MarkInterfaceImplementations (type);
@@ -685,7 +685,7 @@ void ProcessPendingBodies ()
for (int i = 0; i < _unreachableBodies.Count; i++) {
(var body, var scope) = _unreachableBodies[i];
if (Annotations.IsInstantiated (body.Method.DeclaringType)) {
- using (ScopeStack.PushLocalScope (scope))
+ using (ScopeStack.PushScope (scope))
MarkMethodBody (body);
_unreachableBodies.RemoveAt (i--);
@@ -703,7 +703,7 @@ void ProcessVirtualMethod (MethodDefinition method)
foreach (var dimInfo in defaultImplementations) {
ProcessDefaultImplementation (dimInfo.ImplementingType, dimInfo.InterfaceImpl, dimInfo.DefaultInterfaceMethod);
- var ov = new OverrideInformation (method, dimInfo.DefaultInterfaceMethod, Context, dimInfo.InterfaceImpl);
+ var ov = new OverrideInformation (method, dimInfo.DefaultInterfaceMethod, Context);
if (IsInterfaceImplementationMethodNeededByTypeDueToInterface (ov, dimInfo.ImplementingType))
MarkMethod (ov.Override, new DependencyInfo (DependencyKind.Override, ov.Base), ScopeStack.CurrentScope.Origin);
}
@@ -874,7 +874,7 @@ void MarkCustomAttributes (ICustomAttributeProvider provider, in DependencyInfo
return;
IMemberDefinition providerMember = (IMemberDefinition) provider; ;
- using (ScopeStack.PushLocalScope (new MessageOrigin (providerMember)))
+ using (ScopeStack.PushScope (new MessageOrigin (providerMember)))
foreach (var dynamicDependency in Annotations.GetLinkerAttributes (providerMember))
MarkDynamicDependency (dynamicDependency, providerMember);
}
@@ -1407,7 +1407,7 @@ protected virtual void MarkAssembly (AssemblyDefinition assembly, DependencyInfo
if (CheckProcessed (assembly))
return;
- using var assemblyScope = ScopeStack.PushLocalScope (new MessageOrigin (assembly));
+ using var assemblyScope = ScopeStack.PushScope (new MessageOrigin (assembly));
EmbeddedXmlInfo.ProcessDescriptors (assembly, Context);
@@ -1537,7 +1537,7 @@ bool ProcessLazyAttributes ()
Debug.Assert (provider is ModuleDefinition or AssemblyDefinition);
var assembly = (provider is ModuleDefinition module) ? module.Assembly : provider as AssemblyDefinition;
- using var assemblyScope = ScopeStack.PushLocalScope (new MessageOrigin (assembly));
+ using var assemblyScope = ScopeStack.PushScope (new MessageOrigin (assembly));
var resolved = Context.Resolve (customAttribute.Constructor);
if (resolved == null) {
@@ -1607,7 +1607,7 @@ bool ProcessLateMarkedAttributes ()
}
markOccurred = true;
- using (ScopeStack.PushLocalScope (scope)) {
+ using (ScopeStack.PushScope (scope)) {
MarkCustomAttribute (customAttribute, reason);
}
}
@@ -1788,7 +1788,7 @@ void MarkField (FieldDefinition field, in DependencyInfo reason, in MessageOrigi
// Use the original scope for marking the declaring type - it provides better warning message location
MarkType (field.DeclaringType, new DependencyInfo (DependencyKind.DeclaringType, field));
- using var fieldScope = ScopeStack.PushLocalScope (new MessageOrigin (field));
+ using var fieldScope = ScopeStack.PushScope (new MessageOrigin (field));
MarkType (field.FieldType, new DependencyInfo (DependencyKind.FieldType, field));
MarkCustomAttributes (field, new DependencyInfo (DependencyKind.CustomAttribute, field));
MarkMarshalSpec (field, new DependencyInfo (DependencyKind.FieldMarshalSpec, field));
@@ -2007,7 +2007,7 @@ internal void MarkStaticConstructorVisibleToReflection (TypeDefinition type, in
if (reference == null)
return null;
- using MarkScopeStack.LocalScope? localScope = origin.HasValue ? ScopeStack.PushLocalScope (origin.Value) : null;
+ using var localScope = origin.HasValue ? ScopeStack.PushScope (origin.Value) : null;
(reference, reason) = GetOriginalType (reference, reason);
@@ -2053,7 +2053,7 @@ internal void MarkStaticConstructorVisibleToReflection (TypeDefinition type, in
if (type.Scope is ModuleDefinition module)
MarkModule (module, new DependencyInfo (DependencyKind.ScopeOfType, type));
- using var typeScope = ScopeStack.PushLocalScope (new MessageOrigin (type));
+ using var typeScope = ScopeStack.PushScope (new MessageOrigin (type));
foreach (Action handleMarkType in MarkContext.MarkTypeActions)
handleMarkType (type);
@@ -2141,7 +2141,7 @@ internal void MarkStaticConstructorVisibleToReflection (TypeDefinition type, in
}
}
if (ShouldMarkTypeStaticConstructor (type) && reason.Kind != DependencyKind.TriggersCctorForCalledMethod) {
- using (ScopeStack.PopToParentScope ())
+ using (ScopeStack.PopToParent ())
MarkStaticConstructor (type, new DependencyInfo (DependencyKind.CctorForType, type), ScopeStack.CurrentScope.Origin);
}
}
@@ -2440,7 +2440,7 @@ void MarkNamedProperty (TypeDefinition type, string property_name, in Dependency
if (property.Name != property_name)
continue;
- using (ScopeStack.PushLocalScope (new MessageOrigin (property))) {
+ using (ScopeStack.PushScope (new MessageOrigin (property))) {
// This marks methods directly without reporting the property.
MarkMethod (property.GetMethod, reason, ScopeStack.CurrentScope.Origin);
MarkMethod (property.SetMethod, reason, ScopeStack.CurrentScope.Origin);
@@ -2804,7 +2804,7 @@ void MarkGenericArguments (IGenericInstance instance)
// The only two implementations of IGenericInstance both derive from MemberReference
Debug.Assert (instance is MemberReference);
- using MarkScopeStack.LocalScope? _ = ScopeStack.CurrentScope.Origin.Provider == null ? ScopeStack.PushLocalScope (new MessageOrigin (((MemberReference) instance).Resolve ())) : null;
+ using var _ = ScopeStack.CurrentScope.Origin.Provider == null ? ScopeStack.PushScope (new MessageOrigin (((MemberReference) instance).Resolve ())) : null;
var scanner = new GenericArgumentDataFlow (Context, this, ScopeStack.CurrentScope.Origin);
scanner.ProcessGenericArgumentDataFlow (parameter, argument);
}
@@ -2832,7 +2832,7 @@ void MarkGenericArguments (IGenericInstance instance)
void ApplyPreserveInfo (TypeDefinition type)
{
- using var typeScope = ScopeStack.PushLocalScope (new MessageOrigin (type));
+ using var typeScope = ScopeStack.PushScope (new MessageOrigin (type));
if (Annotations.TryGetPreserve (type, out TypePreserve preserve)) {
if (!Annotations.SetAppliedPreserve (type, preserve))
@@ -3203,8 +3203,8 @@ protected virtual void ProcessMethod (MethodDefinition method, in DependencyInfo
throw new InternalErrorException ($"Unsupported method dependency {reason.Kind}");
#endif
ScopeStack.AssertIsEmpty ();
- using var parentScope = ScopeStack.PushLocalScope (new MarkScopeStack.Scope (origin));
- using var methodScope = ScopeStack.PushLocalScope (new MessageOrigin (method));
+ using var parentScope = ScopeStack.PushScope (new MarkScopeStack.Scope (origin));
+ using var methodScope = ScopeStack.PushScope (new MessageOrigin (method));
bool markedForCall =
reason.Kind == DependencyKind.DirectCall ||
@@ -3360,7 +3360,7 @@ protected virtual void MarkRequirementsForInstantiatedTypes (TypeDefinition type
Annotations.MarkInstantiated (type);
- using var typeScope = ScopeStack.PushLocalScope (new MessageOrigin (type));
+ using var typeScope = ScopeStack.PushScope (new MessageOrigin (type));
MarkInterfaceImplementations (type);
@@ -3450,7 +3450,7 @@ bool MarkDisablePrivateReflectionAttribute ()
if (disablePrivateReflection == null)
throw new LinkerFatalErrorException (MessageContainer.CreateErrorMessage (null, DiagnosticId.CouldNotFindType, "System.Runtime.CompilerServices.DisablePrivateReflectionAttribute"));
- using (ScopeStack.PushLocalScope (new MessageOrigin (null as ICustomAttributeProvider))) {
+ using (ScopeStack.PushScope (new MessageOrigin (null as ICustomAttributeProvider))) {
MarkType (disablePrivateReflection, DependencyInfo.DisablePrivateReflectionRequirement);
var ctor = MarkMethodIf (disablePrivateReflection.Methods, MethodDefinitionExtensions.IsDefaultConstructor, new DependencyInfo (DependencyKind.DisablePrivateReflectionRequirement, disablePrivateReflection), ScopeStack.CurrentScope.Origin);
@@ -3570,7 +3570,7 @@ protected internal void MarkProperty (PropertyDefinition prop, in DependencyInfo
if (!Annotations.MarkProcessed (prop, reason))
return;
- using var propertyScope = ScopeStack.PushLocalScope (new MessageOrigin (prop));
+ using var propertyScope = ScopeStack.PushScope (new MessageOrigin (prop));
// Consider making this more similar to MarkEvent method?
MarkCustomAttributes (prop, new DependencyInfo (DependencyKind.CustomAttribute, prop));
@@ -3582,7 +3582,7 @@ protected internal virtual void MarkEvent (EventDefinition evt, in DependencyInf
if (!Annotations.MarkProcessed (evt, reason))
return;
- using var eventScope = ScopeStack.PushLocalScope (new MessageOrigin (evt));
+ using var eventScope = ScopeStack.PushScope (new MessageOrigin (evt));
MarkCustomAttributes (evt, new DependencyInfo (DependencyKind.CustomAttribute, evt));
@@ -3681,7 +3681,7 @@ bool MarkAndCheckRequiresReflectionMethodBodyScanner (MethodIL methodIL)
requiresReflectionMethodBodyScanner =
ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForMethodBody (Context, methodIL.Method);
- using var _ = ScopeStack.PushLocalScope (new MessageOrigin (methodIL.Method));
+ using var _ = ScopeStack.PushScope (new MessageOrigin (methodIL.Method));
foreach (Instruction instruction in methodIL.Instructions)
MarkInstruction (instruction, methodIL.Method, ref requiresReflectionMethodBodyScanner);
@@ -3832,7 +3832,7 @@ protected internal virtual void MarkInterfaceImplementation (InterfaceImplementa
return;
Annotations.MarkProcessed (iface, reason ?? new DependencyInfo (DependencyKind.InterfaceImplementationOnType, ScopeStack.CurrentScope.Origin.Provider));
- using MarkScopeStack.LocalScope? localScope = origin.HasValue ? ScopeStack.PushLocalScope (origin.Value) : null;
+ using var localScope = origin.HasValue ? ScopeStack.PushScope (origin.Value) : null;
// Blame the type that has the interfaceimpl, expecting the type itself to get marked for other reasons.
MarkCustomAttributes (iface, new DependencyInfo (DependencyKind.CustomAttribute, iface));
From b45afddcbba30555d3dccf21b4ed276711b9d783 Mon Sep 17 00:00:00 2001
From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com>
Date: Wed, 21 Feb 2024 15:42:41 -0800
Subject: [PATCH 8/8] local main was outdated when resetting MarkStep.cs
---
.../src/linker/Linker.Steps/MarkStep.cs | 54 +++++++++----------
1 file changed, 27 insertions(+), 27 deletions(-)
diff --git a/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs b/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs
index bb5e95e0a38dd..c7eb071913f59 100644
--- a/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs
+++ b/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs
@@ -297,7 +297,7 @@ bool ProcessInternalsVisibleAttributes ()
Debug.Assert (attr.Provider is ModuleDefinition or AssemblyDefinition);
var assembly = (provider is ModuleDefinition module) ? module.Assembly : provider as AssemblyDefinition;
- using var assemblyScope = ScopeStack.PushScope (new MessageOrigin (assembly));
+ using var assemblyScope = ScopeStack.PushLocalScope (new MessageOrigin (assembly));
if (!Annotations.IsMarked (attr.Attribute) && IsInternalsVisibleAttributeAssemblyMarked (attr.Attribute)) {
MarkCustomAttribute (attr.Attribute, new DependencyInfo (DependencyKind.AssemblyOrModuleAttribute, attr.Provider));
@@ -362,7 +362,7 @@ internal void MarkEntireType (TypeDefinition type, in DependencyInfo reason)
// Prevent cases where there's nothing on the stack (can happen when marking entire assemblies)
// In which case we would generate warnings with no source (hard to debug)
- using var _ = ScopeStack.CurrentScope.Origin.Provider == null ? ScopeStack.PushScope (new MessageOrigin (type)) : null;
+ using MarkScopeStack.LocalScope? _ = ScopeStack.CurrentScope.Origin.Provider == null ? ScopeStack.PushLocalScope (new MessageOrigin (type)) : null;
if (!_entireTypesMarked.Add (type))
return;
@@ -451,7 +451,7 @@ bool MarkFullyPreservedAssemblies ()
// Setup empty scope - there has to be some scope setup since we're doing marking below
// but there's no "origin" right now (command line is the origin really)
- using var localScope = ScopeStack.PushScope (new MessageOrigin ((ICustomAttributeProvider?) null));
+ using var localScope = ScopeStack.PushLocalScope (new MessageOrigin ((ICustomAttributeProvider?) null));
// Beware: this works on loaded assemblies, not marked assemblies, so it should not be tied to marking.
// We could further optimize this to only iterate through assemblies if the last mark iteration loaded
@@ -488,7 +488,7 @@ bool ProcessPrimaryQueue ()
bool ProcessMarkedPending ()
{
- using var emptyScope = ScopeStack.PushScope (new MessageOrigin (null as ICustomAttributeProvider));
+ using var emptyScope = ScopeStack.PushLocalScope (new MessageOrigin (null as ICustomAttributeProvider));
bool marked = false;
foreach (var pending in Annotations.GetMarkedPending ()) {
@@ -498,7 +498,7 @@ bool ProcessMarkedPending ()
if (Annotations.IsProcessed (pending.Key))
continue;
- using var localScope = ScopeStack.PushScope (pending.Value);
+ using var localScope = ScopeStack.PushLocalScope (pending.Value);
switch (pending.Key) {
case TypeDefinition type:
@@ -572,7 +572,7 @@ protected virtual void EnqueueMethod (MethodDefinition method, in DependencyInfo
void ProcessVirtualMethods ()
{
foreach ((var method, var scope) in _virtual_methods) {
- using (ScopeStack.PushScope (scope)) {
+ using (ScopeStack.PushLocalScope (scope)) {
ProcessVirtualMethod (method);
}
}
@@ -597,7 +597,7 @@ void ProcessMarkedTypesWithInterfaces ()
// UnusedInterfaces optimization is turned off mark all interface implementations
bool unusedInterfacesOptimizationEnabled = Context.IsOptimizationEnabled (CodeOptimizations.UnusedInterfaces, type);
- using (ScopeStack.PushScope (scope)) {
+ using (ScopeStack.PushLocalScope (scope)) {
if (Annotations.IsInstantiated (type) || Annotations.IsRelevantToVariantCasting (type) ||
!unusedInterfacesOptimizationEnabled) {
MarkInterfaceImplementations (type);
@@ -685,7 +685,7 @@ void ProcessPendingBodies ()
for (int i = 0; i < _unreachableBodies.Count; i++) {
(var body, var scope) = _unreachableBodies[i];
if (Annotations.IsInstantiated (body.Method.DeclaringType)) {
- using (ScopeStack.PushScope (scope))
+ using (ScopeStack.PushLocalScope (scope))
MarkMethodBody (body);
_unreachableBodies.RemoveAt (i--);
@@ -874,7 +874,7 @@ void MarkCustomAttributes (ICustomAttributeProvider provider, in DependencyInfo
return;
IMemberDefinition providerMember = (IMemberDefinition) provider; ;
- using (ScopeStack.PushScope (new MessageOrigin (providerMember)))
+ using (ScopeStack.PushLocalScope (new MessageOrigin (providerMember)))
foreach (var dynamicDependency in Annotations.GetLinkerAttributes (providerMember))
MarkDynamicDependency (dynamicDependency, providerMember);
}
@@ -1407,7 +1407,7 @@ protected virtual void MarkAssembly (AssemblyDefinition assembly, DependencyInfo
if (CheckProcessed (assembly))
return;
- using var assemblyScope = ScopeStack.PushScope (new MessageOrigin (assembly));
+ using var assemblyScope = ScopeStack.PushLocalScope (new MessageOrigin (assembly));
EmbeddedXmlInfo.ProcessDescriptors (assembly, Context);
@@ -1537,7 +1537,7 @@ bool ProcessLazyAttributes ()
Debug.Assert (provider is ModuleDefinition or AssemblyDefinition);
var assembly = (provider is ModuleDefinition module) ? module.Assembly : provider as AssemblyDefinition;
- using var assemblyScope = ScopeStack.PushScope (new MessageOrigin (assembly));
+ using var assemblyScope = ScopeStack.PushLocalScope (new MessageOrigin (assembly));
var resolved = Context.Resolve (customAttribute.Constructor);
if (resolved == null) {
@@ -1607,7 +1607,7 @@ bool ProcessLateMarkedAttributes ()
}
markOccurred = true;
- using (ScopeStack.PushScope (scope)) {
+ using (ScopeStack.PushLocalScope (scope)) {
MarkCustomAttribute (customAttribute, reason);
}
}
@@ -1788,7 +1788,7 @@ void MarkField (FieldDefinition field, in DependencyInfo reason, in MessageOrigi
// Use the original scope for marking the declaring type - it provides better warning message location
MarkType (field.DeclaringType, new DependencyInfo (DependencyKind.DeclaringType, field));
- using var fieldScope = ScopeStack.PushScope (new MessageOrigin (field));
+ using var fieldScope = ScopeStack.PushLocalScope (new MessageOrigin (field));
MarkType (field.FieldType, new DependencyInfo (DependencyKind.FieldType, field));
MarkCustomAttributes (field, new DependencyInfo (DependencyKind.CustomAttribute, field));
MarkMarshalSpec (field, new DependencyInfo (DependencyKind.FieldMarshalSpec, field));
@@ -2007,7 +2007,7 @@ internal void MarkStaticConstructorVisibleToReflection (TypeDefinition type, in
if (reference == null)
return null;
- using var localScope = origin.HasValue ? ScopeStack.PushScope (origin.Value) : null;
+ using MarkScopeStack.LocalScope? localScope = origin.HasValue ? ScopeStack.PushLocalScope (origin.Value) : null;
(reference, reason) = GetOriginalType (reference, reason);
@@ -2053,7 +2053,7 @@ internal void MarkStaticConstructorVisibleToReflection (TypeDefinition type, in
if (type.Scope is ModuleDefinition module)
MarkModule (module, new DependencyInfo (DependencyKind.ScopeOfType, type));
- using var typeScope = ScopeStack.PushScope (new MessageOrigin (type));
+ using var typeScope = ScopeStack.PushLocalScope (new MessageOrigin (type));
foreach (Action handleMarkType in MarkContext.MarkTypeActions)
handleMarkType (type);
@@ -2141,7 +2141,7 @@ internal void MarkStaticConstructorVisibleToReflection (TypeDefinition type, in
}
}
if (ShouldMarkTypeStaticConstructor (type) && reason.Kind != DependencyKind.TriggersCctorForCalledMethod) {
- using (ScopeStack.PopToParent ())
+ using (ScopeStack.PopToParentScope ())
MarkStaticConstructor (type, new DependencyInfo (DependencyKind.CctorForType, type), ScopeStack.CurrentScope.Origin);
}
}
@@ -2440,7 +2440,7 @@ void MarkNamedProperty (TypeDefinition type, string property_name, in Dependency
if (property.Name != property_name)
continue;
- using (ScopeStack.PushScope (new MessageOrigin (property))) {
+ using (ScopeStack.PushLocalScope (new MessageOrigin (property))) {
// This marks methods directly without reporting the property.
MarkMethod (property.GetMethod, reason, ScopeStack.CurrentScope.Origin);
MarkMethod (property.SetMethod, reason, ScopeStack.CurrentScope.Origin);
@@ -2804,7 +2804,7 @@ void MarkGenericArguments (IGenericInstance instance)
// The only two implementations of IGenericInstance both derive from MemberReference
Debug.Assert (instance is MemberReference);
- using var _ = ScopeStack.CurrentScope.Origin.Provider == null ? ScopeStack.PushScope (new MessageOrigin (((MemberReference) instance).Resolve ())) : null;
+ using MarkScopeStack.LocalScope? _ = ScopeStack.CurrentScope.Origin.Provider == null ? ScopeStack.PushLocalScope (new MessageOrigin (((MemberReference) instance).Resolve ())) : null;
var scanner = new GenericArgumentDataFlow (Context, this, ScopeStack.CurrentScope.Origin);
scanner.ProcessGenericArgumentDataFlow (parameter, argument);
}
@@ -2832,7 +2832,7 @@ void MarkGenericArguments (IGenericInstance instance)
void ApplyPreserveInfo (TypeDefinition type)
{
- using var typeScope = ScopeStack.PushScope (new MessageOrigin (type));
+ using var typeScope = ScopeStack.PushLocalScope (new MessageOrigin (type));
if (Annotations.TryGetPreserve (type, out TypePreserve preserve)) {
if (!Annotations.SetAppliedPreserve (type, preserve))
@@ -3203,8 +3203,8 @@ protected virtual void ProcessMethod (MethodDefinition method, in DependencyInfo
throw new InternalErrorException ($"Unsupported method dependency {reason.Kind}");
#endif
ScopeStack.AssertIsEmpty ();
- using var parentScope = ScopeStack.PushScope (new MarkScopeStack.Scope (origin));
- using var methodScope = ScopeStack.PushScope (new MessageOrigin (method));
+ using var parentScope = ScopeStack.PushLocalScope (new MarkScopeStack.Scope (origin));
+ using var methodScope = ScopeStack.PushLocalScope (new MessageOrigin (method));
bool markedForCall =
reason.Kind == DependencyKind.DirectCall ||
@@ -3360,7 +3360,7 @@ protected virtual void MarkRequirementsForInstantiatedTypes (TypeDefinition type
Annotations.MarkInstantiated (type);
- using var typeScope = ScopeStack.PushScope (new MessageOrigin (type));
+ using var typeScope = ScopeStack.PushLocalScope (new MessageOrigin (type));
MarkInterfaceImplementations (type);
@@ -3450,7 +3450,7 @@ bool MarkDisablePrivateReflectionAttribute ()
if (disablePrivateReflection == null)
throw new LinkerFatalErrorException (MessageContainer.CreateErrorMessage (null, DiagnosticId.CouldNotFindType, "System.Runtime.CompilerServices.DisablePrivateReflectionAttribute"));
- using (ScopeStack.PushScope (new MessageOrigin (null as ICustomAttributeProvider))) {
+ using (ScopeStack.PushLocalScope (new MessageOrigin (null as ICustomAttributeProvider))) {
MarkType (disablePrivateReflection, DependencyInfo.DisablePrivateReflectionRequirement);
var ctor = MarkMethodIf (disablePrivateReflection.Methods, MethodDefinitionExtensions.IsDefaultConstructor, new DependencyInfo (DependencyKind.DisablePrivateReflectionRequirement, disablePrivateReflection), ScopeStack.CurrentScope.Origin);
@@ -3570,7 +3570,7 @@ protected internal void MarkProperty (PropertyDefinition prop, in DependencyInfo
if (!Annotations.MarkProcessed (prop, reason))
return;
- using var propertyScope = ScopeStack.PushScope (new MessageOrigin (prop));
+ using var propertyScope = ScopeStack.PushLocalScope (new MessageOrigin (prop));
// Consider making this more similar to MarkEvent method?
MarkCustomAttributes (prop, new DependencyInfo (DependencyKind.CustomAttribute, prop));
@@ -3582,7 +3582,7 @@ protected internal virtual void MarkEvent (EventDefinition evt, in DependencyInf
if (!Annotations.MarkProcessed (evt, reason))
return;
- using var eventScope = ScopeStack.PushScope (new MessageOrigin (evt));
+ using var eventScope = ScopeStack.PushLocalScope (new MessageOrigin (evt));
MarkCustomAttributes (evt, new DependencyInfo (DependencyKind.CustomAttribute, evt));
@@ -3681,7 +3681,7 @@ bool MarkAndCheckRequiresReflectionMethodBodyScanner (MethodIL methodIL)
requiresReflectionMethodBodyScanner =
ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForMethodBody (Context, methodIL.Method);
- using var _ = ScopeStack.PushScope (new MessageOrigin (methodIL.Method));
+ using var _ = ScopeStack.PushLocalScope (new MessageOrigin (methodIL.Method));
foreach (Instruction instruction in methodIL.Instructions)
MarkInstruction (instruction, methodIL.Method, ref requiresReflectionMethodBodyScanner);
@@ -3832,7 +3832,7 @@ protected internal virtual void MarkInterfaceImplementation (InterfaceImplementa
return;
Annotations.MarkProcessed (iface, reason ?? new DependencyInfo (DependencyKind.InterfaceImplementationOnType, ScopeStack.CurrentScope.Origin.Provider));
- using var localScope = origin.HasValue ? ScopeStack.PushScope (origin.Value) : null;
+ using MarkScopeStack.LocalScope? localScope = origin.HasValue ? ScopeStack.PushLocalScope (origin.Value) : null;
// Blame the type that has the interfaceimpl, expecting the type itself to get marked for other reasons.
MarkCustomAttributes (iface, new DependencyInfo (DependencyKind.CustomAttribute, iface));