Update NativeAot with latest ILLink changes (#86712)
authorSven Boemer <sbomer@gmail.com>
Fri, 26 May 2023 17:44:43 +0000 (10:44 -0700)
committerGitHub <noreply@github.com>
Fri, 26 May 2023 17:44:43 +0000 (10:44 -0700)
This brings us up to date with changes from `dotnet/linker` and
allows us to remove the `ReferenceSource` directories.

* Update Dataflow ReferenceSource

* Update ILCompiler DataFlow

* Update Logging ReferenceSource

* Update ILCompiler Logging

* Update Common/Compiler ReferenceSource

* Apply formatting

* Fix up license headers

* Update Common/Compiler

* Remove ReferenceSource

* Apply suggestions from code review

Co-authored-by: Michal Strehovský <MichalStrehovsky@users.noreply.github.com>
---------

Co-authored-by: Michal Strehovský <MichalStrehovsky@users.noreply.github.com>
55 files changed:
src/coreclr/tools/Common/Compiler/ProcessLinkerXmlBase.cs
src/coreclr/tools/Common/Compiler/ReferenceSource/BodySubstitutionParser.cs [deleted file]
src/coreclr/tools/Common/Compiler/ReferenceSource/DescriptorMarker.cs [deleted file]
src/coreclr/tools/Common/Compiler/ReferenceSource/FeatureSettings.cs [deleted file]
src/coreclr/tools/Common/Compiler/ReferenceSource/GenericParameterProxy.cs [deleted file]
src/coreclr/tools/Common/Compiler/ReferenceSource/LinkAttributesParser.cs [deleted file]
src/coreclr/tools/Common/Compiler/ReferenceSource/MethodProxy.cs [deleted file]
src/coreclr/tools/Common/Compiler/ReferenceSource/ParameterProxy.cs [deleted file]
src/coreclr/tools/Common/Compiler/ReferenceSource/ProcessLinkerXmlBase.cs [deleted file]
src/coreclr/tools/Common/Compiler/ReferenceSource/README.md [deleted file]
src/coreclr/tools/Common/Compiler/ReferenceSource/TypePreserve.cs [deleted file]
src/coreclr/tools/Common/Compiler/ReferenceSource/TypeProxy.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/CompilerGeneratedState.cs
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/FlowAnnotations.cs
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/HoistedLocalKey.cs
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/ArrayValue.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/AttributeDataFlow.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/CompilerGeneratedCallGraph.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/CompilerGeneratedNames.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/CompilerGeneratedState.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/DiagnosticContext.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/DiagnosticUtilities.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/DynamicallyAccessedMembersBinder.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/DynamicallyAccessedMembersTypeHierarchy.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/FieldReferenceValue.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/FieldValue.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/FlowAnnotations.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/GenericArgumentDataFlow.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/GenericParameterValue.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/HandleCallAction.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/HoistedLocalKey.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/IValueWithStaticType.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/InterproceduralState.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/LocalVariableReferenceValue.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/MethodBodyScanner.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/MethodParameterValue.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/MethodReturnValue.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/ParameterReferenceValue.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/README.md [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/ReferenceValue.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/ReflectionMarker.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/ReflectionMethodBodyScanner.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/RequireDynamicallyAccessedMembersAction.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/ScannerExtensions.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/TrimAnalysisAssignmentPattern.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/TrimAnalysisMethodCallPattern.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/TrimAnalysisPatternStore.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/ValueNode.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ValueNode.cs
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Logging/DocumentationSignatureGenerator.PartVisitor.cs
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Logging/ReferenceSource/DocumentationSignatureGenerator.PartVisitor.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Logging/ReferenceSource/DocumentationSignatureParser.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Logging/ReferenceSource/MessageContainer.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Logging/ReferenceSource/MessageOrigin.cs [deleted file]
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Logging/ReferenceSource/README.md [deleted file]

index 77d5091..eb07ab4 100644 (file)
@@ -231,7 +231,7 @@ namespace ILCompiler
         {
             StringBuilder sb = new StringBuilder();
             CecilTypeNameFormatter.Instance.AppendName(sb, type);
-            if (regex.IsMatch(sb.ToString()))
+            if (regex.Match(sb.ToString()).Success)
                 ProcessType(type, nav);
         }
 
diff --git a/src/coreclr/tools/Common/Compiler/ReferenceSource/BodySubstitutionParser.cs b/src/coreclr/tools/Common/Compiler/ReferenceSource/BodySubstitutionParser.cs
deleted file mode 100644 (file)
index 403eb92..0000000
+++ /dev/null
@@ -1,174 +0,0 @@
-using System;
-using System.Diagnostics;
-using System.IO;
-using System.Linq;
-using System.Xml.XPath;
-using ILLink.Shared;
-using Mono.Cecil;
-
-namespace Mono.Linker.Steps
-{
-    public class BodySubstitutionParser : ProcessLinkerXmlBase
-    {
-        SubstitutionInfo? _substitutionInfo;
-
-        public BodySubstitutionParser(LinkContext context, Stream documentStream, string xmlDocumentLocation)
-            : base(context, documentStream, xmlDocumentLocation)
-        {
-        }
-
-        public BodySubstitutionParser(LinkContext context, Stream documentStream, EmbeddedResource resource, AssemblyDefinition resourceAssembly, string xmlDocumentLocation = "")
-            : base(context, documentStream, resource, resourceAssembly, xmlDocumentLocation)
-        {
-        }
-
-        public void Parse(SubstitutionInfo xmlInfo)
-        {
-            _substitutionInfo = xmlInfo;
-            bool stripSubstitutions = _context.IsOptimizationEnabled(CodeOptimizations.RemoveSubstitutions, _resource?.Assembly);
-            ProcessXml(stripSubstitutions, _context.IgnoreSubstitutions);
-        }
-
-        protected override void ProcessAssembly(AssemblyDefinition assembly, XPathNavigator nav, bool warnOnUnresolvedTypes)
-        {
-            ProcessTypes(assembly, nav, warnOnUnresolvedTypes);
-            ProcessResources(assembly, nav);
-        }
-
-        protected override TypeDefinition? ProcessExportedType(ExportedType exported, AssemblyDefinition assembly, XPathNavigator nav) => null;
-
-        protected override bool ProcessTypePattern(string fullname, AssemblyDefinition assembly, XPathNavigator nav) => false;
-
-        protected override void ProcessType(TypeDefinition type, XPathNavigator nav)
-        {
-            Debug.Assert(ShouldProcessElement(nav));
-            ProcessTypeChildren(type, nav);
-        }
-
-        protected override void ProcessMethod(TypeDefinition type, XPathNavigator methodNav, object? _customData)
-        {
-            Debug.Assert(_substitutionInfo != null);
-            string signature = GetSignature(methodNav);
-            if (string.IsNullOrEmpty(signature))
-                return;
-
-            MethodDefinition? method = FindMethod(type, signature);
-            if (method == null)
-            {
-                LogWarning(methodNav, DiagnosticId.XmlCouldNotFindMethodOnType, signature, type.GetDisplayName());
-                return;
-            }
-
-            string action = GetAttribute(methodNav, "body");
-            switch (action)
-            {
-                case "remove":
-                    _substitutionInfo.SetMethodAction(method, MethodAction.ConvertToThrow);
-                    return;
-                case "stub":
-                    string value = GetAttribute(methodNav, "value");
-                    if (!string.IsNullOrEmpty(value))
-                    {
-                        if (!TryConvertValue(value, method.ReturnType, out object? res))
-                        {
-                            LogWarning(methodNav, DiagnosticId.XmlInvalidValueForStub, method.GetDisplayName());
-                            return;
-                        }
-
-                        _substitutionInfo.SetMethodStubValue(method, res);
-                    }
-
-                    _substitutionInfo.SetMethodAction(method, MethodAction.ConvertToStub);
-                    return;
-                default:
-                    LogWarning(methodNav, DiagnosticId.XmlUnkownBodyModification, action, method.GetDisplayName());
-                    return;
-            }
-        }
-
-        protected override void ProcessField(TypeDefinition type, XPathNavigator fieldNav)
-        {
-            Debug.Assert(_substitutionInfo != null);
-            string name = GetAttribute(fieldNav, "name");
-            if (string.IsNullOrEmpty(name))
-                return;
-
-            var field = type.Fields.FirstOrDefault(f => f.Name == name);
-            if (field == null)
-            {
-                LogWarning(fieldNav, DiagnosticId.XmlCouldNotFindFieldOnType, name, type.GetDisplayName());
-                return;
-            }
-
-            if (!field.IsStatic || field.IsLiteral)
-            {
-                LogWarning(fieldNav, DiagnosticId.XmlSubstitutedFieldNeedsToBeStatic, field.GetDisplayName());
-                return;
-            }
-
-            string value = GetAttribute(fieldNav, "value");
-            if (string.IsNullOrEmpty(value))
-            {
-                LogWarning(fieldNav, DiagnosticId.XmlMissingSubstitutionValueForField, field.GetDisplayName());
-                return;
-            }
-            if (!TryConvertValue(value, field.FieldType, out object? res))
-            {
-                LogWarning(fieldNav, DiagnosticId.XmlInvalidSubstitutionValueForField, value, field.GetDisplayName());
-                return;
-            }
-
-            _substitutionInfo.SetFieldValue(field, res);
-
-            string init = GetAttribute(fieldNav, "initialize");
-            if (init?.ToLowerInvariant() == "true")
-            {
-                _substitutionInfo.SetFieldInit(field);
-            }
-        }
-
-        void ProcessResources(AssemblyDefinition assembly, XPathNavigator nav)
-        {
-            foreach (XPathNavigator resourceNav in nav.SelectChildren("resource", ""))
-            {
-                if (!ShouldProcessElement(resourceNav))
-                    continue;
-
-                string name = GetAttribute(resourceNav, "name");
-                if (String.IsNullOrEmpty(name))
-                {
-                    LogWarning(resourceNav, DiagnosticId.XmlMissingNameAttributeInResource);
-                    continue;
-                }
-
-                string action = GetAttribute(resourceNav, "action");
-                if (action != "remove")
-                {
-                    LogWarning(resourceNav, DiagnosticId.XmlInvalidValueForAttributeActionForResource, action, name);
-                    continue;
-                }
-
-                EmbeddedResource? resource = assembly.FindEmbeddedResource(name);
-                if (resource == null)
-                {
-                    LogWarning(resourceNav, DiagnosticId.XmlCouldNotFindResourceToRemoveInAssembly, name, assembly.Name.Name);
-                    continue;
-                }
-
-                _context.Annotations.AddResourceToRemove(assembly, resource);
-            }
-        }
-
-        static MethodDefinition? FindMethod(TypeDefinition type, string signature)
-        {
-            if (!type.HasMethods)
-                return null;
-
-            foreach (MethodDefinition meth in type.Methods)
-                if (signature == DescriptorMarker.GetMethodSignature(meth, includeGenericParameters: true))
-                    return meth;
-
-            return null;
-        }
-    }
-}
diff --git a/src/coreclr/tools/Common/Compiler/ReferenceSource/DescriptorMarker.cs b/src/coreclr/tools/Common/Compiler/ReferenceSource/DescriptorMarker.cs
deleted file mode 100644 (file)
index 4940457..0000000
+++ /dev/null
@@ -1,292 +0,0 @@
-// 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.IO;
-using System.Text;
-using System.Xml.XPath;
-using ILLink.Shared;
-
-using Mono.Cecil;
-
-namespace Mono.Linker.Steps
-{
-    public class DescriptorMarker : ProcessLinkerXmlBase
-    {
-        const string NamespaceElementName = "namespace";
-
-        const string _required = "required";
-        const string _preserve = "preserve";
-        const string _accessors = "accessors";
-
-        static readonly string[] _accessorsAll = new string[] { "all" };
-        static readonly char[] _accessorsSep = new char[] { ';' };
-
-        public DescriptorMarker(LinkContext context, Stream documentStream, string xmlDocumentLocation)
-            : base(context, documentStream, xmlDocumentLocation)
-        {
-        }
-
-        public DescriptorMarker(LinkContext context, Stream documentStream, EmbeddedResource resource, AssemblyDefinition resourceAssembly, string xmlDocumentLocation = "<unspecified>")
-            : base(context, documentStream, resource, resourceAssembly, xmlDocumentLocation)
-        {
-        }
-
-        public void Mark()
-        {
-            bool stripDescriptors = _context.IsOptimizationEnabled(CodeOptimizations.RemoveDescriptors, _resource?.Assembly);
-            ProcessXml(stripDescriptors, _context.IgnoreDescriptors);
-        }
-
-        protected override AllowedAssemblies AllowedAssemblySelector { get => AllowedAssemblies.AnyAssembly; }
-
-        protected override void ProcessAssembly(AssemblyDefinition assembly, XPathNavigator nav, bool warnOnUnresolvedTypes)
-        {
-            if (GetTypePreserve(nav) == TypePreserve.All)
-            {
-                foreach (var type in assembly.MainModule.Types)
-                    MarkAndPreserveAll(type, nav);
-
-                foreach (var exportedType in assembly.MainModule.ExportedTypes)
-                    _context.MarkingHelpers.MarkExportedType(exportedType, assembly.MainModule, new DependencyInfo(DependencyKind.XmlDescriptor, assembly.MainModule), GetMessageOriginForPosition(nav));
-            }
-            else
-            {
-                ProcessTypes(assembly, nav, warnOnUnresolvedTypes);
-                ProcessNamespaces(assembly, nav);
-            }
-        }
-
-        void ProcessNamespaces(AssemblyDefinition assembly, XPathNavigator nav)
-        {
-            foreach (XPathNavigator namespaceNav in nav.SelectChildren(NamespaceElementName, XmlNamespace))
-            {
-                if (!ShouldProcessElement(namespaceNav))
-                    continue;
-
-                string fullname = GetFullName(namespaceNav);
-                bool foundMatch = false;
-                foreach (TypeDefinition type in assembly.MainModule.Types)
-                {
-                    if (type.Namespace != fullname)
-                        continue;
-
-                    foundMatch = true;
-                    MarkAndPreserveAll(type, nav);
-                }
-
-                if (!foundMatch)
-                {
-                    LogWarning(namespaceNav, DiagnosticId.XmlCouldNotFindAnyTypeInNamespace, fullname);
-                }
-            }
-        }
-
-        void MarkAndPreserveAll(TypeDefinition type, XPathNavigator nav)
-        {
-            _context.Annotations.Mark(type, new DependencyInfo(DependencyKind.XmlDescriptor, _xmlDocumentLocation), GetMessageOriginForPosition(nav));
-            _context.Annotations.SetPreserve(type, TypePreserve.All);
-
-            if (!type.HasNestedTypes)
-                return;
-
-            foreach (TypeDefinition nested in type.NestedTypes)
-                MarkAndPreserveAll(nested, nav);
-        }
-
-        protected override TypeDefinition? ProcessExportedType(ExportedType exported, AssemblyDefinition assembly, XPathNavigator nav)
-        {
-            _context.MarkingHelpers.MarkExportedType(exported, assembly.MainModule, new DependencyInfo(DependencyKind.XmlDescriptor, _xmlDocumentLocation), GetMessageOriginForPosition(nav));
-            return base.ProcessExportedType(exported, assembly, nav);
-        }
-
-        protected override void ProcessType(TypeDefinition type, XPathNavigator nav)
-        {
-            Debug.Assert(ShouldProcessElement(nav));
-
-            TypePreserve preserve = GetTypePreserve(nav);
-            switch (preserve)
-            {
-                case TypePreserve.Fields when !type.HasFields:
-                    LogWarning(nav, DiagnosticId.TypeHasNoFieldsToPreserve, type.GetDisplayName());
-                    break;
-
-                case TypePreserve.Methods when !type.HasMethods:
-                    LogWarning(nav, DiagnosticId.TypeHasNoMethodsToPreserve, type.GetDisplayName());
-                    break;
-
-                case TypePreserve.Fields:
-                case TypePreserve.Methods:
-                case TypePreserve.All:
-                    _context.Annotations.SetPreserve(type, preserve);
-                    break;
-            }
-
-            bool required = IsRequired(nav);
-            ProcessTypeChildren(type, nav, required);
-
-            if (!required)
-                return;
-
-            _context.Annotations.Mark(type, new DependencyInfo(DependencyKind.XmlDescriptor, _xmlDocumentLocation), GetMessageOriginForPosition(nav));
-
-            if (type.IsNested)
-            {
-                var currentType = type;
-                while (currentType.IsNested)
-                {
-                    var parent = currentType.DeclaringType;
-                    _context.Annotations.Mark(parent, new DependencyInfo(DependencyKind.DeclaringType, currentType), GetMessageOriginForPosition(nav));
-                    currentType = parent;
-                }
-            }
-        }
-
-        static TypePreserve GetTypePreserve(XPathNavigator nav)
-        {
-            string attribute = GetAttribute(nav, _preserve);
-            if (string.IsNullOrEmpty(attribute))
-                return nav.HasChildren ? TypePreserve.Nothing : TypePreserve.All;
-
-            if (Enum.TryParse(attribute, true, out TypePreserve result))
-                return result;
-            return TypePreserve.Nothing;
-        }
-
-        protected override void ProcessField(TypeDefinition type, FieldDefinition field, XPathNavigator nav)
-        {
-            if (_context.Annotations.IsMarked(field))
-                LogWarning(nav, DiagnosticId.XmlDuplicatePreserveMember, field.FullName);
-
-            _context.Annotations.Mark(field, new DependencyInfo(DependencyKind.XmlDescriptor, _xmlDocumentLocation), GetMessageOriginForPosition(nav));
-        }
-
-        protected override void ProcessMethod(TypeDefinition type, MethodDefinition method, XPathNavigator nav, object? customData)
-        {
-            if (_context.Annotations.IsMarked(method))
-                LogWarning(nav, DiagnosticId.XmlDuplicatePreserveMember, method.GetDisplayName());
-
-            _context.Annotations.MarkIndirectlyCalledMethod(method);
-            _context.Annotations.SetAction(method, MethodAction.Parse);
-
-            if (customData is bool required && !required)
-            {
-                _context.Annotations.AddPreservedMethod(type, method);
-            }
-            else
-            {
-                _context.Annotations.Mark(method, new DependencyInfo(DependencyKind.XmlDescriptor, _xmlDocumentLocation), GetMessageOriginForPosition(nav));
-            }
-        }
-
-        void ProcessMethodIfNotNull(TypeDefinition type, MethodDefinition method, XPathNavigator nav, object? customData)
-        {
-            if (method == null)
-                return;
-
-            ProcessMethod(type, method, nav, customData);
-        }
-
-        protected override MethodDefinition? GetMethod(TypeDefinition type, string signature)
-        {
-            if (type.HasMethods)
-                foreach (MethodDefinition meth in type.Methods)
-                    if (signature == GetMethodSignature(meth, false))
-                        return meth;
-
-            return null;
-        }
-
-        public static string GetMethodSignature(MethodDefinition meth, bool includeGenericParameters)
-        {
-            StringBuilder sb = new StringBuilder();
-            sb.Append(meth.ReturnType.FullName);
-            sb.Append(" ");
-            sb.Append(meth.Name);
-            if (includeGenericParameters && meth.HasGenericParameters)
-            {
-                sb.Append("`");
-                sb.Append(meth.GenericParameters.Count);
-            }
-
-            sb.Append("(");
-            if (meth.HasParameters)
-            {
-                for (int i = 0; i < meth.Parameters.Count; i++)
-                {
-                    if (i > 0)
-                        sb.Append(",");
-
-                    sb.Append(meth.Parameters[i].ParameterType.FullName);
-                }
-            }
-            sb.Append(")");
-            return sb.ToString();
-        }
-
-        protected override void ProcessEvent(TypeDefinition type, EventDefinition @event, XPathNavigator nav, object? customData)
-        {
-            if (_context.Annotations.IsMarked(@event))
-                LogWarning(nav, DiagnosticId.XmlDuplicatePreserveMember, @event.FullName);
-
-            ProcessMethod(type, @event.AddMethod, nav, customData);
-            ProcessMethod(type, @event.RemoveMethod, nav, customData);
-            ProcessMethodIfNotNull(type, @event.InvokeMethod, nav, customData);
-        }
-
-        protected override void ProcessProperty(TypeDefinition type, PropertyDefinition property, XPathNavigator nav, object? customData, bool fromSignature)
-        {
-            string[] accessors = fromSignature ? GetAccessors(nav) : _accessorsAll;
-
-            if (_context.Annotations.IsMarked(property))
-                LogWarning(nav, DiagnosticId.XmlDuplicatePreserveMember, property.FullName);
-
-            if (Array.IndexOf(accessors, "all") >= 0)
-            {
-                ProcessMethodIfNotNull(type, property.GetMethod, nav, customData);
-                ProcessMethodIfNotNull(type, property.SetMethod, nav, customData);
-                return;
-            }
-
-            if (property.GetMethod != null && Array.IndexOf(accessors, "get") >= 0)
-                ProcessMethod(type, property.GetMethod, nav, customData);
-            else if (property.GetMethod == null)
-                LogWarning(nav, DiagnosticId.XmlCouldNotFindGetAccesorOfPropertyOnType, property.Name, type.FullName);
-
-            if (property.SetMethod != null && Array.IndexOf(accessors, "set") >= 0)
-                ProcessMethod(type, property.SetMethod, nav, customData);
-            else if (property.SetMethod == null)
-                LogWarning(nav, DiagnosticId.XmlCouldNotFindSetAccesorOfPropertyOnType, property.Name, type.FullName);
-        }
-
-        static bool IsRequired(XPathNavigator nav)
-        {
-            string attribute = GetAttribute(nav, _required);
-            if (attribute == null || attribute.Length == 0)
-                return true;
-
-            return bool.TryParse(attribute, out bool result) && result;
-        }
-
-        protected static string[] GetAccessors(XPathNavigator nav)
-        {
-            string accessorsValue = GetAttribute(nav, _accessors);
-
-            if (accessorsValue != null)
-            {
-                string[] accessors = accessorsValue.Split(
-                    _accessorsSep, StringSplitOptions.RemoveEmptyEntries);
-
-                if (accessors.Length > 0)
-                {
-                    for (int i = 0; i < accessors.Length; ++i)
-                        accessors[i] = accessors[i].ToLower();
-
-                    return accessors;
-                }
-            }
-            return _accessorsAll;
-        }
-    }
-}
diff --git a/src/coreclr/tools/Common/Compiler/ReferenceSource/FeatureSettings.cs b/src/coreclr/tools/Common/Compiler/ReferenceSource/FeatureSettings.cs
deleted file mode 100644 (file)
index 5e89376..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-// 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.Xml.XPath;
-using ILLink.Shared;
-
-namespace Mono.Linker
-{
-    public static class FeatureSettings
-    {
-        public static bool ShouldProcessElement(XPathNavigator nav, LinkContext context, string documentLocation)
-        {
-            var feature = GetAttribute(nav, "feature");
-            if (string.IsNullOrEmpty(feature))
-                return true;
-
-            var value = GetAttribute(nav, "featurevalue");
-            if (string.IsNullOrEmpty(value))
-            {
-                context.LogError(null, DiagnosticId.XmlFeatureDoesNotSpecifyFeatureValue, documentLocation, feature);
-                return false;
-            }
-
-            if (!bool.TryParse(value, out bool bValue))
-            {
-                context.LogError(null, DiagnosticId.XmlUnsupportedNonBooleanValueForFeature, documentLocation, feature);
-                return false;
-            }
-
-            var isDefault = GetAttribute(nav, "featuredefault");
-            bool bIsDefault = false;
-            if (!string.IsNullOrEmpty(isDefault) && (!bool.TryParse(isDefault, out bIsDefault) || !bIsDefault))
-            {
-                context.LogError(null, DiagnosticId.XmlDocumentLocationHasInvalidFeatureDefault, documentLocation);
-                return false;
-            }
-
-            if (!context.FeatureSettings.TryGetValue(feature, out bool featureSetting))
-                return bIsDefault;
-
-            return bValue == featureSetting;
-        }
-
-        public static string GetAttribute(XPathNavigator nav, string attribute)
-        {
-            return nav.GetAttribute(attribute, String.Empty);
-        }
-    }
-}
diff --git a/src/coreclr/tools/Common/Compiler/ReferenceSource/GenericParameterProxy.cs b/src/coreclr/tools/Common/Compiler/ReferenceSource/GenericParameterProxy.cs
deleted file mode 100644 (file)
index 1c92df4..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using Mono.Cecil;
-
-namespace ILLink.Shared.TypeSystemProxy
-{
-       internal readonly partial struct GenericParameterProxy
-       {
-               public GenericParameterProxy (GenericParameter genericParameter) => GenericParameter = genericParameter;
-
-               public static implicit operator GenericParameterProxy (GenericParameter genericParameter) => new (genericParameter);
-
-               internal partial bool HasDefaultConstructorConstraint () => GenericParameter.HasDefaultConstructorConstraint;
-
-               public readonly GenericParameter GenericParameter;
-
-               public override string ToString () => GenericParameter.ToString ();
-       }
-}
diff --git a/src/coreclr/tools/Common/Compiler/ReferenceSource/LinkAttributesParser.cs b/src/coreclr/tools/Common/Compiler/ReferenceSource/LinkAttributesParser.cs
deleted file mode 100644 (file)
index e4476e0..0000000
+++ /dev/null
@@ -1,578 +0,0 @@
-// 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.Diagnostics.CodeAnalysis;
-using System.IO;
-using System.Linq;
-using System.Text;
-using System.Xml.XPath;
-using ILLink.Shared;
-using Mono.Cecil;
-
-namespace Mono.Linker.Steps
-{
-    public class LinkAttributesParser : ProcessLinkerXmlBase
-    {
-        AttributeInfo? _attributeInfo;
-
-        public LinkAttributesParser(LinkContext context, Stream documentStream, string xmlDocumentLocation)
-            : base(context, documentStream, xmlDocumentLocation)
-        {
-        }
-
-        public LinkAttributesParser(LinkContext context, Stream documentStream, EmbeddedResource resource, AssemblyDefinition resourceAssembly, string xmlDocumentLocation = "<unspecified>")
-            : base(context, documentStream, resource, resourceAssembly, xmlDocumentLocation)
-        {
-        }
-
-        public void Parse(AttributeInfo xmlInfo)
-        {
-            _attributeInfo = xmlInfo;
-            bool stripLinkAttributes = _context.IsOptimizationEnabled(CodeOptimizations.RemoveLinkAttributes, _resource?.Assembly);
-            ProcessXml(stripLinkAttributes, _context.IgnoreLinkAttributes);
-        }
-
-        CustomAttribute[]? ProcessAttributes(XPathNavigator nav, ICustomAttributeProvider provider)
-        {
-            var builder = new ArrayBuilder<CustomAttribute>();
-            foreach (XPathNavigator argumentNav in nav.SelectChildren("attribute", string.Empty))
-            {
-                if (!ShouldProcessElement(argumentNav))
-                    continue;
-
-                TypeDefinition? attributeType;
-                string internalAttribute = GetAttribute(argumentNav, "internal");
-                if (!string.IsNullOrEmpty(internalAttribute))
-                {
-                    attributeType = GenerateRemoveAttributeInstancesAttribute();
-                    if (attributeType == null)
-                        continue;
-
-                    // TODO: Replace with IsAttributeType check once we have it
-                    if (provider is not TypeDefinition)
-                    {
-                        LogWarning(argumentNav, DiagnosticId.XmlRemoveAttributeInstancesCanOnlyBeUsedOnType, attributeType.Name);
-                        continue;
-                    }
-                }
-                else
-                {
-                    string attributeFullName = GetFullName(argumentNav);
-                    if (string.IsNullOrEmpty(attributeFullName))
-                    {
-                        LogWarning(argumentNav, DiagnosticId.XmlElementDoesNotContainRequiredAttributeFullname);
-                        continue;
-                    }
-
-                    if (!GetAttributeType(argumentNav, attributeFullName, out attributeType))
-                        continue;
-                }
-
-                CustomAttribute? customAttribute = CreateCustomAttribute(argumentNav, attributeType);
-                if (customAttribute != null)
-                {
-                    _context.LogMessage($"Assigning external custom attribute '{FormatCustomAttribute(customAttribute)}' instance to '{provider}'.");
-                    builder.Add(customAttribute);
-                }
-            }
-
-            return builder.ToArray();
-
-            static string FormatCustomAttribute(CustomAttribute ca)
-            {
-                StringBuilder sb = new StringBuilder();
-                sb.Append(ca.Constructor.GetDisplayName());
-                sb.Append(" { args: ");
-                for (int i = 0; i < ca.ConstructorArguments.Count; ++i)
-                {
-                    if (i > 0)
-                        sb.Append(", ");
-
-                    var caa = ca.ConstructorArguments[i];
-                    sb.Append($"{caa.Type.GetDisplayName()} {caa.Value}");
-                }
-                sb.Append(" }");
-
-                return sb.ToString();
-            }
-        }
-
-        TypeDefinition? GenerateRemoveAttributeInstancesAttribute()
-        {
-            if (_context.MarkedKnownMembers.RemoveAttributeInstancesAttributeDefinition != null)
-                return _context.MarkedKnownMembers.RemoveAttributeInstancesAttributeDefinition;
-
-            var voidType = BCL.FindPredefinedType("System", "Void", _context);
-            if (voidType == null)
-                return null;
-
-            var attributeType = BCL.FindPredefinedType("System", "Attribute", _context);
-            if (attributeType == null)
-                return null;
-
-            var objectType = BCL.FindPredefinedType("System", "Object", _context);
-            if (objectType == null)
-                return null;
-
-            //
-            // Generates metadata information for internal type
-            //
-            // public sealed class RemoveAttributeInstancesAttribute : Attribute
-            // {
-            //         public RemoveAttributeInstancesAttribute () {}
-            //         public RemoveAttributeInstancesAttribute (object value1) {}
-            // }
-            //
-            var td = new TypeDefinition("", "RemoveAttributeInstancesAttribute", TypeAttributes.Public);
-            td.BaseType = attributeType;
-
-            const MethodAttributes ctorAttributes = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName | MethodAttributes.Final;
-            var ctor = new MethodDefinition(".ctor", ctorAttributes, voidType);
-            td.Methods.Add(ctor);
-
-            ctor = new MethodDefinition(".ctor", ctorAttributes, voidType);
-            ctor.Parameters.Add(new ParameterDefinition(objectType));
-            td.Methods.Add(ctor);
-
-            return _context.MarkedKnownMembers.RemoveAttributeInstancesAttributeDefinition = td;
-        }
-
-        CustomAttribute? CreateCustomAttribute(XPathNavigator nav, TypeDefinition attributeType)
-        {
-            CustomAttributeArgument[] arguments = ReadCustomAttributeArguments(nav, attributeType);
-
-            MethodDefinition? constructor = FindBestMatchingConstructor(attributeType, arguments);
-            if (constructor == null)
-            {
-                LogWarning(nav, DiagnosticId.XmlCouldNotFindMatchingConstructorForCustomAttribute, attributeType.GetDisplayName());
-                return null;
-            }
-
-            CustomAttribute customAttribute = new CustomAttribute(constructor);
-            foreach (var argument in arguments)
-                customAttribute.ConstructorArguments.Add(argument);
-
-            ReadCustomAttributeProperties(nav, attributeType, customAttribute);
-
-            return customAttribute;
-        }
-
-        MethodDefinition? FindBestMatchingConstructor(TypeDefinition attributeType, CustomAttributeArgument[] args)
-        {
-            var methods = attributeType.Methods;
-            for (int i = 0; i < attributeType.Methods.Count; ++i)
-            {
-                var m = methods[i];
-                if (!m.IsInstanceConstructor())
-                    continue;
-
-                var p = m.Parameters;
-                if (args.Length != p.Count)
-                    continue;
-
-                bool match = true;
-                for (int ii = 0; match && ii < args.Length; ++ii)
-                {
-                    //
-                    // No candidates betterness, only exact matches are supported
-                    //
-                    var parameterType = _context.TryResolve(p[ii].ParameterType);
-                    if (parameterType == null || parameterType != _context.TryResolve(args[ii].Type))
-                        match = false;
-                }
-
-                if (match)
-                    return m;
-            }
-
-            return null;
-        }
-
-        void ReadCustomAttributeProperties(XPathNavigator nav, TypeDefinition attributeType, CustomAttribute customAttribute)
-        {
-            foreach (XPathNavigator propertyNav in nav.SelectChildren("property", string.Empty))
-            {
-                string propertyName = GetName(propertyNav);
-                if (string.IsNullOrEmpty(propertyName))
-                {
-                    LogWarning(propertyNav, DiagnosticId.XmlPropertyDoesNotContainAttributeName);
-                    continue;
-                }
-
-                PropertyDefinition? property = attributeType.Properties.Where(prop => prop.Name == propertyName).FirstOrDefault();
-                if (property == null)
-                {
-                    LogWarning(propertyNav, DiagnosticId.XmlCouldNotFindProperty, propertyName);
-                    continue;
-                }
-
-                var caa = ReadCustomAttributeArgument(propertyNav, property);
-                if (caa is null)
-                    continue;
-
-                customAttribute.Properties.Add(new CustomAttributeNamedArgument(property.Name, caa.Value));
-            }
-        }
-
-        CustomAttributeArgument[] ReadCustomAttributeArguments(XPathNavigator nav, TypeDefinition attributeType)
-        {
-            var args = new ArrayBuilder<CustomAttributeArgument>();
-
-            foreach (XPathNavigator argumentNav in nav.SelectChildren("argument", string.Empty))
-            {
-                CustomAttributeArgument? caa = ReadCustomAttributeArgument(argumentNav, attributeType);
-                if (caa is not null)
-                    args.Add(caa.Value);
-            }
-
-            return args.ToArray() ?? Array.Empty<CustomAttributeArgument>();
-        }
-
-        CustomAttributeArgument? ReadCustomAttributeArgument(XPathNavigator nav, IMemberDefinition memberWithAttribute)
-        {
-            TypeReference? typeref = ResolveArgumentType(nav, memberWithAttribute);
-            if (typeref is null)
-                return null;
-
-            string svalue = nav.Value;
-
-            //
-            // Builds CustomAttributeArgument in the same way as it would be
-            // represented in the metadata if encoded there. This simplifies
-            // any custom attributes handling in linker by using same attributes
-            // value extraction or mathing logic.
-            //
-            switch (typeref.MetadataType)
-            {
-                case MetadataType.Object:
-                    var argumentIterator = nav.SelectChildren("argument", string.Empty);
-                    if (argumentIterator?.MoveNext() != true)
-                    {
-                        _context.LogError(null, DiagnosticId.CustomAttributeArgumentForTypeRequiresNestedNode, "System.Object", "argument");
-                        return null;
-                    }
-
-                    var typedef = _context.TryResolve(typeref);
-                    if (typedef == null)
-                        return null;
-
-                    var boxedValue = ReadCustomAttributeArgument(argumentIterator.Current!, typedef);
-                    if (boxedValue is null)
-                        return null;
-
-                    return new CustomAttributeArgument(typeref, boxedValue);
-
-                case MetadataType.Char:
-                case MetadataType.Byte:
-                case MetadataType.SByte:
-                case MetadataType.Int16:
-                case MetadataType.UInt16:
-                case MetadataType.Int32:
-                case MetadataType.UInt32:
-                case MetadataType.UInt64:
-                case MetadataType.Int64:
-                case MetadataType.String:
-                    return new CustomAttributeArgument(typeref, ConvertStringValue(svalue, typeref));
-
-                case MetadataType.ValueType:
-                    var enumType = _context.Resolve(typeref);
-                    if (enumType?.IsEnum != true)
-                        goto default;
-
-                    var enumField = enumType.Fields.Where(f => f.IsStatic && f.Name == svalue).FirstOrDefault();
-                    object evalue = enumField?.Constant ?? svalue;
-
-                    typeref = enumType.GetEnumUnderlyingType();
-                    return new CustomAttributeArgument(enumType, ConvertStringValue(evalue, typeref));
-
-                case MetadataType.Class:
-                    if (!typeref.IsTypeOf("System", "Type"))
-                        goto default;
-
-                    if (!_context.TypeNameResolver.TryResolveTypeName(svalue, memberWithAttribute, out TypeReference? type, out _))
-                    {
-                        _context.LogError(GetMessageOriginForPosition(nav), DiagnosticId.CouldNotResolveCustomAttributeTypeValue, svalue);
-                        return null;
-                    }
-
-                    return new CustomAttributeArgument(typeref, type);
-                default:
-                    // No support for null and arrays, consider adding - dotnet/linker/issues/1957
-                    _context.LogError(GetMessageOriginForPosition(nav), DiagnosticId.UnexpectedAttributeArgumentType, typeref.GetDisplayName());
-                    return null;
-            }
-
-            TypeReference? ResolveArgumentType(XPathNavigator nav, IMemberDefinition memberWithAttribute)
-            {
-                string typeName = GetAttribute(nav, "type");
-                if (string.IsNullOrEmpty(typeName))
-                    typeName = "System.String";
-
-                if (!_context.TypeNameResolver.TryResolveTypeName(typeName, memberWithAttribute, out TypeReference? typeref, out _))
-                {
-                    _context.LogError(GetMessageOriginForPosition(nav), DiagnosticId.TypeUsedWithAttributeValueCouldNotBeFound, typeName, nav.Value);
-                    return null;
-                }
-
-                return typeref;
-            }
-        }
-
-        object? ConvertStringValue(object value, TypeReference targetType)
-        {
-            TypeCode typeCode;
-            switch (targetType.MetadataType)
-            {
-                case MetadataType.String:
-                    typeCode = TypeCode.String;
-                    break;
-                case MetadataType.Char:
-                    typeCode = TypeCode.Char;
-                    break;
-                case MetadataType.Byte:
-                    typeCode = TypeCode.Byte;
-                    break;
-                case MetadataType.SByte:
-                    typeCode = TypeCode.SByte;
-                    break;
-                case MetadataType.Int16:
-                    typeCode = TypeCode.Int16;
-                    break;
-                case MetadataType.UInt16:
-                    typeCode = TypeCode.UInt16;
-                    break;
-                case MetadataType.Int32:
-                    typeCode = TypeCode.Int32;
-                    break;
-                case MetadataType.UInt32:
-                    typeCode = TypeCode.UInt32;
-                    break;
-                case MetadataType.UInt64:
-                    typeCode = TypeCode.UInt64;
-                    break;
-                case MetadataType.Int64:
-                    typeCode = TypeCode.Int64;
-                    break;
-                case MetadataType.Boolean:
-                    typeCode = TypeCode.Boolean;
-                    break;
-                case MetadataType.Single:
-                    typeCode = TypeCode.Single;
-                    break;
-                case MetadataType.Double:
-                    typeCode = TypeCode.Double;
-                    break;
-                default:
-                    throw new NotSupportedException(targetType.ToString());
-            }
-
-            try
-            {
-                return Convert.ChangeType(value, typeCode);
-            }
-            catch
-            {
-                _context.LogError(null, DiagnosticId.CannotConverValueToType, value.ToString() ?? "", targetType.GetDisplayName());
-                return null;
-            }
-        }
-
-        bool GetAttributeType(XPathNavigator nav, string attributeFullName, [NotNullWhen(true)] out TypeDefinition? attributeType)
-        {
-            string assemblyName = GetAttribute(nav, "assembly");
-            if (string.IsNullOrEmpty(assemblyName))
-            {
-                attributeType = _context.GetType(attributeFullName);
-            }
-            else
-            {
-                AssemblyDefinition? assembly;
-                try
-                {
-                    assembly = _context.TryResolve(AssemblyNameReference.Parse(assemblyName));
-                    if (assembly == null)
-                    {
-                        LogWarning(nav, DiagnosticId.XmlCouldNotResolveAssemblyForAttribute, assemblyName, attributeFullName);
-
-                        attributeType = default;
-                        return false;
-                    }
-                }
-                catch (Exception)
-                {
-                    LogWarning(nav, DiagnosticId.XmlCouldNotResolveAssemblyForAttribute, assemblyName, attributeFullName);
-                    attributeType = default;
-                    return false;
-                }
-
-                attributeType = _context.TryResolve(assembly, attributeFullName);
-            }
-
-            if (attributeType == null)
-            {
-                LogWarning(nav, DiagnosticId.XmlAttributeTypeCouldNotBeFound, attributeFullName);
-                return false;
-            }
-
-            return true;
-        }
-
-        protected override AllowedAssemblies AllowedAssemblySelector
-        {
-            get
-            {
-                if (_resource?.Assembly == null)
-                    return AllowedAssemblies.AllAssemblies;
-
-                // Corelib XML may contain assembly wildcard to support compiler-injected attribute types
-                if (_resource?.Assembly.Name.Name == PlatformAssemblies.CoreLib)
-                    return AllowedAssemblies.AllAssemblies;
-
-                return AllowedAssemblies.ContainingAssembly;
-            }
-        }
-
-        protected override void ProcessAssembly(AssemblyDefinition assembly, XPathNavigator nav, bool warnOnUnresolvedTypes)
-        {
-            PopulateAttributeInfo(assembly, nav);
-            ProcessTypes(assembly, nav, warnOnUnresolvedTypes);
-        }
-
-        protected override void ProcessType(TypeDefinition type, XPathNavigator nav)
-        {
-            Debug.Assert(ShouldProcessElement(nav));
-
-            PopulateAttributeInfo(type, nav);
-            ProcessTypeChildren(type, nav);
-
-            if (!type.HasNestedTypes)
-                return;
-
-            foreach (XPathNavigator nestedTypeNav in nav.SelectChildren("type", string.Empty))
-            {
-                foreach (TypeDefinition nested in type.NestedTypes)
-                {
-                    if (nested.Name == GetAttribute(nestedTypeNav, "name") && ShouldProcessElement(nestedTypeNav))
-                        ProcessType(nested, nestedTypeNav);
-                }
-            }
-        }
-
-        protected override void ProcessField(TypeDefinition type, FieldDefinition field, XPathNavigator nav)
-        {
-            PopulateAttributeInfo(field, nav);
-        }
-
-        protected override void ProcessMethod(TypeDefinition type, MethodDefinition method, XPathNavigator nav, object? customData)
-        {
-            PopulateAttributeInfo(method, nav);
-            ProcessReturnParameters(method, nav);
-            ProcessParameters(method, nav);
-        }
-
-        void ProcessParameters(MethodDefinition method, XPathNavigator nav)
-        {
-            Debug.Assert(_attributeInfo != null);
-            foreach (XPathNavigator parameterNav in nav.SelectChildren("parameter", string.Empty))
-            {
-                var attributes = ProcessAttributes(parameterNav, method);
-                if (attributes != null)
-                {
-                    string paramName = GetAttribute(parameterNav, "name");
-                    foreach (ParameterDefinition parameter in method.Parameters)
-                    {
-                        if (paramName == parameter.Name)
-                        {
-                            if (parameter.HasCustomAttributes || _attributeInfo.CustomAttributes.ContainsKey(parameter))
-                                LogWarning(parameterNav, DiagnosticId.XmlMoreThanOneValyForParameterOfMethod, paramName, method.GetDisplayName());
-                            _attributeInfo.AddCustomAttributes(parameter, attributes);
-                            break;
-                        }
-                    }
-                }
-            }
-        }
-
-        void ProcessReturnParameters(MethodDefinition method, XPathNavigator nav)
-        {
-            bool firstAppearance = true;
-            foreach (XPathNavigator returnNav in nav.SelectChildren("return", string.Empty))
-            {
-                if (firstAppearance)
-                {
-                    firstAppearance = false;
-                    PopulateAttributeInfo(method.MethodReturnType, returnNav);
-                }
-                else
-                {
-                    LogWarning(returnNav, DiagnosticId.XmlMoreThanOneReturnElementForMethod, method.GetDisplayName());
-                }
-            }
-        }
-
-        protected override MethodDefinition? GetMethod(TypeDefinition type, string signature)
-        {
-            if (type.HasMethods)
-                foreach (MethodDefinition method in type.Methods)
-                    if (signature.Replace(" ", "") == GetMethodSignature(method) || signature.Replace(" ", "") == GetMethodSignature(method, true))
-                        return method;
-
-            return null;
-        }
-
-        static string GetMethodSignature(MethodDefinition method, bool includeReturnType = false)
-        {
-            StringBuilder sb = new StringBuilder();
-            if (includeReturnType)
-            {
-                sb.Append(method.ReturnType.FullName);
-            }
-            sb.Append(method.Name);
-            if (method.HasGenericParameters)
-            {
-                sb.Append("<");
-                for (int i = 0; i < method.GenericParameters.Count; i++)
-                {
-                    if (i > 0)
-                        sb.Append(",");
-
-                    sb.Append(method.GenericParameters[i].Name);
-                }
-                sb.Append(">");
-            }
-            sb.Append("(");
-            if (method.HasParameters)
-            {
-                for (int i = 0; i < method.Parameters.Count; i++)
-                {
-                    if (i > 0)
-                        sb.Append(",");
-
-                    sb.Append(method.Parameters[i].ParameterType.FullName);
-                }
-            }
-            sb.Append(")");
-            return sb.ToString();
-        }
-
-        protected override void ProcessProperty(TypeDefinition type, PropertyDefinition property, XPathNavigator nav, object? customData, bool fromSignature)
-        {
-            PopulateAttributeInfo(property, nav);
-        }
-
-        protected override void ProcessEvent(TypeDefinition type, EventDefinition @event, XPathNavigator nav, object? customData)
-        {
-            PopulateAttributeInfo(@event, nav);
-        }
-
-        void PopulateAttributeInfo(ICustomAttributeProvider provider, XPathNavigator nav)
-        {
-            Debug.Assert(_attributeInfo != null);
-            var attributes = ProcessAttributes(nav, provider);
-            if (attributes != null)
-                _attributeInfo.AddCustomAttributes(provider, attributes);
-        }
-    }
-}
diff --git a/src/coreclr/tools/Common/Compiler/ReferenceSource/MethodProxy.cs b/src/coreclr/tools/Common/Compiler/ReferenceSource/MethodProxy.cs
deleted file mode 100644 (file)
index 421db0a..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System;
-using System.Collections.Immutable;
-using Mono.Cecil;
-using Mono.Linker;
-
-namespace ILLink.Shared.TypeSystemProxy
-{
-       readonly partial struct MethodProxy : IEquatable<MethodProxy>
-       {
-               public MethodProxy (MethodDefinition method) => Method = method;
-
-               public static implicit operator MethodProxy (MethodDefinition method) => new (method);
-
-               public readonly MethodDefinition Method;
-
-               public string Name { get => Method.Name; }
-
-               public string GetDisplayName () => Method.GetDisplayName ();
-
-               internal partial bool IsDeclaredOnType (string fullTypeName) => Method.IsDeclaredOnType (fullTypeName);
-
-               internal partial bool HasMetadataParameters () => Method.HasMetadataParameters ();
-
-               /// <summary>
-               /// Gets the number of entries in the 'Parameters' section of a method's metadata (i.e. excludes the implicit 'this' from the count)
-               /// </summary>
-               internal partial int GetMetadataParametersCount () => Method.GetMetadataParametersCount ();
-
-               /// <summary>
-               /// Returns the number of parameters that are passed to the method in IL (including the implicit 'this' parameter).
-               /// In pseudocode: <code>method.HasImplicitThis() ? 1 + MetadataParametersCount : MetadataParametersCount;</code>
-               /// </summary>
-               internal partial int GetParametersCount () => Method.GetParametersCount ();
-
-               /// <summary>
-               /// Use only when iterating over all parameters. When wanting to index, use GetParameters(ParameterIndex)
-               /// </summary>
-               internal partial ParameterProxyEnumerable GetParameters () => Method.GetParameters ();
-
-               internal partial ParameterProxy GetParameter (ParameterIndex index) => Method.GetParameter (index);
-
-               internal partial bool HasGenericParameters () => Method.HasGenericParameters;
-
-               internal partial bool HasGenericParametersCount (int genericParameterCount) => Method.GenericParameters.Count == genericParameterCount;
-
-               internal partial ImmutableArray<GenericParameterProxy> GetGenericParameters ()
-               {
-                       if (!Method.HasGenericParameters)
-                               return ImmutableArray<GenericParameterProxy>.Empty;
-
-                       var builder = ImmutableArray.CreateBuilder<GenericParameterProxy> (Method.GenericParameters.Count);
-                       foreach (var genericParameter in Method.GenericParameters) {
-                               builder.Add (new GenericParameterProxy (genericParameter));
-                       }
-
-                       return builder.ToImmutableArray ();
-               }
-
-               internal partial bool IsStatic () => Method.IsStatic;
-
-               internal partial bool HasImplicitThis () => Method.HasImplicitThis ();
-
-               internal partial bool ReturnsVoid () => Method.ReturnsVoid ();
-
-               public override string ToString () => Method.ToString ();
-
-               public bool Equals (MethodProxy other) => Method.Equals (other.Method);
-
-               public override bool Equals (object? obj) => obj is MethodProxy other && Equals (other);
-
-               public override int GetHashCode () => Method.GetHashCode ();
-       }
-}
diff --git a/src/coreclr/tools/Common/Compiler/ReferenceSource/ParameterProxy.cs b/src/coreclr/tools/Common/Compiler/ReferenceSource/ParameterProxy.cs
deleted file mode 100644 (file)
index bbcb230..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using Mono.Cecil;
-using Mono.Linker;
-
-namespace ILLink.Shared.TypeSystemProxy
-{
-       internal partial struct ParameterProxy
-       {
-               public partial ReferenceKind GetReferenceKind ()
-               {
-                       if (IsImplicitThis)
-                               return Method.Method.DeclaringType.IsValueType ? ReferenceKind.Ref : ReferenceKind.None;
-#pragma warning disable RS0030 // MethodReference.Parameters is banned -- this class provides wrappers to use
-                       var param = Method.Method.Parameters[MetadataIndex];
-#pragma warning restore RS0030 // Do not used banned APIs
-                       if (!param.ParameterType.IsByReference)
-                               return ReferenceKind.None;
-                       if (param.IsIn)
-                               return ReferenceKind.In;
-                       if (param.IsOut)
-                               return ReferenceKind.Out;
-                       return ReferenceKind.Ref;
-               }
-
-               public TypeReference ParameterType {
-                       get {
-                               if (IsImplicitThis)
-                                       return Method.Method.DeclaringType;
-#pragma warning disable RS0030 // MethodReference.Parameters is banned -- this class provides wrappers to use
-                               return Method.Method.Parameters[MetadataIndex].ParameterType;
-#pragma warning restore RS0030 // Do not used banned APIs
-                       }
-               }
-
-#pragma warning disable RS0030 // MethodReference.Parameters is banned -- this class provides wrappers to use
-               public partial string GetDisplayName () => IsImplicitThis ? "this"
-                       : !string.IsNullOrEmpty (Method.Method.Parameters[MetadataIndex].Name) ? Method.Method.Parameters[MetadataIndex].Name
-                       : $"#{Index}";
-#pragma warning restore RS0030 // Do not used banned APIs
-
-               public ICustomAttributeProvider GetCustomAttributeProvider ()
-               {
-                       if (IsImplicitThis)
-                               return Method.Method;
-#pragma warning disable RS0030 // MethodReference.Parameters is banned -- this class provides wrappers to use
-                       return Method.Method.Parameters[MetadataIndex];
-#pragma warning restore RS0030 // Do not used banned APIs
-               }
-
-               public partial bool IsTypeOf (string typeName) => ParameterType.IsTypeOf (typeName);
-
-               public bool IsTypeOf (WellKnownType type) => ParameterType.IsTypeOf (type);
-       }
-}
diff --git a/src/coreclr/tools/Common/Compiler/ReferenceSource/ProcessLinkerXmlBase.cs b/src/coreclr/tools/Common/Compiler/ReferenceSource/ProcessLinkerXmlBase.cs
deleted file mode 100644 (file)
index 49df21f..0000000
+++ /dev/null
@@ -1,662 +0,0 @@
-// 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.Diagnostics.CodeAnalysis;
-using System.Globalization;
-using System.IO;
-using System.Linq;
-using System.Text.RegularExpressions;
-using System.Xml;
-using System.Xml.Linq;
-using System.Xml.XPath;
-using ILLink.Shared;
-using Mono.Cecil;
-
-namespace Mono.Linker.Steps
-{
-    [Flags]
-    public enum AllowedAssemblies
-    {
-        ContainingAssembly = 0x1,
-        AnyAssembly = 0x2 | ContainingAssembly,
-        AllAssemblies = 0x4 | AnyAssembly
-    }
-
-    public abstract class ProcessLinkerXmlBase
-    {
-        const string FullNameAttributeName = "fullname";
-        const string LinkerElementName = "linker";
-        const string TypeElementName = "type";
-        const string SignatureAttributeName = "signature";
-        const string NameAttributeName = "name";
-        const string FieldElementName = "field";
-        const string MethodElementName = "method";
-        const string EventElementName = "event";
-        const string PropertyElementName = "property";
-        const string AllAssembliesFullName = "*";
-        protected const string XmlNamespace = "";
-
-        protected readonly string _xmlDocumentLocation;
-        readonly XPathNavigator _document;
-        protected readonly (EmbeddedResource Resource, AssemblyDefinition Assembly)? _resource;
-        protected readonly LinkContext _context;
-
-        protected ProcessLinkerXmlBase(LinkContext context, Stream documentStream, string xmlDocumentLocation)
-        {
-            _context = context;
-            using (documentStream)
-            {
-                _document = XDocument.Load(documentStream, LoadOptions.SetLineInfo).CreateNavigator();
-            }
-            _xmlDocumentLocation = xmlDocumentLocation;
-        }
-
-        protected ProcessLinkerXmlBase(LinkContext context, Stream documentStream, EmbeddedResource resource, AssemblyDefinition resourceAssembly, string xmlDocumentLocation)
-            : this(context, documentStream, xmlDocumentLocation)
-        {
-            _resource = (
-                resource ?? throw new ArgumentNullException(nameof(resource)),
-                resourceAssembly ?? throw new ArgumentNullException(nameof(resourceAssembly))
-            );
-        }
-
-        protected virtual bool ShouldProcessElement(XPathNavigator nav) => FeatureSettings.ShouldProcessElement(nav, _context, _xmlDocumentLocation);
-
-        protected virtual void ProcessXml(bool stripResource, bool ignoreResource)
-        {
-            if (!AllowedAssemblySelector.HasFlag(AllowedAssemblies.AnyAssembly) && _resource == null)
-                throw new InvalidOperationException("The containing assembly must be specified for XML which is restricted to modifying that assembly only.");
-
-            try
-            {
-                XPathNavigator nav = _document.CreateNavigator();
-
-                // Initial structure check - ignore XML document which don't look like linker XML format
-                if (!nav.MoveToChild(LinkerElementName, XmlNamespace))
-                    return;
-
-                if (_resource != null)
-                {
-                    if (stripResource)
-                        _context.Annotations.AddResourceToRemove(_resource.Value.Assembly, _resource.Value.Resource);
-                    if (ignoreResource)
-                        return;
-                }
-
-                if (!ShouldProcessElement(nav))
-                    return;
-
-                ProcessAssemblies(nav);
-
-                // For embedded XML, allow not specifying the assembly explicitly in XML.
-                if (_resource != null)
-                    ProcessAssembly(_resource.Value.Assembly, nav, warnOnUnresolvedTypes: true);
-
-            }
-            catch (Exception ex) when (!(ex is LinkerFatalErrorException))
-            {
-                throw new LinkerFatalErrorException(MessageContainer.CreateErrorMessage(null, DiagnosticId.ErrorProcessingXmlLocation, _xmlDocumentLocation), ex);
-            }
-        }
-
-        protected virtual AllowedAssemblies AllowedAssemblySelector { get => _resource != null ? AllowedAssemblies.ContainingAssembly : AllowedAssemblies.AnyAssembly; }
-
-        bool ShouldProcessAllAssemblies(XPathNavigator nav, [NotNullWhen(false)] out AssemblyNameReference? assemblyName)
-        {
-            assemblyName = null;
-            if (GetFullName(nav) == AllAssembliesFullName)
-                return true;
-
-            assemblyName = GetAssemblyName(nav);
-            return false;
-        }
-
-        protected virtual void ProcessAssemblies(XPathNavigator nav)
-        {
-            foreach (XPathNavigator assemblyNav in nav.SelectChildren("assembly", ""))
-            {
-                // Errors for invalid assembly names should show up even if this element will be
-                // skipped due to feature conditions.
-                bool processAllAssemblies = ShouldProcessAllAssemblies(assemblyNav, out AssemblyNameReference? name);
-                if (processAllAssemblies && AllowedAssemblySelector != AllowedAssemblies.AllAssemblies)
-                {
-                    LogWarning(assemblyNav, DiagnosticId.XmlUnsuportedWildcard);
-                    continue;
-                }
-
-                AssemblyDefinition? assemblyToProcess = null;
-                if (!AllowedAssemblySelector.HasFlag(AllowedAssemblies.AnyAssembly))
-                {
-                    Debug.Assert(!processAllAssemblies);
-                    Debug.Assert(_resource != null);
-                    if (_resource.Value.Assembly.Name.Name != name!.Name)
-                    {
-                        LogWarning(assemblyNav, DiagnosticId.AssemblyWithEmbeddedXmlApplyToAnotherAssembly, _resource.Value.Assembly.Name.Name, name.ToString());
-                        continue;
-                    }
-                    assemblyToProcess = _resource.Value.Assembly;
-                }
-
-                if (!ShouldProcessElement(assemblyNav))
-                    continue;
-
-                if (processAllAssemblies)
-                {
-                    // We could avoid loading all references in this case: https://github.com/dotnet/linker/issues/1708
-                    foreach (AssemblyDefinition assembly in _context.GetReferencedAssemblies())
-                        ProcessAssembly(assembly, assemblyNav, warnOnUnresolvedTypes: false);
-                }
-                else
-                {
-                    Debug.Assert(!processAllAssemblies);
-                    AssemblyDefinition? assembly = assemblyToProcess ?? _context.TryResolve(name!);
-
-                    if (assembly == null)
-                    {
-                        LogWarning(assemblyNav, DiagnosticId.XmlCouldNotResolveAssembly, name!.Name);
-                        continue;
-                    }
-
-                    ProcessAssembly(assembly, assemblyNav, warnOnUnresolvedTypes: true);
-                }
-            }
-        }
-
-        protected abstract void ProcessAssembly(AssemblyDefinition assembly, XPathNavigator nav, bool warnOnUnresolvedTypes);
-
-        protected virtual void ProcessTypes(AssemblyDefinition assembly, XPathNavigator nav, bool warnOnUnresolvedTypes)
-        {
-            foreach (XPathNavigator typeNav in nav.SelectChildren(TypeElementName, XmlNamespace))
-            {
-
-                if (!ShouldProcessElement(typeNav))
-                    continue;
-
-                string fullname = GetFullName(typeNav);
-
-                if (fullname.IndexOf("*") != -1)
-                {
-                    if (ProcessTypePattern(fullname, assembly, typeNav))
-                        continue;
-                }
-
-                TypeDefinition type = assembly.MainModule.GetType(fullname);
-
-                if (type == null && assembly.MainModule.HasExportedTypes)
-                {
-                    foreach (var exported in assembly.MainModule.ExportedTypes)
-                    {
-                        if (fullname == exported.FullName)
-                        {
-                            var resolvedExternal = ProcessExportedType(exported, assembly, typeNav);
-                            if (resolvedExternal != null)
-                            {
-                                type = resolvedExternal;
-                                break;
-                            }
-                        }
-                    }
-                }
-
-                if (type == null)
-                {
-                    if (warnOnUnresolvedTypes)
-                        LogWarning(typeNav, DiagnosticId.XmlCouldNotResolveType, fullname);
-                    continue;
-                }
-
-                ProcessType(type, typeNav);
-            }
-        }
-
-        protected virtual TypeDefinition? ProcessExportedType(ExportedType exported, AssemblyDefinition assembly, XPathNavigator nav) => exported.Resolve();
-
-        void MatchType(TypeDefinition type, Regex regex, XPathNavigator nav)
-        {
-            if (regex.IsMatch(type.FullName))
-                ProcessType(type, nav);
-
-            if (!type.HasNestedTypes)
-                return;
-
-            foreach (var nt in type.NestedTypes)
-                MatchType(nt, regex, nav);
-        }
-
-        protected virtual bool ProcessTypePattern(string fullname, AssemblyDefinition assembly, XPathNavigator nav)
-        {
-            Regex regex = new Regex(fullname.Replace(".", @"\.").Replace("*", "(.*)"));
-
-            foreach (TypeDefinition type in assembly.MainModule.Types)
-            {
-                MatchType(type, regex, nav);
-            }
-
-            if (assembly.MainModule.HasExportedTypes)
-            {
-                foreach (var exported in assembly.MainModule.ExportedTypes)
-                {
-                    if (regex.IsMatch(exported.FullName))
-                    {
-                        var type = ProcessExportedType(exported, assembly, nav);
-                        if (type != null)
-                        {
-                            ProcessType(type, nav);
-                        }
-                    }
-                }
-            }
-
-            return true;
-        }
-
-        protected abstract void ProcessType(TypeDefinition type, XPathNavigator nav);
-
-        protected void ProcessTypeChildren(TypeDefinition type, XPathNavigator nav, object? customData = null)
-        {
-            if (nav.HasChildren)
-            {
-                ProcessSelectedFields(nav, type);
-                ProcessSelectedMethods(nav, type, customData);
-                ProcessSelectedEvents(nav, type, customData);
-                ProcessSelectedProperties(nav, type, customData);
-            }
-        }
-
-        void ProcessSelectedFields(XPathNavigator nav, TypeDefinition type)
-        {
-            foreach (XPathNavigator fieldNav in nav.SelectChildren(FieldElementName, XmlNamespace))
-            {
-                if (!ShouldProcessElement(fieldNav))
-                    continue;
-                ProcessField(type, fieldNav);
-            }
-        }
-
-        protected virtual void ProcessField(TypeDefinition type, XPathNavigator nav)
-        {
-            string signature = GetSignature(nav);
-            if (!String.IsNullOrEmpty(signature))
-            {
-                FieldDefinition? field = GetField(type, signature);
-                if (field == null)
-                {
-                    LogWarning(nav, DiagnosticId.XmlCouldNotFindFieldOnType, signature, type.GetDisplayName());
-                    return;
-                }
-
-                ProcessField(type, field, nav);
-            }
-
-            string name = GetName(nav);
-            if (!String.IsNullOrEmpty(name))
-            {
-                bool foundMatch = false;
-                if (type.HasFields)
-                {
-                    foreach (FieldDefinition field in type.Fields)
-                    {
-                        if (field.Name == name)
-                        {
-                            foundMatch = true;
-                            ProcessField(type, field, nav);
-                        }
-                    }
-                }
-
-                if (!foundMatch)
-                {
-                    LogWarning(nav, DiagnosticId.XmlCouldNotFindFieldOnType, name, type.GetDisplayName());
-                }
-            }
-        }
-
-        protected static FieldDefinition? GetField(TypeDefinition type, string signature)
-        {
-            if (!type.HasFields)
-                return null;
-
-            foreach (FieldDefinition field in type.Fields)
-                if (signature == field.FieldType.FullName + " " + field.Name)
-                    return field;
-
-            return null;
-        }
-
-        protected virtual void ProcessField(TypeDefinition type, FieldDefinition field, XPathNavigator nav) { }
-
-        void ProcessSelectedMethods(XPathNavigator nav, TypeDefinition type, object? customData)
-        {
-            foreach (XPathNavigator methodNav in nav.SelectChildren(MethodElementName, XmlNamespace))
-            {
-                if (!ShouldProcessElement(methodNav))
-                    continue;
-                ProcessMethod(type, methodNav, customData);
-            }
-        }
-
-        protected virtual void ProcessMethod(TypeDefinition type, XPathNavigator nav, object? customData)
-        {
-            string signature = GetSignature(nav);
-            if (!String.IsNullOrEmpty(signature))
-            {
-                MethodDefinition? method = GetMethod(type, signature);
-                if (method == null)
-                {
-                    LogWarning(nav, DiagnosticId.XmlCouldNotFindMethodOnType, signature, type.GetDisplayName());
-                    return;
-                }
-
-                ProcessMethod(type, method, nav, customData);
-            }
-
-            string name = GetAttribute(nav, NameAttributeName);
-            if (!String.IsNullOrEmpty(name))
-            {
-                bool foundMatch = false;
-                if (type.HasMethods)
-                {
-                    foreach (MethodDefinition method in type.Methods)
-                    {
-                        if (name == method.Name)
-                        {
-                            foundMatch = true;
-                            ProcessMethod(type, method, nav, customData);
-                        }
-                    }
-                }
-
-                if (!foundMatch)
-                {
-                    LogWarning(nav, DiagnosticId.XmlCouldNotFindMethodOnType, name, type.GetDisplayName());
-                }
-            }
-        }
-
-        protected virtual MethodDefinition? GetMethod(TypeDefinition type, string signature) => null;
-
-        protected virtual void ProcessMethod(TypeDefinition type, MethodDefinition method, XPathNavigator nav, object? customData) { }
-
-        void ProcessSelectedEvents(XPathNavigator nav, TypeDefinition type, object? customData)
-        {
-            foreach (XPathNavigator eventNav in nav.SelectChildren(EventElementName, XmlNamespace))
-            {
-                if (!ShouldProcessElement(eventNav))
-                    continue;
-                ProcessEvent(type, eventNav, customData);
-            }
-        }
-
-        protected virtual void ProcessEvent(TypeDefinition type, XPathNavigator nav, object? customData)
-        {
-            string signature = GetSignature(nav);
-            if (!String.IsNullOrEmpty(signature))
-            {
-                EventDefinition? @event = GetEvent(type, signature);
-                if (@event == null)
-                {
-                    LogWarning(nav, DiagnosticId.XmlCouldNotFindEventOnType, signature, type.GetDisplayName());
-                    return;
-                }
-
-                ProcessEvent(type, @event, nav, customData);
-            }
-
-            string name = GetAttribute(nav, NameAttributeName);
-            if (!String.IsNullOrEmpty(name))
-            {
-                bool foundMatch = false;
-                foreach (EventDefinition @event in type.Events)
-                {
-                    if (@event.Name == name)
-                    {
-                        foundMatch = true;
-                        ProcessEvent(type, @event, nav, customData);
-                    }
-                }
-
-                if (!foundMatch)
-                {
-                    LogWarning(nav, DiagnosticId.XmlCouldNotFindEventOnType, name, type.GetDisplayName());
-                }
-            }
-        }
-
-        protected static EventDefinition? GetEvent(TypeDefinition type, string signature)
-        {
-            if (!type.HasEvents)
-                return null;
-
-            foreach (EventDefinition @event in type.Events)
-                if (signature == @event.EventType.FullName + " " + @event.Name)
-                    return @event;
-
-            return null;
-        }
-
-        protected virtual void ProcessEvent(TypeDefinition type, EventDefinition @event, XPathNavigator nav, object? customData) { }
-
-        void ProcessSelectedProperties(XPathNavigator nav, TypeDefinition type, object? customData)
-        {
-            foreach (XPathNavigator propertyNav in nav.SelectChildren(PropertyElementName, XmlNamespace))
-            {
-                if (!ShouldProcessElement(propertyNav))
-                    continue;
-                ProcessProperty(type, propertyNav, customData);
-            }
-        }
-
-        protected virtual void ProcessProperty(TypeDefinition type, XPathNavigator nav, object? customData)
-        {
-            string signature = GetSignature(nav);
-            if (!String.IsNullOrEmpty(signature))
-            {
-                PropertyDefinition? property = GetProperty(type, signature);
-                if (property == null)
-                {
-                    LogWarning(nav, DiagnosticId.XmlCouldNotFindPropertyOnType, signature, type.GetDisplayName());
-                    return;
-                }
-
-                ProcessProperty(type, property, nav, customData, true);
-            }
-
-            string name = GetAttribute(nav, NameAttributeName);
-            if (!String.IsNullOrEmpty(name))
-            {
-                bool foundMatch = false;
-                foreach (PropertyDefinition property in type.Properties)
-                {
-                    if (property.Name == name)
-                    {
-                        foundMatch = true;
-                        ProcessProperty(type, property, nav, customData, false);
-                    }
-                }
-
-                if (!foundMatch)
-                {
-                    LogWarning(nav, DiagnosticId.XmlCouldNotFindPropertyOnType, name, type.GetDisplayName());
-                }
-            }
-        }
-
-        protected static PropertyDefinition? GetProperty(TypeDefinition type, string signature)
-        {
-            if (!type.HasProperties)
-                return null;
-
-            foreach (PropertyDefinition property in type.Properties)
-                if (signature == property.PropertyType.FullName + " " + property.Name)
-                    return property;
-
-            return null;
-        }
-
-        protected virtual void ProcessProperty(TypeDefinition type, PropertyDefinition property, XPathNavigator nav, object? customData, bool fromSignature) { }
-
-        protected virtual AssemblyNameReference GetAssemblyName(XPathNavigator nav)
-        {
-            return AssemblyNameReference.Parse(GetFullName(nav));
-        }
-
-        protected static string GetFullName(XPathNavigator nav)
-        {
-            return GetAttribute(nav, FullNameAttributeName);
-        }
-
-        protected static string GetName(XPathNavigator nav)
-        {
-            return GetAttribute(nav, NameAttributeName);
-        }
-
-        protected static string GetSignature(XPathNavigator nav)
-        {
-            return GetAttribute(nav, SignatureAttributeName);
-        }
-
-        protected static string GetAttribute(XPathNavigator nav, string attribute)
-        {
-            return nav.GetAttribute(attribute, XmlNamespace);
-        }
-
-        protected MessageOrigin GetMessageOriginForPosition(XPathNavigator position)
-        {
-            return (position is IXmlLineInfo lineInfo)
-                    ? new MessageOrigin(_xmlDocumentLocation, lineInfo.LineNumber, lineInfo.LinePosition, _resource?.Assembly)
-                    : new MessageOrigin(_xmlDocumentLocation, 0, 0, _resource?.Assembly);
-        }
-        protected void LogWarning(string message, int warningCode, XPathNavigator position)
-        {
-            _context.LogWarning(message, warningCode, GetMessageOriginForPosition(position));
-        }
-
-        protected void LogWarning(XPathNavigator position, DiagnosticId id, params string[] args)
-        {
-            _context.LogWarning(GetMessageOriginForPosition(position), id, args);
-        }
-
-        public override string ToString() => GetType().Name + ": " + _xmlDocumentLocation;
-
-        public bool TryConvertValue(string value, TypeReference target, out object? result)
-        {
-            switch (target.MetadataType)
-            {
-                case MetadataType.Boolean:
-                    if (bool.TryParse(value, out bool bvalue))
-                    {
-                        result = bvalue ? 1 : 0;
-                        return true;
-                    }
-
-                    goto case MetadataType.Int32;
-
-                case MetadataType.Byte:
-                    if (!byte.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out byte byteresult))
-                        break;
-
-                    result = (int)byteresult;
-                    return true;
-
-                case MetadataType.SByte:
-                    if (!sbyte.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out sbyte sbyteresult))
-                        break;
-
-                    result = (int)sbyteresult;
-                    return true;
-
-                case MetadataType.Int16:
-                    if (!short.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out short shortresult))
-                        break;
-
-                    result = (int)shortresult;
-                    return true;
-
-                case MetadataType.UInt16:
-                    if (!ushort.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out ushort ushortresult))
-                        break;
-
-                    result = (int)ushortresult;
-                    return true;
-
-                case MetadataType.Int32:
-                    if (!int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out int iresult))
-                        break;
-
-                    result = iresult;
-                    return true;
-
-                case MetadataType.UInt32:
-                    if (!uint.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out uint uresult))
-                        break;
-
-                    result = (int)uresult;
-                    return true;
-
-                case MetadataType.Double:
-                    if (!double.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out double dresult))
-                        break;
-
-                    result = dresult;
-                    return true;
-
-                case MetadataType.Single:
-                    if (!float.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out float fresult))
-                        break;
-
-                    result = fresult;
-                    return true;
-
-                case MetadataType.Int64:
-                    if (!long.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out long lresult))
-                        break;
-
-                    result = lresult;
-                    return true;
-
-                case MetadataType.UInt64:
-                    if (!ulong.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out ulong ulresult))
-                        break;
-
-                    result = (long)ulresult;
-                    return true;
-
-                case MetadataType.Char:
-                    if (!char.TryParse(value, out char chresult))
-                        break;
-
-                    result = (int)chresult;
-                    return true;
-
-                case MetadataType.String:
-                    if (value is string || value == null)
-                    {
-                        result = value;
-                        return true;
-                    }
-
-                    break;
-
-                case MetadataType.ValueType:
-                    if (value is string &&
-                        _context.TryResolve(target) is TypeDefinition typeDefinition &&
-                        typeDefinition.IsEnum)
-                    {
-                        var enumField = typeDefinition.Fields.Where(f => f.IsStatic && f.Name == value).FirstOrDefault();
-                        if (enumField != null)
-                        {
-                            result = Convert.ToInt32(enumField.Constant);
-                            return true;
-                        }
-                    }
-
-                    break;
-            }
-
-            result = null;
-            return false;
-        }
-    }
-}
diff --git a/src/coreclr/tools/Common/Compiler/ReferenceSource/README.md b/src/coreclr/tools/Common/Compiler/ReferenceSource/README.md
deleted file mode 100644 (file)
index a75e53a..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Sources taken from https://github.com/dotnet/linker/tree/c4abaf33f967a8fa42eb20fc386b774ad74ef319/src/linker/Linker.Steps.
diff --git a/src/coreclr/tools/Common/Compiler/ReferenceSource/TypePreserve.cs b/src/coreclr/tools/Common/Compiler/ReferenceSource/TypePreserve.cs
deleted file mode 100644 (file)
index ff38c92..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-namespace Mono.Linker
-{
-       public enum TypePreserve
-       {
-               Nothing,
-               All,
-               Fields,
-               Methods
-       }
-}
\ No newline at end of file
diff --git a/src/coreclr/tools/Common/Compiler/ReferenceSource/TypeProxy.cs b/src/coreclr/tools/Common/Compiler/ReferenceSource/TypeProxy.cs
deleted file mode 100644 (file)
index 52a43ec..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System.Collections.Immutable;
-using Mono.Cecil;
-using Mono.Linker;
-
-namespace ILLink.Shared.TypeSystemProxy
-{
-       internal readonly partial struct TypeProxy
-       {
-               public TypeProxy (TypeDefinition type) => Type = type;
-
-               public static implicit operator TypeProxy (TypeDefinition type) => new (type);
-
-               internal partial ImmutableArray<GenericParameterProxy> GetGenericParameters ()
-               {
-                       if (!Type.HasGenericParameters)
-                               return ImmutableArray<GenericParameterProxy>.Empty;
-
-                       var builder = ImmutableArray.CreateBuilder<GenericParameterProxy> (Type.GenericParameters.Count);
-                       foreach (var genericParameter in Type.GenericParameters) {
-                               builder.Add (new GenericParameterProxy (genericParameter));
-                       }
-
-                       return builder.ToImmutableArray ();
-               }
-
-               public TypeDefinition Type { get; }
-
-               public string Name { get => Type.Name; }
-
-               public string? Namespace { get => Type.Namespace; }
-
-               public bool IsTypeOf (string @namespace, string name) => Type.IsTypeOf (@namespace, name);
-
-               public bool IsTypeOf (WellKnownType wellKnownType) => Type.IsTypeOf (wellKnownType);
-
-               public string GetDisplayName () => Type.GetDisplayName ();
-
-               public override string ToString () => Type.ToString ();
-       }
-}
index cbfb822..f8cc53c 100644 (file)
@@ -79,6 +79,7 @@ namespace ILCompiler.Dataflow
 
                 var callGraph = new CompilerGeneratedCallGraph();
                 var userDefinedMethods = new HashSet<MethodDesc>();
+                var generatedTypeToTypeArgs = new Dictionary<MetadataType, TypeArgumentInfo>();
 
                 void ProcessMethod(MethodDesc method)
                 {
@@ -124,6 +125,7 @@ namespace ILCompiler.Dataflow
 
                                         referencedMethod = referencedMethod.GetTypicalMethodDefinition();
 
+                                        // Find calls to state machine constructors that occur outside the type
                                         if (referencedMethod.IsConstructor &&
                                             referencedMethod.OwningType is MetadataType generatedType &&
                                             // Don't consider calls in the same type, like inside a static constructor
@@ -133,11 +135,9 @@ namespace ILCompiler.Dataflow
                                             Debug.Assert(generatedType.IsTypeDefinition);
 
                                             // fill in null for now, attribute providers will be filled in later
-                                            _generatedTypeToTypeArgumentInfo ??= new Dictionary<MetadataType, TypeArgumentInfo>();
-
-                                            if (!_generatedTypeToTypeArgumentInfo.TryAdd(generatedType, new TypeArgumentInfo(method, null)))
+                                            if (!generatedTypeToTypeArgs.TryAdd(generatedType, new TypeArgumentInfo(method, null)))
                                             {
-                                                var alreadyAssociatedMethod = _generatedTypeToTypeArgumentInfo[generatedType].CreatingMethod;
+                                                var alreadyAssociatedMethod = generatedTypeToTypeArgs[generatedType].CreatingMethod;
                                                 logger?.LogWarning(new MessageOrigin(method), DiagnosticId.MethodsAreAssociatedWithUserMethod, method.GetDisplayName(), alreadyAssociatedMethod.GetDisplayName(), generatedType.GetDisplayName());
                                             }
                                             continue;
@@ -173,9 +173,7 @@ namespace ILCompiler.Dataflow
                                         {
                                             Debug.Assert(generatedType.IsTypeDefinition);
 
-                                            _generatedTypeToTypeArgumentInfo ??= new Dictionary<MetadataType, TypeArgumentInfo>();
-
-                                            if (!_generatedTypeToTypeArgumentInfo.TryAdd(generatedType, new TypeArgumentInfo(method, null)))
+                                            if (!generatedTypeToTypeArgs.TryAdd(generatedType, new TypeArgumentInfo(method, null)))
                                             {
                                                 // It's expected that there may be multiple methods associated with the same static closure environment.
                                                 // All of these methods will substitute the same type arguments into the closure environment
@@ -210,8 +208,7 @@ namespace ILCompiler.Dataflow
                         }
                         // Already warned above if multiple methods map to the same type
                         // Fill in null for argument providers now, the real providers will be filled in later
-                        _generatedTypeToTypeArgumentInfo ??= new Dictionary<MetadataType, TypeArgumentInfo>();
-                        _generatedTypeToTypeArgumentInfo[stateMachineType] = new TypeArgumentInfo(method, null);
+                        generatedTypeToTypeArgs[stateMachineType] = new TypeArgumentInfo(method, null);
                     }
                 }
 
@@ -282,23 +279,52 @@ namespace ILCompiler.Dataflow
 
                 // Now that we have instantiating methods fully filled out, walk the generated types and fill in the attribute
                 // providers
-                if (_generatedTypeToTypeArgumentInfo != null)
+                foreach (var generatedType in generatedTypeToTypeArgs.Keys)
                 {
-                    foreach (var generatedType in _generatedTypeToTypeArgumentInfo.Keys)
-                    {
-                        Debug.Assert(generatedType == generatedType.GetTypeDefinition());
+                    Debug.Assert(generatedType == generatedType.GetTypeDefinition());
 
-                        if (generatedType.HasInstantiation)
-                            MapGeneratedTypeTypeParameters(generatedType);
+                    if (generatedType.HasInstantiation) {
+                        MapGeneratedTypeTypeParameters(generatedType, generatedTypeToTypeArgs);
+                        // Finally, add resolved type arguments to the cache
+                        var info = generatedTypeToTypeArgs[generatedType];
+                        _generatedTypeToTypeArgumentInfo ??= new Dictionary<MetadataType, TypeArgumentInfo>();
+                        if (!_generatedTypeToTypeArgumentInfo.TryAdd(generatedType, info))
+                        {
+                            var method = info.CreatingMethod;
+                            var alreadyAssociatedMethod = _generatedTypeToTypeArgumentInfo[generatedType].CreatingMethod;
+                            logger?.LogWarning(new MessageOrigin(method), DiagnosticId.MethodsAreAssociatedWithUserMethod, method.GetDisplayName(), alreadyAssociatedMethod.GetDisplayName(), generatedType.GetDisplayName());
+                        }
                     }
                 }
 
-                void MapGeneratedTypeTypeParameters(MetadataType generatedType)
+                /// Attempts to reverse the process of the compiler's alpha renaming. So if the original code was
+                /// something like this:
+                /// <code>
+                /// void M&lt;T&gt; () {
+                ///     Action a = () => { Console.WriteLine (typeof (T)); };
+                /// }
+                /// </code>
+                /// The compiler will generate a nested class like this:
+                /// <code>
+                /// class &lt;&gt;c__DisplayClass0&lt;T&gt; {
+                ///     public void &lt;M&gt;b__0 () {
+                ///         Console.WriteLine (typeof (T));
+                ///     }
+                /// }
+                /// </code>
+                /// The task of this method is to figure out that the type parameter T in the nested class is the same
+                /// as the type parameter T in the parent method M.
+                /// <paramref name="generatedTypeToTypeArgs"/> acts as a memoization table to avoid recalculating the
+                /// mapping multiple times.
+                /// </summary>
+                void MapGeneratedTypeTypeParameters(
+                    MetadataType generatedType,
+                    Dictionary<MetadataType, TypeArgumentInfo> generatedTypeToTypeArgs)
                 {
                     Debug.Assert(CompilerGeneratedNames.IsGeneratedType(generatedType.Name));
                     Debug.Assert(generatedType == generatedType.GetTypeDefinition());
 
-                    var typeInfo = _generatedTypeToTypeArgumentInfo[generatedType];
+                    var typeInfo = generatedTypeToTypeArgs[generatedType];
                     if (typeInfo.OriginalAttributes is not null)
                     {
                         return;
@@ -342,8 +368,8 @@ namespace ILCompiler.Dataflow
                                 else
                                 {
                                     owningType = (MetadataType)owningType.GetTypeDefinition();
-                                    MapGeneratedTypeTypeParameters(owningType);
-                                    if (_generatedTypeToTypeArgumentInfo[owningType].OriginalAttributes is { } owningAttrs)
+                                    MapGeneratedTypeTypeParameters(owningType, generatedTypeToTypeArgs);
+                                    if (generatedTypeToTypeArgs[owningType].OriginalAttributes is { } owningAttrs)
                                     {
                                         userAttrs = owningAttrs[param.Index];
                                     }
@@ -358,10 +384,10 @@ namespace ILCompiler.Dataflow
                         typeArgs[i] = userAttrs;
                     }
 
-                    _generatedTypeToTypeArgumentInfo[generatedType] = typeInfo with { OriginalAttributes = typeArgs };
+                    generatedTypeToTypeArgs[generatedType] = typeInfo with { OriginalAttributes = typeArgs };
                 }
 
-                MetadataType? ScanForInit(MetadataType compilerGeneratedType, MethodIL body)
+                static MetadataType? ScanForInit(MetadataType compilerGeneratedType, MethodIL body)
                 {
                     ILReader reader = new ILReader(body.GetILBytes());
                     while (reader.HasNext)
index e489edc..52a61a3 100644 (file)
@@ -455,8 +455,6 @@ namespace ILLink.Shared.TrimAnalysis
                                 continue;
                             }
 
-                            // We convert indices from metadata space to IL space here.
-                            // IL space assigns index 0 to the `this` parameter on instance methods.
                             paramAnnotations ??= new DynamicallyAccessedMemberTypes[method.GetParametersCount()];
                             paramAnnotations[parameter.SequenceNumber - 1 + (signature.IsStatic ? 0 : 1)] = pa;
                         }
index 289a622..76b3fd4 100644 (file)
@@ -28,5 +28,8 @@ namespace ILCompiler.Dataflow
         public override bool Equals(object? obj) => obj is HoistedLocalKey other && Equals(other);
 
         public override int GetHashCode() => Field.GetHashCode();
+
+        public static bool operator ==(HoistedLocalKey left, HoistedLocalKey right) => left.Equals (right);
+        public static bool operator !=(HoistedLocalKey left, HoistedLocalKey right) => !(left == right);
     }
 }
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/ArrayValue.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/ArrayValue.cs
deleted file mode 100644 (file)
index 570714f..0000000
+++ /dev/null
@@ -1,121 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System;
-using System.Collections.Generic;
-using System.Text;
-using ILLink.Shared.DataFlow;
-using Mono.Cecil;
-using Mono.Linker.Dataflow;
-using MultiValue = ILLink.Shared.DataFlow.ValueSet<ILLink.Shared.DataFlow.SingleValue>;
-
-
-namespace ILLink.Shared.TrimAnalysis
-{
-       partial record ArrayValue
-       {
-               public static MultiValue Create (MultiValue size, TypeReference elementType)
-               {
-                       MultiValue result = MultiValueLattice.Top;
-                       foreach (var sizeValue in size) {
-                               result = MultiValueLattice.Meet (result, new MultiValue (new ArrayValue (sizeValue, elementType)));
-                       }
-
-                       return result;
-               }
-
-               public static ArrayValue Create (int size, TypeReference elementType)
-               {
-                       return new ArrayValue (new ConstIntValue (size), elementType);
-               }
-
-               /// <summary>
-               /// Constructs an array value of the given size
-               /// </summary>
-               ArrayValue (SingleValue size, TypeReference elementType)
-               {
-                       Size = size;
-                       ElementType = elementType;
-                       IndexValues = new Dictionary<int, ValueBasicBlockPair> ();
-               }
-
-               public TypeReference ElementType { get; }
-               public Dictionary<int, ValueBasicBlockPair> IndexValues { get; }
-
-               public partial bool TryGetValueByIndex (int index, out MultiValue value)
-               {
-                       if (IndexValues.TryGetValue (index, out var valuePair)) {
-                               value = valuePair.Value;
-                               return true;
-                       }
-
-                       value = default;
-                       return false;
-               }
-
-               public override int GetHashCode ()
-               {
-                       return HashCode.Combine (GetType ().GetHashCode (), Size);
-               }
-
-               public bool Equals (ArrayValue? otherArr)
-               {
-                       if (otherArr == null)
-                               return false;
-
-                       bool equals = Size.Equals (otherArr.Size);
-                       equals &= IndexValues.Count == otherArr.IndexValues.Count;
-                       if (!equals)
-                               return false;
-
-                       // If both sets T and O are the same size and "T intersect O" is empty, then T == O.
-                       HashSet<KeyValuePair<int, ValueBasicBlockPair>> thisValueSet = new (IndexValues);
-                       HashSet<KeyValuePair<int, ValueBasicBlockPair>> otherValueSet = new (otherArr.IndexValues);
-                       thisValueSet.ExceptWith (otherValueSet);
-                       return thisValueSet.Count == 0;
-               }
-
-               public override SingleValue DeepCopy ()
-               {
-                       var newValue = new ArrayValue (Size.DeepCopy (), ElementType);
-                       foreach (var kvp in IndexValues) {
-                               newValue.IndexValues.Add (kvp.Key, new ValueBasicBlockPair (kvp.Value.Value.Clone (), kvp.Value.BasicBlockIndex));
-                       }
-
-                       return newValue;
-               }
-
-               public override string ToString ()
-               {
-                       StringBuilder result = new ();
-                       result.Append ("Array Size:");
-                       result.Append (this.ValueToString (Size));
-
-                       result.Append (", Values:(");
-                       bool first = true;
-                       foreach (var element in IndexValues) {
-                               if (!first) {
-                                       result.Append (",");
-                                       first = false;
-                               }
-
-                               result.Append ("(");
-                               result.Append (element.Key);
-                               result.Append (",(");
-                               bool firstValue = true;
-                               foreach (var v in element.Value.Value) {
-                                       if (firstValue) {
-                                               result.Append (",");
-                                               firstValue = false;
-                                       }
-
-                                       result.Append (v.ToString ());
-                               }
-                               result.Append ("))");
-                       }
-                       result.Append (')');
-
-                       return result.ToString ();
-               }
-       }
-}
\ No newline at end of file
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/AttributeDataFlow.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/AttributeDataFlow.cs
deleted file mode 100644 (file)
index fa2aa69..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System;
-using System.Collections.Generic;
-using System.Diagnostics.CodeAnalysis;
-using ILLink.Shared.TrimAnalysis;
-using Mono.Cecil;
-using Mono.Linker.Steps;
-using MultiValue = ILLink.Shared.DataFlow.ValueSet<ILLink.Shared.DataFlow.SingleValue>;
-
-namespace Mono.Linker.Dataflow
-{
-       public readonly struct AttributeDataFlow
-       {
-               readonly LinkContext _context;
-               readonly MarkStep _markStep;
-               readonly MessageOrigin _origin;
-
-               public AttributeDataFlow (LinkContext context, MarkStep markStep, in MessageOrigin origin)
-               {
-                       _context = context;
-                       _markStep = markStep;
-                       _origin = origin;
-               }
-
-               public void ProcessAttributeDataflow (MethodDefinition method, IList<CustomAttributeArgument> arguments)
-               {
-                       foreach (var parameter in method.GetMetadataParameters ()) {
-                               var parameterValue = _context.Annotations.FlowAnnotations.GetMethodParameterValue (parameter);
-                               if (parameterValue.DynamicallyAccessedMemberTypes != DynamicallyAccessedMemberTypes.None) {
-                                       MultiValue value = GetValueForCustomAttributeArgument (arguments[parameter.MetadataIndex]);
-                                       var diagnosticContext = new DiagnosticContext (_origin, diagnosticsEnabled: true, _context);
-                                       RequireDynamicallyAccessedMembers (diagnosticContext, value, parameterValue);
-                               }
-                       }
-               }
-
-               public void ProcessAttributeDataflow (FieldDefinition field, CustomAttributeArgument value)
-               {
-                       MultiValue valueNode = GetValueForCustomAttributeArgument (value);
-                       var fieldValueCandidate = _context.Annotations.FlowAnnotations.GetFieldValue (field);
-                       if (fieldValueCandidate is not ValueWithDynamicallyAccessedMembers fieldValue)
-                               return;
-
-                       var diagnosticContext = new DiagnosticContext (_origin, diagnosticsEnabled: true, _context);
-                       RequireDynamicallyAccessedMembers (diagnosticContext, valueNode, fieldValue);
-               }
-
-               MultiValue GetValueForCustomAttributeArgument (CustomAttributeArgument argument)
-               {
-                       if (argument.Type.Name == "Type") {
-                               if (argument.Value is null)
-                                       return NullValue.Instance;
-
-                               TypeDefinition? referencedType = ((TypeReference) argument.Value).ResolveToTypeDefinition (_context);
-                               return referencedType == null
-                                       ? UnknownValue.Instance
-                                       : new SystemTypeValue (referencedType);
-                       }
-
-                       if (argument.Type.MetadataType == MetadataType.String)
-                               return argument.Value is null ? NullValue.Instance : new KnownStringValue ((string) argument.Value);
-
-                       // We shouldn't have gotten a non-null annotation for this from GetParameterAnnotation
-                       throw new InvalidOperationException ();
-               }
-
-               void RequireDynamicallyAccessedMembers (in DiagnosticContext diagnosticContext, in MultiValue value, ValueWithDynamicallyAccessedMembers targetValue)
-               {
-                       var reflectionMarker = new ReflectionMarker (_context, _markStep, enabled: true);
-                       var requireDynamicallyAccessedMembersAction = new RequireDynamicallyAccessedMembersAction (reflectionMarker, diagnosticContext);
-                       requireDynamicallyAccessedMembersAction.Invoke (value, targetValue);
-               }
-       }
-}
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/CompilerGeneratedCallGraph.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/CompilerGeneratedCallGraph.cs
deleted file mode 100644 (file)
index 1cfbc87..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System.Collections.Generic;
-using System.Diagnostics;
-using Mono.Cecil;
-
-namespace Mono.Linker.Dataflow
-{
-       sealed class CompilerGeneratedCallGraph
-       {
-               readonly Dictionary<IMemberDefinition, HashSet<IMemberDefinition>> _callGraph;
-
-               public CompilerGeneratedCallGraph () => _callGraph = new Dictionary<IMemberDefinition, HashSet<IMemberDefinition>> ();
-
-               void TrackCallInternal (IMemberDefinition fromMember, IMemberDefinition toMember)
-               {
-                       if (!_callGraph.TryGetValue (fromMember, out HashSet<IMemberDefinition>? toMembers)) {
-                               toMembers = new HashSet<IMemberDefinition> ();
-                               _callGraph.Add (fromMember, toMembers);
-                       }
-                       toMembers.Add (toMember);
-               }
-
-               public void TrackCall (MethodDefinition fromMethod, MethodDefinition toMethod)
-               {
-                       Debug.Assert (CompilerGeneratedNames.IsLambdaOrLocalFunction (toMethod.Name));
-                       TrackCallInternal (fromMethod, toMethod);
-               }
-
-               public void TrackCall (MethodDefinition fromMethod, TypeDefinition toType)
-               {
-                       Debug.Assert (CompilerGeneratedNames.IsStateMachineType (toType.Name));
-                       TrackCallInternal (fromMethod, toType);
-               }
-
-               public void TrackCall (TypeDefinition fromType, MethodDefinition toMethod)
-               {
-                       Debug.Assert (CompilerGeneratedNames.IsStateMachineType (fromType.Name));
-                       Debug.Assert (CompilerGeneratedNames.IsLambdaOrLocalFunction (toMethod.Name));
-                       TrackCallInternal (fromType, toMethod);
-               }
-
-               public IEnumerable<IMemberDefinition> GetReachableMembers (MethodDefinition start)
-               {
-                       Queue<IMemberDefinition> queue = new ();
-                       HashSet<IMemberDefinition> visited = new ();
-                       visited.Add (start);
-                       queue.Enqueue (start);
-                       while (queue.TryDequeue (out IMemberDefinition? method)) {
-                               if (!_callGraph.TryGetValue (method, out HashSet<IMemberDefinition>? callees))
-                                       continue;
-
-                               foreach (var callee in callees) {
-                                       if (visited.Add (callee)) {
-                                               queue.Enqueue (callee);
-                                               yield return callee;
-                                       }
-                               }
-                       }
-               }
-       }
-}
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/CompilerGeneratedNames.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/CompilerGeneratedNames.cs
deleted file mode 100644 (file)
index afdb716..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-namespace Mono.Linker.Dataflow
-{
-       sealed class CompilerGeneratedNames
-       {
-               internal static bool IsGeneratedMemberName (string memberName)
-               {
-                       return memberName.Length > 0 && memberName[0] == '<';
-               }
-
-               internal static bool IsLambdaDisplayClass (string className)
-               {
-                       if (!IsGeneratedMemberName (className))
-                               return false;
-
-                       // This is true for static lambdas (which are emitted into a class like <>c)
-                       // and for instance lambdas (which are emitted into a class like <>c__DisplayClass1_0)
-                       return className.StartsWith ("<>c");
-               }
-
-               internal static bool IsStateMachineType (string typeName)
-               {
-                       if (!IsGeneratedMemberName (typeName))
-                               return false;
-
-                       // State machines are generated into types with names like <OwnerMethodName>d__0
-                       // Or if its nested in a local function the name will look like <<OwnerMethodName>g__Local>d and so on
-                       int i = typeName.LastIndexOf ('>');
-                       if (i == -1)
-                               return false;
-
-                       return typeName.Length > i + 1 && typeName[i + 1] == 'd';
-               }
-
-               internal static bool IsStateMachineCurrentField (string fieldName)
-               {
-                       if (!IsGeneratedMemberName (fieldName))
-                               return false;
-
-                       int i = fieldName.LastIndexOf ('>');
-                       if (i == -1)
-                               return false;
-
-                       // Current field is <>2__current
-                       return fieldName.Length > i + 1 && fieldName[i + 1] == '2';
-               }
-
-               internal static bool IsGeneratedType (string name) => IsStateMachineType (name) || IsLambdaDisplayClass (name);
-
-               internal static bool IsLambdaOrLocalFunction (string methodName) => IsLambdaMethod (methodName) || IsLocalFunction (methodName);
-
-               // Lambda methods have generated names like "<UserMethod>b__0_1" where "UserMethod" is the name
-               // of the original user code that contains the lambda method declaration.
-               internal static bool IsLambdaMethod (string methodName)
-               {
-                       if (!IsGeneratedMemberName (methodName))
-                               return false;
-
-                       int i = methodName.IndexOf ('>', 1);
-                       if (i == -1)
-                               return false;
-
-                       // Ignore the method ordinal/generation and lambda ordinal/generation.
-                       return methodName.Length > i + 1 && methodName[i + 1] == 'b';
-               }
-
-               // Local functions have generated names like "<UserMethod>g__LocalFunction|0_1" where "UserMethod" is the name
-               // of the original user code that contains the lambda method declaration, and "LocalFunction" is the name of
-               // the local function.
-               internal static bool IsLocalFunction (string methodName)
-               {
-                       if (!IsGeneratedMemberName (methodName))
-                               return false;
-
-                       int i = methodName.IndexOf ('>', 1);
-                       if (i == -1)
-                               return false;
-
-                       // Ignore the method ordinal/generation and local function ordinal/generation.
-                       return methodName.Length > i + 1 && methodName[i + 1] == 'g';
-               }
-       }
-}
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/CompilerGeneratedState.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/CompilerGeneratedState.cs
deleted file mode 100644 (file)
index 36950fb..0000000
+++ /dev/null
@@ -1,475 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Linq;
-using ILLink.Shared;
-using Mono.Cecil;
-using Mono.Cecil.Cil;
-
-namespace Mono.Linker.Dataflow
-{
-       // Currently this is implemented using heuristics
-       public class CompilerGeneratedState
-       {
-               readonly LinkContext _context;
-               readonly Dictionary<TypeDefinition, MethodDefinition> _compilerGeneratedTypeToUserCodeMethod;
-               readonly Dictionary<TypeDefinition, TypeArgumentInfo> _generatedTypeToTypeArgumentInfo;
-               readonly record struct TypeArgumentInfo (
-                       /// <summary>The method which calls the ctor for the given type</summary>
-                       MethodDefinition CreatingMethod,
-                       /// <summary>Attributes for the type, pulled from the creators type arguments</summary>
-                       IReadOnlyList<ICustomAttributeProvider>? OriginalAttributes);
-
-               readonly Dictionary<MethodDefinition, MethodDefinition> _compilerGeneratedMethodToUserCodeMethod;
-
-               // For each type that has had its cache populated, stores a map of methods which have corresponding
-               // compiler-generated members (either methods or state machine types) to those compiler-generated members,
-               // or null if the type has no methods with compiler-generated members.
-               readonly Dictionary<TypeDefinition, Dictionary<MethodDefinition, List<IMemberDefinition>>?> _cachedTypeToCompilerGeneratedMembers;
-
-               public CompilerGeneratedState (LinkContext context)
-               {
-                       _context = context;
-                       _compilerGeneratedTypeToUserCodeMethod = new Dictionary<TypeDefinition, MethodDefinition> ();
-                       _generatedTypeToTypeArgumentInfo = new Dictionary<TypeDefinition, TypeArgumentInfo> ();
-                       _compilerGeneratedMethodToUserCodeMethod = new Dictionary<MethodDefinition, MethodDefinition> ();
-                       _cachedTypeToCompilerGeneratedMembers = new Dictionary<TypeDefinition, Dictionary<MethodDefinition, List<IMemberDefinition>>?> ();
-               }
-
-               static IEnumerable<TypeDefinition> GetCompilerGeneratedNestedTypes (TypeDefinition type)
-               {
-                       foreach (var nestedType in type.NestedTypes) {
-                               if (!CompilerGeneratedNames.IsGeneratedMemberName (nestedType.Name))
-                                       continue;
-
-                               yield return nestedType;
-
-                               foreach (var recursiveNestedType in GetCompilerGeneratedNestedTypes (nestedType))
-                                       yield return recursiveNestedType;
-                       }
-               }
-
-               public static bool IsHoistedLocal (FieldDefinition field)
-               {
-                       if (CompilerGeneratedNames.IsLambdaDisplayClass (field.DeclaringType.Name))
-                               return true;
-
-                       if (CompilerGeneratedNames.IsStateMachineType (field.DeclaringType.Name)) {
-                               // Don't track the "current" field which is used for state machine return values,
-                               // because this can be expensive to track.
-                               return !CompilerGeneratedNames.IsStateMachineCurrentField (field.Name);
-                       }
-
-                       return false;
-               }
-
-               // "Nested function" refers to lambdas and local functions.
-               public static bool IsNestedFunctionOrStateMachineMember (IMemberDefinition member)
-               {
-                       if (member is MethodDefinition method && CompilerGeneratedNames.IsLambdaOrLocalFunction (method.Name))
-                               return true;
-
-                       if (member.DeclaringType is not TypeDefinition declaringType)
-                               return false;
-
-                       return CompilerGeneratedNames.IsStateMachineType (declaringType.Name);
-               }
-
-               public static bool TryGetStateMachineType (MethodDefinition method, [NotNullWhen (true)] out TypeDefinition? stateMachineType)
-               {
-                       stateMachineType = null;
-                       // Discover state machine methods.
-                       if (!method.HasCustomAttributes)
-                               return false;
-
-                       foreach (var attribute in method.CustomAttributes) {
-                               if (attribute.AttributeType.Namespace != "System.Runtime.CompilerServices")
-                                       continue;
-
-                               switch (attribute.AttributeType.Name) {
-                               case "AsyncIteratorStateMachineAttribute":
-                               case "AsyncStateMachineAttribute":
-                               case "IteratorStateMachineAttribute":
-                                       stateMachineType = GetFirstConstructorArgumentAsType (attribute);
-                                       return stateMachineType != null;
-                               }
-                       }
-                       return false;
-               }
-
-               /// <summary>
-               /// Walks the type and its descendents to find Roslyn-compiler generated
-               /// code and gather information to map it back to original user code. If
-               /// a compiler-generated type is passed in directly, this method will walk
-               /// up and find the nearest containing user type. Returns the nearest user type,
-               /// or null if none was found.
-               /// </summary>
-               TypeDefinition? GetCompilerGeneratedStateForType (TypeDefinition type)
-               {
-                       // Look in the declaring type if this is a compiler-generated type (state machine or display class).
-                       // State machines can be emitted into display classes, so we may also need to go one more level up.
-                       // To avoid depending on implementation details, we go up until we see a non-compiler-generated type.
-                       // This is the counterpart to GetCompilerGeneratedNestedTypes.
-                       while (type != null && CompilerGeneratedNames.IsGeneratedMemberName (type.Name))
-                               type = type.DeclaringType;
-
-                       if (type is null)
-                               return null;
-
-                       // Avoid repeat scans of the same type
-                       if (_cachedTypeToCompilerGeneratedMembers.ContainsKey (type))
-                               return type;
-
-                       var callGraph = new CompilerGeneratedCallGraph ();
-                       var userDefinedMethods = new HashSet<MethodDefinition> ();
-
-                       void ProcessMethod (MethodDefinition method)
-                       {
-                               bool isStateMachineMember = CompilerGeneratedNames.IsStateMachineType (method.DeclaringType.Name);
-                               if (!CompilerGeneratedNames.IsLambdaOrLocalFunction (method.Name)) {
-                                       if (!isStateMachineMember) {
-                                               // If it's not a nested function, track as an entry point to the call graph.
-                                               var added = userDefinedMethods.Add (method);
-                                               Debug.Assert (added);
-                                       }
-                               } else {
-                                       // We don't expect lambdas or local functions to be emitted directly into
-                                       // state machine types.
-                                       Debug.Assert (!isStateMachineMember);
-                               }
-
-                               // Discover calls or references to lambdas or local functions. This includes
-                               // calls to local functions, and lambda assignments (which use ldftn).
-                               if (method.Body != null) {
-                                       foreach (var instruction in _context.GetMethodIL (method).Instructions) {
-                                               switch (instruction.OpCode.OperandType) {
-                                               case OperandType.InlineMethod: {
-                                                               MethodDefinition? referencedMethod = _context.TryResolve ((MethodReference) instruction.Operand);
-                                                               if (referencedMethod == null)
-                                                                       continue;
-
-                                                               if (referencedMethod.IsConstructor &&
-                                                                       referencedMethod.DeclaringType is var generatedType &&
-                                                                       // Don't consider calls in the same type, like inside a static constructor
-                                                                       method.DeclaringType != generatedType &&
-                                                                       CompilerGeneratedNames.IsLambdaDisplayClass (generatedType.Name)) {
-                                                                       // fill in null for now, attribute providers will be filled in later
-                                                                       if (!_generatedTypeToTypeArgumentInfo.TryAdd (generatedType, new TypeArgumentInfo (method, null))) {
-                                                                               var alreadyAssociatedMethod = _generatedTypeToTypeArgumentInfo[generatedType].CreatingMethod;
-                                                                               _context.LogWarning (new MessageOrigin (method), DiagnosticId.MethodsAreAssociatedWithUserMethod, method.GetDisplayName (), alreadyAssociatedMethod.GetDisplayName (), generatedType.GetDisplayName ());
-                                                                       }
-                                                                       continue;
-                                                               }
-
-                                                               if (!CompilerGeneratedNames.IsLambdaOrLocalFunction (referencedMethod.Name))
-                                                                       continue;
-
-                                                               if (isStateMachineMember) {
-                                                                       callGraph.TrackCall (method.DeclaringType, referencedMethod);
-                                                               } else {
-                                                                       callGraph.TrackCall (method, referencedMethod);
-                                                               }
-                                                       }
-                                                       break;
-
-                                               case OperandType.InlineField: {
-                                                               // Same as above, but stsfld instead of a call to the constructor
-                                                               if (instruction.OpCode.Code is not Code.Stsfld)
-                                                                       continue;
-
-                                                               FieldDefinition? field = _context.TryResolve ((FieldReference) instruction.Operand);
-                                                               if (field == null)
-                                                                       continue;
-
-                                                               if (field.DeclaringType is var generatedType &&
-                                                                       // Don't consider field accesses in the same type, like inside a static constructor
-                                                                       method.DeclaringType != generatedType &&
-                                                                       CompilerGeneratedNames.IsLambdaDisplayClass (generatedType.Name)) {
-                                                                       if (!_generatedTypeToTypeArgumentInfo.TryAdd (generatedType, new TypeArgumentInfo (method, null))) {
-                                                                               // It's expected that there may be multiple methods associated with the same static closure environment.
-                                                                               // All of these methods will substitute the same type arguments into the closure environment
-                                                                               // (if it is generic). Don't warn.
-                                                                       }
-                                                                       continue;
-                                                               }
-                                                       }
-                                                       break;
-                                               }
-                                       }
-                               }
-
-                               if (TryGetStateMachineType (method, out TypeDefinition? stateMachineType)) {
-                                       Debug.Assert (stateMachineType.DeclaringType == type ||
-                                               CompilerGeneratedNames.IsGeneratedMemberName (stateMachineType.DeclaringType.Name) &&
-                                                stateMachineType.DeclaringType.DeclaringType == type);
-                                       callGraph.TrackCall (method, stateMachineType);
-
-                                       if (!_compilerGeneratedTypeToUserCodeMethod.TryAdd (stateMachineType, method)) {
-                                               var alreadyAssociatedMethod = _compilerGeneratedTypeToUserCodeMethod[stateMachineType];
-                                               _context.LogWarning (new MessageOrigin (method), DiagnosticId.MethodsAreAssociatedWithStateMachine, method.GetDisplayName (), alreadyAssociatedMethod.GetDisplayName (), stateMachineType.GetDisplayName ());
-                                       }
-                                       // Already warned above if multiple methods map to the same type
-                                       // Fill in null for argument providers now, the real providers will be filled in later
-                                       _generatedTypeToTypeArgumentInfo[stateMachineType] = new TypeArgumentInfo (method, null);
-                               }
-                       }
-
-                       // Look for state machine methods, and methods which call local functions.
-                       foreach (MethodDefinition method in type.Methods)
-                               ProcessMethod (method);
-
-                       // Also scan compiler-generated state machine methods (in case they have calls to nested functions),
-                       // and nested functions inside compiler-generated closures (in case they call other nested functions).
-
-                       // State machines can be emitted into lambda display classes, so we need to go down at least two
-                       // levels to find calls from iterator nested functions to other nested functions. We just recurse into
-                       // all compiler-generated nested types to avoid depending on implementation details.
-
-                       foreach (var nestedType in GetCompilerGeneratedNestedTypes (type)) {
-                               foreach (var method in nestedType.Methods)
-                                       ProcessMethod (method);
-                       }
-
-                       // Now we've discovered the call graphs for calls to nested functions.
-                       // Use this to map back from nested functions to the declaring user methods.
-
-                       // Note: This maps all nested functions back to the user code, not to the immediately
-                       // declaring local function. The IL doesn't contain enough information in general for
-                       // us to determine the nesting of local functions and lambdas.
-
-                       // Note: this only discovers nested functions which are referenced from the user
-                       // code or its referenced nested functions. There is no reliable way to determine from
-                       // IL which user code an unused nested function belongs to.
-
-                       Dictionary<MethodDefinition, List<IMemberDefinition>>? compilerGeneratedCallees = null;
-                       foreach (var userDefinedMethod in userDefinedMethods) {
-                               var callees = callGraph.GetReachableMembers (userDefinedMethod);
-                               if (!callees.Any ())
-                                       continue;
-
-                               compilerGeneratedCallees ??= new Dictionary<MethodDefinition, List<IMemberDefinition>> ();
-                               compilerGeneratedCallees.Add (userDefinedMethod, new List<IMemberDefinition> (callees));
-
-                               foreach (var compilerGeneratedMember in callees) {
-                                       switch (compilerGeneratedMember) {
-                                       case MethodDefinition nestedFunction:
-                                               Debug.Assert (CompilerGeneratedNames.IsLambdaOrLocalFunction (nestedFunction.Name));
-                                               // Nested functions get suppressions from the user method only.
-                                               if (!_compilerGeneratedMethodToUserCodeMethod.TryAdd (nestedFunction, userDefinedMethod)) {
-                                                       var alreadyAssociatedMethod = _compilerGeneratedMethodToUserCodeMethod[nestedFunction];
-                                                       _context.LogWarning (new MessageOrigin (userDefinedMethod), DiagnosticId.MethodsAreAssociatedWithUserMethod, userDefinedMethod.GetDisplayName (), alreadyAssociatedMethod.GetDisplayName (), nestedFunction.GetDisplayName ());
-                                               }
-                                               break;
-                                       case TypeDefinition stateMachineType:
-                                               // Types in the call graph are always state machine types
-                                               // For those all their methods are not tracked explicitly in the call graph; instead, they
-                                               // are represented by the state machine type itself.
-                                               // We are already tracking the association of the state machine type to the user code method
-                                               // above, so no need to track it here.
-                                               Debug.Assert (CompilerGeneratedNames.IsStateMachineType (stateMachineType.Name));
-                                               break;
-                                       default:
-                                               throw new InvalidOperationException ();
-                                       }
-                               }
-                       }
-
-                       // Now that we have instantiating methods fully filled out, walk the generated types and fill in the attribute
-                       // providers
-                       foreach (var generatedType in _generatedTypeToTypeArgumentInfo.Keys) {
-                               if (HasGenericParameters (generatedType))
-                                       MapGeneratedTypeTypeParameters (generatedType);
-                       }
-
-                       _cachedTypeToCompilerGeneratedMembers.Add (type, compilerGeneratedCallees);
-                       return type;
-
-                       /// <summary>
-                       /// Check if the type itself is generic. The only difference is that
-                       /// if the type is a nested type, the generic parameters from its
-                       /// parent type don't count.
-                       /// </summary>
-                       static bool HasGenericParameters (TypeDefinition typeDef)
-                       {
-                               if (!typeDef.IsNested)
-                                       return typeDef.HasGenericParameters;
-
-                               return typeDef.GenericParameters.Count > typeDef.DeclaringType.GenericParameters.Count;
-                       }
-
-                       void MapGeneratedTypeTypeParameters (TypeDefinition generatedType)
-                       {
-                               Debug.Assert (CompilerGeneratedNames.IsGeneratedType (generatedType.Name));
-
-                               var typeInfo = _generatedTypeToTypeArgumentInfo[generatedType];
-                               if (typeInfo.OriginalAttributes is not null) {
-                                       return;
-                               }
-                               var method = typeInfo.CreatingMethod;
-                               if (method.Body is { } body) {
-                                       var typeArgs = new ICustomAttributeProvider[generatedType.GenericParameters.Count];
-                                       var typeRef = ScanForInit (generatedType, body);
-                                       if (typeRef is null) {
-                                               return;
-                                       }
-
-                                       for (int i = 0; i < typeRef.GenericArguments.Count; i++) {
-                                               var typeArg = typeRef.GenericArguments[i];
-                                               // Start with the existing parameters, in case we can't find the mapped one
-                                               ICustomAttributeProvider userAttrs = generatedType.GenericParameters[i];
-                                               // The type parameters of the state machine types are alpha renames of the
-                                               // the method parameters, so the type ref should always be a GenericParameter. However,
-                                               // in the case of nesting, there may be multiple renames, so if the parameter is a method
-                                               // we know we're done, but if it's another state machine, we have to keep looking to find
-                                               // the original owner of that state machine.
-                                               if (typeArg is GenericParameter { Owner: { } owner } param) {
-                                                       if (owner is MethodReference) {
-                                                               userAttrs = param;
-                                                       } else {
-                                                               // Must be a type ref
-                                                               var owningRef = (TypeReference) owner;
-                                                               if (!CompilerGeneratedNames.IsGeneratedType (owningRef.Name)) {
-                                                                       userAttrs = param;
-                                                               } else if (_context.TryResolve ((TypeReference) param.Owner) is { } owningType) {
-                                                                       MapGeneratedTypeTypeParameters (owningType);
-                                                                       if (_generatedTypeToTypeArgumentInfo[owningType].OriginalAttributes is { } owningAttrs) {
-                                                                               userAttrs = owningAttrs[param.Position];
-                                                                       } else {
-                                                                               Debug.Assert (false, "This should be impossible in valid code");
-                                                                       }
-                                                               }
-                                                       }
-                                               }
-
-                                               typeArgs[i] = userAttrs;
-                                       }
-
-                                       _generatedTypeToTypeArgumentInfo[generatedType] = typeInfo with { OriginalAttributes = typeArgs };
-                               }
-                       }
-
-                       GenericInstanceType? ScanForInit (TypeDefinition compilerGeneratedType, MethodBody body)
-                       {
-                               foreach (var instr in _context.GetMethodIL (body).Instructions) {
-                                       bool handled = false;
-                                       switch (instr.OpCode.Code) {
-                                       case Code.Initobj:
-                                       case Code.Newobj: {
-                                                       if (instr.Operand is MethodReference { DeclaringType: GenericInstanceType typeRef }
-                                                               && compilerGeneratedType == _context.TryResolve (typeRef)) {
-                                                               return typeRef;
-                                                       }
-                                                       handled = true;
-                                               }
-                                               break;
-                                       case Code.Stsfld: {
-                                                       if (instr.Operand is FieldReference { DeclaringType: GenericInstanceType typeRef }
-                                                               && compilerGeneratedType == _context.TryResolve (typeRef)) {
-                                                               return typeRef;
-                                                       }
-                                                       handled = true;
-                                               }
-                                               break;
-                                       }
-
-                                       // Also look for type substitutions into generic methods
-                                       // (such as AsyncTaskMethodBuilder::Start<TStateMachine>).
-                                       if (!handled && instr.OpCode.OperandType is OperandType.InlineMethod) {
-                                               if (instr.Operand is GenericInstanceMethod gim) {
-                                                       foreach (var tr in gim.GenericArguments) {
-                                                               if (tr is GenericInstanceType git && compilerGeneratedType == _context.TryResolve (git)) {
-                                                                       return git;
-                                                               }
-                                                       }
-                                               }
-                                       }
-                               }
-                               return null;
-                       }
-               }
-
-               static TypeDefinition? GetFirstConstructorArgumentAsType (CustomAttribute attribute)
-               {
-                       if (!attribute.HasConstructorArguments)
-                               return null;
-
-                       return attribute.ConstructorArguments[0].Value as TypeDefinition;
-               }
-
-               public bool TryGetCompilerGeneratedCalleesForUserMethod (MethodDefinition method, [NotNullWhen (true)] out List<IMemberDefinition>? callees)
-               {
-                       callees = null;
-                       if (IsNestedFunctionOrStateMachineMember (method))
-                               return false;
-
-                       var typeToCache = GetCompilerGeneratedStateForType (method.DeclaringType);
-                       if (typeToCache is null)
-                               return false;
-
-                       return _cachedTypeToCompilerGeneratedMembers[typeToCache]?.TryGetValue (method, out callees) == true;
-               }
-
-               /// <summary>
-               /// Gets the attributes on the "original" method of a generated type, i.e. the
-               /// attributes on the corresponding type parameters from the owning method.
-               /// </summary>
-               public IReadOnlyList<ICustomAttributeProvider>? GetGeneratedTypeAttributes (TypeDefinition generatedType)
-               {
-                       Debug.Assert (CompilerGeneratedNames.IsGeneratedType (generatedType.Name));
-
-                       var typeToCache = GetCompilerGeneratedStateForType (generatedType);
-                       if (typeToCache is null)
-                               return null;
-
-                       if (_generatedTypeToTypeArgumentInfo.TryGetValue (generatedType, out var typeInfo)) {
-                               return typeInfo.OriginalAttributes;
-                       }
-                       return null;
-               }
-
-               // For state machine types/members, maps back to the state machine method.
-               // For local functions and lambdas, maps back to the owning method in user code (not the declaring
-               // lambda or local function, because the IL doesn't contain enough information to figure this out).
-               public bool TryGetOwningMethodForCompilerGeneratedMember (IMemberDefinition sourceMember, [NotNullWhen (true)] out MethodDefinition? owningMethod)
-               {
-                       owningMethod = null;
-                       if (sourceMember == null)
-                               return false;
-
-                       MethodDefinition? compilerGeneratedMethod = sourceMember as MethodDefinition;
-                       if (compilerGeneratedMethod != null) {
-                               if (_compilerGeneratedMethodToUserCodeMethod.TryGetValue (compilerGeneratedMethod, out owningMethod))
-                                       return true;
-                       }
-
-                       TypeDefinition sourceType = sourceMember as TypeDefinition ?? sourceMember.DeclaringType;
-
-                       if (_compilerGeneratedTypeToUserCodeMethod.TryGetValue (sourceType, out owningMethod))
-                               return true;
-
-                       if (!IsNestedFunctionOrStateMachineMember (sourceMember))
-                               return false;
-
-                       // sourceType is a state machine type, or the type containing a lambda or local function.
-                       // Search all methods to find the one which points to the type as its
-                       // state machine implementation.
-                       var typeToCache = GetCompilerGeneratedStateForType (sourceType);
-                       if (typeToCache is null)
-                               return false;
-
-                       if (compilerGeneratedMethod != null) {
-                               if (_compilerGeneratedMethodToUserCodeMethod.TryGetValue (compilerGeneratedMethod, out owningMethod))
-                                       return true;
-                       }
-
-                       if (_compilerGeneratedTypeToUserCodeMethod.TryGetValue (sourceType, out owningMethod))
-                               return true;
-
-                       return false;
-               }
-       }
-}
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/DiagnosticContext.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/DiagnosticContext.cs
deleted file mode 100644 (file)
index bce75d7..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using Mono.Linker;
-
-namespace ILLink.Shared.TrimAnalysis
-{
-       internal readonly partial struct DiagnosticContext
-       {
-               public readonly MessageOrigin Origin;
-               public readonly bool DiagnosticsEnabled;
-               readonly LinkContext _context;
-
-               public DiagnosticContext (in MessageOrigin origin, bool diagnosticsEnabled, LinkContext context)
-                       => (Origin, DiagnosticsEnabled, _context) = (origin, diagnosticsEnabled, context);
-
-               public partial void AddDiagnostic (DiagnosticId id, params string[] args)
-               {
-                       if (DiagnosticsEnabled)
-                               _context.LogWarning (Origin, id, args);
-               }
-
-#pragma warning disable IDE0060, CA1822
-               public partial void AddDiagnostic (DiagnosticId id, ValueWithDynamicallyAccessedMembers actualValue, ValueWithDynamicallyAccessedMembers expectedAnnotationsValue, params string[] args)
-               {
-                       AddDiagnostic (id, args);
-               }
-#pragma warning restore IDE0060, CA1822
-       }
-}
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/DiagnosticUtilities.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/DiagnosticUtilities.cs
deleted file mode 100644 (file)
index 390081b..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using Mono.Cecil;
-
-namespace Mono.Linker.Dataflow
-{
-       static class DiagnosticUtilities
-       {
-               internal static string GetParameterNameForErrorMessage (ParameterDefinition parameterDefinition) =>
-                       string.IsNullOrEmpty (parameterDefinition.Name) ? $"#{parameterDefinition.Index}" : parameterDefinition.Name;
-
-               internal static string GetGenericParameterDeclaringMemberDisplayName (GenericParameter genericParameter) =>
-                       genericParameter.DeclaringMethod != null ?
-                               genericParameter.DeclaringMethod.GetDisplayName () :
-                               genericParameter.DeclaringType.GetDisplayName ();
-
-               internal static string GetMethodSignatureDisplayName (IMethodSignature methodSignature) =>
-                       (methodSignature is MethodReference method) ? method.GetDisplayName () : (methodSignature.ToString () ?? string.Empty);
-       }
-}
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/DynamicallyAccessedMembersBinder.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/DynamicallyAccessedMembersBinder.cs
deleted file mode 100644 (file)
index dd69710..0000000
+++ /dev/null
@@ -1,424 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System;
-using System.Collections.Generic;
-using System.Diagnostics.CodeAnalysis;
-using System.Reflection;
-using ILLink.Shared;
-using Mono.Cecil;
-
-namespace Mono.Linker
-{
-       internal static class DynamicallyAccessedMembersBinder
-       {
-               // Returns the members of the type bound by memberTypes. For DynamicallyAccessedMemberTypes.All, this returns all members of the type and its
-               // nested types, including interface implementations, plus the same or any base types or implemented interfaces.
-               // DynamicallyAccessedMemberTypes.PublicNestedTypes and NonPublicNestedTypes do the same for members of the selected nested types.
-               public static IEnumerable<IMetadataTokenProvider> GetDynamicallyAccessedMembers (this TypeDefinition typeDefinition, LinkContext context, DynamicallyAccessedMemberTypes memberTypes, bool declaredOnly = false)
-               {
-                       if (memberTypes == DynamicallyAccessedMemberTypes.None)
-                               yield break;
-
-                       if (memberTypes == DynamicallyAccessedMemberTypes.All) {
-                               var members = new List<IMetadataTokenProvider> ();
-                               typeDefinition.GetAllOnType (context, declaredOnly, members);
-                               foreach (var m in members)
-                                       yield return m;
-                               yield break;
-                       }
-
-                       var declaredOnlyFlags = declaredOnly ? BindingFlags.DeclaredOnly : BindingFlags.Default;
-
-                       if (memberTypes.HasFlag (DynamicallyAccessedMemberTypes.NonPublicConstructors)) {
-                               foreach (var c in typeDefinition.GetConstructorsOnType (filter: null, bindingFlags: BindingFlags.NonPublic))
-                                       yield return c;
-                       }
-
-                       if (memberTypes.HasFlag (DynamicallyAccessedMemberTypes.PublicConstructors)) {
-                               foreach (var c in typeDefinition.GetConstructorsOnType (filter: null, bindingFlags: BindingFlags.Public))
-                                       yield return c;
-                       }
-
-                       if (memberTypes.HasFlag (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)) {
-                               foreach (var c in typeDefinition.GetConstructorsOnType (filter: m => m.IsPublic && !m.HasMetadataParameters ()))
-                                       yield return c;
-                       }
-
-                       if (memberTypes.HasFlag (DynamicallyAccessedMemberTypes.NonPublicMethods)) {
-                               foreach (var m in typeDefinition.GetMethodsOnTypeHierarchy (context, filter: null, bindingFlags: BindingFlags.NonPublic | declaredOnlyFlags))
-                                       yield return m;
-                       }
-
-                       if (memberTypes.HasFlag (DynamicallyAccessedMemberTypes.PublicMethods)) {
-                               foreach (var m in typeDefinition.GetMethodsOnTypeHierarchy (context, filter: null, bindingFlags: BindingFlags.Public | declaredOnlyFlags))
-                                       yield return m;
-                       }
-
-                       if (memberTypes.HasFlag (DynamicallyAccessedMemberTypes.NonPublicFields)) {
-                               foreach (var f in typeDefinition.GetFieldsOnTypeHierarchy (context, filter: null, bindingFlags: BindingFlags.NonPublic | declaredOnlyFlags))
-                                       yield return f;
-                       }
-
-                       if (memberTypes.HasFlag (DynamicallyAccessedMemberTypes.PublicFields)) {
-                               foreach (var f in typeDefinition.GetFieldsOnTypeHierarchy (context, filter: null, bindingFlags: BindingFlags.Public | declaredOnlyFlags))
-                                       yield return f;
-                       }
-
-                       if (memberTypes.HasFlag (DynamicallyAccessedMemberTypes.NonPublicNestedTypes)) {
-                               foreach (var nested in typeDefinition.GetNestedTypesOnType (filter: null, bindingFlags: BindingFlags.NonPublic)) {
-                                       yield return nested;
-                                       var members = new List<IMetadataTokenProvider> ();
-                                       nested.GetAllOnType (context, declaredOnly: false, members);
-                                       foreach (var m in members)
-                                               yield return m;
-                               }
-                       }
-
-                       if (memberTypes.HasFlag (DynamicallyAccessedMemberTypes.PublicNestedTypes)) {
-                               foreach (var nested in typeDefinition.GetNestedTypesOnType (filter: null, bindingFlags: BindingFlags.Public)) {
-                                       yield return nested;
-                                       var members = new List<IMetadataTokenProvider> ();
-                                       nested.GetAllOnType (context, declaredOnly: false, members);
-                                       foreach (var m in members)
-                                               yield return m;
-                               }
-                       }
-
-                       if (memberTypes.HasFlag (DynamicallyAccessedMemberTypes.NonPublicProperties)) {
-                               foreach (var p in typeDefinition.GetPropertiesOnTypeHierarchy (context, filter: null, bindingFlags: BindingFlags.NonPublic | declaredOnlyFlags))
-                                       yield return p;
-                       }
-
-                       if (memberTypes.HasFlag (DynamicallyAccessedMemberTypes.PublicProperties)) {
-                               foreach (var p in typeDefinition.GetPropertiesOnTypeHierarchy (context, filter: null, bindingFlags: BindingFlags.Public | declaredOnlyFlags))
-                                       yield return p;
-                       }
-
-                       if (memberTypes.HasFlag (DynamicallyAccessedMemberTypes.NonPublicEvents)) {
-                               foreach (var e in typeDefinition.GetEventsOnTypeHierarchy (context, filter: null, bindingFlags: BindingFlags.NonPublic | declaredOnlyFlags))
-                                       yield return e;
-                       }
-
-                       if (memberTypes.HasFlag (DynamicallyAccessedMemberTypes.PublicEvents)) {
-                               foreach (var e in typeDefinition.GetEventsOnTypeHierarchy (context, filter: null, bindingFlags: BindingFlags.Public | declaredOnlyFlags))
-                                       yield return e;
-                       }
-
-                       if (memberTypes.HasFlag (DynamicallyAccessedMemberTypesOverlay.Interfaces)) {
-                               foreach (var i in typeDefinition.GetAllInterfaceImplementations (context, declaredOnly))
-                                       yield return i;
-                       }
-               }
-
-               public static IEnumerable<MethodDefinition> GetConstructorsOnType (this TypeDefinition type, Func<MethodDefinition, bool>? filter, BindingFlags? bindingFlags = null)
-               {
-                       foreach (var method in type.Methods) {
-                               if (!method.IsConstructor)
-                                       continue;
-
-                               if (filter != null && !filter (method))
-                                       continue;
-
-                               if ((bindingFlags & (BindingFlags.Instance | BindingFlags.Static)) == BindingFlags.Static && !method.IsStatic)
-                                       continue;
-
-                               if ((bindingFlags & (BindingFlags.Instance | BindingFlags.Static)) == BindingFlags.Instance && method.IsStatic)
-                                       continue;
-
-                               if ((bindingFlags & (BindingFlags.Public | BindingFlags.NonPublic)) == BindingFlags.Public && !method.IsPublic)
-                                       continue;
-
-                               if ((bindingFlags & (BindingFlags.Public | BindingFlags.NonPublic)) == BindingFlags.NonPublic && method.IsPublic)
-                                       continue;
-
-                               yield return method;
-                       }
-               }
-
-               public static IEnumerable<MethodDefinition> GetMethodsOnTypeHierarchy (this TypeDefinition thisType, LinkContext context, Func<MethodDefinition, bool>? filter, BindingFlags? bindingFlags = null)
-               {
-                       TypeDefinition? type = thisType;
-                       bool onBaseType = false;
-                       while (type != null) {
-                               foreach (var method in type.Methods) {
-                                       // Ignore constructors as those are not considered methods from a reflection's point of view
-                                       if (method.IsConstructor)
-                                               continue;
-
-                                       // Ignore private methods on a base type - those are completely ignored by reflection
-                                       // (anything private on the base type is not visible via the derived type)
-                                       if (onBaseType && method.IsPrivate)
-                                               continue;
-
-                                       // Note that special methods like property getter/setter, event adder/remover will still get through and will be marked.
-                                       // This is intentional as reflection treats these as methods as well.
-
-                                       if (filter != null && !filter (method))
-                                               continue;
-
-                                       if ((bindingFlags & (BindingFlags.Instance | BindingFlags.Static)) == BindingFlags.Static && !method.IsStatic)
-                                               continue;
-
-                                       if ((bindingFlags & (BindingFlags.Instance | BindingFlags.Static)) == BindingFlags.Instance && method.IsStatic)
-                                               continue;
-
-                                       if ((bindingFlags & (BindingFlags.Public | BindingFlags.NonPublic)) == BindingFlags.Public && !method.IsPublic)
-                                               continue;
-
-                                       if ((bindingFlags & (BindingFlags.Public | BindingFlags.NonPublic)) == BindingFlags.NonPublic && method.IsPublic)
-                                               continue;
-
-                                       yield return method;
-                               }
-
-                               if ((bindingFlags & BindingFlags.DeclaredOnly) == BindingFlags.DeclaredOnly)
-                                       yield break;
-
-                               type = context.TryResolve (type.BaseType);
-                               onBaseType = true;
-                       }
-               }
-
-               public static IEnumerable<FieldDefinition> GetFieldsOnTypeHierarchy (this TypeDefinition thisType, LinkContext context, Func<FieldDefinition, bool>? filter, BindingFlags? bindingFlags = BindingFlags.Default)
-               {
-                       TypeDefinition? type = thisType;
-                       bool onBaseType = false;
-                       while (type != null) {
-                               foreach (var field in type.Fields) {
-                                       // Ignore private fields on a base type - those are completely ignored by reflection
-                                       // (anything private on the base type is not visible via the derived type)
-                                       if (onBaseType && field.IsPrivate)
-                                               continue;
-
-                                       // Note that compiler generated fields backing some properties and events will get through here.
-                                       // This is intentional as reflection treats these as fields as well.
-
-                                       if (filter != null && !filter (field))
-                                               continue;
-
-                                       if ((bindingFlags & (BindingFlags.Instance | BindingFlags.Static)) == BindingFlags.Static && !field.IsStatic)
-                                               continue;
-
-                                       if ((bindingFlags & (BindingFlags.Instance | BindingFlags.Static)) == BindingFlags.Instance && field.IsStatic)
-                                               continue;
-
-                                       if ((bindingFlags & (BindingFlags.Public | BindingFlags.NonPublic)) == BindingFlags.Public && !field.IsPublic)
-                                               continue;
-
-                                       if ((bindingFlags & (BindingFlags.Public | BindingFlags.NonPublic)) == BindingFlags.NonPublic && field.IsPublic)
-                                               continue;
-
-                                       yield return field;
-                               }
-
-                               if ((bindingFlags & BindingFlags.DeclaredOnly) == BindingFlags.DeclaredOnly)
-                                       yield break;
-
-                               type = context.TryResolve (type.BaseType);
-                               onBaseType = true;
-                       }
-               }
-
-               public static IEnumerable<TypeDefinition> GetNestedTypesOnType (this TypeDefinition type, Func<TypeDefinition, bool>? filter, BindingFlags? bindingFlags = BindingFlags.Default)
-               {
-                       foreach (var nestedType in type.NestedTypes) {
-                               if (filter != null && !filter (nestedType))
-                                       continue;
-
-                               if ((bindingFlags & (BindingFlags.Public | BindingFlags.NonPublic)) == BindingFlags.Public) {
-                                       if (!nestedType.IsNestedPublic)
-                                               continue;
-                               }
-
-                               if ((bindingFlags & (BindingFlags.Public | BindingFlags.NonPublic)) == BindingFlags.NonPublic) {
-                                       if (nestedType.IsNestedPublic)
-                                               continue;
-                               }
-
-                               yield return nestedType;
-                       }
-               }
-
-               public static IEnumerable<PropertyDefinition> GetPropertiesOnTypeHierarchy (this TypeDefinition thisType, LinkContext context, Func<PropertyDefinition, bool>? filter, BindingFlags? bindingFlags = BindingFlags.Default)
-               {
-                       TypeDefinition? type = thisType;
-                       bool onBaseType = false;
-                       while (type != null) {
-                               foreach (var property in type.Properties) {
-                                       // Ignore private properties on a base type - those are completely ignored by reflection
-                                       // (anything private on the base type is not visible via the derived type)
-                                       // Note that properties themselves are not actually private, their accessors are
-                                       if (onBaseType &&
-                                               (property.GetMethod == null || property.GetMethod.IsPrivate) &&
-                                               (property.SetMethod == null || property.SetMethod.IsPrivate))
-                                               continue;
-
-                                       if (filter != null && !filter (property))
-                                               continue;
-
-                                       if ((bindingFlags & (BindingFlags.Instance | BindingFlags.Static)) == BindingFlags.Static) {
-                                               if ((property.GetMethod != null) && !property.GetMethod.IsStatic) continue;
-                                               if ((property.SetMethod != null) && !property.SetMethod.IsStatic) continue;
-                                       }
-
-                                       if ((bindingFlags & (BindingFlags.Instance | BindingFlags.Static)) == BindingFlags.Instance) {
-                                               if ((property.GetMethod != null) && property.GetMethod.IsStatic) continue;
-                                               if ((property.SetMethod != null) && property.SetMethod.IsStatic) continue;
-                                       }
-
-                                       if ((bindingFlags & (BindingFlags.Public | BindingFlags.NonPublic)) == BindingFlags.Public) {
-                                               if ((property.GetMethod == null || !property.GetMethod.IsPublic)
-                                                       && (property.SetMethod == null || !property.SetMethod.IsPublic))
-                                                       continue;
-                                       }
-
-                                       if ((bindingFlags & (BindingFlags.Public | BindingFlags.NonPublic)) == BindingFlags.NonPublic) {
-                                               if ((property.GetMethod != null) && property.GetMethod.IsPublic) continue;
-                                               if ((property.SetMethod != null) && property.SetMethod.IsPublic) continue;
-                                       }
-
-                                       yield return property;
-                               }
-
-                               if ((bindingFlags & BindingFlags.DeclaredOnly) == BindingFlags.DeclaredOnly)
-                                       yield break;
-
-                               type = context.TryResolve (type.BaseType);
-                               onBaseType = true;
-                       }
-               }
-
-               public static IEnumerable<EventDefinition> GetEventsOnTypeHierarchy (this TypeDefinition thisType, LinkContext context, Func<EventDefinition, bool>? filter, BindingFlags? bindingFlags = BindingFlags.Default)
-               {
-                       TypeDefinition? type = thisType;
-                       bool onBaseType = false;
-                       while (type != null) {
-                               foreach (var @event in type.Events) {
-                                       // Ignore private properties on a base type - those are completely ignored by reflection
-                                       // (anything private on the base type is not visible via the derived type)
-                                       // Note that properties themselves are not actually private, their accessors are
-                                       if (onBaseType &&
-                                               (@event.AddMethod == null || @event.AddMethod.IsPrivate) &&
-                                               (@event.RemoveMethod == null || @event.RemoveMethod.IsPrivate))
-                                               continue;
-
-                                       if (filter != null && !filter (@event))
-                                               continue;
-
-                                       if ((bindingFlags & (BindingFlags.Instance | BindingFlags.Static)) == BindingFlags.Static) {
-                                               if ((@event.AddMethod != null) && !@event.AddMethod.IsStatic) continue;
-                                               if ((@event.RemoveMethod != null) && !@event.RemoveMethod.IsStatic) continue;
-                                       }
-
-                                       if ((bindingFlags & (BindingFlags.Instance | BindingFlags.Static)) == BindingFlags.Instance) {
-                                               if ((@event.AddMethod != null) && @event.AddMethod.IsStatic) continue;
-                                               if ((@event.RemoveMethod != null) && @event.RemoveMethod.IsStatic) continue;
-                                       }
-
-                                       if ((bindingFlags & (BindingFlags.Public | BindingFlags.NonPublic)) == BindingFlags.Public) {
-                                               if ((@event.AddMethod == null || !@event.AddMethod.IsPublic)
-                                                       && (@event.RemoveMethod == null || !@event.RemoveMethod.IsPublic))
-                                                       continue;
-                                       }
-
-                                       if ((bindingFlags & (BindingFlags.Public | BindingFlags.NonPublic)) == BindingFlags.NonPublic) {
-                                               if ((@event.AddMethod != null) && @event.AddMethod.IsPublic) continue;
-                                               if ((@event.RemoveMethod != null) && @event.RemoveMethod.IsPublic) continue;
-                                       }
-
-                                       yield return @event;
-                               }
-
-                               if ((bindingFlags & BindingFlags.DeclaredOnly) == BindingFlags.DeclaredOnly)
-                                       yield break;
-
-                               type = context.TryResolve (type.BaseType);
-                               onBaseType = true;
-                       }
-               }
-
-               // declaredOnly will cause this to retrieve interfaces recursively required by the type, but doesn't necessarily
-               // include interfaces required by any base types.
-               public static IEnumerable<InterfaceImplementation> GetAllInterfaceImplementations (this TypeDefinition thisType, LinkContext context, bool declaredOnly)
-               {
-                       TypeDefinition? type = thisType;
-                       while (type != null) {
-                               foreach (var i in type.Interfaces) {
-                                       yield return i;
-
-                                       TypeDefinition? interfaceType = context.TryResolve (i.InterfaceType);
-                                       if (interfaceType != null) {
-                                               // declaredOnly here doesn't matter since interfaces don't have base types
-                                               foreach (var innerInterface in interfaceType.GetAllInterfaceImplementations (context, declaredOnly: true))
-                                                       yield return innerInterface;
-                                       }
-                               }
-
-                               if (declaredOnly)
-                                       yield break;
-
-                               type = context.TryResolve (type.BaseType);
-                       }
-               }
-
-               // declaredOnly will cause this to retrieve only members of the type, not of its base types. This includes interfaces recursively
-               // required by this type (but not members of these interfaces, or interfaces required only by base types).
-               public static void GetAllOnType (this TypeDefinition type, LinkContext context, bool declaredOnly, List<IMetadataTokenProvider> members) => GetAllOnType (type, context, declaredOnly, members, new HashSet<TypeDefinition> ());
-
-               static void GetAllOnType (TypeDefinition type, LinkContext context, bool declaredOnly, List<IMetadataTokenProvider> members, HashSet<TypeDefinition> types)
-               {
-                       if (!types.Add (type))
-                               return;
-
-                       if (type.HasNestedTypes) {
-                               foreach (var nested in type.NestedTypes) {
-                                       members.Add (nested);
-                                       // Base types and interfaces of nested types are always included.
-                                       GetAllOnType (nested, context, declaredOnly: false, members, types);
-                               }
-                       }
-
-                       if (!declaredOnly) {
-                               var baseType = context.TryResolve (type.BaseType);
-                               if (baseType != null)
-                                       GetAllOnType (baseType, context, declaredOnly: false, members, types);
-                       }
-
-                       if (type.HasInterfaces) {
-                               if (declaredOnly) {
-                                       foreach (var iface in type.GetAllInterfaceImplementations (context, declaredOnly: true))
-                                               members.Add (iface);
-                               } else {
-                                       foreach (var iface in type.Interfaces) {
-                                               members.Add (iface);
-                                               var interfaceType = context.TryResolve (iface.InterfaceType);
-                                               if (interfaceType == null)
-                                                       continue;
-                                               GetAllOnType (interfaceType, context, declaredOnly: false, members, types);
-                                       }
-                               }
-                       }
-
-                       if (type.HasFields) {
-                               foreach (var f in type.Fields)
-                                       members.Add (f);
-                       }
-
-                       if (type.HasMethods) {
-                               foreach (var m in type.Methods)
-                                       members.Add (m);
-                       }
-
-                       if (type.HasProperties) {
-                               foreach (var p in type.Properties)
-                                       members.Add (p);
-                       }
-
-                       if (type.HasEvents) {
-                               foreach (var e in type.Events)
-                                       members.Add (e);
-                       }
-               }
-       }
-}
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/DynamicallyAccessedMembersTypeHierarchy.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/DynamicallyAccessedMembersTypeHierarchy.cs
deleted file mode 100644 (file)
index caa1be8..0000000
+++ /dev/null
@@ -1,264 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using ILLink.Shared;
-using Mono.Cecil;
-using Mono.Linker.Steps;
-
-namespace Mono.Linker.Dataflow
-{
-       sealed class DynamicallyAccessedMembersTypeHierarchy
-       {
-               readonly LinkContext _context;
-               readonly MarkStep _markStep;
-
-               // Cache of DynamicallyAccessedMembers annotations applied to types and their hierarchies
-               // Values
-               //   annotation - the aggregated annotation value from the entire base and interface hierarchy of the given type
-               //                If the type has a base class with annotation a1 and an interface with annotation a2, the stored
-               //                annotation is a1 | a2.
-               //   applied - set to true once the annotation was applied to the type
-               //             This only happens once the right reflection pattern is found.
-               //             If a new type is being marked and one of its base types/interface has the applied set to true
-               //             the new type will apply its annotation and will also set its applied to true.
-               // Non-interface types
-               //   - Only marked types with non-empty annotation are put into the cache
-               //   - Non-marked types are not stored in the cache
-               //   - Marked types which are not in the cache don't have any annotation
-               // Interface types
-               //   - All interface types accessible from marked types are stored in the cache
-               //   - If the interface type doesn't have annotation the value None is stored here
-               //
-               // It's not possible to use the marking as a filter for interfaces in the cache
-               // because interfaces are marked late and in effectively random order.
-               // For this cache to be effective we need to be able to fill it for all base types and interfaces
-               // of a type which is currently being marked - at which point the interfaces are not yet marked.
-               readonly Dictionary<TypeDefinition, (DynamicallyAccessedMemberTypes annotation, bool applied)> _typesInDynamicallyAccessedMembersHierarchy;
-
-               public DynamicallyAccessedMembersTypeHierarchy (LinkContext context, MarkStep markStep)
-               {
-                       _context = context;
-                       _markStep = markStep;
-                       _typesInDynamicallyAccessedMembersHierarchy = new Dictionary<TypeDefinition, (DynamicallyAccessedMemberTypes, bool)> ();
-               }
-
-               public (DynamicallyAccessedMemberTypes annotation, bool applied) ProcessMarkedTypeForDynamicallyAccessedMembersHierarchy (TypeDefinition type)
-               {
-                       // We'll use the cache also as a way to detect and avoid recursion for interfaces and annotated base types
-                       if (_typesInDynamicallyAccessedMembersHierarchy.TryGetValue (type, out var existingValue))
-                               return existingValue;
-
-                       DynamicallyAccessedMemberTypes annotation = _context.Annotations.FlowAnnotations.GetTypeAnnotation (type);
-                       bool apply = false;
-
-                       if (type.IsInterface)
-                               _typesInDynamicallyAccessedMembersHierarchy.Add (type, (annotation, false));
-
-                       TypeDefinition? baseType = _context.TryResolve (type.BaseType);
-                       if (baseType != null) {
-                               var baseValue = ProcessMarkedTypeForDynamicallyAccessedMembersHierarchy (baseType);
-                               annotation |= baseValue.annotation;
-                               apply |= baseValue.applied;
-                       }
-
-                       // For the purposes of the DynamicallyAccessedMembers type hierarchies
-                       // we consider interfaces of marked types to be also "marked" in that 
-                       // their annotations will be applied to the type regardless if later on
-                       // we decide to remove the interface. This is to keep the complexity of the implementation
-                       // relatively low. In the future it could be possibly optimized.
-                       if (type.HasInterfaces) {
-                               foreach (InterfaceImplementation iface in type.Interfaces) {
-                                       var interfaceType = _context.TryResolve (iface.InterfaceType);
-                                       if (interfaceType != null) {
-                                               var interfaceValue = ProcessMarkedTypeForDynamicallyAccessedMembersHierarchy (interfaceType);
-                                               annotation |= interfaceValue.annotation;
-                                               apply |= interfaceValue.applied;
-                                       }
-                               }
-                       }
-
-                       Debug.Assert (!apply || annotation != DynamicallyAccessedMemberTypes.None);
-
-                       // If OptimizeTypeHierarchyAnnotations is disabled, we will apply the annotations without seeing object.GetType()
-                       bool applyOptimizeTypeHierarchyAnnotations = (annotation != DynamicallyAccessedMemberTypes.None) && !_context.IsOptimizationEnabled (CodeOptimizations.OptimizeTypeHierarchyAnnotations, type);
-                       // Unfortunately, we cannot apply the annotation to type derived from EventSource - Revisit after https://github.com/dotnet/runtime/issues/54859
-                       // Breaking the logic to make it easier to maintain in the future since the logic is convoluted
-                       // DisableEventSourceSpecialHandling is closely tied to a type derived from EventSource and should always go together
-                       // However, logically it should be possible to use DisableEventSourceSpecialHandling to allow marking types derived from EventSource when OptimizeTypeHierarchyAnnotations is disabled
-                       apply |= applyOptimizeTypeHierarchyAnnotations && (_context.DisableEventSourceSpecialHandling || !BCL.EventTracingForWindows.IsEventSourceImplementation (type, _context));
-
-                       // Store the results in the cache
-                       // Don't store empty annotations for non-interface types - we can use the presence of the row
-                       // in the cache as indication of it instead.
-                       // This doesn't work for interfaces, since we can't rely on them being marked (and thus have the cache
-                       // already filled), so we need to always store the row (even if empty) for interfaces.
-                       if (annotation != DynamicallyAccessedMemberTypes.None || type.IsInterface) {
-                               _typesInDynamicallyAccessedMembersHierarchy[type] = (annotation, apply);
-                       }
-
-                       // It's important to first store the annotation in the cache and only then apply the annotation.
-                       // Applying the annotation will lead to marking additional types which in turn calls back into this
-                       // method to look for annotations. If the newly marked type derives from the one we're processing
-                       // it will rely on the cache to know if it's annotated - so the record must be in the cache
-                       // before it happens.
-                       if (apply) {
-                               // One of the base/interface types is already marked as having the annotation applied
-                               // so we need to apply the annotation to this type as well
-                               var origin = new MessageOrigin (type);
-                               var reflectionMarker = new ReflectionMarker (_context, _markStep, enabled: true);
-                               // Report warnings on access to annotated members, with the annotated type as the origin.
-                               ApplyDynamicallyAccessedMembersToType (reflectionMarker, origin, type, annotation);
-                       }
-
-                       return (annotation, apply);
-               }
-
-               public DynamicallyAccessedMemberTypes ApplyDynamicallyAccessedMembersToTypeHierarchy (TypeDefinition type)
-               {
-                       (var annotation, var applied) = ProcessMarkedTypeForDynamicallyAccessedMembersHierarchy (type);
-
-                       // If the annotation was already applied to this type, there's no reason to repeat the operation, the result will
-                       // be no change.
-                       if (applied || annotation == DynamicallyAccessedMemberTypes.None)
-                               return annotation;
-
-                       // Apply the effective annotation for the type
-                       var origin = new MessageOrigin (type);
-                       var reflectionMarker = new ReflectionMarker (_context, _markStep, enabled: true);
-                       // Report warnings on access to annotated members, with the annotated type as the origin.
-                       ApplyDynamicallyAccessedMembersToType (reflectionMarker, origin, type, annotation);
-
-                       // Mark it as applied in the cache
-                       _typesInDynamicallyAccessedMembersHierarchy[type] = (annotation, true);
-
-                       // Propagate the newly applied annotation to all derived/implementation types
-                       // Since we don't have a data structure which would allow us to enumerate all derived/implementation types
-                       // walk all of the types in the cache. These are good candidates as types not in the cache don't apply.
-                       //
-                       // Applying annotations can lead to marking additional types which can lead to adding new records
-                       // to the cache. So we can't simply iterate over the cache. We also can't rely on the auto-applying annotations
-                       // which is triggered from marking via ProcessMarkedTypeForDynamicallyAccessedMembersHierarchy as that will
-                       // only reliably work once the annotations are applied to all types in the cache first. Partially
-                       // applied annotations to the cache are not enough. So we have to apply the annotations to any types
-                       // added to the cache during the application as well.
-                       //
-                       HashSet<TypeDefinition> typesProcessed = new HashSet<TypeDefinition> ();
-                       List<TypeDefinition> candidateTypes = new List<TypeDefinition> ();
-                       while (true) {
-                               candidateTypes.Clear ();
-                               foreach (var candidate in _typesInDynamicallyAccessedMembersHierarchy) {
-                                       if (candidate.Value.annotation == DynamicallyAccessedMemberTypes.None || candidate.Value.applied)
-                                               continue;
-
-                                       if (typesProcessed.Add (candidate.Key))
-                                               candidateTypes.Add (candidate.Key);
-                               }
-
-                               if (candidateTypes.Count == 0)
-                                       break;
-
-                               foreach (var candidateType in candidateTypes) {
-                                       ApplyDynamicallyAccessedMembersToTypeHierarchyInner (reflectionMarker, candidateType);
-                               }
-                       }
-
-                       return annotation;
-               }
-
-               bool ApplyDynamicallyAccessedMembersToTypeHierarchyInner (
-                       in ReflectionMarker reflectionMarker,
-                       TypeDefinition type)
-               {
-                       (var annotation, var applied) = GetCachedInfoForTypeInHierarchy (type);
-
-                       if (annotation == DynamicallyAccessedMemberTypes.None)
-                               return false;
-
-                       if (applied)
-                               return true;
-
-                       TypeDefinition? baseType = _context.TryResolve (type.BaseType);
-                       if (baseType != null)
-                               applied = ApplyDynamicallyAccessedMembersToTypeHierarchyInner (reflectionMarker, baseType);
-
-                       if (!applied && type.HasInterfaces) {
-                               foreach (InterfaceImplementation iface in type.Interfaces) {
-                                       var interfaceType = _context.TryResolve (iface.InterfaceType);
-                                       if (interfaceType != null) {
-                                               if (ApplyDynamicallyAccessedMembersToTypeHierarchyInner (reflectionMarker, interfaceType)) {
-                                                       applied = true;
-                                                       break;
-                                               }
-                                       }
-                               }
-                       }
-
-                       if (applied) {
-                               var origin = new MessageOrigin (type);
-                               // Report warnings on access to annotated members, with the annotated type as the origin.
-                               ApplyDynamicallyAccessedMembersToType (reflectionMarker, origin, type, annotation);
-                               _typesInDynamicallyAccessedMembersHierarchy[type] = (annotation, true);
-                       }
-
-                       return applied;
-               }
-
-               void ApplyDynamicallyAccessedMembersToType (in ReflectionMarker reflectionMarker, in MessageOrigin origin, TypeDefinition type, DynamicallyAccessedMemberTypes annotation)
-               {
-                       Debug.Assert (annotation != DynamicallyAccessedMemberTypes.None);
-
-                       // We need to apply annotations to this type, and its base/interface types (recursively)
-                       // But the annotations on base/interfaces are already applied so we don't need to apply those
-                       // again (and should avoid doing so as it would produce extra warnings).
-                       var baseType = _context.TryResolve (type.BaseType);
-                       if (baseType != null) {
-                               var baseAnnotation = GetCachedInfoForTypeInHierarchy (baseType);
-                               var annotationToApplyToBase = Annotations.GetMissingMemberTypes (annotation, baseAnnotation.annotation);
-
-                               // Apply any annotations that didn't exist on the base type to the base type.
-                               // This may produce redundant warnings when the annotation is DAMT.All or DAMT.PublicConstructors and the base already has a
-                               // subset of those annotations.
-                               reflectionMarker.MarkTypeForDynamicallyAccessedMembers (origin, baseType, annotationToApplyToBase, DependencyKind.DynamicallyAccessedMemberOnType, declaredOnly: false);
-                       }
-
-                       // Most of the DynamicallyAccessedMemberTypes don't select members on interfaces. We only need to apply
-                       // annotations to interfaces separately if dealing with DAMT.All or DAMT.Interfaces.
-                       if (annotation.HasFlag (DynamicallyAccessedMemberTypesOverlay.Interfaces) && type.HasInterfaces) {
-                               var annotationToApplyToInterfaces = annotation == DynamicallyAccessedMemberTypes.All ? annotation : DynamicallyAccessedMemberTypesOverlay.Interfaces;
-                               foreach (var iface in type.Interfaces) {
-                                       var interfaceType = _context.TryResolve (iface.InterfaceType);
-                                       if (interfaceType == null)
-                                               continue;
-
-                                       var interfaceAnnotation = GetCachedInfoForTypeInHierarchy (interfaceType);
-                                       if (interfaceAnnotation.annotation.HasFlag (annotationToApplyToInterfaces))
-                                               continue;
-
-                                       // Apply All or Interfaces to the interface type.
-                                       // DAMT.All may produce redundant warnings from implementing types, when the interface type already had some annotations.
-                                       reflectionMarker.MarkTypeForDynamicallyAccessedMembers (origin, interfaceType, annotationToApplyToInterfaces, DependencyKind.DynamicallyAccessedMemberOnType, declaredOnly: false);
-                               }
-                       }
-
-                       // The annotations this type inherited from its base types or interfaces should not produce
-                       // warnings on the respective base/interface members, since those are already covered by applying
-                       // the annotations to those types. So we only need to handle the members directly declared on this type.
-                       reflectionMarker.MarkTypeForDynamicallyAccessedMembers (origin, type, annotation, DependencyKind.DynamicallyAccessedMemberOnType, declaredOnly: true);
-               }
-
-               (DynamicallyAccessedMemberTypes annotation, bool applied) GetCachedInfoForTypeInHierarchy (TypeDefinition type)
-               {
-                       // The type should be in our cache already
-                       if (!_typesInDynamicallyAccessedMembersHierarchy.TryGetValue (type, out var existingValue)) {
-                               // If it's not in the cache it should be a non-interface type in which case it means there were no annotations
-                               Debug.Assert (!type.IsInterface);
-                               return (DynamicallyAccessedMemberTypes.None, false);
-                       }
-
-                       return existingValue;
-               }
-       }
-}
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/FieldReferenceValue.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/FieldReferenceValue.cs
deleted file mode 100644 (file)
index 37f7771..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-using ILLink.Shared.DataFlow;
-using Mono.Cecil;
-
-namespace ILLink.Shared.TrimAnalysis
-{
-       public partial record FieldReferenceValue (FieldDefinition FieldDefinition)
-               : ReferenceValue (FieldDefinition.FieldType)
-       {
-               public override SingleValue DeepCopy () => this;
-       }
-}
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/FieldValue.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/FieldValue.cs
deleted file mode 100644 (file)
index 6d20f83..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System.Collections.Generic;
-using System.Diagnostics.CodeAnalysis;
-using ILLink.Shared.DataFlow;
-using Mono.Linker;
-using Mono.Linker.Dataflow;
-using FieldDefinition = Mono.Cecil.FieldDefinition;
-using TypeDefinition = Mono.Cecil.TypeDefinition;
-
-
-namespace ILLink.Shared.TrimAnalysis
-{
-
-       /// <summary>
-       /// A representation of a field. Typically a result of ldfld.
-       /// </summary>
-       sealed partial record FieldValue : IValueWithStaticType
-       {
-               public FieldValue (TypeDefinition? staticType, FieldDefinition fieldToLoad, DynamicallyAccessedMemberTypes dynamicallyAccessedMemberTypes)
-               {
-                       StaticType = staticType;
-                       Field = fieldToLoad;
-                       DynamicallyAccessedMemberTypes = dynamicallyAccessedMemberTypes;
-               }
-
-               public readonly FieldDefinition Field;
-
-               public override DynamicallyAccessedMemberTypes DynamicallyAccessedMemberTypes { get; }
-
-               public override IEnumerable<string> GetDiagnosticArgumentsForAnnotationMismatch ()
-                       => new string[] { Field.GetDisplayName () };
-
-               public TypeDefinition? StaticType { get; }
-
-               public override SingleValue DeepCopy () => this; // This value is immutable
-
-               public override string ToString () => this.ValueToString (Field, DynamicallyAccessedMemberTypes);
-       }
-}
\ No newline at end of file
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/FlowAnnotations.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/FlowAnnotations.cs
deleted file mode 100644 (file)
index 45d1bc0..0000000
+++ /dev/null
@@ -1,761 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Linq;
-using ILLink.Shared.DataFlow;
-using ILLink.Shared.TypeSystemProxy;
-using Mono.Cecil;
-using Mono.Cecil.Cil;
-using Mono.Linker;
-using Mono.Linker.Dataflow;
-
-namespace ILLink.Shared.TrimAnalysis
-{
-       sealed partial class FlowAnnotations
-       {
-               readonly LinkContext _context;
-               readonly Dictionary<TypeDefinition, TypeAnnotations> _annotations = new Dictionary<TypeDefinition, TypeAnnotations> ();
-               readonly TypeHierarchyCache _hierarchyInfo;
-
-               public FlowAnnotations (LinkContext context)
-               {
-                       _context = context;
-                       _hierarchyInfo = new TypeHierarchyCache (context);
-               }
-
-               public bool RequiresDataFlowAnalysis (MethodDefinition method) =>
-                       GetAnnotations (method.DeclaringType).TryGetAnnotation (method, out var methodAnnotations)
-                               && (methodAnnotations.ReturnParameterAnnotation != DynamicallyAccessedMemberTypes.None || methodAnnotations.ParameterAnnotations != null);
-
-               public bool RequiresVirtualMethodDataFlowAnalysis (MethodDefinition method) =>
-                       GetAnnotations (method.DeclaringType).TryGetAnnotation (method, out _);
-
-               public bool RequiresDataFlowAnalysis (FieldDefinition field) =>
-                       GetAnnotations (field.DeclaringType).TryGetAnnotation (field, out _);
-
-               public bool RequiresGenericArgumentDataFlowAnalysis (GenericParameter genericParameter) =>
-                       GetGenericParameterAnnotation (genericParameter) != DynamicallyAccessedMemberTypes.None;
-
-               public DynamicallyAccessedMemberTypes GetParameterAnnotation (ParameterProxy param)
-               {
-                       if (GetAnnotations (param.Method.Method.DeclaringType).TryGetAnnotation (param.Method.Method, out var annotation) &&
-                               annotation.ParameterAnnotations != null)
-                               return annotation.ParameterAnnotations[(int) param.Index];
-
-                       return DynamicallyAccessedMemberTypes.None;
-               }
-
-               public DynamicallyAccessedMemberTypes GetReturnParameterAnnotation (MethodDefinition method)
-               {
-                       if (GetAnnotations (method.DeclaringType).TryGetAnnotation (method, out var annotation))
-                               return annotation.ReturnParameterAnnotation;
-
-                       return DynamicallyAccessedMemberTypes.None;
-               }
-
-               public DynamicallyAccessedMemberTypes GetFieldAnnotation (FieldDefinition field)
-               {
-                       if (GetAnnotations (field.DeclaringType).TryGetAnnotation (field, out var annotation))
-                               return annotation.Annotation;
-
-                       return DynamicallyAccessedMemberTypes.None;
-               }
-
-               public DynamicallyAccessedMemberTypes GetTypeAnnotation (TypeDefinition type) =>
-                       GetAnnotations (type).TypeAnnotation;
-
-               public bool ShouldWarnWhenAccessedForReflection (IMemberDefinition provider) =>
-                       provider switch {
-                               MethodDefinition method => ShouldWarnWhenAccessedForReflection (method),
-                               FieldDefinition field => ShouldWarnWhenAccessedForReflection (field),
-                               _ => false
-                       };
-
-               public DynamicallyAccessedMemberTypes GetGenericParameterAnnotation (GenericParameter genericParameter)
-               {
-                       TypeDefinition? declaringType = _context.Resolve (genericParameter.DeclaringType);
-                       if (declaringType != null) {
-                               if (GetAnnotations (declaringType).TryGetAnnotation (genericParameter, out var annotation))
-                                       return annotation;
-
-                               return DynamicallyAccessedMemberTypes.None;
-                       }
-
-                       MethodDefinition? declaringMethod = _context.Resolve (genericParameter.DeclaringMethod);
-                       if (declaringMethod != null && GetAnnotations (declaringMethod.DeclaringType).TryGetAnnotation (declaringMethod, out var methodTypeAnnotations) &&
-                               methodTypeAnnotations.TryGetAnnotation (genericParameter, out var methodAnnotation))
-                               return methodAnnotation;
-
-                       return DynamicallyAccessedMemberTypes.None;
-               }
-
-               public bool ShouldWarnWhenAccessedForReflection (MethodDefinition method)
-               {
-                       if (!GetAnnotations (method.DeclaringType).TryGetAnnotation (method, out var annotation))
-                               return false;
-
-                       if (annotation.ParameterAnnotations == null && annotation.ReturnParameterAnnotation == DynamicallyAccessedMemberTypes.None)
-                               return false;
-
-                       // If the method only has annotation on the return value and it's not virtual avoid warning.
-                       // Return value annotations are "consumed" by the caller of a method, and as such there is nothing
-                       // wrong calling these dynamically. The only problem can happen if something overrides a virtual
-                       // method with annotated return value at runtime - in this case the trimmer can't validate
-                       // that the method will return only types which fulfill the annotation's requirements.
-                       // For example:
-                       //   class BaseWithAnnotation
-                       //   {
-                       //       [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)]
-                       //       public abstract Type GetTypeWithFields();
-                       //   }
-                       //
-                       //   class UsingTheBase
-                       //   {
-                       //       public void PrintFields(Base base)
-                       //       {
-                       //            // No warning here - GetTypeWithFields is correctly annotated to allow GetFields on the return value.
-                       //            Console.WriteLine(string.Join(" ", base.GetTypeWithFields().GetFields().Select(f => f.Name)));
-                       //       }
-                       //   }
-                       //
-                       // If at runtime (through ref emit) something generates code like this:
-                       //   class DerivedAtRuntimeFromBase
-                       //   {
-                       //       // No point in adding annotation on the return value - nothing will look at it anyway
-                       //       // Linker will not see this code, so there are no checks
-                       //       public override Type GetTypeWithFields() { return typeof(TestType); }
-                       //   }
-                       //
-                       // If TestType from above is trimmed, it may note have all its fields, and there would be no warnings generated.
-                       // But there has to be code like this somewhere in the app, in order to generate the override:
-                       //   class RuntimeTypeGenerator
-                       //   {
-                       //       public MethodInfo GetBaseMethod()
-                       //       {
-                       //            // This must warn - that the GetTypeWithFields has annotation on the return value
-                       //            return typeof(BaseWithAnnotation).GetMethod("GetTypeWithFields");
-                       //       }
-                       //   }
-                       return method.IsVirtual || annotation.ParameterAnnotations != null;
-               }
-
-               public bool ShouldWarnWhenAccessedForReflection (FieldDefinition field) =>
-                       GetAnnotations (field.DeclaringType).TryGetAnnotation (field, out _);
-
-               public bool IsTypeInterestingForDataflow (TypeReference typeReference)
-               {
-                       if (typeReference.MetadataType == MetadataType.String)
-                               return true;
-
-                       TypeDefinition? type = _context.TryResolve (typeReference);
-                       return type != null && (
-                               _hierarchyInfo.IsSystemType (type) ||
-                               _hierarchyInfo.IsSystemReflectionIReflect (type));
-               }
-
-               TypeAnnotations GetAnnotations (TypeDefinition type)
-               {
-                       if (!_annotations.TryGetValue (type, out TypeAnnotations value)) {
-                               value = BuildTypeAnnotations (type);
-                               _annotations.Add (type, value);
-                       }
-
-                       return value;
-               }
-
-               static bool IsDynamicallyAccessedMembersAttribute (CustomAttribute attribute)
-               {
-                       var attributeType = attribute.AttributeType;
-                       return attributeType.Name == "DynamicallyAccessedMembersAttribute" && attributeType.Namespace == "System.Diagnostics.CodeAnalysis";
-               }
-
-               DynamicallyAccessedMemberTypes GetMemberTypesForDynamicallyAccessedMembersAttribute (IMemberDefinition member, ICustomAttributeProvider? providerIfNotMember = null)
-               {
-                       ICustomAttributeProvider provider = providerIfNotMember ?? member;
-                       if (!_context.CustomAttributes.HasAny (provider))
-                               return DynamicallyAccessedMemberTypes.None;
-                       foreach (var attribute in _context.CustomAttributes.GetCustomAttributes (provider)) {
-                               if (!IsDynamicallyAccessedMembersAttribute (attribute))
-                                       continue;
-                               if (attribute.ConstructorArguments.Count == 1)
-                                       return (DynamicallyAccessedMemberTypes) (int) attribute.ConstructorArguments[0].Value;
-                               else
-                                       _context.LogWarning (member, DiagnosticId.AttributeDoesntHaveTheRequiredNumberOfParameters, "System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute");
-                       }
-                       return DynamicallyAccessedMemberTypes.None;
-               }
-
-               TypeAnnotations BuildTypeAnnotations (TypeDefinition type)
-               {
-                       // class, interface, struct can have annotations
-                       DynamicallyAccessedMemberTypes typeAnnotation = GetMemberTypesForDynamicallyAccessedMembersAttribute (type);
-
-                       var annotatedFields = new ArrayBuilder<FieldAnnotation> ();
-
-                       // First go over all fields with an explicit annotation
-                       if (type.HasFields) {
-                               foreach (FieldDefinition field in type.Fields) {
-                                       DynamicallyAccessedMemberTypes annotation = GetMemberTypesForDynamicallyAccessedMembersAttribute (field);
-                                       if (annotation == DynamicallyAccessedMemberTypes.None) {
-                                               continue;
-                                       }
-
-                                       if (!IsTypeInterestingForDataflow (field.FieldType)) {
-                                               // Already know that there's a non-empty annotation on a field which is not System.Type/String and we're about to ignore it
-                                               _context.LogWarning (field, DiagnosticId.DynamicallyAccessedMembersOnFieldCanOnlyApplyToTypesOrStrings, field.GetDisplayName ());
-                                               continue;
-                                       }
-
-                                       annotatedFields.Add (new FieldAnnotation (field, annotation));
-                               }
-                       }
-
-                       var annotatedMethods = new List<MethodAnnotations> ();
-
-                       // Next go over all methods with an explicit annotation
-                       if (type.HasMethods) {
-                               foreach (MethodDefinition method in type.Methods) {
-                                       DynamicallyAccessedMemberTypes[]? paramAnnotations = null;
-
-                                       // Warn if there is an annotation on a method without a `this` parameter -- we won't catch it in the for loop if there's no parameters
-                                       if (GetMemberTypesForDynamicallyAccessedMembersAttribute (method) != DynamicallyAccessedMemberTypes.None
-                                               && !method.HasImplicitThis ()) {
-                                               _context.LogWarning (method, DiagnosticId.DynamicallyAccessedMembersIsNotAllowedOnMethods);
-                                       }
-
-                                       // We convert indices from metadata space to IL space here.
-                                       // IL space assigns index 0 to the `this` parameter on instance methods.
-                                       foreach (var param in method.GetParameters ()) {
-                                               DynamicallyAccessedMemberTypes pa = GetMemberTypesForDynamicallyAccessedMembersAttribute (method, param.GetCustomAttributeProvider ());
-                                               if (pa == DynamicallyAccessedMemberTypes.None)
-                                                       continue;
-
-                                               if (!IsTypeInterestingForDataflow (param.ParameterType)) {
-                                                       if (param.IsImplicitThis)
-                                                               _context.LogWarning (method, DiagnosticId.DynamicallyAccessedMembersIsNotAllowedOnMethods);
-                                                       else
-                                                               _context.LogWarning (method, DiagnosticId.DynamicallyAccessedMembersOnMethodParameterCanOnlyApplyToTypesOrStrings,
-                                                                       param.GetDisplayName (), DiagnosticUtilities.GetMethodSignatureDisplayName (method));
-                                                       continue;
-                                               }
-                                               paramAnnotations ??= new DynamicallyAccessedMemberTypes[method.GetParametersCount ()];
-                                               paramAnnotations[(int) param.Index] = pa;
-                                       }
-
-                                       DynamicallyAccessedMemberTypes returnAnnotation = GetMemberTypesForDynamicallyAccessedMembersAttribute (method, providerIfNotMember: method.MethodReturnType);
-                                       if (returnAnnotation != DynamicallyAccessedMemberTypes.None && !IsTypeInterestingForDataflow (method.ReturnType)) {
-                                               _context.LogWarning (method, DiagnosticId.DynamicallyAccessedMembersOnMethodReturnValueCanOnlyApplyToTypesOrStrings, method.GetDisplayName ());
-                                       }
-
-                                       DynamicallyAccessedMemberTypes[]? genericParameterAnnotations = null;
-                                       if (method.HasGenericParameters) {
-                                               for (int genericParameterIndex = 0; genericParameterIndex < method.GenericParameters.Count; genericParameterIndex++) {
-                                                       var genericParameter = method.GenericParameters[genericParameterIndex];
-                                                       var annotation = GetMemberTypesForDynamicallyAccessedMembersAttribute (method, providerIfNotMember: genericParameter);
-                                                       if (annotation != DynamicallyAccessedMemberTypes.None) {
-                                                               genericParameterAnnotations ??= new DynamicallyAccessedMemberTypes[method.GenericParameters.Count];
-                                                               genericParameterAnnotations[genericParameterIndex] = annotation;
-                                                       }
-                                               }
-                                       }
-
-                                       if (returnAnnotation != DynamicallyAccessedMemberTypes.None || paramAnnotations != null || genericParameterAnnotations != null) {
-                                               annotatedMethods.Add (new MethodAnnotations (method, paramAnnotations, returnAnnotation, genericParameterAnnotations));
-                                       }
-                               }
-                       }
-
-                       // Next up are properties. Annotations on properties are kind of meta because we need to
-                       // map them to annotations on methods/fields. They're syntactic sugar - what they do is expressible
-                       // by placing attribute on the accessor/backing field. For complex properties, that's what people
-                       // will need to do anyway. Like so:
-                       //
-                       // [field: Attribute]
-                       // Type MyProperty {
-                       //     [return: Attribute]
-                       //     get;
-                       //     [value: Attribute]
-                       //     set;
-                       //  }
-                       //
-
-                       if (type.HasProperties) {
-                               foreach (PropertyDefinition property in type.Properties) {
-                                       DynamicallyAccessedMemberTypes annotation = GetMemberTypesForDynamicallyAccessedMembersAttribute (property);
-                                       if (annotation == DynamicallyAccessedMemberTypes.None)
-                                               continue;
-
-                                       if (!IsTypeInterestingForDataflow (property.PropertyType)) {
-                                               _context.LogWarning (property, DiagnosticId.DynamicallyAccessedMembersOnPropertyCanOnlyApplyToTypesOrStrings, property.GetDisplayName ());
-                                               continue;
-                                       }
-
-                                       FieldDefinition? backingFieldFromSetter = null;
-
-                                       // Propagate the annotation to the setter method
-                                       MethodDefinition setMethod = property.SetMethod;
-                                       if (setMethod != null) {
-
-                                               // Abstract property backing field propagation doesn't make sense, and any derived property will be validated
-                                               // to have the exact same annotations on getter/setter, and thus if it has a detectable backing field that will be validated as well.
-                                               if (setMethod.HasBody) {
-                                                       // Look for the compiler generated backing field. If it doesn't work out simply move on. In such case we would still
-                                                       // propagate the annotation to the setter/getter and later on when analyzing the setter/getter we will warn
-                                                       // that the field (which ever it is) must be annotated as well.
-                                                       ScanMethodBodyForFieldAccess (setMethod.Body, write: true, out backingFieldFromSetter);
-                                               }
-
-                                               MethodAnnotations? setterAnnotation = null;
-                                               foreach (var annotatedMethod in annotatedMethods) {
-                                                       if (annotatedMethod.Method == setMethod)
-                                                               setterAnnotation = annotatedMethod;
-                                               }
-
-                                               // If 'value' parameter is annotated, then warn. Other parameters can be annotated for indexable properties
-                                               if (setterAnnotation?.ParameterAnnotations?[^1] is not (null or DynamicallyAccessedMemberTypes.None)) {
-                                                       _context.LogWarning (setMethod, DiagnosticId.DynamicallyAccessedMembersConflictsBetweenPropertyAndAccessor, property.GetDisplayName (), setMethod.GetDisplayName ());
-                                               } else {
-                                                       if (setterAnnotation is not null)
-                                                               annotatedMethods.Remove (setterAnnotation.Value);
-
-                                                       DynamicallyAccessedMemberTypes[] paramAnnotations;
-                                                       if (setterAnnotation?.ParameterAnnotations is null)
-                                                               paramAnnotations = new DynamicallyAccessedMemberTypes[setMethod.GetParametersCount ()];
-                                                       else
-                                                               paramAnnotations = setterAnnotation.Value.ParameterAnnotations;
-
-                                                       paramAnnotations[paramAnnotations.Length - 1] = annotation;
-                                                       annotatedMethods.Add (new MethodAnnotations (setMethod, paramAnnotations, DynamicallyAccessedMemberTypes.None, null));
-                                               }
-                                       }
-
-                                       FieldDefinition? backingFieldFromGetter = null;
-
-                                       // Propagate the annotation to the getter method
-                                       MethodDefinition getMethod = property.GetMethod;
-                                       if (getMethod != null) {
-
-                                               // Abstract property backing field propagation doesn't make sense, and any derived property will be validated
-                                               // to have the exact same annotations on getter/setter, and thus if it has a detectable backing field that will be validated as well.
-                                               if (getMethod.HasBody) {
-                                                       // Look for the compiler generated backing field. If it doesn't work out simply move on. In such case we would still
-                                                       // propagate the annotation to the setter/getter and later on when analyzing the setter/getter we will warn
-                                                       // that the field (which ever it is) must be annotated as well.
-                                                       ScanMethodBodyForFieldAccess (getMethod.Body, write: false, out backingFieldFromGetter);
-                                               }
-                                               MethodAnnotations? getterAnnotation = null;
-                                               foreach (var annotatedMethod in annotatedMethods) {
-                                                       if (annotatedMethod.Method == getMethod)
-                                                               getterAnnotation = annotatedMethod;
-                                               }
-
-                                               // If return value is annotated, then warn. Otherwise, parameters can be annotated for indexable properties
-                                               if (getterAnnotation?.ReturnParameterAnnotation is not (null or DynamicallyAccessedMemberTypes.None)) {
-                                                       _context.LogWarning (getMethod, DiagnosticId.DynamicallyAccessedMembersConflictsBetweenPropertyAndAccessor, property.GetDisplayName (), getMethod.GetDisplayName ());
-                                               } else {
-                                                       int offset = getMethod.HasImplicitThis () ? 1 : 0;
-                                                       if (getterAnnotation is not null)
-                                                               annotatedMethods.Remove (getterAnnotation.Value);
-
-                                                       annotatedMethods.Add (new MethodAnnotations (getMethod, getterAnnotation?.ParameterAnnotations, annotation, null));
-                                               }
-                                       }
-
-                                       FieldDefinition? backingField;
-                                       if (backingFieldFromGetter != null && backingFieldFromSetter != null &&
-                                               backingFieldFromGetter != backingFieldFromSetter) {
-                                               _context.LogWarning (property, DiagnosticId.DynamicallyAccessedMembersCouldNotFindBackingField, property.GetDisplayName ());
-                                               backingField = null;
-                                       } else {
-                                               backingField = backingFieldFromGetter ?? backingFieldFromSetter;
-                                       }
-
-                                       if (backingField != null) {
-                                               if (annotatedFields.Any (a => a.Field == backingField)) {
-                                                       _context.LogWarning (backingField, DiagnosticId.DynamicallyAccessedMembersOnPropertyConflictsWithBackingField, property.GetDisplayName (), backingField.GetDisplayName ());
-                                               } else {
-                                                       annotatedFields.Add (new FieldAnnotation (backingField, annotation));
-                                               }
-                                       }
-                               }
-                       }
-
-                       DynamicallyAccessedMemberTypes[]? typeGenericParameterAnnotations = null;
-                       if (type.HasGenericParameters) {
-                               var attrs = GetGeneratedTypeAttributes (type);
-                               for (int genericParameterIndex = 0; genericParameterIndex < type.GenericParameters.Count; genericParameterIndex++) {
-                                       var provider = attrs?[genericParameterIndex] ?? type.GenericParameters[genericParameterIndex];
-                                       var annotation = GetMemberTypesForDynamicallyAccessedMembersAttribute (type, providerIfNotMember: provider);
-                                       if (annotation != DynamicallyAccessedMemberTypes.None) {
-                                               typeGenericParameterAnnotations ??= new DynamicallyAccessedMemberTypes[type.GenericParameters.Count];
-                                               typeGenericParameterAnnotations[genericParameterIndex] = annotation;
-                                       }
-                               }
-                       }
-
-                       return new TypeAnnotations (type, typeAnnotation, annotatedMethods.ToArray (), annotatedFields.ToArray (), typeGenericParameterAnnotations);
-               }
-
-               private IReadOnlyList<ICustomAttributeProvider>? GetGeneratedTypeAttributes (TypeDefinition typeDef)
-               {
-                       if (!CompilerGeneratedNames.IsGeneratedType (typeDef.Name)) {
-                               return null;
-                       }
-                       var attrs = _context.CompilerGeneratedState.GetGeneratedTypeAttributes (typeDef);
-                       Debug.Assert (attrs is null || attrs.Count == typeDef.GenericParameters.Count);
-                       return attrs;
-               }
-
-               bool ScanMethodBodyForFieldAccess (MethodBody body, bool write, out FieldDefinition? found)
-               {
-                       // Tries to find the backing field for a property getter/setter.
-                       // Returns true if this is a method body that we can unambiguously analyze.
-                       // The found field could still be null if there's no backing store.
-
-                       FieldReference? foundReference = null;
-
-                       foreach (Instruction instruction in _context.GetMethodIL (body).Instructions) {
-                               switch (instruction.OpCode.Code) {
-                               case Code.Ldsfld when !write:
-                               case Code.Ldfld when !write:
-                               case Code.Stsfld when write:
-                               case Code.Stfld when write:
-
-                                       if (foundReference != null) {
-                                               // This writes/reads multiple fields - can't guess which one is the backing store.
-                                               // Return failure.
-                                               found = null;
-                                               return false;
-                                       }
-
-                                       foundReference = (FieldReference) instruction.Operand;
-                                       break;
-                               }
-                       }
-
-                       if (foundReference == null) {
-                               // Doesn't access any fields. Could be e.g. "Type Foo => typeof(Bar);"
-                               // Return success.
-                               found = null;
-                               return true;
-                       }
-
-                       found = _context.Resolve (foundReference);
-
-                       if (found == null) {
-                               // If the field doesn't resolve, it can't be a field on the current type
-                               // anyway. Return failure.
-                               return false;
-                       }
-
-                       if (found.DeclaringType != body.Method.DeclaringType ||
-                               found.IsStatic != body.Method.IsStatic ||
-                               !found.IsCompilerGenerated ()) {
-                               // A couple heuristics to make sure we got the right field.
-                               // Return failure.
-                               found = null;
-                               return false;
-                       }
-
-                       return true;
-               }
-
-               internal void ValidateMethodAnnotationsAreSame (MethodDefinition method, MethodDefinition baseMethod)
-               {
-                       GetAnnotations (method.DeclaringType).TryGetAnnotation (method, out var methodAnnotations);
-                       GetAnnotations (baseMethod.DeclaringType).TryGetAnnotation (baseMethod, out var baseMethodAnnotations);
-
-                       if (methodAnnotations.ReturnParameterAnnotation != baseMethodAnnotations.ReturnParameterAnnotation)
-                               LogValidationWarning (method.MethodReturnType, baseMethod.MethodReturnType, method);
-
-                       if (methodAnnotations.ParameterAnnotations != null || baseMethodAnnotations.ParameterAnnotations != null) {
-                               if (methodAnnotations.ParameterAnnotations == null)
-                                       ValidateMethodParametersHaveNoAnnotations (baseMethodAnnotations.ParameterAnnotations!, method, baseMethod, method);
-                               else if (baseMethodAnnotations.ParameterAnnotations == null)
-                                       ValidateMethodParametersHaveNoAnnotations (methodAnnotations.ParameterAnnotations, method, baseMethod, method);
-                               else {
-                                       if (methodAnnotations.ParameterAnnotations.Length != baseMethodAnnotations.ParameterAnnotations.Length)
-                                               return;
-
-                                       for (int parameterIndex = 0; parameterIndex < methodAnnotations.ParameterAnnotations.Length; parameterIndex++) {
-                                               if (methodAnnotations.ParameterAnnotations[parameterIndex] != baseMethodAnnotations.ParameterAnnotations[parameterIndex])
-                                                       LogValidationWarning (
-                                                               method.TryGetParameter ((ParameterIndex) parameterIndex)?.GetCustomAttributeProvider ()!,
-                                                               baseMethod.TryGetParameter ((ParameterIndex) parameterIndex)?.GetCustomAttributeProvider ()!,
-                                                               method);
-                                       }
-                               }
-                       }
-
-                       if (methodAnnotations.GenericParameterAnnotations != null || baseMethodAnnotations.GenericParameterAnnotations != null) {
-                               if (methodAnnotations.GenericParameterAnnotations == null)
-                                       ValidateMethodGenericParametersHaveNoAnnotations (baseMethodAnnotations.GenericParameterAnnotations!, method, baseMethod, method);
-                               else if (baseMethodAnnotations.GenericParameterAnnotations == null)
-                                       ValidateMethodGenericParametersHaveNoAnnotations (methodAnnotations.GenericParameterAnnotations, method, baseMethod, method);
-                               else {
-                                       if (methodAnnotations.GenericParameterAnnotations.Length != baseMethodAnnotations.GenericParameterAnnotations.Length)
-                                               return;
-
-                                       for (int genericParameterIndex = 0; genericParameterIndex < methodAnnotations.GenericParameterAnnotations.Length; genericParameterIndex++) {
-                                               if (methodAnnotations.GenericParameterAnnotations[genericParameterIndex] != baseMethodAnnotations.GenericParameterAnnotations[genericParameterIndex]) {
-                                                       LogValidationWarning (
-                                                               method.GenericParameters[genericParameterIndex],
-                                                               baseMethod.GenericParameters[genericParameterIndex],
-                                                               method);
-                                               }
-                                       }
-                               }
-                       }
-               }
-
-               void ValidateMethodParametersHaveNoAnnotations (DynamicallyAccessedMemberTypes[] parameterAnnotations, MethodDefinition method, MethodDefinition baseMethod, IMemberDefinition origin)
-               {
-                       for (int parameterIndex = 0; parameterIndex < parameterAnnotations.Length; parameterIndex++) {
-                               var annotation = parameterAnnotations[parameterIndex];
-                               if (annotation != DynamicallyAccessedMemberTypes.None)
-                                       LogValidationWarning (
-                                               method.GetParameter ((ParameterIndex) parameterIndex).GetCustomAttributeProvider ()!,
-                                               baseMethod.GetParameter ((ParameterIndex) parameterIndex).GetCustomAttributeProvider ()!,
-                                               origin);
-                       }
-               }
-
-               void ValidateMethodGenericParametersHaveNoAnnotations (DynamicallyAccessedMemberTypes[] genericParameterAnnotations, MethodDefinition method, MethodDefinition baseMethod, IMemberDefinition origin)
-               {
-                       for (int genericParameterIndex = 0; genericParameterIndex < genericParameterAnnotations.Length; genericParameterIndex++) {
-                               if (genericParameterAnnotations[genericParameterIndex] != DynamicallyAccessedMemberTypes.None) {
-                                       LogValidationWarning (
-                                               method.GenericParameters[genericParameterIndex],
-                                               baseMethod.GenericParameters[genericParameterIndex],
-                                               origin);
-                               }
-                       }
-               }
-
-               void LogValidationWarning (IMetadataTokenProvider provider, IMetadataTokenProvider baseProvider, IMemberDefinition origin)
-               {
-                       Debug.Assert (provider.GetType () == baseProvider.GetType ());
-                       Debug.Assert (!(provider is GenericParameter genericParameter) || genericParameter.DeclaringMethod != null);
-                       switch (provider) {
-                       case ParameterDefinition parameterDefinition:
-                               var baseParameterDefinition = (ParameterDefinition) baseProvider;
-                               _context.LogWarning (origin, DiagnosticId.DynamicallyAccessedMembersMismatchOnMethodParameterBetweenOverrides,
-                                       DiagnosticUtilities.GetParameterNameForErrorMessage (parameterDefinition), DiagnosticUtilities.GetMethodSignatureDisplayName (parameterDefinition.Method),
-                                       DiagnosticUtilities.GetParameterNameForErrorMessage (baseParameterDefinition), DiagnosticUtilities.GetMethodSignatureDisplayName (baseParameterDefinition.Method));
-                               break;
-                       case MethodReturnType methodReturnType:
-                               _context.LogWarning (origin, DiagnosticId.DynamicallyAccessedMembersMismatchOnMethodReturnValueBetweenOverrides,
-                                       DiagnosticUtilities.GetMethodSignatureDisplayName (methodReturnType.Method), DiagnosticUtilities.GetMethodSignatureDisplayName (((MethodReturnType) baseProvider).Method));
-                               break;
-                       // No fields - it's not possible to have a virtual field and override it
-                       case MethodDefinition methodDefinition:
-                               _context.LogWarning (origin, DiagnosticId.DynamicallyAccessedMembersMismatchOnImplicitThisBetweenOverrides,
-                                       DiagnosticUtilities.GetMethodSignatureDisplayName (methodDefinition), DiagnosticUtilities.GetMethodSignatureDisplayName ((MethodDefinition) baseProvider));
-                               break;
-                       case GenericParameter genericParameterOverride:
-                               var genericParameterBase = (GenericParameter) baseProvider;
-                               _context.LogWarning (origin, DiagnosticId.DynamicallyAccessedMembersMismatchOnGenericParameterBetweenOverrides,
-                                       genericParameterOverride.Name, DiagnosticUtilities.GetGenericParameterDeclaringMemberDisplayName (genericParameterOverride),
-                                       genericParameterBase.Name, DiagnosticUtilities.GetGenericParameterDeclaringMemberDisplayName (genericParameterBase));
-                               break;
-                       default:
-                               throw new NotImplementedException ($"Unsupported provider type '{provider.GetType ()}'.");
-                       }
-               }
-
-               readonly struct TypeAnnotations
-               {
-                       readonly TypeDefinition _type;
-                       readonly DynamicallyAccessedMemberTypes _typeAnnotation;
-                       readonly MethodAnnotations[]? _annotatedMethods;
-                       readonly FieldAnnotation[]? _annotatedFields;
-                       readonly DynamicallyAccessedMemberTypes[]? _genericParameterAnnotations;
-
-                       public TypeAnnotations (
-                               TypeDefinition type,
-                               DynamicallyAccessedMemberTypes typeAnnotation,
-                               MethodAnnotations[]? annotatedMethods,
-                               FieldAnnotation[]? annotatedFields,
-                               DynamicallyAccessedMemberTypes[]? genericParameterAnnotations)
-                               => (_type, _typeAnnotation, _annotatedMethods, _annotatedFields, _genericParameterAnnotations)
-                                = (type, typeAnnotation, annotatedMethods, annotatedFields, genericParameterAnnotations);
-
-                       public DynamicallyAccessedMemberTypes TypeAnnotation { get => _typeAnnotation; }
-
-                       public bool TryGetAnnotation (MethodDefinition method, out MethodAnnotations annotations)
-                       {
-                               annotations = default;
-
-                               if (_annotatedMethods == null) {
-                                       return false;
-                               }
-
-                               foreach (var m in _annotatedMethods) {
-                                       if (m.Method == method) {
-                                               annotations = m;
-                                               return true;
-                                       }
-                               }
-
-                               return false;
-                       }
-
-                       public bool TryGetAnnotation (FieldDefinition field, out FieldAnnotation annotation)
-                       {
-                               annotation = default;
-
-                               if (_annotatedFields == null) {
-                                       return false;
-                               }
-
-                               foreach (var f in _annotatedFields) {
-                                       if (f.Field == field) {
-                                               annotation = f;
-                                               return true;
-                                       }
-                               }
-
-                               return false;
-                       }
-
-                       public bool TryGetAnnotation (GenericParameter genericParameter, out DynamicallyAccessedMemberTypes annotation)
-                       {
-                               annotation = default;
-
-                               if (_genericParameterAnnotations == null)
-                                       return false;
-
-                               for (int genericParameterIndex = 0; genericParameterIndex < _genericParameterAnnotations.Length; genericParameterIndex++) {
-                                       if (_type.GenericParameters[genericParameterIndex] == genericParameter) {
-                                               annotation = _genericParameterAnnotations[genericParameterIndex];
-                                               return true;
-                                       }
-                               }
-
-                               return false;
-                       }
-               }
-
-               readonly struct MethodAnnotations
-               {
-                       public readonly MethodDefinition Method;
-                       public readonly DynamicallyAccessedMemberTypes[]? ParameterAnnotations;
-                       public readonly DynamicallyAccessedMemberTypes ReturnParameterAnnotation;
-                       public readonly DynamicallyAccessedMemberTypes[]? GenericParameterAnnotations;
-
-                       public MethodAnnotations (
-                               MethodDefinition method,
-                               DynamicallyAccessedMemberTypes[]? paramAnnotations,
-                               DynamicallyAccessedMemberTypes returnParamAnnotations,
-                               DynamicallyAccessedMemberTypes[]? genericParameterAnnotations)
-                               => (Method, ParameterAnnotations, ReturnParameterAnnotation, GenericParameterAnnotations) =
-                                       (method, paramAnnotations, returnParamAnnotations, genericParameterAnnotations);
-
-                       public bool TryGetAnnotation (GenericParameter genericParameter, out DynamicallyAccessedMemberTypes annotation)
-                       {
-                               annotation = default;
-
-                               if (GenericParameterAnnotations == null)
-                                       return false;
-
-                               for (int genericParameterIndex = 0; genericParameterIndex < GenericParameterAnnotations.Length; genericParameterIndex++) {
-                                       if (Method.GenericParameters[genericParameterIndex] == genericParameter) {
-                                               annotation = GenericParameterAnnotations[genericParameterIndex];
-                                               return true;
-                                       }
-                               }
-
-                               return false;
-                       }
-               }
-
-               readonly struct FieldAnnotation
-               {
-                       public readonly FieldDefinition Field;
-                       public readonly DynamicallyAccessedMemberTypes Annotation;
-
-                       public FieldAnnotation (FieldDefinition field, DynamicallyAccessedMemberTypes annotation)
-                               => (Field, Annotation) = (field, annotation);
-               }
-
-               internal partial bool MethodRequiresDataFlowAnalysis (MethodProxy method)
-                       => RequiresDataFlowAnalysis (method.Method);
-
-               internal partial MethodReturnValue GetMethodReturnValue (MethodProxy method, DynamicallyAccessedMemberTypes dynamicallyAccessedMemberTypes)
-                       => new MethodReturnValue (method.Method.ReturnType.ResolveToTypeDefinition (_context), method.Method, dynamicallyAccessedMemberTypes);
-
-               internal partial MethodReturnValue GetMethodReturnValue (MethodProxy method)
-                       => GetMethodReturnValue (method, GetReturnParameterAnnotation (method.Method));
-
-               internal partial GenericParameterValue GetGenericParameterValue (GenericParameterProxy genericParameter)
-                       => new GenericParameterValue (genericParameter.GenericParameter, GetGenericParameterAnnotation (genericParameter.GenericParameter));
-
-               internal partial MethodParameterValue GetMethodParameterValue (ParameterProxy param, DynamicallyAccessedMemberTypes dynamicallyAccessedMemberTypes)
-                       => new (param.ParameterType.ResolveToTypeDefinition (_context), param, dynamicallyAccessedMemberTypes);
-
-               internal partial MethodParameterValue GetMethodParameterValue (ParameterProxy param)
-                       => GetMethodParameterValue (param, GetParameterAnnotation (param));
-
-#pragma warning disable CA1822 // Mark members as static - Should be an instance method for consistency
-               // overrideIsThis is needed for backwards compatibility with MakeGenericType/Method https://github.com/dotnet/linker/issues/2428
-               internal MethodParameterValue GetMethodThisParameterValue (MethodProxy method, DynamicallyAccessedMemberTypes dynamicallyAccessedMemberTypes, bool overrideIsThis = false)
-               {
-                       if (!method.HasImplicitThis () && !overrideIsThis)
-                               throw new InvalidOperationException ($"Cannot get 'this' parameter of method {method.GetDisplayName ()} with no 'this' parameter.");
-                       return new MethodParameterValue (method.Method.DeclaringType, new ParameterProxy (method, (ParameterIndex) 0), dynamicallyAccessedMemberTypes, overrideIsThis);
-               }
-#pragma warning restore CA1822 // Mark members as static
-
-               internal partial MethodParameterValue GetMethodThisParameterValue (MethodProxy method, DynamicallyAccessedMemberTypes dynamicallyAccessedMemberTypes)
-                       => GetMethodThisParameterValue (method, dynamicallyAccessedMemberTypes, false);
-
-               internal partial MethodParameterValue GetMethodThisParameterValue (MethodProxy method)
-               {
-                       if (!method.HasImplicitThis ())
-                               throw new InvalidOperationException ($"Cannot get 'this' parameter of method {method.GetDisplayName ()} with no 'this' parameter.");
-                       ParameterProxy param = new (method, (ParameterIndex) 0);
-                       var damt = GetParameterAnnotation (param);
-                       return GetMethodParameterValue (new ParameterProxy (method, (ParameterIndex) 0), damt);
-               }
-
-               // Linker-specific dataflow value creation. Eventually more of these should be shared.
-               internal SingleValue GetFieldValue (FieldDefinition field)
-                       => field.Name switch {
-                               "EmptyTypes" when field.DeclaringType.IsTypeOf (WellKnownType.System_Type) => ArrayValue.Create (0, field.DeclaringType),
-                               "Empty" when field.DeclaringType.IsTypeOf (WellKnownType.System_String) => new KnownStringValue (string.Empty),
-                               _ => new FieldValue (field.FieldType.ResolveToTypeDefinition (_context), field, GetFieldAnnotation (field))
-                       };
-
-               internal SingleValue GetTypeValueFromGenericArgument (TypeReference genericArgument)
-               {
-                       if (genericArgument is GenericParameter inputGenericParameter) {
-                               // Technically this should be a new value node type as it's not a System.Type instance representation, but just the generic parameter
-                               // That said we only use it to perform the dynamically accessed members checks and for that purpose treating it as System.Type is perfectly valid.
-                               return GetGenericParameterValue (inputGenericParameter);
-                       } else if (genericArgument.ResolveToTypeDefinition (_context) is TypeDefinition genericArgumentType) {
-                               if (genericArgumentType.IsTypeOf (WellKnownType.System_Nullable_T)) {
-                                       var innerGenericArgument = (genericArgument as IGenericInstance)?.GenericArguments.FirstOrDefault ();
-                                       switch (innerGenericArgument) {
-                                       case GenericParameter gp:
-                                               return new NullableValueWithDynamicallyAccessedMembers (genericArgumentType,
-                                                       new GenericParameterValue (gp, _context.Annotations.FlowAnnotations.GetGenericParameterAnnotation (gp)));
-
-                                       case TypeReference underlyingType:
-                                               if (underlyingType.ResolveToTypeDefinition (_context) is TypeDefinition underlyingTypeDefinition)
-                                                       return new NullableSystemTypeValue (genericArgumentType, new SystemTypeValue (underlyingTypeDefinition));
-                                               else
-                                                       return UnknownValue.Instance;
-                                       }
-                               }
-                               // All values except for Nullable<T>, including Nullable<> (with no type arguments)
-                               return new SystemTypeValue (genericArgumentType);
-                       } else {
-                               return UnknownValue.Instance;
-                       }
-               }
-       }
-}
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/GenericArgumentDataFlow.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/GenericArgumentDataFlow.cs
deleted file mode 100644 (file)
index a4092c4..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using ILLink.Shared.TrimAnalysis;
-using Mono.Cecil;
-using Mono.Linker.Steps;
-using MultiValue = ILLink.Shared.DataFlow.ValueSet<ILLink.Shared.DataFlow.SingleValue>;
-
-namespace Mono.Linker.Dataflow
-{
-       public readonly struct GenericArgumentDataFlow
-       {
-               readonly LinkContext _context;
-               readonly MarkStep _markStep;
-               readonly MessageOrigin _origin;
-
-               public GenericArgumentDataFlow (LinkContext context, MarkStep markStep, in MessageOrigin origin)
-               {
-                       _context = context;
-                       _markStep = markStep;
-                       _origin = origin;
-               }
-
-               public void ProcessGenericArgumentDataFlow (GenericParameter genericParameter, TypeReference genericArgument)
-               {
-                       var genericParameterValue = _context.Annotations.FlowAnnotations.GetGenericParameterValue (genericParameter);
-                       Debug.Assert (genericParameterValue.DynamicallyAccessedMemberTypes != DynamicallyAccessedMemberTypes.None);
-
-                       MultiValue genericArgumentValue = _context.Annotations.FlowAnnotations.GetTypeValueFromGenericArgument (genericArgument);
-
-                       var diagnosticContext = new DiagnosticContext (_origin, !_context.Annotations.ShouldSuppressAnalysisWarningsForRequiresUnreferencedCode (_origin.Provider), _context);
-                       RequireDynamicallyAccessedMembers (diagnosticContext, genericArgumentValue, genericParameterValue);
-               }
-
-               void RequireDynamicallyAccessedMembers (in DiagnosticContext diagnosticContext, in MultiValue value, ValueWithDynamicallyAccessedMembers targetValue)
-               {
-                       var reflectionMarker = new ReflectionMarker (_context, _markStep, enabled: true);
-                       var requireDynamicallyAccessedMembersAction = new RequireDynamicallyAccessedMembersAction (reflectionMarker, diagnosticContext);
-                       requireDynamicallyAccessedMembersAction.Invoke (value, targetValue);
-               }
-       }
-}
\ No newline at end of file
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/GenericParameterValue.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/GenericParameterValue.cs
deleted file mode 100644 (file)
index 8f1d606..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System.Collections.Generic;
-using System.Diagnostics.CodeAnalysis;
-using ILLink.Shared.DataFlow;
-using Mono.Linker.Dataflow;
-using GenericParameter = Mono.Cecil.GenericParameter;
-
-namespace ILLink.Shared.TrimAnalysis
-{
-       /// <summary>
-       /// This is a System.Type value which represents generic parameter (basically result of typeof(T))
-       /// Its actual type is unknown, but it can have annotations.
-       /// </summary>
-       partial record GenericParameterValue
-       {
-               public GenericParameterValue (GenericParameter genericParameter, DynamicallyAccessedMemberTypes dynamicallyAccessedMemberTypes)
-               {
-                       GenericParameter = new (genericParameter);
-                       DynamicallyAccessedMemberTypes = dynamicallyAccessedMemberTypes;
-               }
-
-               public override DynamicallyAccessedMemberTypes DynamicallyAccessedMemberTypes { get; }
-
-               public override IEnumerable<string> GetDiagnosticArgumentsForAnnotationMismatch ()
-                       => new string[] { GenericParameter.GenericParameter.Name, DiagnosticUtilities.GetGenericParameterDeclaringMemberDisplayName (GenericParameter.GenericParameter) };
-
-               public override SingleValue DeepCopy () => this; // This value is immutable
-
-               public override string ToString () => this.ValueToString (GenericParameter, DynamicallyAccessedMemberTypes);
-       }
-}
\ No newline at end of file
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/HandleCallAction.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/HandleCallAction.cs
deleted file mode 100644 (file)
index 4b045a7..0000000
+++ /dev/null
@@ -1,132 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System.Collections.Generic;
-using System.Reflection;
-using ILLink.Shared.TypeSystemProxy;
-using Mono.Cecil;
-using Mono.Linker;
-using Mono.Linker.Dataflow;
-
-namespace ILLink.Shared.TrimAnalysis
-{
-       partial struct HandleCallAction
-       {
-#pragma warning disable CA1822 // Mark members as static - the other partial implementations might need to be instance methods
-
-               readonly LinkContext _context;
-               readonly ReflectionMarker _reflectionMarker;
-               readonly MethodDefinition _callingMethodDefinition;
-
-               public HandleCallAction (
-                       LinkContext context,
-                       ReflectionMarker reflectionMarker,
-                       in DiagnosticContext diagnosticContext,
-                       MethodDefinition callingMethodDefinition)
-               {
-                       _context = context;
-                       _reflectionMarker = reflectionMarker;
-                       _diagnosticContext = diagnosticContext;
-                       _callingMethodDefinition = callingMethodDefinition;
-                       _annotations = context.Annotations.FlowAnnotations;
-                       _requireDynamicallyAccessedMembersAction = new (reflectionMarker, diagnosticContext);
-               }
-
-               private partial bool MethodIsTypeConstructor (MethodProxy method)
-               {
-                       if (!method.Method.IsConstructor)
-                               return false;
-                       TypeDefinition? type = method.Method.DeclaringType;
-                       while (type is not null) {
-                               if (type.IsTypeOf (WellKnownType.System_Type))
-                                       return true;
-                               type = _context.Resolve (type.BaseType);
-                       }
-                       return false;
-               }
-
-               private partial IEnumerable<SystemReflectionMethodBaseValue> GetMethodsOnTypeHierarchy (TypeProxy type, string name, BindingFlags? bindingFlags)
-               {
-                       foreach (var method in type.Type.GetMethodsOnTypeHierarchy (_context, m => m.Name == name, bindingFlags))
-                               yield return new SystemReflectionMethodBaseValue (new MethodProxy (method));
-               }
-
-               private partial IEnumerable<SystemTypeValue> GetNestedTypesOnType (TypeProxy type, string name, BindingFlags? bindingFlags)
-               {
-                       foreach (var nestedType in type.Type.GetNestedTypesOnType (t => t.Name == name, bindingFlags))
-                               yield return new SystemTypeValue (new TypeProxy (nestedType));
-               }
-
-               private partial bool TryGetBaseType (TypeProxy type, out TypeProxy? baseType)
-               {
-                       if (type.Type.BaseType is TypeReference baseTypeRef && _context.TryResolve (baseTypeRef) is TypeDefinition baseTypeDefinition) {
-                               baseType = new TypeProxy (baseTypeDefinition);
-                               return true;
-                       }
-
-                       baseType = null;
-                       return false;
-               }
-
-               private partial bool TryResolveTypeNameForCreateInstanceAndMark (in MethodProxy calledMethod, string assemblyName, string typeName, out TypeProxy resolvedType)
-               {
-                       var resolvedAssembly = _context.TryResolve (assemblyName);
-                       if (resolvedAssembly == null) {
-                               _diagnosticContext.AddDiagnostic (DiagnosticId.UnresolvedAssemblyInCreateInstance,
-                                       assemblyName,
-                                       calledMethod.GetDisplayName ());
-                               resolvedType = default;
-                               return false;
-                       }
-
-                       if (!_reflectionMarker.TryResolveTypeNameAndMark (resolvedAssembly, typeName, _diagnosticContext, out TypeDefinition? resolvedTypeDefinition)
-                               || resolvedTypeDefinition.IsTypeOf (WellKnownType.System_Array)) {
-                               // It's not wrong to have a reference to non-existing type - the code may well expect to get an exception in this case
-                               // Note that we did find the assembly, so it's not a linker config problem, it's either intentional, or wrong versions of assemblies
-                               // but linker can't know that. In case a user tries to create an array using System.Activator we should simply ignore it, the user
-                               // might expect an exception to be thrown.
-                               resolvedType = default;
-                               return false;
-                       }
-
-                       resolvedType = new TypeProxy (resolvedTypeDefinition);
-                       return true;
-               }
-
-               private partial void MarkStaticConstructor (TypeProxy type)
-                       => _reflectionMarker.MarkStaticConstructor (_diagnosticContext.Origin, type.Type);
-
-               private partial void MarkEventsOnTypeHierarchy (TypeProxy type, string name, BindingFlags? bindingFlags)
-                       => _reflectionMarker.MarkEventsOnTypeHierarchy (_diagnosticContext.Origin, type.Type, e => e.Name == name, bindingFlags);
-
-               private partial void MarkFieldsOnTypeHierarchy (TypeProxy type, string name, BindingFlags? bindingFlags)
-                       => _reflectionMarker.MarkFieldsOnTypeHierarchy (_diagnosticContext.Origin, type.Type, f => f.Name == name, bindingFlags);
-
-               private partial void MarkPropertiesOnTypeHierarchy (TypeProxy type, string name, BindingFlags? bindingFlags)
-                       => _reflectionMarker.MarkPropertiesOnTypeHierarchy (_diagnosticContext.Origin, type.Type, p => p.Name == name, bindingFlags);
-
-               private partial void MarkPublicParameterlessConstructorOnType (TypeProxy type)
-                       => _reflectionMarker.MarkConstructorsOnType (_diagnosticContext.Origin, type.Type, m => m.IsPublic && m.GetMetadataParametersCount () == 0);
-
-               private partial void MarkConstructorsOnType (TypeProxy type, BindingFlags? bindingFlags, int? parameterCount)
-                       => _reflectionMarker.MarkConstructorsOnType (_diagnosticContext.Origin, type.Type, (parameterCount == null) ? null : m => m.GetMetadataParametersCount () == parameterCount, bindingFlags);
-
-               private partial void MarkMethod (MethodProxy method)
-                       => _reflectionMarker.MarkMethod (_diagnosticContext.Origin, method.Method);
-
-               private partial void MarkType (TypeProxy type)
-                       => _reflectionMarker.MarkType (_diagnosticContext.Origin, type.Type);
-
-               private partial bool MarkAssociatedProperty (MethodProxy method)
-               {
-                       if (method.Method.TryGetProperty (out PropertyDefinition? propertyDefinition)) {
-                               _reflectionMarker.MarkProperty (_diagnosticContext.Origin, propertyDefinition);
-                               return true;
-                       }
-
-                       return false;
-               }
-
-               private partial string GetContainingSymbolDisplayName () => _callingMethodDefinition.GetDisplayName ();
-       }
-}
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/HoistedLocalKey.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/HoistedLocalKey.cs
deleted file mode 100644 (file)
index b721df2..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System;
-using System.Diagnostics;
-using Mono.Cecil;
-
-namespace Mono.Linker.Dataflow
-{
-       // This represents a field which has been generated by the compiler as the
-       // storage location for a hoisted local (a local variable which is lifted to a
-       // field on a state machine type, or to a field on a closure accessed by lambdas
-       // or local functions).
-       public readonly struct HoistedLocalKey : IEquatable<HoistedLocalKey>
-       {
-               readonly FieldDefinition Field;
-
-               public HoistedLocalKey (FieldDefinition field)
-               {
-                       Debug.Assert (CompilerGeneratedState.IsHoistedLocal (field));
-                       Field = field;
-               }
-
-               public bool Equals (HoistedLocalKey other) => Field.Equals (other.Field);
-
-               public override bool Equals (object? obj) => obj is HoistedLocalKey other && Equals (other);
-
-               public override int GetHashCode () => Field.GetHashCode ();
-       }
-}
\ No newline at end of file
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/IValueWithStaticType.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/IValueWithStaticType.cs
deleted file mode 100644 (file)
index e18561f..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using Mono.Cecil;
-
-namespace Mono.Linker.Dataflow
-{
-       interface IValueWithStaticType
-       {
-               /// <summary>
-               /// The IL type of the value, represented as closely as possible, but not always exact.  It can be null, for
-               /// example, when the analysis is imprecise or operating on malformed IL.
-               /// </summary>
-               TypeDefinition? StaticType { get; }
-       }
-}
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/InterproceduralState.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/InterproceduralState.cs
deleted file mode 100644 (file)
index bfb5cf5..0000000
+++ /dev/null
@@ -1,106 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using ILLink.Shared.DataFlow;
-using Mono.Cecil;
-using Mono.Cecil.Cil;
-using HoistedLocalState = ILLink.Shared.DataFlow.DefaultValueDictionary<
-       Mono.Linker.Dataflow.HoistedLocalKey,
-       ILLink.Shared.DataFlow.ValueSet<ILLink.Shared.DataFlow.SingleValue>>;
-using MultiValue = ILLink.Shared.DataFlow.ValueSet<ILLink.Shared.DataFlow.SingleValue>;
-
-namespace Mono.Linker.Dataflow
-{
-       // Tracks the set of methods which get analyzer together during interprocedural analysis,
-       // and the possible states of hoisted locals in state machine methods and lambdas/local functions.
-       struct InterproceduralState : IEquatable<InterproceduralState>
-       {
-               public ValueSet<MethodIL> MethodBodies;
-               public HoistedLocalState HoistedLocals;
-               readonly InterproceduralStateLattice lattice;
-
-               public InterproceduralState (ValueSet<MethodIL> methodBodies, HoistedLocalState hoistedLocals, InterproceduralStateLattice lattice)
-                       => (MethodBodies, HoistedLocals, this.lattice) = (methodBodies, hoistedLocals, lattice);
-
-               public bool Equals (InterproceduralState other)
-                       => MethodBodies.Equals (other.MethodBodies) && HoistedLocals.Equals (other.HoistedLocals);
-
-               public override bool Equals (object? obj)
-                       => obj is InterproceduralState state && Equals (state);
-
-               public override int GetHashCode () => base.GetHashCode ();
-
-               public InterproceduralState Clone ()
-                       => new (MethodBodies.Clone (), HoistedLocals.Clone (), lattice);
-
-               public void TrackMethod (MethodDefinition method)
-               {
-                       if (method.Body is not MethodBody methodBody)
-                               return;
-
-                       TrackMethod (methodBody);
-               }
-
-               public void TrackMethod (MethodBody methodBody)
-               {
-                       TrackMethod (lattice.Context.GetMethodIL (methodBody));
-               }
-
-               public void TrackMethod (MethodIL methodIL)
-               {
-                       // Work around the fact that ValueSet is readonly
-                       var methodsList = new List<MethodIL> (MethodBodies);
-                       methodsList.Add (methodIL);
-
-                       // For state machine methods, also scan the state machine members.
-                       // Simplification: assume that all generated methods of the state machine type are
-                       // reached at the point where the state machine method is reached.
-                       if (CompilerGeneratedState.TryGetStateMachineType (methodIL.Method, out TypeDefinition? stateMachineType)) {
-                               foreach (var stateMachineMethod in stateMachineType.Methods) {
-                                       Debug.Assert (!CompilerGeneratedNames.IsLambdaOrLocalFunction (stateMachineMethod.Name));
-                                       if (stateMachineMethod.Body is MethodBody stateMachineMethodBody)
-                                               methodsList.Add (lattice.Context.GetMethodIL (stateMachineMethodBody));
-                               }
-                       }
-
-                       MethodBodies = new ValueSet<MethodIL> (methodsList);
-               }
-
-               public void SetHoistedLocal (HoistedLocalKey key, MultiValue value)
-               {
-                       // For hoisted locals, we track the entire set of assigned values seen
-                       // in the closure of a method, so setting a hoisted local value meets
-                       // it with any existing value.
-                       HoistedLocals.Set (key,
-                               lattice.HoistedLocalsLattice.ValueLattice.Meet (
-                                       HoistedLocals.Get (key), value));
-               }
-
-               public MultiValue GetHoistedLocal (HoistedLocalKey key)
-                       => HoistedLocals.Get (key);
-       }
-
-       readonly struct InterproceduralStateLattice : ILattice<InterproceduralState>
-       {
-               public readonly ValueSetLattice<MethodIL> MethodBodyLattice;
-               public readonly DictionaryLattice<HoistedLocalKey, MultiValue, ValueSetLattice<SingleValue>> HoistedLocalsLattice;
-               public readonly LinkContext Context;
-
-               public InterproceduralStateLattice (
-                       ValueSetLattice<MethodIL> methodBodyLattice,
-                       DictionaryLattice<HoistedLocalKey, MultiValue, ValueSetLattice<SingleValue>> hoistedLocalsLattice,
-                       LinkContext context)
-                       => (MethodBodyLattice, HoistedLocalsLattice, Context) = (methodBodyLattice, hoistedLocalsLattice, context);
-
-               public InterproceduralState Top => new InterproceduralState (MethodBodyLattice.Top, HoistedLocalsLattice.Top, this);
-
-               public InterproceduralState Meet (InterproceduralState left, InterproceduralState right)
-                       => new (
-                               MethodBodyLattice.Meet (left.MethodBodies, right.MethodBodies),
-                               HoistedLocalsLattice.Meet (left.HoistedLocals, right.HoistedLocals),
-                               this);
-       }
-}
\ No newline at end of file
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/LocalVariableReferenceValue.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/LocalVariableReferenceValue.cs
deleted file mode 100644 (file)
index 2c405be..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-using ILLink.Shared.DataFlow;
-using Mono.Cecil.Cil;
-
-namespace ILLink.Shared.TrimAnalysis
-{
-       public partial record LocalVariableReferenceValue (VariableDefinition LocalDefinition)
-               : ReferenceValue (LocalDefinition.VariableType)
-       {
-               public override SingleValue DeepCopy ()
-               {
-                       return this;
-               }
-       }
-}
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/MethodBodyScanner.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/MethodBodyScanner.cs
deleted file mode 100644 (file)
index fab08ed..0000000
+++ /dev/null
@@ -1,1210 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-using ILLink.Shared;
-using ILLink.Shared.DataFlow;
-using ILLink.Shared.TrimAnalysis;
-using ILLink.Shared.TypeSystemProxy;
-using Mono.Cecil;
-using Mono.Cecil.Cil;
-using Mono.Collections.Generic;
-using LocalVariableStore = System.Collections.Generic.Dictionary<
-       Mono.Cecil.Cil.VariableDefinition,
-       Mono.Linker.Dataflow.ValueBasicBlockPair>;
-using MultiValue = ILLink.Shared.DataFlow.ValueSet<ILLink.Shared.DataFlow.SingleValue>;
-
-namespace Mono.Linker.Dataflow
-{
-       /// <summary>
-       /// Tracks information about the contents of a stack slot
-       /// </summary>
-       readonly struct StackSlot
-       {
-               public MultiValue Value { get; }
-
-               public StackSlot ()
-               {
-                       Value = new MultiValue (UnknownValue.Instance);
-               }
-
-               public StackSlot (SingleValue value)
-               {
-                       Value = new MultiValue (value);
-               }
-
-               public StackSlot (MultiValue value)
-               {
-                       Value = value;
-               }
-       }
-
-       abstract partial class MethodBodyScanner
-       {
-               protected readonly LinkContext _context;
-               protected readonly InterproceduralStateLattice InterproceduralStateLattice;
-               protected static ValueSetLattice<SingleValue> MultiValueLattice => default;
-
-               protected MethodBodyScanner (LinkContext context)
-               {
-                       this._context = context;
-                       this.InterproceduralStateLattice = new InterproceduralStateLattice (default, default, context);
-               }
-
-               internal MultiValue ReturnValue { private set; get; }
-
-               protected virtual void WarnAboutInvalidILInMethod (MethodBody method, int ilOffset)
-               {
-               }
-
-               private void CheckForInvalidStack (Stack<StackSlot> stack, int depthRequired, MethodBody method, int ilOffset)
-               {
-                       if (stack.Count < depthRequired) {
-                               WarnAboutInvalidILInMethod (method, ilOffset);
-                               while (stack.Count < depthRequired)
-                                       stack.Push (new StackSlot ()); // Push dummy values to avoid crashes.
-                                                                                                  // Analysis of this method will be incorrect.
-                       }
-               }
-
-               private static void PushUnknown (Stack<StackSlot> stack)
-               {
-                       stack.Push (new StackSlot ());
-               }
-
-               private void PushUnknownAndWarnAboutInvalidIL (Stack<StackSlot> stack, MethodBody methodBody, int offset)
-               {
-                       WarnAboutInvalidILInMethod (methodBody, offset);
-                       PushUnknown (stack);
-               }
-
-               private StackSlot PopUnknown (Stack<StackSlot> stack, int count, MethodBody method, int ilOffset)
-               {
-                       if (count < 1)
-                               throw new InvalidOperationException ();
-
-                       StackSlot topOfStack = default;
-                       CheckForInvalidStack (stack, count, method, ilOffset);
-
-                       for (int i = 0; i < count; ++i) {
-                               StackSlot slot = stack.Pop ();
-                               if (i == 0)
-                                       topOfStack = slot;
-                       }
-                       return topOfStack;
-               }
-
-               private static StackSlot MergeStackElement (StackSlot a, StackSlot b)
-               {
-                       return new StackSlot (MultiValueLattice.Meet (a.Value, b.Value));
-               }
-
-               // Merge stacks together. This may return the first stack, the stack length must be the same for the two stacks.
-               private static Stack<StackSlot> MergeStack (Stack<StackSlot> a, Stack<StackSlot> b)
-               {
-                       if (a.Count != b.Count) {
-                               // Force stacks to be of equal size to avoid crashes.
-                               // Analysis of this method will be incorrect.
-                               while (a.Count < b.Count)
-                                       a.Push (new StackSlot ());
-
-                               while (b.Count < a.Count)
-                                       b.Push (new StackSlot ());
-                       }
-
-                       Stack<StackSlot> newStack = new Stack<StackSlot> (a.Count);
-                       IEnumerator<StackSlot> aEnum = a.GetEnumerator ();
-                       IEnumerator<StackSlot> bEnum = b.GetEnumerator ();
-                       while (aEnum.MoveNext () && bEnum.MoveNext ()) {
-                               newStack.Push (MergeStackElement (aEnum.Current, bEnum.Current));
-                       }
-
-                       // The new stack is reversed. Use the copy constructor to reverse it back
-                       return new Stack<StackSlot> (newStack);
-               }
-
-               private static void ClearStack (ref Stack<StackSlot>? stack)
-               {
-                       stack = null;
-               }
-
-               private static void NewKnownStack (Dictionary<int, Stack<StackSlot>> knownStacks, int newOffset, Stack<StackSlot> newStack)
-               {
-                       // No need to merge in empty stacks
-                       if (newStack.Count == 0) {
-                               return;
-                       }
-
-                       if (knownStacks.ContainsKey (newOffset)) {
-                               knownStacks[newOffset] = MergeStack (knownStacks[newOffset], newStack);
-                       } else {
-                               knownStacks.Add (newOffset, new Stack<StackSlot> (newStack.Reverse ()));
-                       }
-               }
-
-               private struct BasicBlockIterator
-               {
-                       readonly HashSet<int> _methodBranchTargets;
-                       int _currentBlockIndex;
-                       bool _foundEndOfPrevBlock;
-
-                       public BasicBlockIterator (MethodIL methodIL)
-                       {
-                               _methodBranchTargets = methodIL.ComputeBranchTargets ();
-                               _currentBlockIndex = -1;
-                               _foundEndOfPrevBlock = true;
-                       }
-
-                       public int CurrentBlockIndex {
-                               get {
-                                       return _currentBlockIndex;
-                               }
-                       }
-
-                       public int MoveNext (Instruction op)
-                       {
-                               if (_foundEndOfPrevBlock || _methodBranchTargets.Contains (op.Offset)) {
-                                       _currentBlockIndex++;
-                                       _foundEndOfPrevBlock = false;
-                               }
-
-                               if (op.OpCode.IsControlFlowInstruction ()) {
-                                       _foundEndOfPrevBlock = true;
-                               }
-
-                               return CurrentBlockIndex;
-                       }
-               }
-
-               [Conditional ("DEBUG")]
-               static void ValidateNoReferenceToReference (LocalVariableStore locals, MethodDefinition method, int ilOffset)
-               {
-                       foreach (var keyValuePair in locals) {
-                               MultiValue localValue = keyValuePair.Value.Value;
-                               VariableDefinition localVariable = keyValuePair.Key;
-                               foreach (var val in localValue) {
-                                       if (val is LocalVariableReferenceValue localReference && localReference.ReferencedType.IsByReference) {
-                                               string displayName = $"local variable V_{localReference.LocalDefinition.Index}";
-                                               throw new LinkerFatalErrorException (MessageContainer.CreateErrorMessage (
-                                                       $"""In method {method.FullName}, local variable V_{localVariable.Index} references {displayName} of type {localReference.ReferencedType.GetDisplayName ()} which is a reference. Linker dataflow tracking has failed.""",
-                                                       (int) DiagnosticId.LinkerUnexpectedError,
-                                                       origin: new MessageOrigin (method, ilOffset)));
-                                       }
-                               }
-                       }
-               }
-
-               protected static void StoreMethodLocalValue<KeyType> (
-                       Dictionary<KeyType, ValueBasicBlockPair> valueCollection,
-                       in MultiValue valueToStore,
-                       KeyType collectionKey,
-                       int curBasicBlock,
-                       int? maxTrackedValues = null)
-                       where KeyType : notnull
-               {
-                       if (valueCollection.TryGetValue (collectionKey, out ValueBasicBlockPair existingValue)) {
-                               MultiValue value;
-                               if (existingValue.BasicBlockIndex == curBasicBlock) {
-                                       // If the previous value was stored in the current basic block, then we can safely
-                                       // overwrite the previous value with the new one.
-                                       value = valueToStore;
-                               } else {
-                                       // If the previous value came from a previous basic block, then some other use of
-                                       // the local could see the previous value, so we must merge the new value with the
-                                       // old value.
-                                       value = MultiValueLattice.Meet (existingValue.Value, valueToStore);
-                               }
-                               valueCollection[collectionKey] = new ValueBasicBlockPair (value, curBasicBlock);
-                       } else if (maxTrackedValues == null || valueCollection.Count < maxTrackedValues) {
-                               // We're not currently tracking a value a this index, so store the value now.
-                               valueCollection[collectionKey] = new ValueBasicBlockPair (valueToStore, curBasicBlock);
-                       }
-               }
-
-               // Scans the method as well as any nested functions (local functions or lambdas) and state machines
-               // reachable from it.
-               public virtual void InterproceduralScan (MethodIL startingMethodIL)
-               {
-                       MethodDefinition startingMethod = startingMethodIL.Method;
-
-                       // Note that the default value of a hoisted local will be MultiValueLattice.Top, not UnknownValue.Instance.
-                       // This ensures that there are no warnings for the "unassigned state" of a parameter.
-                       // Definite assignment should ensure that there is no way for this to be an analysis hole.
-                       var interproceduralState = InterproceduralStateLattice.Top;
-
-                       var oldInterproceduralState = interproceduralState.Clone ();
-                       interproceduralState.TrackMethod (startingMethodIL);
-
-                       while (!interproceduralState.Equals (oldInterproceduralState)) {
-                               oldInterproceduralState = interproceduralState.Clone ();
-
-                               // Flow state through all methods encountered so far, as long as there
-                               // are changes discovered in the hoisted local state on entry to any method.
-                               foreach (var methodIL in oldInterproceduralState.MethodBodies)
-                                       Scan (methodIL, ref interproceduralState);
-                       }
-
-#if DEBUG
-                       // Validate that the compiler-generated callees tracked by the compiler-generated state
-                       // are the same set of methods that we discovered and scanned above.
-                       if (_context.CompilerGeneratedState.TryGetCompilerGeneratedCalleesForUserMethod (startingMethod, out List<IMemberDefinition>? compilerGeneratedCallees)) {
-                               var calleeMethods = compilerGeneratedCallees.OfType<MethodDefinition> ();
-                               // https://github.com/dotnet/linker/issues/2845
-                               // Disabled asserts due to a bug
-                               // Debug.Assert (interproceduralState.Count == 1 + calleeMethods.Count ());
-                               // foreach (var method in calleeMethods)
-                               //      Debug.Assert (interproceduralState.Any (kvp => kvp.Key.Method == method));
-                       } else {
-                               Debug.Assert (interproceduralState.MethodBodies.Count () == 1);
-                       }
-#endif
-               }
-
-               void TrackNestedFunctionReference (MethodReference referencedMethod, ref InterproceduralState interproceduralState)
-               {
-                       if (_context.TryResolve (referencedMethod) is not MethodDefinition method)
-                               return;
-
-                       if (!CompilerGeneratedNames.IsLambdaOrLocalFunction (method.Name))
-                               return;
-
-                       interproceduralState.TrackMethod (method);
-               }
-
-               protected virtual void Scan (MethodIL methodIL, ref InterproceduralState interproceduralState)
-               {
-                       MethodBody methodBody = methodIL.Body;
-                       MethodDefinition thisMethod = methodBody.Method;
-
-                       LocalVariableStore locals = new (methodIL.Variables.Count);
-
-                       Dictionary<int, Stack<StackSlot>> knownStacks = new Dictionary<int, Stack<StackSlot>> ();
-                       Stack<StackSlot>? currentStack = new Stack<StackSlot> (methodBody.MaxStackSize);
-
-                       ScanExceptionInformation (knownStacks, methodIL);
-
-                       BasicBlockIterator blockIterator = new BasicBlockIterator (methodIL);
-
-                       ReturnValue = new ();
-                       foreach (Instruction operation in methodIL.Instructions) {
-                               int curBasicBlock = blockIterator.MoveNext (operation);
-
-                               if (knownStacks.ContainsKey (operation.Offset)) {
-                                       if (currentStack == null) {
-                                               // The stack copy constructor reverses the stack
-                                               currentStack = new Stack<StackSlot> (knownStacks[operation.Offset].Reverse ());
-                                       } else {
-                                               currentStack = MergeStack (currentStack, knownStacks[operation.Offset]);
-                                       }
-                               }
-
-                               currentStack ??= new Stack<StackSlot> (methodBody.MaxStackSize);
-
-                               switch (operation.OpCode.Code) {
-                               case Code.Add:
-                               case Code.Add_Ovf:
-                               case Code.Add_Ovf_Un:
-                               case Code.And:
-                               case Code.Div:
-                               case Code.Div_Un:
-                               case Code.Mul:
-                               case Code.Mul_Ovf:
-                               case Code.Mul_Ovf_Un:
-                               case Code.Or:
-                               case Code.Rem:
-                               case Code.Rem_Un:
-                               case Code.Sub:
-                               case Code.Sub_Ovf:
-                               case Code.Sub_Ovf_Un:
-                               case Code.Xor:
-                               case Code.Cgt:
-                               case Code.Cgt_Un:
-                               case Code.Clt:
-                               case Code.Clt_Un:
-                               case Code.Shl:
-                               case Code.Shr:
-                               case Code.Shr_Un:
-                               case Code.Ceq:
-                                       PopUnknown (currentStack, 2, methodBody, operation.Offset);
-                                       PushUnknown (currentStack);
-                                       break;
-
-                               case Code.Dup:
-                                       currentStack.Push (currentStack.Peek ());
-                                       break;
-
-                               case Code.Ldnull:
-                                       currentStack.Push (new StackSlot (NullValue.Instance));
-                                       break;
-
-
-                               case Code.Ldc_I4_0:
-                               case Code.Ldc_I4_1:
-                               case Code.Ldc_I4_2:
-                               case Code.Ldc_I4_3:
-                               case Code.Ldc_I4_4:
-                               case Code.Ldc_I4_5:
-                               case Code.Ldc_I4_6:
-                               case Code.Ldc_I4_7:
-                               case Code.Ldc_I4_8: {
-                                               int value = operation.OpCode.Code - Code.Ldc_I4_0;
-                                               ConstIntValue civ = new ConstIntValue (value);
-                                               StackSlot slot = new StackSlot (civ);
-                                               currentStack.Push (slot);
-                                       }
-                                       break;
-
-                               case Code.Ldc_I4_M1: {
-                                               ConstIntValue civ = new ConstIntValue (-1);
-                                               StackSlot slot = new StackSlot (civ);
-                                               currentStack.Push (slot);
-                                       }
-                                       break;
-
-                               case Code.Ldc_I4: {
-                                               int value = (int) operation.Operand;
-                                               ConstIntValue civ = new ConstIntValue (value);
-                                               StackSlot slot = new StackSlot (civ);
-                                               currentStack.Push (slot);
-                                       }
-                                       break;
-
-                               case Code.Ldc_I4_S: {
-                                               int value = (sbyte) operation.Operand;
-                                               ConstIntValue civ = new ConstIntValue (value);
-                                               StackSlot slot = new StackSlot (civ);
-                                               currentStack.Push (slot);
-                                       }
-                                       break;
-
-                               case Code.Arglist:
-                               case Code.Sizeof:
-                               case Code.Ldc_I8:
-                               case Code.Ldc_R4:
-                               case Code.Ldc_R8:
-                                       PushUnknown (currentStack);
-                                       break;
-
-                               case Code.Ldftn:
-                                       TrackNestedFunctionReference ((MethodReference) operation.Operand, ref interproceduralState);
-                                       PushUnknown (currentStack);
-                                       break;
-
-                               case Code.Ldarg:
-                               case Code.Ldarg_0:
-                               case Code.Ldarg_1:
-                               case Code.Ldarg_2:
-                               case Code.Ldarg_3:
-                               case Code.Ldarg_S:
-                               case Code.Ldarga:
-                               case Code.Ldarga_S:
-                                       ScanLdarg (operation, currentStack, thisMethod);
-                                       break;
-
-                               case Code.Ldloc:
-                               case Code.Ldloc_0:
-                               case Code.Ldloc_1:
-                               case Code.Ldloc_2:
-                               case Code.Ldloc_3:
-                               case Code.Ldloc_S:
-                               case Code.Ldloca:
-                               case Code.Ldloca_S:
-                                       ScanLdloc (operation, currentStack, methodIL, locals);
-                                       ValidateNoReferenceToReference (locals, methodBody.Method, operation.Offset);
-                                       break;
-
-                               case Code.Ldstr: {
-                                               StackSlot slot = new StackSlot (new KnownStringValue ((string) operation.Operand));
-                                               currentStack.Push (slot);
-                                       }
-                                       break;
-
-                               case Code.Ldtoken:
-                                       ScanLdtoken (operation, currentStack);
-                                       break;
-
-                               case Code.Ldind_I:
-                               case Code.Ldind_I1:
-                               case Code.Ldind_I2:
-                               case Code.Ldind_I4:
-                               case Code.Ldind_I8:
-                               case Code.Ldind_R4:
-                               case Code.Ldind_R8:
-                               case Code.Ldind_U1:
-                               case Code.Ldind_U2:
-                               case Code.Ldind_U4:
-                               case Code.Ldlen:
-                               case Code.Ldvirtftn:
-                               case Code.Localloc:
-                               case Code.Refanytype:
-                               case Code.Refanyval:
-                               case Code.Conv_I1:
-                               case Code.Conv_I2:
-                               case Code.Conv_I4:
-                               case Code.Conv_Ovf_I1:
-                               case Code.Conv_Ovf_I1_Un:
-                               case Code.Conv_Ovf_I2:
-                               case Code.Conv_Ovf_I2_Un:
-                               case Code.Conv_Ovf_I4:
-                               case Code.Conv_Ovf_I4_Un:
-                               case Code.Conv_Ovf_U:
-                               case Code.Conv_Ovf_U_Un:
-                               case Code.Conv_Ovf_U1:
-                               case Code.Conv_Ovf_U1_Un:
-                               case Code.Conv_Ovf_U2:
-                               case Code.Conv_Ovf_U2_Un:
-                               case Code.Conv_Ovf_U4:
-                               case Code.Conv_Ovf_U4_Un:
-                               case Code.Conv_U1:
-                               case Code.Conv_U2:
-                               case Code.Conv_U4:
-                               case Code.Conv_I8:
-                               case Code.Conv_Ovf_I8:
-                               case Code.Conv_Ovf_I8_Un:
-                               case Code.Conv_Ovf_U8:
-                               case Code.Conv_Ovf_U8_Un:
-                               case Code.Conv_U8:
-                               case Code.Conv_I:
-                               case Code.Conv_Ovf_I:
-                               case Code.Conv_Ovf_I_Un:
-                               case Code.Conv_U:
-                               case Code.Conv_R_Un:
-                               case Code.Conv_R4:
-                               case Code.Conv_R8:
-                               case Code.Ldind_Ref:
-                               case Code.Ldobj:
-                               case Code.Mkrefany:
-                               case Code.Unbox:
-                               case Code.Unbox_Any:
-                               case Code.Box:
-                               case Code.Neg:
-                               case Code.Not:
-                                       PopUnknown (currentStack, 1, methodBody, operation.Offset);
-                                       PushUnknown (currentStack);
-                                       break;
-
-                               case Code.Isinst:
-                               case Code.Castclass:
-                                       // We can consider a NOP because the value doesn't change.
-                                       // It might change to NULL, but for the purposes of dataflow analysis
-                                       // it doesn't hurt much.
-                                       break;
-
-                               case Code.Ldfld:
-                               case Code.Ldsfld:
-                               case Code.Ldflda:
-                               case Code.Ldsflda:
-                                       ScanLdfld (operation, currentStack, methodBody, ref interproceduralState);
-                                       break;
-
-                               case Code.Newarr: {
-                                               StackSlot count = PopUnknown (currentStack, 1, methodBody, operation.Offset);
-                                               currentStack.Push (new StackSlot (ArrayValue.Create (count.Value, (TypeReference) operation.Operand)));
-                                       }
-                                       break;
-
-                               case Code.Stelem_I:
-                               case Code.Stelem_I1:
-                               case Code.Stelem_I2:
-                               case Code.Stelem_I4:
-                               case Code.Stelem_I8:
-                               case Code.Stelem_R4:
-                               case Code.Stelem_R8:
-                               case Code.Stelem_Any:
-                               case Code.Stelem_Ref:
-                                       ScanStelem (operation, currentStack, methodBody, curBasicBlock);
-                                       break;
-
-                               case Code.Ldelem_I:
-                               case Code.Ldelem_I1:
-                               case Code.Ldelem_I2:
-                               case Code.Ldelem_I4:
-                               case Code.Ldelem_I8:
-                               case Code.Ldelem_R4:
-                               case Code.Ldelem_R8:
-                               case Code.Ldelem_U1:
-                               case Code.Ldelem_U2:
-                               case Code.Ldelem_U4:
-                               case Code.Ldelem_Any:
-                               case Code.Ldelem_Ref:
-                               case Code.Ldelema:
-                                       ScanLdelem (operation, currentStack, methodBody, curBasicBlock);
-                                       break;
-
-                               case Code.Cpblk:
-                               case Code.Initblk:
-                                       PopUnknown (currentStack, 3, methodBody, operation.Offset);
-                                       break;
-
-                               case Code.Stfld:
-                               case Code.Stsfld:
-                                       ScanStfld (operation, currentStack, thisMethod, methodBody, locals, ref interproceduralState);
-                                       break;
-
-                               case Code.Cpobj:
-                                       PopUnknown (currentStack, 2, methodBody, operation.Offset);
-                                       break;
-
-                               case Code.Stind_I:
-                               case Code.Stind_I1:
-                               case Code.Stind_I2:
-                               case Code.Stind_I4:
-                               case Code.Stind_I8:
-                               case Code.Stind_R4:
-                               case Code.Stind_R8:
-                               case Code.Stind_Ref:
-                               case Code.Stobj:
-                                       ScanIndirectStore (operation, currentStack, methodBody, locals, curBasicBlock, ref interproceduralState);
-                                       ValidateNoReferenceToReference (locals, methodBody.Method, operation.Offset);
-                                       break;
-
-                               case Code.Initobj:
-                               case Code.Pop:
-                                       PopUnknown (currentStack, 1, methodBody, operation.Offset);
-                                       break;
-
-                               case Code.Starg:
-                               case Code.Starg_S:
-                                       ScanStarg (operation, currentStack, thisMethod, methodBody);
-                                       break;
-
-                               case Code.Stloc:
-                               case Code.Stloc_S:
-                               case Code.Stloc_0:
-                               case Code.Stloc_1:
-                               case Code.Stloc_2:
-                               case Code.Stloc_3:
-                                       ScanStloc (operation, currentStack, methodIL, locals, curBasicBlock);
-                                       ValidateNoReferenceToReference (locals, methodBody.Method, operation.Offset);
-                                       break;
-
-                               case Code.Constrained:
-                               case Code.No:
-                               case Code.Readonly:
-                               case Code.Tail:
-                               case Code.Unaligned:
-                               case Code.Volatile:
-                                       break;
-
-                               case Code.Brfalse:
-                               case Code.Brfalse_S:
-                               case Code.Brtrue:
-                               case Code.Brtrue_S:
-                                       PopUnknown (currentStack, 1, methodBody, operation.Offset);
-                                       NewKnownStack (knownStacks, ((Instruction) operation.Operand).Offset, currentStack);
-                                       break;
-
-                               case Code.Calli: {
-                                               var signature = (CallSite) operation.Operand;
-                                               if (signature.HasThis && !signature.ExplicitThis) {
-                                                       PopUnknown (currentStack, 1, methodBody, operation.Offset);
-                                               }
-
-                                               // Pop arguments
-                                               if (signature.Parameters.Count > 0)
-                                                       PopUnknown (currentStack, signature.Parameters.Count, methodBody, operation.Offset);
-
-                                               // Pop function pointer
-                                               PopUnknown (currentStack, 1, methodBody, operation.Offset);
-
-                                               if (!signature.ReturnsVoid ())
-                                                       PushUnknown (currentStack);
-                                       }
-                                       break;
-
-                               case Code.Call:
-                               case Code.Callvirt:
-                               case Code.Newobj:
-                                       TrackNestedFunctionReference ((MethodReference) operation.Operand, ref interproceduralState);
-                                       HandleCall (methodBody, operation, currentStack, locals, ref interproceduralState, curBasicBlock);
-                                       ValidateNoReferenceToReference (locals, methodBody.Method, operation.Offset);
-                                       break;
-
-                               case Code.Jmp:
-                                       // Not generated by mainstream compilers
-                                       break;
-
-                               case Code.Br:
-                               case Code.Br_S:
-                                       NewKnownStack (knownStacks, ((Instruction) operation.Operand).Offset, currentStack);
-                                       ClearStack (ref currentStack);
-                                       break;
-
-                               case Code.Leave:
-                               case Code.Leave_S:
-                                       ClearStack (ref currentStack);
-                                       NewKnownStack (knownStacks, ((Instruction) operation.Operand).Offset, new Stack<StackSlot> (methodBody.MaxStackSize));
-                                       break;
-
-                               case Code.Endfilter:
-                               case Code.Endfinally:
-                               case Code.Rethrow:
-                               case Code.Throw:
-                                       ClearStack (ref currentStack);
-                                       break;
-
-                               case Code.Ret: {
-
-                                               bool hasReturnValue = !methodBody.Method.ReturnsVoid ();
-
-                                               if (currentStack.Count != (hasReturnValue ? 1 : 0)) {
-                                                       WarnAboutInvalidILInMethod (methodBody, operation.Offset);
-                                               }
-                                               if (hasReturnValue) {
-                                                       StackSlot retValue = PopUnknown (currentStack, 1, methodBody, operation.Offset);
-                                                       // If the return value is a reference, treat it as the value itself for now
-                                                       //      We can handle ref return values better later
-                                                       ReturnValue = MultiValueLattice.Meet (ReturnValue, DereferenceValue (retValue.Value, locals, ref interproceduralState));
-                                                       ValidateNoReferenceToReference (locals, methodBody.Method, operation.Offset);
-                                               }
-                                               ClearStack (ref currentStack);
-                                               break;
-                                       }
-
-                               case Code.Switch: {
-                                               PopUnknown (currentStack, 1, methodBody, operation.Offset);
-                                               Instruction[] targets = (Instruction[]) operation.Operand;
-                                               foreach (Instruction target in targets) {
-                                                       NewKnownStack (knownStacks, target.Offset, currentStack);
-                                               }
-                                               break;
-                                       }
-
-                               case Code.Beq:
-                               case Code.Beq_S:
-                               case Code.Bne_Un:
-                               case Code.Bne_Un_S:
-                               case Code.Bge:
-                               case Code.Bge_S:
-                               case Code.Bge_Un:
-                               case Code.Bge_Un_S:
-                               case Code.Bgt:
-                               case Code.Bgt_S:
-                               case Code.Bgt_Un:
-                               case Code.Bgt_Un_S:
-                               case Code.Ble:
-                               case Code.Ble_S:
-                               case Code.Ble_Un:
-                               case Code.Ble_Un_S:
-                               case Code.Blt:
-                               case Code.Blt_S:
-                               case Code.Blt_Un:
-                               case Code.Blt_Un_S:
-                                       PopUnknown (currentStack, 2, methodBody, operation.Offset);
-                                       NewKnownStack (knownStacks, ((Instruction) operation.Operand).Offset, currentStack);
-                                       break;
-                               }
-                       }
-               }
-
-               private static void ScanExceptionInformation (Dictionary<int, Stack<StackSlot>> knownStacks, MethodIL methodIL)
-               {
-                       foreach (ExceptionHandler exceptionClause in methodIL.ExceptionHandlers) {
-                               Stack<StackSlot> catchStack = new Stack<StackSlot> (1);
-                               catchStack.Push (new StackSlot ());
-
-                               if (exceptionClause.HandlerType == ExceptionHandlerType.Filter) {
-                                       NewKnownStack (knownStacks, exceptionClause.FilterStart.Offset, catchStack);
-                                       NewKnownStack (knownStacks, exceptionClause.HandlerStart.Offset, catchStack);
-                               }
-                               if (exceptionClause.HandlerType == ExceptionHandlerType.Catch) {
-                                       NewKnownStack (knownStacks, exceptionClause.HandlerStart.Offset, catchStack);
-                               }
-                       }
-               }
-
-               protected abstract SingleValue GetMethodParameterValue (ParameterProxy parameter);
-
-               private void ScanLdarg (Instruction operation, Stack<StackSlot> currentStack, MethodDefinition thisMethod)
-               {
-                       Code code = operation.OpCode.Code;
-
-                       ParameterIndex paramNum = ParameterHelpers.GetParameterIndex (thisMethod, operation);
-                       ParameterProxy param = thisMethod.GetParameter (paramNum);
-                       TypeReference paramType = param.ParameterType;
-
-                       bool isByRef = code == Code.Ldarga || code == Code.Ldarga_S;
-                       isByRef |= paramType.IsByRefOrPointer ();
-                       isByRef |= param.IsImplicitThis == true && paramType.IsValueType;
-
-                       StackSlot slot = new StackSlot (
-                               isByRef
-                               ? new ParameterReferenceValue (param)
-                               : GetMethodParameterValue (param));
-                       currentStack.Push (slot);
-               }
-
-               private void ScanStarg (
-                       Instruction operation,
-                       Stack<StackSlot> currentStack,
-                       MethodDefinition thisMethod,
-                       MethodBody methodBody)
-               {
-                       var valueToStore = PopUnknown (currentStack, 1, methodBody, operation.Offset);
-                       ParameterIndex paramNum = ParameterHelpers.GetParameterIndex (thisMethod, operation);
-                       ParameterProxy param = new (thisMethod, paramNum);
-                       var targetValue = GetMethodParameterValue (param);
-                       if (targetValue is MethodParameterValue targetParameterValue)
-                               HandleStoreParameter (thisMethod, targetParameterValue, operation, valueToStore.Value);
-
-                       // If the targetValue is MethodThisValue do nothing - it should never happen really, and if it does, there's nothing we can track there
-               }
-
-               private void ScanLdloc (
-                       Instruction operation,
-                       Stack<StackSlot> currentStack,
-                       MethodIL methodIL,
-                       LocalVariableStore locals)
-               {
-                       VariableDefinition localDef = GetLocalDef (operation, methodIL.Variables);
-                       if (localDef == null) {
-                               PushUnknownAndWarnAboutInvalidIL (currentStack, methodIL.Body, operation.Offset);
-                               return;
-                       }
-
-                       bool isByRef = operation.OpCode.Code == Code.Ldloca || operation.OpCode.Code == Code.Ldloca_S;
-
-                       StackSlot newSlot;
-                       if (isByRef) {
-                               newSlot = new StackSlot (new LocalVariableReferenceValue (localDef));
-                       } else if (locals.TryGetValue (localDef, out ValueBasicBlockPair localValue))
-                               newSlot = new StackSlot (localValue.Value);
-                       else
-                               newSlot = new StackSlot (UnknownValue.Instance);
-                       currentStack.Push (newSlot);
-               }
-
-               void ScanLdtoken (Instruction operation, Stack<StackSlot> currentStack)
-               {
-                       switch (operation.Operand) {
-                       case GenericParameter genericParameter:
-                               var param = new RuntimeTypeHandleForGenericParameterValue (genericParameter);
-                               currentStack.Push (new StackSlot (param));
-                               return;
-                       case TypeReference typeReference when ResolveToTypeDefinition (typeReference) is TypeDefinition resolvedDefinition:
-                               // Note that Nullable types without a generic argument (i.e. Nullable<>) will be RuntimeTypeHandleValue / SystemTypeValue
-                               if (typeReference is IGenericInstance instance && resolvedDefinition.IsTypeOf (WellKnownType.System_Nullable_T)) {
-                                       switch (instance.GenericArguments[0]) {
-                                       case GenericParameter genericParam:
-                                               var nullableDam = new RuntimeTypeHandleForNullableValueWithDynamicallyAccessedMembers (new TypeProxy (resolvedDefinition),
-                                                       new RuntimeTypeHandleForGenericParameterValue (genericParam));
-                                               currentStack.Push (new StackSlot (nullableDam));
-                                               return;
-                                       case TypeReference underlyingTypeReference when ResolveToTypeDefinition (underlyingTypeReference) is TypeDefinition underlyingType:
-                                               var nullableType = new RuntimeTypeHandleForNullableSystemTypeValue (new TypeProxy (resolvedDefinition), new SystemTypeValue (underlyingType));
-                                               currentStack.Push (new StackSlot (nullableType));
-                                               return;
-                                       default:
-                                               PushUnknown (currentStack);
-                                               return;
-                                       }
-                               } else {
-                                       var typeHandle = new RuntimeTypeHandleValue (new TypeProxy (resolvedDefinition));
-                                       currentStack.Push (new StackSlot (typeHandle));
-                                       return;
-                               }
-                       case MethodReference methodReference when _context.TryResolve (methodReference) is MethodDefinition resolvedMethod:
-                               var method = new RuntimeMethodHandleValue (resolvedMethod);
-                               currentStack.Push (new StackSlot (method));
-                               return;
-                       default:
-                               PushUnknown (currentStack);
-                               return;
-                       }
-               }
-
-               private void ScanStloc (
-                       Instruction operation,
-                       Stack<StackSlot> currentStack,
-                       MethodIL methodIL,
-                       LocalVariableStore locals,
-                       int curBasicBlock)
-               {
-                       StackSlot valueToStore = PopUnknown (currentStack, 1, methodIL.Body, operation.Offset);
-                       VariableDefinition localDef = GetLocalDef (operation, methodIL.Variables);
-                       if (localDef == null) {
-                               WarnAboutInvalidILInMethod (methodIL.Body, operation.Offset);
-                               return;
-                       }
-
-                       StoreMethodLocalValue (locals, valueToStore.Value, localDef, curBasicBlock);
-               }
-
-               private void ScanIndirectStore (
-                       Instruction operation,
-                       Stack<StackSlot> currentStack,
-                       MethodBody methodBody,
-                       LocalVariableStore locals,
-                       int curBasicBlock,
-                       ref InterproceduralState ipState)
-               {
-                       StackSlot valueToStore = PopUnknown (currentStack, 1, methodBody, operation.Offset);
-                       StackSlot destination = PopUnknown (currentStack, 1, methodBody, operation.Offset);
-
-                       StoreInReference (destination.Value, valueToStore.Value, methodBody.Method, operation, locals, curBasicBlock, ref ipState);
-               }
-
-               /// <summary>
-               /// Handles storing the source value in a target <see cref="ReferenceValue"/> or MultiValue of ReferenceValues.
-               /// </summary>
-               /// <param name="target">A set of <see cref="ReferenceValue"/> that a value is being stored into</param>
-               /// <param name="source">The value to store</param>
-               /// <param name="method">The method body that contains the operation causing the store</param>
-               /// <param name="operation">The instruction causing the store</param>
-               /// <exception cref="LinkerFatalErrorException">Throws if <paramref name="target"/> is not a valid target for an indirect store.</exception>
-               protected void StoreInReference (MultiValue target, MultiValue source, MethodDefinition method, Instruction operation, LocalVariableStore locals, int curBasicBlock, ref InterproceduralState ipState)
-               {
-                       foreach (var value in target) {
-                               switch (value) {
-                               case LocalVariableReferenceValue localReference:
-                                       StoreMethodLocalValue (locals, source, localReference.LocalDefinition, curBasicBlock);
-                                       break;
-                               case FieldReferenceValue fieldReference
-                               when GetFieldValue (fieldReference.FieldDefinition).AsSingleValue () is FieldValue fieldValue:
-                                       HandleStoreField (method, fieldValue, operation, source);
-                                       break;
-                               case ParameterReferenceValue parameterReference
-                               when GetMethodParameterValue (parameterReference.Parameter) is MethodParameterValue parameterValue:
-                                       HandleStoreParameter (method, parameterValue, operation, source);
-                                       break;
-                               case MethodReturnValue methodReturnValue:
-                                       // Ref returns don't have special ReferenceValue values, so assume if the target here is a MethodReturnValue then it must be a ref return value
-                                       HandleStoreMethodReturnValue (method, methodReturnValue, operation, source);
-                                       break;
-                               case FieldValue fieldValue:
-                                       HandleStoreField (method, fieldValue, operation, DereferenceValue (source, locals, ref ipState));
-                                       break;
-                               case IValueWithStaticType valueWithStaticType:
-                                       if (valueWithStaticType.StaticType is not null && _context.Annotations.FlowAnnotations.IsTypeInterestingForDataflow (valueWithStaticType.StaticType))
-                                               throw new LinkerFatalErrorException (MessageContainer.CreateErrorMessage (
-                                                       $"Unhandled StoreReference call. Unhandled attempt to store a value in {value} of type {value.GetType ()}.",
-                                                       (int) DiagnosticId.LinkerUnexpectedError,
-                                                       origin: new MessageOrigin (method, operation.Offset)));
-                                       // This should only happen for pointer derefs, which can't point to interesting types
-                                       break;
-                               default:
-                                       // These cases should only be refs to array elements
-                                       // References to array elements are not yet tracked and since we don't allow annotations on arrays, they won't cause problems
-                                       break;
-                               }
-                       }
-
-               }
-
-               protected abstract MultiValue GetFieldValue (FieldDefinition field);
-
-               private void ScanLdfld (
-                       Instruction operation,
-                       Stack<StackSlot> currentStack,
-                       MethodBody methodBody,
-                       ref InterproceduralState interproceduralState)
-               {
-                       Code code = operation.OpCode.Code;
-                       if (code == Code.Ldfld || code == Code.Ldflda)
-                               PopUnknown (currentStack, 1, methodBody, operation.Offset);
-
-                       bool isByRef = code == Code.Ldflda || code == Code.Ldsflda;
-
-                       FieldDefinition? field = _context.TryResolve ((FieldReference) operation.Operand);
-                       if (field == null) {
-                               PushUnknown (currentStack);
-                               return;
-                       }
-
-                       MultiValue value;
-                       if (isByRef) {
-                               value = new FieldReferenceValue (field);
-                       } else if (CompilerGeneratedState.IsHoistedLocal (field)) {
-                               value = interproceduralState.GetHoistedLocal (new HoistedLocalKey (field));
-                       } else {
-                               value = GetFieldValue (field);
-                       }
-                       currentStack.Push (new StackSlot (value));
-               }
-
-               protected virtual void HandleStoreField (MethodDefinition method, FieldValue field, Instruction operation, MultiValue valueToStore)
-               {
-               }
-
-               protected virtual void HandleStoreParameter (MethodDefinition method, MethodParameterValue parameter, Instruction operation, MultiValue valueToStore)
-               {
-               }
-
-               protected virtual void HandleStoreMethodReturnValue (MethodDefinition method, MethodReturnValue thisParameter, Instruction operation, MultiValue sourceValue)
-               {
-               }
-
-               private void ScanStfld (
-                       Instruction operation,
-                       Stack<StackSlot> currentStack,
-                       MethodDefinition thisMethod,
-                       MethodBody methodBody,
-                       LocalVariableStore locals,
-                       ref InterproceduralState interproceduralState)
-               {
-                       StackSlot valueToStoreSlot = PopUnknown (currentStack, 1, methodBody, operation.Offset);
-                       if (operation.OpCode.Code == Code.Stfld)
-                               PopUnknown (currentStack, 1, methodBody, operation.Offset);
-
-                       FieldDefinition? field = _context.TryResolve ((FieldReference) operation.Operand);
-                       if (field != null) {
-                               if (CompilerGeneratedState.IsHoistedLocal (field)) {
-                                       interproceduralState.SetHoistedLocal (new HoistedLocalKey (field), valueToStoreSlot.Value);
-                                       return;
-                               }
-
-                               foreach (var value in GetFieldValue (field)) {
-                                       // GetFieldValue may return different node types, in which case they can't be stored to.
-                                       // At least not yet.
-                                       if (value is not FieldValue fieldValue)
-                                               continue;
-
-                                       // Incomplete handling of ref fields -- if we're storing a reference to a value, pretend it's just the value
-                                       MultiValue valueToStore = DereferenceValue (valueToStoreSlot.Value, locals, ref interproceduralState);
-
-                                       HandleStoreField (thisMethod, fieldValue, operation, valueToStore);
-                               }
-                       }
-               }
-
-               private static VariableDefinition GetLocalDef (Instruction operation, Collection<VariableDefinition> localVariables)
-               {
-                       Code code = operation.OpCode.Code;
-                       if (code >= Code.Ldloc_0 && code <= Code.Ldloc_3)
-                               return localVariables[code - Code.Ldloc_0];
-                       if (code >= Code.Stloc_0 && code <= Code.Stloc_3)
-                               return localVariables[code - Code.Stloc_0];
-
-                       return (VariableDefinition) operation.Operand;
-               }
-
-               private ValueNodeList PopCallArguments (
-                       Stack<StackSlot> currentStack,
-                       MethodReference methodCalled,
-                       MethodBody containingMethodBody,
-                       bool isNewObj, int ilOffset,
-                       out SingleValue? newObjValue)
-               {
-                       newObjValue = null;
-
-                       int countToPop = 0;
-                       if (!isNewObj && methodCalled.HasThis && !methodCalled.ExplicitThis)
-                               countToPop++;
-                       countToPop += methodCalled.GetMetadataParametersCount ();
-
-                       ValueNodeList methodParams = new ValueNodeList (countToPop);
-                       for (int iParam = 0; iParam < countToPop; ++iParam) {
-                               StackSlot slot = PopUnknown (currentStack, 1, containingMethodBody, ilOffset);
-                               methodParams.Add (slot.Value);
-                       }
-
-                       if (isNewObj) {
-                               newObjValue = UnknownValue.Instance;
-                               methodParams.Add (newObjValue);
-                       }
-                       methodParams.Reverse ();
-                       return methodParams;
-               }
-
-               internal MultiValue DereferenceValue (MultiValue maybeReferenceValue, LocalVariableStore locals, ref InterproceduralState interproceduralState)
-               {
-                       MultiValue dereferencedValue = MultiValueLattice.Top;
-                       foreach (var value in maybeReferenceValue) {
-                               switch (value) {
-                               case FieldReferenceValue fieldReferenceValue:
-                                       dereferencedValue = MultiValue.Meet (
-                                               dereferencedValue,
-                                               CompilerGeneratedState.IsHoistedLocal (fieldReferenceValue.FieldDefinition)
-                                                       ? interproceduralState.GetHoistedLocal (new HoistedLocalKey (fieldReferenceValue.FieldDefinition))
-                                                       : GetFieldValue (fieldReferenceValue.FieldDefinition));
-                                       break;
-                               case ParameterReferenceValue parameterReferenceValue:
-                                       dereferencedValue = MultiValue.Meet (
-                                               dereferencedValue,
-                                               GetMethodParameterValue (parameterReferenceValue.Parameter));
-                                       break;
-                               case LocalVariableReferenceValue localVariableReferenceValue:
-                                       if (locals.TryGetValue (localVariableReferenceValue.LocalDefinition, out var valueBasicBlockPair))
-                                               dereferencedValue = MultiValue.Meet (dereferencedValue, valueBasicBlockPair.Value);
-                                       else
-                                               dereferencedValue = MultiValue.Meet (dereferencedValue, UnknownValue.Instance);
-                                       break;
-                               case ReferenceValue referenceValue:
-                                       throw new NotImplementedException ($"Unhandled dereference of ReferenceValue of type {referenceValue.GetType ().FullName}");
-                               // Incomplete handling for ref values
-                               case FieldValue fieldValue:
-                                       dereferencedValue = MultiValue.Meet (dereferencedValue, fieldValue);
-                                       break;
-                               default:
-                                       dereferencedValue = MultiValue.Meet (dereferencedValue, value);
-                                       break;
-                               }
-                       }
-                       return dereferencedValue;
-               }
-
-               /// <summary>
-               /// Assigns a MethodParameterValue to the location of each parameter passed by reference. (i.e. assigns the value to x when passing `ref x` as a parameter)
-               /// </summary>
-               protected void AssignRefAndOutParameters (
-                       MethodBody callingMethodBody,
-                       MethodReference calledMethod,
-                       ValueNodeList methodArguments,
-                       Instruction operation,
-                       LocalVariableStore locals,
-                       int curBasicBlock,
-                       ref InterproceduralState ipState)
-               {
-                       if (_context.TryResolve (calledMethod) is MethodDefinition calledMethodDefinition) {
-                               // We resolved the method and can put the ref/out values into the arguments
-                               foreach (var parameter in calledMethodDefinition.GetParameters ()) {
-                                       if (parameter.GetReferenceKind () is not (ReferenceKind.Ref or ReferenceKind.Out))
-                                               continue;
-                                       var newByRefValue = _context.Annotations.FlowAnnotations.GetMethodParameterValue (parameter);
-                                       StoreInReference (methodArguments[(int) parameter.Index], newByRefValue, callingMethodBody.Method, operation, locals, curBasicBlock, ref ipState);
-                               }
-                       } else {
-                               // We couldn't resolve the method, so we put unknown values into the ref and out arguments
-                               // Should be a very cold path, so using Linq.Zip should be okay
-                               foreach (var (argument, refKind) in methodArguments.Zip (calledMethod.GetParameterReferenceKinds ())) {
-                                       if (refKind is not (ReferenceKind.Ref or ReferenceKind.Out))
-                                               continue;
-                                       StoreInReference (argument, UnknownValue.Instance, callingMethodBody.Method, operation, locals, curBasicBlock, ref ipState);
-                               }
-                       }
-               }
-
-               private void HandleCall (
-                       MethodBody callingMethodBody,
-                       Instruction operation,
-                       Stack<StackSlot> currentStack,
-                       LocalVariableStore locals,
-                       ref InterproceduralState interproceduralState,
-                       int curBasicBlock)
-               {
-                       MethodReference calledMethod = (MethodReference) operation.Operand;
-
-                       bool isNewObj = operation.OpCode.Code == Code.Newobj;
-
-                       SingleValue? newObjValue;
-                       ValueNodeList methodArguments = PopCallArguments (currentStack, calledMethod, callingMethodBody, isNewObj,
-                                                                                                                  operation.Offset, out newObjValue);
-                       var dereferencedMethodParams = new List<MultiValue> ();
-                       foreach (var argument in methodArguments)
-                               dereferencedMethodParams.Add (DereferenceValue (argument, locals, ref interproceduralState));
-                       MultiValue methodReturnValue;
-                       bool handledFunction = HandleCall (
-                               callingMethodBody,
-                               calledMethod,
-                               operation,
-                               new ValueNodeList (dereferencedMethodParams),
-                               out methodReturnValue);
-
-                       // Handle the return value or newobj result
-                       if (!handledFunction) {
-                               if (isNewObj) {
-                                       if (newObjValue == null)
-                                               methodReturnValue = new MultiValue (UnknownValue.Instance);
-                                       else
-                                               methodReturnValue = newObjValue;
-                               } else {
-                                       if (!calledMethod.ReturnsVoid ()) {
-                                               methodReturnValue = UnknownValue.Instance;
-                                       }
-                               }
-                       }
-
-                       if (isNewObj || !calledMethod.ReturnsVoid ())
-                               currentStack.Push (new StackSlot (methodReturnValue));
-
-                       AssignRefAndOutParameters (callingMethodBody, calledMethod, methodArguments, operation, locals, curBasicBlock, ref interproceduralState);
-
-                       foreach (var param in methodArguments) {
-                               foreach (var v in param) {
-                                       if (v is ArrayValue arr) {
-                                               MarkArrayValuesAsUnknown (arr, curBasicBlock);
-                                       }
-                               }
-                       }
-               }
-
-               public TypeDefinition? ResolveToTypeDefinition (TypeReference typeReference) => typeReference.ResolveToTypeDefinition (_context);
-
-               public abstract bool HandleCall (
-                       MethodBody callingMethodBody,
-                       MethodReference calledMethod,
-                       Instruction operation,
-                       ValueNodeList methodParams,
-                       out MultiValue methodReturnValue);
-
-               // Limit tracking array values to 32 values for performance reasons. There are many arrays much longer than 32 elements in .NET, but the interesting ones for the linker are nearly always less than 32 elements.
-               private const int MaxTrackedArrayValues = 32;
-
-               private static void MarkArrayValuesAsUnknown (ArrayValue arrValue, int curBasicBlock)
-               {
-                       // Since we can't know the current index we're storing the value at, clear all indices.
-                       // That way we won't accidentally think we know the value at a given index when we cannot.
-                       foreach (var knownIndex in arrValue.IndexValues.Keys) {
-                               // Don't pass MaxTrackedArrayValues since we are only looking at keys we've already seen.
-                               StoreMethodLocalValue (arrValue.IndexValues, UnknownValue.Instance, knownIndex, curBasicBlock);
-                       }
-               }
-
-               private void ScanStelem (
-                       Instruction operation,
-                       Stack<StackSlot> currentStack,
-                       MethodBody methodBody,
-                       int curBasicBlock)
-               {
-                       StackSlot valueToStore = PopUnknown (currentStack, 1, methodBody, operation.Offset);
-                       StackSlot indexToStoreAt = PopUnknown (currentStack, 1, methodBody, operation.Offset);
-                       StackSlot arrayToStoreIn = PopUnknown (currentStack, 1, methodBody, operation.Offset);
-                       int? indexToStoreAtInt = indexToStoreAt.Value.AsConstInt ();
-                       foreach (var array in arrayToStoreIn.Value) {
-                               if (array is ArrayValue arrValue) {
-                                       if (indexToStoreAtInt == null) {
-                                               MarkArrayValuesAsUnknown (arrValue, curBasicBlock);
-                                       } else {
-                                               // When we know the index, we can record the value at that index.
-                                               StoreMethodLocalValue (arrValue.IndexValues, valueToStore.Value, indexToStoreAtInt.Value, curBasicBlock, MaxTrackedArrayValues);
-                                       }
-                               }
-                       }
-               }
-
-               private void ScanLdelem (
-                       Instruction operation,
-                       Stack<StackSlot> currentStack,
-                       MethodBody methodBody,
-                       int curBasicBlock)
-               {
-                       StackSlot indexToLoadFrom = PopUnknown (currentStack, 1, methodBody, operation.Offset);
-                       StackSlot arrayToLoadFrom = PopUnknown (currentStack, 1, methodBody, operation.Offset);
-                       if (arrayToLoadFrom.Value.AsSingleValue () is not ArrayValue arr) {
-                               PushUnknown (currentStack);
-                               return;
-                       }
-                       // We don't yet handle arrays of references or pointers
-                       bool isByRef = operation.OpCode.Code == Code.Ldelema;
-
-                       int? index = indexToLoadFrom.Value.AsConstInt ();
-                       if (index == null) {
-                               PushUnknown (currentStack);
-                               if (isByRef) {
-                                       MarkArrayValuesAsUnknown (arr, curBasicBlock);
-                               }
-                       }
-                       // Don't try to track refs to array elements. Set it as unknown, then push unknown to the stack
-                       else if (isByRef) {
-                               arr.IndexValues[index.Value] = new ValueBasicBlockPair (UnknownValue.Instance, curBasicBlock);
-                               PushUnknown (currentStack);
-                       } else if (arr.IndexValues.TryGetValue (index.Value, out ValueBasicBlockPair arrayIndexValue))
-                               currentStack.Push (new StackSlot (arrayIndexValue.Value));
-                       else
-                               PushUnknown (currentStack);
-               }
-       }
-}
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/MethodParameterValue.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/MethodParameterValue.cs
deleted file mode 100644 (file)
index 8fac8fe..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System.Diagnostics.CodeAnalysis;
-using ILLink.Shared.TypeSystemProxy;
-using Mono.Linker.Dataflow;
-using TypeDefinition = Mono.Cecil.TypeDefinition;
-
-
-namespace ILLink.Shared.TrimAnalysis
-{
-
-       /// <summary>
-       /// A value that came from a method parameter - such as the result of a ldarg.
-       /// </summary>
-       partial record MethodParameterValue : IValueWithStaticType
-       {
-               public MethodParameterValue (TypeDefinition? staticType, ParameterProxy param, DynamicallyAccessedMemberTypes dynamicallyAccessedMemberTypes, bool overrideIsThis = false)
-               {
-                       StaticType = staticType;
-                       DynamicallyAccessedMemberTypes = dynamicallyAccessedMemberTypes;
-                       Parameter = param;
-                       _overrideIsThis = overrideIsThis;
-               }
-
-               public override DynamicallyAccessedMemberTypes DynamicallyAccessedMemberTypes { get; }
-
-               public TypeDefinition? StaticType { get; }
-       }
-}
\ No newline at end of file
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/MethodReturnValue.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/MethodReturnValue.cs
deleted file mode 100644 (file)
index f6cb423..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System.Collections.Generic;
-using System.Diagnostics.CodeAnalysis;
-using ILLink.Shared.DataFlow;
-using Mono.Cecil;
-using Mono.Linker.Dataflow;
-using TypeDefinition = Mono.Cecil.TypeDefinition;
-
-
-namespace ILLink.Shared.TrimAnalysis
-{
-       /// <summary>
-       /// Return value from a method
-       /// </summary>
-       partial record MethodReturnValue : IValueWithStaticType
-       {
-               public MethodReturnValue (TypeDefinition? staticType, MethodDefinition method, DynamicallyAccessedMemberTypes dynamicallyAccessedMemberTypes)
-               {
-                       StaticType = staticType;
-                       Method = method;
-                       DynamicallyAccessedMemberTypes = dynamicallyAccessedMemberTypes;
-               }
-
-               public readonly MethodDefinition Method;
-
-               public override DynamicallyAccessedMemberTypes DynamicallyAccessedMemberTypes { get; }
-
-               public override IEnumerable<string> GetDiagnosticArgumentsForAnnotationMismatch ()
-                       => new string[] { DiagnosticUtilities.GetMethodSignatureDisplayName (Method) };
-
-               public TypeDefinition? StaticType { get; }
-
-               public override SingleValue DeepCopy () => this; // This value is immutable
-
-               public override string ToString () => this.ValueToString (Method, DynamicallyAccessedMemberTypes);
-       }
-}
\ No newline at end of file
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/ParameterReferenceValue.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/ParameterReferenceValue.cs
deleted file mode 100644 (file)
index c6ef6ec..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-using ILLink.Shared.DataFlow;
-using ILLink.Shared.TypeSystemProxy;
-
-namespace ILLink.Shared.TrimAnalysis
-{
-       internal sealed partial record ParameterReferenceValue (ParameterProxy Parameter)
-               : ReferenceValue (Parameter.ParameterType)
-       {
-               public override SingleValue DeepCopy ()
-               {
-                       return this;
-               }
-       }
-}
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/README.md b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/README.md
deleted file mode 100644 (file)
index 9211e43..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Sources taken from https://github.com/dotnet/linker/tree/e502e7255030dde029e984e397924338485d1079/src/linker/Linker.Dataflow.
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/ReferenceValue.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/ReferenceValue.cs
deleted file mode 100644 (file)
index 2ea8d37..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-using ILLink.Shared.DataFlow;
-using Mono.Cecil;
-
-namespace ILLink.Shared.TrimAnalysis
-{
-       /// <summary>
-       /// Acts as the base class for all values that represent a reference to another value. These should only be held in a ref type or on the stack as a result of a 'load address' instruction (e.g. ldloca).
-       /// </summary>
-       public abstract record ReferenceValue (TypeReference ReferencedType) : SingleValue { }
-}
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/ReflectionMarker.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/ReflectionMarker.cs
deleted file mode 100644 (file)
index be69951..0000000
+++ /dev/null
@@ -1,199 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System;
-using System.Collections.Generic;
-using System.Diagnostics.CodeAnalysis;
-using System.Reflection;
-using ILLink.Shared.TrimAnalysis;
-using Mono.Cecil;
-using Mono.Linker.Steps;
-
-namespace Mono.Linker.Dataflow
-{
-       public readonly struct ReflectionMarker
-       {
-               readonly LinkContext _context;
-               readonly MarkStep _markStep;
-               readonly bool _enabled;
-
-               public ReflectionMarker (LinkContext context, MarkStep markStep, bool enabled)
-               {
-                       _context = context;
-                       _markStep = markStep;
-                       _enabled = enabled;
-               }
-
-               internal void MarkTypeForDynamicallyAccessedMembers (in MessageOrigin origin, TypeDefinition typeDefinition, DynamicallyAccessedMemberTypes requiredMemberTypes, DependencyKind dependencyKind, bool declaredOnly = false)
-               {
-                       if (!_enabled)
-                               return;
-
-                       foreach (var member in typeDefinition.GetDynamicallyAccessedMembers (_context, requiredMemberTypes, declaredOnly)) {
-                               switch (member) {
-                               case MethodDefinition method:
-                                       MarkMethod (origin, method, dependencyKind);
-                                       break;
-                               case FieldDefinition field:
-                                       MarkField (origin, field, dependencyKind);
-                                       break;
-                               case TypeDefinition nestedType:
-                                       MarkType (origin, nestedType, dependencyKind);
-                                       break;
-                               case PropertyDefinition property:
-                                       MarkProperty (origin, property, dependencyKind);
-                                       break;
-                               case EventDefinition @event:
-                                       MarkEvent (origin, @event, dependencyKind);
-                                       break;
-                               case InterfaceImplementation interfaceImplementation:
-                                       MarkInterfaceImplementation (origin, interfaceImplementation, dependencyKind);
-                                       break;
-                               }
-                       }
-               }
-
-               // Resolve a (potentially assembly qualified) type name based on the current context (taken from DiagnosticContext) and mark the type for reflection.
-               // This method will probe the current context assembly and if that fails CoreLib for the specified type. Emulates behavior of Type.GetType.
-               internal bool TryResolveTypeNameAndMark (string typeName, in DiagnosticContext diagnosticContext, bool needsAssemblyName, [NotNullWhen (true)] out TypeDefinition? type)
-               {
-                       if (!_context.TypeNameResolver.TryResolveTypeName (typeName, diagnosticContext, out TypeReference? typeRef, out var typeResolutionRecords, needsAssemblyName)
-                               || typeRef.ResolveToTypeDefinition (_context) is not TypeDefinition foundType) {
-                               type = default;
-                               return false;
-                       }
-
-                       MarkResolvedType (diagnosticContext, typeRef, foundType, typeResolutionRecords);
-
-                       type = foundType;
-                       return true;
-               }
-
-               // Resolve a type from the specified assembly and mark it for reflection.
-               internal bool TryResolveTypeNameAndMark (AssemblyDefinition assembly, string typeName, in DiagnosticContext diagnosticContext, [NotNullWhen (true)] out TypeDefinition? type)
-               {
-                       if (!_context.TypeNameResolver.TryResolveTypeName (assembly, typeName, out TypeReference? typeRef, out var typeResolutionRecords)
-                               || typeRef.ResolveToTypeDefinition (_context) is not TypeDefinition foundType) {
-                               type = default;
-                               return false;
-                       }
-
-                       MarkResolvedType (diagnosticContext, typeRef, foundType, typeResolutionRecords);
-
-                       type = foundType;
-                       return true;
-               }
-
-               void MarkResolvedType (
-                       in DiagnosticContext diagnosticContext,
-                       TypeReference typeReference,
-                       TypeDefinition typeDefinition,
-                       List<TypeNameResolver.TypeResolutionRecord> typeResolutionRecords)
-               {
-                       if (_enabled) {
-                               // Mark the resolved type for reflection access, but also go over all types which were resolved in the process
-                               // of resolving the outer type (typically generic arguments) and make sure we mark all type forwarders
-                               // used for that resolution.
-                               // This is necessary because if the app's code contains the input string as literal (which is pretty much always the case)
-                               // that string has to work at runtime, and if it relies on type forwarders we need to preserve those as well.
-                               var origin = diagnosticContext.Origin;
-                               _markStep.MarkTypeVisibleToReflection (typeReference, typeDefinition, new DependencyInfo (DependencyKind.AccessedViaReflection, origin.Provider), origin);
-                               foreach (var typeResolutionRecord in typeResolutionRecords) {
-                                       _context.MarkingHelpers.MarkMatchingExportedType (typeResolutionRecord.ResolvedType, typeResolutionRecord.ReferringAssembly, new DependencyInfo (DependencyKind.DynamicallyAccessedMember, typeDefinition), origin);
-                               }
-                       }
-               }
-
-               internal void MarkType (in MessageOrigin origin, TypeDefinition type, DependencyKind dependencyKind = DependencyKind.AccessedViaReflection)
-               {
-                       if (!_enabled)
-                               return;
-
-                       _markStep.MarkTypeVisibleToReflection (type, type, new DependencyInfo (dependencyKind, origin.Provider), origin);
-               }
-
-               internal void MarkMethod (in MessageOrigin origin, MethodDefinition method, DependencyKind dependencyKind = DependencyKind.AccessedViaReflection)
-               {
-                       if (!_enabled)
-                               return;
-
-                       _markStep.MarkMethodVisibleToReflection (method, new DependencyInfo (dependencyKind, origin.Provider), origin);
-               }
-
-               void MarkField (in MessageOrigin origin, FieldDefinition field, DependencyKind dependencyKind = DependencyKind.AccessedViaReflection)
-               {
-                       if (!_enabled)
-                               return;
-
-                       _markStep.MarkFieldVisibleToReflection (field, new DependencyInfo (dependencyKind, origin.Provider), origin);
-               }
-
-               internal void MarkProperty (in MessageOrigin origin, PropertyDefinition property, DependencyKind dependencyKind = DependencyKind.AccessedViaReflection)
-               {
-                       if (!_enabled)
-                               return;
-
-                       _markStep.MarkPropertyVisibleToReflection (property, new DependencyInfo (dependencyKind, origin.Provider), origin);
-               }
-
-               void MarkEvent (in MessageOrigin origin, EventDefinition @event, DependencyKind dependencyKind = DependencyKind.AccessedViaReflection)
-               {
-                       if (!_enabled)
-                               return;
-
-                       _markStep.MarkEventVisibleToReflection (@event, new DependencyInfo (dependencyKind, origin.Provider), origin);
-               }
-
-               void MarkInterfaceImplementation (in MessageOrigin origin, InterfaceImplementation interfaceImplementation, DependencyKind dependencyKind = DependencyKind.AccessedViaReflection)
-               {
-                       if (!_enabled)
-                               return;
-
-                       _markStep.MarkInterfaceImplementation (interfaceImplementation, null, new DependencyInfo (dependencyKind, origin.Provider));
-               }
-
-               internal void MarkConstructorsOnType (in MessageOrigin origin, TypeDefinition type, Func<MethodDefinition, bool>? filter, BindingFlags? bindingFlags = null)
-               {
-                       if (!_enabled)
-                               return;
-
-                       foreach (var ctor in type.GetConstructorsOnType (filter, bindingFlags))
-                               MarkMethod (origin, ctor);
-               }
-
-               internal void MarkFieldsOnTypeHierarchy (in MessageOrigin origin, TypeDefinition type, Func<FieldDefinition, bool> filter, BindingFlags? bindingFlags = BindingFlags.Default)
-               {
-                       if (!_enabled)
-                               return;
-
-                       foreach (var field in type.GetFieldsOnTypeHierarchy (_context, filter, bindingFlags))
-                               MarkField (origin, field);
-               }
-
-               internal void MarkPropertiesOnTypeHierarchy (in MessageOrigin origin, TypeDefinition type, Func<PropertyDefinition, bool> filter, BindingFlags? bindingFlags = BindingFlags.Default)
-               {
-                       if (!_enabled)
-                               return;
-
-                       foreach (var property in type.GetPropertiesOnTypeHierarchy (_context, filter, bindingFlags))
-                               MarkProperty (origin, property);
-               }
-
-               internal void MarkEventsOnTypeHierarchy (in MessageOrigin origin, TypeDefinition type, Func<EventDefinition, bool> filter, BindingFlags? bindingFlags = BindingFlags.Default)
-               {
-                       if (!_enabled)
-                               return;
-
-                       foreach (var @event in type.GetEventsOnTypeHierarchy (_context, filter, bindingFlags))
-                               MarkEvent (origin, @event);
-               }
-
-               internal void MarkStaticConstructor (in MessageOrigin origin, TypeDefinition type)
-               {
-                       if (!_enabled)
-                               return;
-
-                       _markStep.MarkStaticConstructorVisibleToReflection (type, new DependencyInfo (DependencyKind.AccessedViaReflection, origin.Provider), origin);
-               }
-       }
-}
\ No newline at end of file
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/ReflectionMethodBodyScanner.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/ReflectionMethodBodyScanner.cs
deleted file mode 100644 (file)
index 804e5a2..0000000
+++ /dev/null
@@ -1,450 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System;
-using System.Collections.Immutable;
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Linq;
-using ILLink.Shared;
-using ILLink.Shared.TrimAnalysis;
-using ILLink.Shared.TypeSystemProxy;
-using Mono.Cecil;
-using Mono.Cecil.Cil;
-using Mono.Linker.Steps;
-using MultiValue = ILLink.Shared.DataFlow.ValueSet<ILLink.Shared.DataFlow.SingleValue>;
-
-namespace Mono.Linker.Dataflow
-{
-       sealed class ReflectionMethodBodyScanner : MethodBodyScanner
-       {
-               readonly MarkStep _markStep;
-               MessageOrigin _origin;
-               readonly FlowAnnotations _annotations;
-               readonly ReflectionMarker _reflectionMarker;
-               public readonly TrimAnalysisPatternStore TrimAnalysisPatterns;
-
-               public static bool RequiresReflectionMethodBodyScannerForCallSite (LinkContext context, MethodReference calledMethod)
-               {
-                       MethodDefinition? methodDefinition = context.TryResolve (calledMethod);
-                       if (methodDefinition == null)
-                               return false;
-
-                       return Intrinsics.GetIntrinsicIdForMethod (methodDefinition) > IntrinsicId.RequiresReflectionBodyScanner_Sentinel ||
-                               context.Annotations.FlowAnnotations.RequiresDataFlowAnalysis (methodDefinition) ||
-                               context.Annotations.DoesMethodRequireUnreferencedCode (methodDefinition, out _) ||
-                               methodDefinition.IsPInvokeImpl && ComDangerousMethod (methodDefinition, context);
-               }
-
-               public static bool RequiresReflectionMethodBodyScannerForMethodBody (LinkContext context, MethodDefinition methodDefinition)
-               {
-                       return Intrinsics.GetIntrinsicIdForMethod (methodDefinition) > IntrinsicId.RequiresReflectionBodyScanner_Sentinel ||
-                               context.Annotations.FlowAnnotations.RequiresDataFlowAnalysis (methodDefinition);
-               }
-
-               public static bool RequiresReflectionMethodBodyScannerForAccess (LinkContext context, FieldReference field)
-               {
-                       FieldDefinition? fieldDefinition = context.TryResolve (field);
-                       if (fieldDefinition == null)
-                               return false;
-
-                       return context.Annotations.FlowAnnotations.RequiresDataFlowAnalysis (fieldDefinition);
-               }
-
-               public ReflectionMethodBodyScanner (LinkContext context, MarkStep parent, MessageOrigin origin)
-                       : base (context)
-               {
-                       _markStep = parent;
-                       _origin = origin;
-                       _annotations = context.Annotations.FlowAnnotations;
-                       _reflectionMarker = new ReflectionMarker (context, parent, enabled: false);
-                       TrimAnalysisPatterns = new TrimAnalysisPatternStore (MultiValueLattice, context);
-               }
-
-               public override void InterproceduralScan (MethodIL methodIL)
-               {
-                       base.InterproceduralScan (methodIL);
-
-                       var reflectionMarker = new ReflectionMarker (_context, _markStep, enabled: true);
-                       TrimAnalysisPatterns.MarkAndProduceDiagnostics (reflectionMarker, _markStep);
-               }
-
-               protected override void Scan (MethodIL methodIL, ref InterproceduralState interproceduralState)
-               {
-                       _origin = new MessageOrigin (methodIL.Method);
-                       base.Scan (methodIL, ref interproceduralState);
-
-                       if (!methodIL.Method.ReturnsVoid ()) {
-                               var method = methodIL.Method;
-                               var methodReturnValue = _annotations.GetMethodReturnValue (method);
-                               if (methodReturnValue.DynamicallyAccessedMemberTypes != 0)
-                                       HandleAssignmentPattern (_origin, ReturnValue, methodReturnValue);
-                       }
-               }
-
-               protected override void WarnAboutInvalidILInMethod (MethodBody method, int ilOffset)
-               {
-                       // Serves as a debug helper to make sure valid IL is not considered invalid.
-                       //
-                       // The .NET Native compiler used to warn if it detected invalid IL during treeshaking,
-                       // but the warnings were often triggered in autogenerated dead code of a major game engine
-                       // and resulted in support calls. No point in warning. If the code gets exercised at runtime,
-                       // an InvalidProgramException will likely be raised.
-                       Debug.Fail ("Invalid IL or a bug in the scanner");
-               }
-
-               protected override ValueWithDynamicallyAccessedMembers GetMethodParameterValue (ParameterProxy parameter)
-                       => GetMethodParameterValue (parameter, _context.Annotations.FlowAnnotations.GetParameterAnnotation (parameter));
-
-               MethodParameterValue GetMethodParameterValue (ParameterProxy parameter, DynamicallyAccessedMemberTypes dynamicallyAccessedMemberTypes)
-                       => _annotations.GetMethodParameterValue (parameter, dynamicallyAccessedMemberTypes);
-
-               protected override MultiValue GetFieldValue (FieldDefinition field) => _annotations.GetFieldValue (field);
-
-               private void HandleStoreValueWithDynamicallyAccessedMembers (ValueWithDynamicallyAccessedMembers targetValue, Instruction operation, MultiValue sourceValue)
-               {
-                       if (targetValue.DynamicallyAccessedMemberTypes != 0) {
-                               _origin = _origin.WithInstructionOffset (operation.Offset);
-                               HandleAssignmentPattern (_origin, sourceValue, targetValue);
-                       }
-               }
-
-               protected override void HandleStoreField (MethodDefinition method, FieldValue field, Instruction operation, MultiValue valueToStore)
-                       => HandleStoreValueWithDynamicallyAccessedMembers (field, operation, valueToStore);
-
-               protected override void HandleStoreParameter (MethodDefinition method, MethodParameterValue parameter, Instruction operation, MultiValue valueToStore)
-                       => HandleStoreValueWithDynamicallyAccessedMembers (parameter, operation, valueToStore);
-
-               protected override void HandleStoreMethodReturnValue (MethodDefinition method, MethodReturnValue returnValue, Instruction operation, MultiValue valueToStore)
-                       => HandleStoreValueWithDynamicallyAccessedMembers (returnValue, operation, valueToStore);
-
-               public override bool HandleCall (MethodBody callingMethodBody, MethodReference calledMethod, Instruction operation, ValueNodeList methodParams, out MultiValue methodReturnValue)
-               {
-                       methodReturnValue = new ();
-
-                       var reflectionProcessed = _markStep.ProcessReflectionDependency (callingMethodBody, operation);
-                       if (reflectionProcessed)
-                               return false;
-
-                       Debug.Assert (callingMethodBody.Method == _origin.Provider);
-                       var calledMethodDefinition = _context.TryResolve (calledMethod);
-                       if (calledMethodDefinition == null)
-                               return false;
-
-                       _origin = _origin.WithInstructionOffset (operation.Offset);
-
-                       MultiValue instanceValue;
-                       ImmutableArray<MultiValue> arguments;
-                       if (calledMethodDefinition.HasImplicitThis ()) {
-                               instanceValue = methodParams[0];
-                               arguments = methodParams.Skip (1).ToImmutableArray ();
-                       } else {
-                               instanceValue = MultiValueLattice.Top;
-                               arguments = methodParams.ToImmutableArray ();
-                       }
-
-                       TrimAnalysisPatterns.Add (new TrimAnalysisMethodCallPattern (
-                               operation,
-                               calledMethod,
-                               instanceValue,
-                               arguments,
-                               _origin
-                       ));
-
-                       var diagnosticContext = new DiagnosticContext (_origin, diagnosticsEnabled: false, _context);
-                       return HandleCall (
-                               operation,
-                               calledMethod,
-                               instanceValue,
-                               arguments,
-                               diagnosticContext,
-                               _reflectionMarker,
-                               _context,
-                               _markStep,
-                               out methodReturnValue);
-               }
-
-               public static bool HandleCall (
-                       Instruction operation,
-                       MethodReference calledMethod,
-                       MultiValue instanceValue,
-                       ImmutableArray<MultiValue> argumentValues,
-                       DiagnosticContext diagnosticContext,
-                       ReflectionMarker reflectionMarker,
-                       LinkContext context,
-                       MarkStep markStep,
-                       out MultiValue methodReturnValue)
-               {
-                       var origin = diagnosticContext.Origin;
-                       var calledMethodDefinition = context.TryResolve (calledMethod);
-                       Debug.Assert (calledMethodDefinition != null);
-                       var callingMethodDefinition = origin.Provider as MethodDefinition;
-                       Debug.Assert (callingMethodDefinition != null);
-
-                       bool requiresDataFlowAnalysis = context.Annotations.FlowAnnotations.RequiresDataFlowAnalysis (calledMethodDefinition);
-                       var annotatedMethodReturnValue = context.Annotations.FlowAnnotations.GetMethodReturnValue (calledMethodDefinition);
-                       Debug.Assert (requiresDataFlowAnalysis || annotatedMethodReturnValue.DynamicallyAccessedMemberTypes == DynamicallyAccessedMemberTypes.None);
-
-                       MultiValue? maybeMethodReturnValue = null;
-
-                       var handleCallAction = new HandleCallAction (context, reflectionMarker, diagnosticContext, callingMethodDefinition);
-                       var intrinsicId = Intrinsics.GetIntrinsicIdForMethod (calledMethodDefinition);
-                       switch (intrinsicId) {
-                       case IntrinsicId.IntrospectionExtensions_GetTypeInfo:
-                       case IntrinsicId.TypeInfo_AsType:
-                       case IntrinsicId.Type_get_UnderlyingSystemType:
-                       case IntrinsicId.Type_GetTypeFromHandle:
-                       case IntrinsicId.Type_get_TypeHandle:
-                       case IntrinsicId.Type_GetInterface:
-                       case IntrinsicId.Type_get_AssemblyQualifiedName:
-                       case IntrinsicId.RuntimeHelpers_RunClassConstructor:
-                       case IntrinsicId.Type_GetConstructors__BindingFlags:
-                       case IntrinsicId.Type_GetMethods__BindingFlags:
-                       case IntrinsicId.Type_GetFields__BindingFlags:
-                       case IntrinsicId.Type_GetProperties__BindingFlags:
-                       case IntrinsicId.Type_GetEvents__BindingFlags:
-                       case IntrinsicId.Type_GetNestedTypes__BindingFlags:
-                       case IntrinsicId.Type_GetMembers__BindingFlags:
-                       case IntrinsicId.Type_GetField:
-                       case IntrinsicId.Type_GetProperty:
-                       case IntrinsicId.Type_GetEvent:
-                       case IntrinsicId.RuntimeReflectionExtensions_GetRuntimeEvent:
-                       case IntrinsicId.RuntimeReflectionExtensions_GetRuntimeField:
-                       case IntrinsicId.RuntimeReflectionExtensions_GetRuntimeMethod:
-                       case IntrinsicId.RuntimeReflectionExtensions_GetRuntimeProperty:
-                       case IntrinsicId.Type_GetMember:
-                       case IntrinsicId.Type_GetMethod:
-                       case IntrinsicId.Type_GetNestedType:
-                       case IntrinsicId.Nullable_GetUnderlyingType:
-                       case IntrinsicId.Expression_Property:
-                       case IntrinsicId.Expression_Field:
-                       case IntrinsicId.Type_get_BaseType:
-                       case IntrinsicId.Type_GetConstructor:
-                       case IntrinsicId.MethodBase_GetMethodFromHandle:
-                       case IntrinsicId.MethodBase_get_MethodHandle:
-                       case IntrinsicId.Type_MakeGenericType:
-                       case IntrinsicId.MethodInfo_MakeGenericMethod:
-                       case IntrinsicId.Expression_Call:
-                       case IntrinsicId.Expression_New:
-                       case IntrinsicId.Type_GetType:
-                       case IntrinsicId.Activator_CreateInstance__Type:
-                       case IntrinsicId.Activator_CreateInstance__AssemblyName_TypeName:
-                       case IntrinsicId.Activator_CreateInstanceFrom:
-                       case IntrinsicId.AppDomain_CreateInstance:
-                       case IntrinsicId.AppDomain_CreateInstanceAndUnwrap:
-                       case IntrinsicId.AppDomain_CreateInstanceFrom:
-                       case IntrinsicId.AppDomain_CreateInstanceFromAndUnwrap:
-                       case IntrinsicId.Assembly_CreateInstance: {
-                                       return handleCallAction.Invoke (calledMethodDefinition, instanceValue, argumentValues, intrinsicId, out methodReturnValue);
-                               }
-
-                       case IntrinsicId.None: {
-                                       if (calledMethodDefinition.IsPInvokeImpl && ComDangerousMethod (calledMethodDefinition, context))
-                                               diagnosticContext.AddDiagnostic (DiagnosticId.CorrectnessOfCOMCannotBeGuaranteed, calledMethodDefinition.GetDisplayName ());
-                                       if (context.Annotations.DoesMethodRequireUnreferencedCode (calledMethodDefinition, out RequiresUnreferencedCodeAttribute? requiresUnreferencedCode))
-                                               MarkStep.ReportRequiresUnreferencedCode (calledMethodDefinition.GetDisplayName (), requiresUnreferencedCode, diagnosticContext);
-
-                                       return handleCallAction.Invoke (calledMethodDefinition, instanceValue, argumentValues, intrinsicId, out methodReturnValue);
-                               }
-
-                       case IntrinsicId.TypeDelegator_Ctor: {
-                                       // This is an identity function for analysis purposes
-                                       if (operation.OpCode == OpCodes.Newobj)
-                                               AddReturnValue (argumentValues[0]);
-                               }
-                               break;
-
-                       case IntrinsicId.Array_Empty: {
-                                       AddReturnValue (ArrayValue.Create (0, ((GenericInstanceMethod) calledMethod).GenericArguments[0]));
-                               }
-                               break;
-
-                       case IntrinsicId.Enum_GetValues:
-                       case IntrinsicId.Marshal_SizeOf:
-                       case IntrinsicId.Marshal_OffsetOf:
-                       case IntrinsicId.Marshal_PtrToStructure:
-                       case IntrinsicId.Marshal_DestroyStructure:
-                       case IntrinsicId.Marshal_GetDelegateForFunctionPointer:
-                               // These intrinsics are not interesting for trimmer (they are interesting for AOT and that's why they are recognized)
-                               break;
-
-                       //
-                       // System.Object
-                       //
-                       // GetType()
-                       //
-                       case IntrinsicId.Object_GetType: {
-                                       foreach (var valueNode in instanceValue) {
-                                               // Note that valueNode can be statically typed in IL as some generic argument type.
-                                               // For example:
-                                               //   void Method<T>(T instance) { instance.GetType().... }
-                                               // Currently this case will end up with null StaticType - since there's no typedef for the generic argument type.
-                                               // But it could be that T is annotated with for example PublicMethods:
-                                               //   void Method<[DAM(PublicMethods)] T>(T instance) { instance.GetType().GetMethod("Test"); }
-                                               // In this case it's in theory possible to handle it, by treating the T basically as a base class
-                                               // for the actual type of "instance". But the analysis for this would be pretty complicated (as the marking
-                                               // has to happen on the callsite, which doesn't know that GetType() will be used...).
-                                               // For now we're intentionally ignoring this case - it will produce a warning.
-                                               // The counter example is:
-                                               //   Method<Base>(new Derived);
-                                               // In this case to get correct results, trimmer would have to mark all public methods on Derived. Which
-                                               // currently it won't do.
-
-                                               TypeDefinition? staticType = (valueNode as IValueWithStaticType)?.StaticType;
-                                               if (staticType is null) {
-                                                       // We don't know anything about the type GetType was called on. Track this as a usual result of a method call without any annotations
-                                                       AddReturnValue (context.Annotations.FlowAnnotations.GetMethodReturnValue (calledMethodDefinition));
-                                               } else if (staticType.IsSealed || staticType.IsTypeOf ("System", "Delegate")) {
-                                                       // We can treat this one the same as if it was a typeof() expression
-
-                                                       // We can allow Object.GetType to be modeled as System.Delegate because we keep all methods
-                                                       // on delegates anyway so reflection on something this approximation would miss is actually safe.
-
-                                                       // We ignore the fact that the type can be annotated (see below for handling of annotated types)
-                                                       // This means the annotations (if any) won't be applied - instead we rely on the exact knowledge
-                                                       // of the type. So for example even if the type is annotated with PublicMethods
-                                                       // but the code calls GetProperties on it - it will work - mark properties, don't mark methods
-                                                       // since we ignored the fact that it's annotated.
-                                                       // This can be seen a little bit as a violation of the annotation, but we already have similar cases
-                                                       // where a parameter is annotated and if something in the method sets a specific known type to it
-                                                       // we will also make it just work, even if the annotation doesn't match the usage.
-                                                       AddReturnValue (new SystemTypeValue (staticType));
-                                               } else {
-                                                       // Make sure the type is marked (this will mark it as used via reflection, which is sort of true)
-                                                       // This should already be true for most cases (method params, fields, ...), but just in case
-                                                       reflectionMarker.MarkType (origin, staticType);
-
-                                                       var annotation = markStep.DynamicallyAccessedMembersTypeHierarchy
-                                                               .ApplyDynamicallyAccessedMembersToTypeHierarchy (staticType);
-
-                                                       // Return a value which is "unknown type" with annotation. For now we'll use the return value node
-                                                       // for the method, which means we're loosing the information about which staticType this
-                                                       // started with. For now we don't need it, but we can add it later on.
-                                                       AddReturnValue (context.Annotations.FlowAnnotations.GetMethodReturnValue (calledMethodDefinition, annotation));
-                                               }
-                                       }
-                               }
-                               break;
-
-                       // Note about Activator.CreateInstance<T>
-                       // There are 2 interesting cases:
-                       //  - The generic argument for T is either specific type or annotated - in that case generic instantiation will handle this
-                       //    since from .NET 6+ the T is annotated with PublicParameterlessConstructor annotation, so the linker would apply this as for any other method.
-                       //  - The generic argument for T is unannotated type - the generic instantiantion handling has a special case for handling PublicParameterlessConstructor requirement
-                       //    in such that if the generic argument type has the "new" constraint it will not warn (as it is effectively the same thing semantically).
-                       //    For all other cases, the linker would have already produced a warning.
-
-                       default:
-                               throw new NotImplementedException ("Unhandled intrinsic");
-                       }
-
-                       // If we get here, we handled this as an intrinsic.  As a convenience, if the code above
-                       // didn't set the return value (and the method has a return value), we will set it to be an
-                       // unknown value with the return type of the method.
-                       bool returnsVoid = calledMethod.ReturnsVoid ();
-                       methodReturnValue = maybeMethodReturnValue ?? (returnsVoid ?
-                               MultiValueLattice.Top :
-                               annotatedMethodReturnValue);
-
-                       // Validate that the return value has the correct annotations as per the method return value annotations
-                       if (annotatedMethodReturnValue.DynamicallyAccessedMemberTypes != 0) {
-                               foreach (var uniqueValue in methodReturnValue) {
-                                       if (uniqueValue is ValueWithDynamicallyAccessedMembers methodReturnValueWithMemberTypes) {
-                                               if (!methodReturnValueWithMemberTypes.DynamicallyAccessedMemberTypes.HasFlag (annotatedMethodReturnValue.DynamicallyAccessedMemberTypes))
-                                                       throw new InvalidOperationException ($"Internal linker error: processing of call from {callingMethodDefinition.GetDisplayName ()} to {calledMethod.GetDisplayName ()} returned value which is not correctly annotated with the expected dynamic member access kinds.");
-                                       } else if (uniqueValue is SystemTypeValue) {
-                                               // SystemTypeValue can fulfill any requirement, so it's always valid
-                                               // The requirements will be applied at the point where it's consumed (passed as a method parameter, set as field value, returned from the method)
-                                       } else {
-                                               throw new InvalidOperationException ($"Internal linker error: processing of call from {callingMethodDefinition.GetDisplayName ()} to {calledMethod.GetDisplayName ()} returned value which is not correctly annotated with the expected dynamic member access kinds.");
-                                       }
-                               }
-                       }
-
-                       return true;
-
-                       void AddReturnValue (MultiValue value)
-                       {
-                               maybeMethodReturnValue = (maybeMethodReturnValue is null) ? value : MultiValueLattice.Meet ((MultiValue) maybeMethodReturnValue, value);
-                       }
-               }
-
-               static bool IsComInterop (IMarshalInfoProvider marshalInfoProvider, TypeReference parameterType, LinkContext context)
-               {
-                       // This is best effort. One can likely find ways how to get COM without triggering these alarms.
-                       // AsAny marshalling of a struct with an object-typed field would be one, for example.
-
-                       // This logic roughly corresponds to MarshalInfo::MarshalInfo in CoreCLR,
-                       // not trying to handle invalid cases and distinctions that are not interesting wrt
-                       // "is this COM?" question.
-
-                       NativeType nativeType = NativeType.None;
-                       if (marshalInfoProvider.HasMarshalInfo) {
-                               nativeType = marshalInfoProvider.MarshalInfo.NativeType;
-                       }
-
-                       if (nativeType == NativeType.IUnknown || nativeType == NativeType.IDispatch || nativeType == NativeType.IntF) {
-                               // This is COM by definition
-                               return true;
-                       }
-
-                       if (nativeType == NativeType.None) {
-                               // Resolve will look at the element type
-                               var parameterTypeDef = context.TryResolve (parameterType);
-
-                               if (parameterTypeDef != null) {
-                                       if (parameterTypeDef.IsTypeOf (WellKnownType.System_Array)) {
-                                               // System.Array marshals as IUnknown by default
-                                               return true;
-                                       } else if (parameterTypeDef.IsTypeOf (WellKnownType.System_String) ||
-                                               parameterTypeDef.IsTypeOf ("System.Text", "StringBuilder")) {
-                                               // String and StringBuilder are special cased by interop
-                                               return false;
-                                       }
-
-                                       if (parameterTypeDef.IsValueType) {
-                                               // Value types don't marshal as COM
-                                               return false;
-                                       } else if (parameterTypeDef.IsInterface) {
-                                               // Interface types marshal as COM by default
-                                               return true;
-                                       } else if (parameterTypeDef.IsMulticastDelegate ()) {
-                                               // Delegates are special cased by interop
-                                               return false;
-                                       } else if (parameterTypeDef.IsSubclassOf ("System.Runtime.InteropServices", "CriticalHandle", context)) {
-                                               // Subclasses of CriticalHandle are special cased by interop
-                                               return false;
-                                       } else if (parameterTypeDef.IsSubclassOf ("System.Runtime.InteropServices", "SafeHandle", context)) {
-                                               // Subclasses of SafeHandle are special cased by interop
-                                               return false;
-                                       } else if (!parameterTypeDef.IsSequentialLayout && !parameterTypeDef.IsExplicitLayout) {
-                                               // Rest of classes that don't have layout marshal as COM
-                                               return true;
-                                       }
-                               }
-                       }
-
-                       return false;
-               }
-
-               void HandleAssignmentPattern (
-                       in MessageOrigin origin,
-                       in MultiValue value,
-                       ValueWithDynamicallyAccessedMembers targetValue)
-               {
-                       TrimAnalysisPatterns.Add (new TrimAnalysisAssignmentPattern (value, targetValue, origin));
-               }
-
-               private static bool ComDangerousMethod (MethodDefinition methodDefinition, LinkContext context)
-               {
-                       bool comDangerousMethod = IsComInterop (methodDefinition.MethodReturnType, methodDefinition.ReturnType, context);
-#pragma warning disable RS0030 // MethodDefinition.Parameters is banned. Here we iterate through the parameters and don't need to worry about the 'this' parameter.
-                       foreach (ParameterDefinition pd in methodDefinition.Parameters) {
-                               comDangerousMethod |= IsComInterop (pd, pd.ParameterType, context);
-                       }
-#pragma warning restore RS0030
-
-                       return comDangerousMethod;
-               }
-       }
-}
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/RequireDynamicallyAccessedMembersAction.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/RequireDynamicallyAccessedMembersAction.cs
deleted file mode 100644 (file)
index 5f1f8ee..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System.Diagnostics.CodeAnalysis;
-using ILLink.Shared.TypeSystemProxy;
-using Mono.Cecil;
-using Mono.Linker;
-using Mono.Linker.Dataflow;
-
-namespace ILLink.Shared.TrimAnalysis
-{
-       partial struct RequireDynamicallyAccessedMembersAction
-       {
-               readonly ReflectionMarker _reflectionMarker;
-
-               public RequireDynamicallyAccessedMembersAction (
-                       ReflectionMarker reflectionMarker,
-                       in DiagnosticContext diagnosticContext)
-               {
-                       _reflectionMarker = reflectionMarker;
-                       _diagnosticContext = diagnosticContext;
-               }
-
-               public partial bool TryResolveTypeNameAndMark (string typeName, bool needsAssemblyName, out TypeProxy type)
-               {
-                       if (_reflectionMarker.TryResolveTypeNameAndMark (typeName, _diagnosticContext, needsAssemblyName, out TypeDefinition? foundType)) {
-                               type = new (foundType);
-                               return true;
-                       } else {
-                               type = default;
-                               return false;
-                       }
-               }
-
-               private partial void MarkTypeForDynamicallyAccessedMembers (in TypeProxy type, DynamicallyAccessedMemberTypes dynamicallyAccessedMemberTypes)
-               {
-                       _reflectionMarker.MarkTypeForDynamicallyAccessedMembers (_diagnosticContext.Origin, type.Type, dynamicallyAccessedMemberTypes, DependencyKind.DynamicallyAccessedMember);
-               }
-       }
-}
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/ScannerExtensions.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/ScannerExtensions.cs
deleted file mode 100644 (file)
index 7b8dbba..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System;
-using System.Collections.Generic;
-using Mono.Cecil.Cil;
-
-namespace Mono.Linker.Dataflow
-{
-       static class ScannerExtensions
-       {
-               public static bool IsControlFlowInstruction (in this OpCode opcode)
-               {
-                       return opcode.FlowControl == FlowControl.Branch
-                               || opcode.FlowControl == FlowControl.Cond_Branch
-                               || (opcode.FlowControl == FlowControl.Return && opcode.Code != Code.Ret);
-               }
-
-               public static HashSet<int> ComputeBranchTargets (this MethodIL methodIL)
-               {
-                       HashSet<int> branchTargets = new HashSet<int> ();
-                       foreach (Instruction operation in methodIL.Instructions) {
-                               if (!operation.OpCode.IsControlFlowInstruction ())
-                                       continue;
-                               Object value = operation.Operand;
-                               if (value is Instruction inst) {
-                                       branchTargets.Add (inst.Offset);
-                               } else if (value is Instruction[] instructions) {
-                                       foreach (Instruction switchLabel in instructions) {
-                                               branchTargets.Add (switchLabel.Offset);
-                                       }
-                               }
-                       }
-                       foreach (ExceptionHandler einfo in methodIL.ExceptionHandlers) {
-                               if (einfo.HandlerType == ExceptionHandlerType.Filter) {
-                                       branchTargets.Add (einfo.FilterStart.Offset);
-                               }
-                               branchTargets.Add (einfo.HandlerStart.Offset);
-                       }
-                       return branchTargets;
-               }
-       }
-
-}
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/TrimAnalysisAssignmentPattern.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/TrimAnalysisAssignmentPattern.cs
deleted file mode 100644 (file)
index 81010a3..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System;
-using System.Diagnostics;
-using ILLink.Shared.DataFlow;
-using ILLink.Shared.TrimAnalysis;
-using MultiValue = ILLink.Shared.DataFlow.ValueSet<ILLink.Shared.DataFlow.SingleValue>;
-
-namespace Mono.Linker.Dataflow
-{
-       public readonly record struct TrimAnalysisAssignmentPattern
-       {
-               public MultiValue Source { init; get; }
-               public MultiValue Target { init; get; }
-               public MessageOrigin Origin { init; get; }
-
-               public TrimAnalysisAssignmentPattern (MultiValue source, MultiValue target, MessageOrigin origin)
-               {
-                       Source = source.Clone ();
-                       Target = target.Clone ();
-                       Origin = origin;
-               }
-
-               public TrimAnalysisAssignmentPattern Merge (ValueSetLattice<SingleValue> lattice, TrimAnalysisAssignmentPattern other)
-               {
-                       Debug.Assert (Origin == other.Origin);
-
-                       return new TrimAnalysisAssignmentPattern (
-                               lattice.Meet (Source, other.Source),
-                               lattice.Meet (Target, other.Target),
-                               Origin);
-               }
-
-               public void MarkAndProduceDiagnostics (ReflectionMarker reflectionMarker, LinkContext context)
-               {
-                       bool diagnosticsEnabled = !context.Annotations.ShouldSuppressAnalysisWarningsForRequiresUnreferencedCode (Origin.Provider);
-                       var diagnosticContext = new DiagnosticContext (Origin, diagnosticsEnabled, context);
-
-                       foreach (var sourceValue in Source) {
-                               foreach (var targetValue in Target) {
-                                       if (targetValue is not ValueWithDynamicallyAccessedMembers targetWithDynamicallyAccessedMembers)
-                                               throw new NotImplementedException ();
-
-                                       var requireDynamicallyAccessedMembersAction = new RequireDynamicallyAccessedMembersAction (reflectionMarker, diagnosticContext);
-                                       requireDynamicallyAccessedMembersAction.Invoke (sourceValue, targetWithDynamicallyAccessedMembers);
-                               }
-                       }
-               }
-       }
-}
\ No newline at end of file
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/TrimAnalysisMethodCallPattern.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/TrimAnalysisMethodCallPattern.cs
deleted file mode 100644 (file)
index be4219a..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System.Collections.Immutable;
-using System.Diagnostics;
-using ILLink.Shared.DataFlow;
-using ILLink.Shared.TrimAnalysis;
-using Mono.Cecil;
-using Mono.Cecil.Cil;
-using Mono.Linker.Steps;
-using MultiValue = ILLink.Shared.DataFlow.ValueSet<ILLink.Shared.DataFlow.SingleValue>;
-
-namespace Mono.Linker.Dataflow
-{
-       public readonly record struct TrimAnalysisMethodCallPattern
-       {
-               public readonly Instruction Operation;
-               public readonly MethodReference CalledMethod;
-               public readonly MultiValue Instance;
-               public readonly ImmutableArray<MultiValue> Arguments;
-               public readonly MessageOrigin Origin;
-
-               public TrimAnalysisMethodCallPattern (
-                       Instruction operation,
-                       MethodReference calledMethod,
-                       MultiValue instance,
-                       ImmutableArray<MultiValue> arguments,
-                       MessageOrigin origin)
-               {
-                       Debug.Assert (origin.Provider is MethodDefinition);
-                       Operation = operation;
-                       CalledMethod = calledMethod;
-                       Instance = instance.Clone ();
-                       if (arguments.IsEmpty) {
-                               Arguments = ImmutableArray<MultiValue>.Empty;
-                       } else {
-                               var builder = ImmutableArray.CreateBuilder<MultiValue> ();
-                               foreach (var argument in arguments)
-                                       builder.Add (argument.Clone ());
-                               Arguments = builder.ToImmutableArray ();
-                       }
-                       Origin = origin;
-               }
-
-               public TrimAnalysisMethodCallPattern Merge (ValueSetLattice<SingleValue> lattice, TrimAnalysisMethodCallPattern other)
-               {
-                       Debug.Assert (Operation == other.Operation);
-                       Debug.Assert (Origin == other.Origin);
-                       Debug.Assert (CalledMethod == other.CalledMethod);
-                       Debug.Assert (Arguments.Length == other.Arguments.Length);
-
-                       var argumentsBuilder = ImmutableArray.CreateBuilder<MultiValue> ();
-                       for (int i = 0; i < Arguments.Length; i++)
-                               argumentsBuilder.Add (lattice.Meet (Arguments[i], other.Arguments[i]));
-
-                       return new TrimAnalysisMethodCallPattern (
-                               Operation,
-                               CalledMethod,
-                               lattice.Meet (Instance, other.Instance),
-                               argumentsBuilder.ToImmutable (),
-                               Origin);
-               }
-
-               public void MarkAndProduceDiagnostics (ReflectionMarker reflectionMarker, MarkStep markStep, LinkContext context)
-               {
-                       bool diagnosticsEnabled = !context.Annotations.ShouldSuppressAnalysisWarningsForRequiresUnreferencedCode (Origin.Provider);
-                       var diagnosticContext = new DiagnosticContext (Origin, diagnosticsEnabled, context);
-                       ReflectionMethodBodyScanner.HandleCall (Operation, CalledMethod, Instance, Arguments,
-                               diagnosticContext,
-                               reflectionMarker,
-                               context,
-                               markStep,
-                               out MultiValue _);
-               }
-       }
-}
\ No newline at end of file
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/TrimAnalysisPatternStore.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/TrimAnalysisPatternStore.cs
deleted file mode 100644 (file)
index ee88e9d..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System.Collections.Generic;
-using ILLink.Shared.DataFlow;
-using ILLink.Shared.TrimAnalysis;
-using Mono.Linker.Steps;
-
-namespace Mono.Linker.Dataflow
-{
-       public readonly struct TrimAnalysisPatternStore
-       {
-               readonly Dictionary<(MessageOrigin, bool), TrimAnalysisAssignmentPattern> AssignmentPatterns;
-               readonly Dictionary<MessageOrigin, TrimAnalysisMethodCallPattern> MethodCallPatterns;
-               readonly ValueSetLattice<SingleValue> Lattice;
-               readonly LinkContext _context;
-
-               public TrimAnalysisPatternStore (ValueSetLattice<SingleValue> lattice, LinkContext context)
-               {
-                       AssignmentPatterns = new Dictionary<(MessageOrigin, bool), TrimAnalysisAssignmentPattern> ();
-                       MethodCallPatterns = new Dictionary<MessageOrigin, TrimAnalysisMethodCallPattern> ();
-                       Lattice = lattice;
-                       _context = context;
-               }
-
-               public void Add (TrimAnalysisAssignmentPattern pattern)
-               {
-                       // In the linker, each pattern should have a unique origin (which has ILOffset)
-                       // but we don't track the correct ILOffset for return instructions.
-                       // https://github.com/dotnet/linker/issues/2778
-                       // For now, work around it with a separate bit.
-                       bool isReturnValue = pattern.Target.AsSingleValue () is MethodReturnValue;
-
-                       if (!AssignmentPatterns.TryGetValue ((pattern.Origin, isReturnValue), out var existingPattern)) {
-                               AssignmentPatterns.Add ((pattern.Origin, isReturnValue), pattern);
-                               return;
-                       }
-
-                       AssignmentPatterns[(pattern.Origin, isReturnValue)] = pattern.Merge (Lattice, existingPattern);
-               }
-
-               public void Add (TrimAnalysisMethodCallPattern pattern)
-               {
-                       if (!MethodCallPatterns.TryGetValue (pattern.Origin, out var existingPattern)) {
-                               MethodCallPatterns.Add (pattern.Origin, pattern);
-                               return;
-                       }
-
-                       MethodCallPatterns[pattern.Origin] = pattern.Merge (Lattice, existingPattern);
-               }
-
-               public void MarkAndProduceDiagnostics (ReflectionMarker reflectionMarker, MarkStep markStep)
-               {
-                       foreach (var pattern in AssignmentPatterns.Values)
-                               pattern.MarkAndProduceDiagnostics (reflectionMarker, _context);
-
-                       foreach (var pattern in MethodCallPatterns.Values)
-                               pattern.MarkAndProduceDiagnostics (reflectionMarker, markStep, _context);
-               }
-       }
-}
\ No newline at end of file
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/ValueNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReferenceSource/ValueNode.cs
deleted file mode 100644 (file)
index 81d5e05..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System;
-using System.Collections.Generic;
-using ILLink.Shared;
-using MultiValue = ILLink.Shared.DataFlow.ValueSet<ILLink.Shared.DataFlow.SingleValue>;
-
-namespace Mono.Linker.Dataflow
-{
-       public class ValueNodeList : List<MultiValue>
-       {
-               public ValueNodeList ()
-               {
-               }
-
-               public ValueNodeList (int capacity)
-                       : base (capacity)
-               {
-               }
-
-               public ValueNodeList (List<MultiValue> other)
-                       : base (other)
-               {
-               }
-
-               public override int GetHashCode ()
-               {
-                       HashCode hashCode = new HashCode ();
-                       foreach (var item in this)
-                               hashCode.Add (item.GetHashCode ());
-                       return hashCode.ToHashCode ();
-               }
-
-               public override bool Equals (object? other)
-               {
-                       if (!(other is ValueNodeList otherList))
-                               return false;
-
-                       if (otherList.Count != Count)
-                               return false;
-
-                       for (int i = 0; i < Count; i++) {
-                               if (!otherList[i].Equals (this[i]))
-                                       return false;
-                       }
-                       return true;
-               }
-       }
-
-       public struct ValueBasicBlockPair : IEquatable<ValueBasicBlockPair>
-       {
-               public ValueBasicBlockPair (MultiValue value, int basicBlockIndex)
-               {
-                       Value = value;
-                       BasicBlockIndex = basicBlockIndex;
-               }
-
-               public MultiValue Value { get; }
-               public int BasicBlockIndex { get; }
-
-               public bool Equals (ValueBasicBlockPair other) => Value.Equals (other.Value) && BasicBlockIndex.Equals (other.BasicBlockIndex);
-
-               public override bool Equals (object? obj) => obj is ValueBasicBlockPair other && Equals (other);
-
-               public override int GetHashCode () => HashUtils.Combine (Value.GetHashCode (), BasicBlockIndex);
-       }
-}
index f18186d..41f89f3 100644 (file)
@@ -67,5 +67,8 @@ namespace ILCompiler.Dataflow
         public override bool Equals(object? obj) => obj is ValueBasicBlockPair other && Equals(other);
 
         public override int GetHashCode() => HashUtils.Combine(Value.GetHashCode(), BasicBlockIndex);
+
+        public static bool operator ==(ValueBasicBlockPair left, ValueBasicBlockPair right) => left.Equals(right);
+        public static bool operator !=(ValueBasicBlockPair left, ValueBasicBlockPair right) => !(left == right);
     }
 }
index a7cf34c..6f98159 100644 (file)
@@ -88,8 +88,10 @@ namespace ILCompiler.Logging
                 if (method.HasGenericParameters)
                     builder.Append("``").Append(method.GenericParameters.Count);
 
-                if (method.HasParameters || (method.CallingConvention == MethodCallingConvention.VarArg))
+                if (method.HasMetadataParameters() || (method.CallingConvention == MethodCallingConvention.VarArg))
+#pragma warning disable RS0030 // MethodReference.Parameters is banned. This generates documentation signatures, so it's okay to use it here
                     VisitParameters(method.Parameters, method.CallingConvention == MethodCallingConvention.VarArg, builder);
+#pragma warning restore RS0030
 
                 if (method.Name == "op_Implicit" || method.Name == "op_Explicit")
                 {
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Logging/ReferenceSource/DocumentationSignatureGenerator.PartVisitor.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Logging/ReferenceSource/DocumentationSignatureGenerator.PartVisitor.cs
deleted file mode 100644 (file)
index 65211ab..0000000
+++ /dev/null
@@ -1,213 +0,0 @@
-// 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.Collections.Generic;
-using System.Diagnostics;
-using System.Text;
-using Mono.Cecil;
-
-namespace Mono.Linker
-{
-
-       public sealed partial class DocumentationSignatureGenerator
-       {
-               /// <summary>
-               ///  A visitor that generates the part of the documentation comment after the initial type
-               ///  and colon.
-               ///  Adapted from Roslyn's DocumentattionCommentIDVisitor.PartVisitor:
-               ///  https://github.com/dotnet/roslyn/blob/master/src/Compilers/CSharp/Portable/DocumentationComments/DocumentationCommentIDVisitor.PartVisitor.cs
-               /// </summary>
-               internal sealed class PartVisitor
-               {
-                       internal static readonly PartVisitor Instance = new PartVisitor ();
-
-                       private PartVisitor ()
-                       {
-                       }
-
-                       public void VisitArrayType (ArrayType arrayType, StringBuilder builder, ITryResolveMetadata resolver)
-                       {
-                               VisitTypeReference (arrayType.ElementType, builder, resolver);
-
-                               // Rank-one arrays are displayed different than rectangular arrays
-                               if (arrayType.IsVector) {
-                                       builder.Append ("[]");
-                               } else {
-                                       // C# arrays only support zero lower bounds
-                                       if (arrayType.Dimensions[0].LowerBound != 0)
-                                               throw new NotImplementedException ();
-                                       builder.Append ("[0:");
-                                       for (int i = 1; i < arrayType.Rank; i++) {
-                                               if (arrayType.Dimensions[0].LowerBound != 0)
-                                                       throw new NotImplementedException ();
-                                               builder.Append (",0:");
-                                       }
-
-                                       builder.Append (']');
-                               }
-                       }
-
-                       public void VisitField (FieldDefinition field, StringBuilder builder, ITryResolveMetadata resolver)
-                       {
-                               VisitTypeReference (field.DeclaringType, builder, resolver);
-                               builder.Append ('.').Append (field.Name);
-                       }
-
-                       private void VisitParameters (IEnumerable<ParameterDefinition> parameters, bool isVararg, StringBuilder builder, ITryResolveMetadata resolver)
-                       {
-                               builder.Append ('(');
-                               bool needsComma = false;
-
-                               foreach (var parameter in parameters) {
-                                       if (needsComma)
-                                               builder.Append (',');
-
-                                       // byrefs are tracked on the parameter type, not the parameter,
-                                       // so we don't have VisitParameter that Roslyn uses.
-                                       VisitTypeReference (parameter.ParameterType, builder, resolver);
-                                       needsComma = true;
-                               }
-
-                               // note: the C# doc comment generator outputs an extra comma for varargs
-                               // methods that also have fixed parameters
-                               if (isVararg && needsComma)
-                                       builder.Append (',');
-
-                               builder.Append (')');
-                       }
-
-                       public void VisitMethodDefinition (MethodDefinition method, StringBuilder builder, ITryResolveMetadata resolver)
-                       {
-                               VisitTypeReference (method.DeclaringType, builder, resolver);
-                               builder.Append ('.').Append (GetEscapedMetadataName (method));
-
-                               if (method.HasGenericParameters)
-                                       builder.Append ("``").Append (method.GenericParameters.Count);
-
-                               if (method.HasParameters || (method.CallingConvention == MethodCallingConvention.VarArg))
-                                       VisitParameters (method.Parameters, method.CallingConvention == MethodCallingConvention.VarArg, builder, resolver);
-
-                               if (method.Name == "op_Implicit" || method.Name == "op_Explicit") {
-                                       builder.Append ('~');
-                                       VisitTypeReference (method.ReturnType, builder, resolver);
-                               }
-                       }
-
-                       public void VisitProperty (PropertyDefinition property, StringBuilder builder, ITryResolveMetadata resolver)
-                       {
-                               VisitTypeReference (property.DeclaringType, builder, resolver);
-                               builder.Append ('.').Append (GetEscapedMetadataName (property));
-
-                               if (property.Parameters.Count > 0)
-                                       VisitParameters (property.Parameters, false, builder, resolver);
-                       }
-
-                       public void VisitEvent (EventDefinition evt, StringBuilder builder, ITryResolveMetadata resolver)
-                       {
-                               VisitTypeReference (evt.DeclaringType, builder, resolver);
-                               builder.Append ('.').Append (GetEscapedMetadataName (evt));
-                       }
-
-                       public static void VisitGenericParameter (GenericParameter genericParameter, StringBuilder builder)
-                       {
-                               Debug.Assert (genericParameter.DeclaringMethod == null ^ genericParameter.DeclaringType == null);
-                               // Is this a type parameter on a type?
-                               if (genericParameter.DeclaringMethod != null) {
-                                       builder.Append ("``");
-                               } else {
-                                       Debug.Assert (genericParameter.DeclaringType != null);
-
-                                       // If the containing type is nested within other types.
-                                       // e.g. A<T>.B<U>.M<V>(T t, U u, V v) should be M(`0, `1, ``0).
-                                       // Roslyn needs to add generic arities of parents, but the innermost type redeclares 
-                                       // all generic parameters so we don't need to add them.
-                                       builder.Append ('`');
-                               }
-
-                               builder.Append (genericParameter.Position);
-                       }
-
-                       public void VisitTypeReference (TypeReference typeReference, StringBuilder builder, ITryResolveMetadata resolver)
-                       {
-                               switch (typeReference) {
-                               case ByReferenceType byReferenceType:
-                                       VisitByReferenceType (byReferenceType, builder, resolver);
-                                       return;
-                               case PointerType pointerType:
-                                       VisitPointerType (pointerType, builder, resolver);
-                                       return;
-                               case ArrayType arrayType:
-                                       VisitArrayType (arrayType, builder, resolver);
-                                       return;
-                               case GenericParameter genericParameter:
-                                       VisitGenericParameter (genericParameter, builder);
-                                       return;
-                               }
-
-                               if (typeReference.IsNested) {
-                                       Debug.Assert (typeReference is not SentinelType && typeReference is not PinnedType);
-                                       // GetInflatedDeclaringType may return null for generic parameters, byrefs, and pointers, but these
-                                       // are separately handled above.
-                                       VisitTypeReference (typeReference.GetInflatedDeclaringType (resolver)!, builder, resolver);
-                                       builder.Append ('.');
-                               }
-
-                               if (!String.IsNullOrEmpty (typeReference.Namespace))
-                                       builder.Append (typeReference.Namespace).Append ('.');
-
-                               // This includes '`n' for mangled generic types
-                               builder.Append (typeReference.Name);
-
-                               // For uninstantiated generic types (we already built the mangled name)
-                               // or non-generic types, we are done.
-                               if (typeReference.HasGenericParameters || typeReference is not GenericInstanceType genericInstance)
-                                       return;
-
-                               // Compute arity counting only the newly-introduced generic parameters
-                               var declaringType = genericInstance.DeclaringType;
-                               var declaringArity = 0;
-                               if (declaringType != null && declaringType.HasGenericParameters)
-                                       declaringArity = declaringType.GenericParameters.Count;
-                               var totalArity = genericInstance.GenericArguments.Count;
-                               var arity = totalArity - declaringArity;
-
-                               // Un-mangle the generic type name
-                               var suffixLength = arity.ToString ().Length + 1;
-                               builder.Remove (builder.Length - suffixLength, suffixLength);
-
-                               // Append type arguments excluding arguments for re-declared parent generic parameters
-                               builder.Append ('{');
-                               bool needsComma = false;
-                               for (int i = totalArity - arity; i < totalArity; ++i) {
-                                       if (needsComma)
-                                               builder.Append (',');
-                                       var typeArgument = genericInstance.GenericArguments[i];
-                                       VisitTypeReference (typeArgument, builder, resolver);
-                                       needsComma = true;
-                               }
-                               builder.Append ('}');
-                       }
-
-                       public void VisitPointerType (PointerType pointerType, StringBuilder builder, ITryResolveMetadata resolver)
-                       {
-                               VisitTypeReference (pointerType.ElementType, builder, resolver);
-                               builder.Append ('*');
-                       }
-
-                       public void VisitByReferenceType (ByReferenceType byReferenceType, StringBuilder builder, ITryResolveMetadata resolver)
-                       {
-                               VisitTypeReference (byReferenceType.ElementType, builder, resolver);
-                               builder.Append ('@');
-                       }
-
-                       private static string GetEscapedMetadataName (IMemberDefinition member)
-                       {
-                               var name = member.Name.Replace ('.', '#');
-                               // Not sure if the following replacements are necessary, but
-                               // they are included to match Roslyn.
-                               return name.Replace ('<', '{').Replace ('>', '}');
-                       }
-               }
-       }
-}
\ No newline at end of file
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Logging/ReferenceSource/DocumentationSignatureParser.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Logging/ReferenceSource/DocumentationSignatureParser.cs
deleted file mode 100644 (file)
index 8a6594e..0000000
+++ /dev/null
@@ -1,726 +0,0 @@
-// 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.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-using System.Text;
-using Mono.Cecil;
-using Mono.Collections.Generic;
-
-namespace Mono.Linker
-{
-       /// <summary>
-       ///  Parses a signature for a member, in the format used for C# Documentation Comments:
-       ///  https://github.com/dotnet/csharplang/blob/master/spec/documentation-comments.md#id-string-format
-       ///  Adapted from Roslyn's DocumentationCommentId:
-       ///  https://github.com/dotnet/roslyn/blob/master/src/Compilers/Core/Portable/DocumentationCommentId.cs
-       /// </summary>
-       ///
-       /// Roslyn's API works with ISymbol, which represents a symbol exposed by the compiler.
-       /// a Symbol has information about the source language, name, metadata name,
-       /// containing scopes, visibility/accessibility, attributes, etc.
-       /// This API instead works with the Cecil OM. It can be used to refer to IL definitions
-       /// where the signature of a member can contain references to instantiated generics.
-       ///
-       public static class DocumentationSignatureParser
-       {
-               [Flags]
-               public enum MemberType
-               {
-                       Method = 0x0001,
-                       Field = 0x0002,
-                       Type = 0x0004,
-                       Property = 0x0008,
-                       Event = 0x0010,
-                       All = Method | Field | Type | Property | Event
-               }
-
-               public static IEnumerable<IMemberDefinition> GetMembersForDocumentationSignature (string id, ModuleDefinition module, ITryResolveMetadata resolver)
-               {
-                       var results = new List<IMemberDefinition> ();
-                       if (id == null || module == null)
-                               return results;
-
-                       ParseDocumentationSignature (id, module, results, resolver);
-                       return results;
-               }
-
-               // Takes a documentation signature (not including the documentation member type prefix) and resolves it to a type
-               // in the assembly.
-               public static TypeDefinition? GetTypeByDocumentationSignature (AssemblyDefinition assembly, string signature, ITryResolveMetadata resolver)
-               {
-                       int index = 0;
-                       var results = new List<IMemberDefinition> ();
-                       DocumentationSignatureParser.ParseSignaturePart (signature, ref index, assembly.MainModule, DocumentationSignatureParser.MemberType.Type, results, resolver);
-                       Debug.Assert (results.Count <= 1);
-                       return results.Count == 0 ? null : (TypeDefinition) results[0];
-               }
-
-               // Takes a member signature (not including the declaring type) and returns the matching members on the type.
-               public static IEnumerable<IMemberDefinition> GetMembersByDocumentationSignature (TypeDefinition type, string signature, ITryResolveMetadata resolver, bool acceptName = false)
-               {
-                       int index = 0;
-                       var results = new List<IMemberDefinition> ();
-                       var nameBuilder = new StringBuilder ();
-                       var (name, arity) = DocumentationSignatureParser.ParseTypeOrNamespaceName (signature, ref index, nameBuilder);
-                       DocumentationSignatureParser.GetMatchingMembers (signature, ref index, type.Module, type, name, arity, DocumentationSignatureParser.MemberType.All, results, resolver, acceptName);
-                       return results;
-               }
-
-               static string GetSignaturePart (TypeReference type, ITryResolveMetadata resolver)
-               {
-                       var builder = new StringBuilder ();
-                       DocumentationSignatureGenerator.PartVisitor.Instance.VisitTypeReference (type, builder, resolver);
-                       return builder.ToString ();
-               }
-
-               static bool ParseDocumentationSignature (string id, ModuleDefinition module, List<IMemberDefinition> results, ITryResolveMetadata resolver)
-               {
-                       if (id == null)
-                               return false;
-
-                       if (id.Length < 2)
-                               return false;
-
-                       int index = 0;
-                       results.Clear ();
-                       ParseSignature (id, ref index, module, results, resolver);
-                       return results.Count > 0;
-               }
-
-               static void ParseSignature (string id, ref int index, ModuleDefinition module, List<IMemberDefinition> results, ITryResolveMetadata resolver)
-               {
-                       Debug.Assert (results.Count == 0);
-                       var memberTypeChar = PeekNextChar (id, index);
-                       MemberType memberType;
-
-                       switch (memberTypeChar) {
-                       case 'E':
-                               memberType = MemberType.Event;
-                               break;
-                       case 'F':
-                               memberType = MemberType.Field;
-                               break;
-                       case 'M':
-                               memberType = MemberType.Method;
-                               break;
-                       case 'N':
-                               // We do not support namespaces, which do not exist in IL.
-                               return;
-                       case 'P':
-                               memberType = MemberType.Property;
-                               break;
-                       case 'T':
-                               memberType = MemberType.Type;
-                               break;
-                       default:
-                               // Documentation comment id must start with E, F, M, P, or T
-                               return;
-                       }
-
-                       index++;
-                       // Note: this allows leaving out the ':'.
-                       if (PeekNextChar (id, index) == ':')
-                               index++;
-
-                       ParseSignaturePart (id, ref index, module, memberType, results, resolver);
-               }
-
-               // Parses and resolves a fully-qualified (namespace and nested types but no assembly) member signature,
-               // without the member type prefix. The results include all members matching the specified member types.
-               public static void ParseSignaturePart (string id, ref int index, ModuleDefinition module, MemberType memberTypes, List<IMemberDefinition> results, ITryResolveMetadata resolver)
-               {
-                       // Roslyn resolves types by searching namespaces top-down.
-                       // We don't have namespace info. Instead try treating each part of a
-                       // dotted name as a type first, then as a namespace if it fails
-                       // to resolve to a type.
-                       TypeDefinition? containingType = null;
-                       var nameBuilder = new StringBuilder ();
-
-                       string name;
-                       int arity;
-
-                       // process dotted names
-                       while (true) {
-                               (name, arity) = ParseTypeOrNamespaceName (id, ref index, nameBuilder);
-                               // if we are at the end of the dotted name and still haven't resolved it to
-                               // a type, there are no results.
-                               if (String.IsNullOrEmpty (name))
-                                       return;
-
-                               // no more dots, so don't loop any more
-                               if (PeekNextChar (id, index) != '.')
-                                       break;
-
-                               // must be a namespace or type since name continues after dot
-                               index++;
-
-                               // try to resolve it as a type
-                               var typeOrNamespaceName = nameBuilder.ToString ();
-                               GetMatchingTypes (module, declaringType: containingType, name: typeOrNamespaceName, arity: arity, results: results, resolver);
-                               Debug.Assert (results.Count <= 1);
-                               if (results.Any ()) {
-                                       // the name resolved to a type
-                                       var result = results.Single ();
-                                       Debug.Assert (result is TypeDefinition);
-                                       // result becomes the new container
-                                       containingType = result as TypeDefinition;
-                                       nameBuilder.Clear ();
-                                       results.Clear ();
-                                       continue;
-                               }
-
-                               // it didn't resolve as a type.
-
-                               // only types have arity.
-                               if (arity > 0)
-                                       return;
-
-                               // treat it as a namespace and continue building up the type name
-                               nameBuilder.Append ('.');
-                       }
-
-                       var memberName = nameBuilder.ToString ();
-                       GetMatchingMembers (id, ref index, module, containingType, memberName, arity, memberTypes, results, resolver);
-               }
-
-               // Gets all members of the specified member kinds of the containing type, with
-               // mathing name, arity, and signature at the current index (for methods and properties).
-               // This will also resolve types from the given module if no containing type is given.
-               public static void GetMatchingMembers (string id, ref int index, ModuleDefinition module, TypeDefinition? containingType, string memberName, int arity, MemberType memberTypes, List<IMemberDefinition> results, ITryResolveMetadata resolver, bool acceptName = false)
-               {
-                       if (memberTypes.HasFlag (MemberType.Type))
-                               GetMatchingTypes (module, containingType, memberName, arity, results, resolver);
-
-                       if (containingType == null)
-                               return;
-
-                       int startIndex = index;
-                       int endIndex = index;
-
-                       if (memberTypes.HasFlag (MemberType.Method)) {
-                               GetMatchingMethods (id, ref index, containingType, memberName, arity, results, resolver, acceptName);
-                               endIndex = index;
-                               index = startIndex;
-                       }
-
-                       if (memberTypes.HasFlag (MemberType.Property)) {
-                               GetMatchingProperties (id, ref index, containingType, memberName, results, resolver, acceptName);
-                               endIndex = index;
-                               index = startIndex;
-                       }
-
-                       index = endIndex;
-
-                       if (memberTypes.HasFlag (MemberType.Event))
-                               GetMatchingEvents (containingType, memberName, results);
-
-                       if (memberTypes.HasFlag (MemberType.Field))
-                               GetMatchingFields (containingType, memberName, results);
-               }
-
-               // Parses a part of a dotted declaration name, including generic definitions.
-               // Returns the name (either a namespace or the unmangled name of a C# type) and an arity
-               // which may be non-zero for generic types.
-               public static (string name, int arity) ParseTypeOrNamespaceName (string id, ref int index, StringBuilder nameBuilder)
-               {
-                       var name = ParseName (id, ref index);
-                       // don't parse ` after an empty name
-                       if (string.IsNullOrEmpty (name))
-                               return (name, 0);
-
-                       nameBuilder.Append (name);
-                       var arity = 0;
-
-                       // has type parameters?
-                       if (PeekNextChar (id, index) == '`') {
-                               index++;
-
-                               bool genericType = true;
-
-                               // method type parameters?
-                               // note: this allows `` for type parameters
-                               if (PeekNextChar (id, index) == '`') {
-                                       index++;
-                                       genericType = false;
-                               }
-
-                               arity = ReadNextInteger (id, ref index);
-
-                               if (genericType) {
-                                       // We need to mangle generic type names but not generic method names.
-                                       nameBuilder.Append ('`');
-                                       nameBuilder.Append (arity);
-                               }
-                       }
-
-                       return (name, arity);
-               }
-
-               // Roslyn resolves types in a signature to their declaration by searching through namespaces.
-               // To avoid looking for types by name in all referenced assemblies, we just represent types
-               // that are part of a signature by their doc comment strings, and we check for matching
-               // strings when looking for matching member signatures.
-               static string? ParseTypeSymbol (string id, ref int index, IGenericParameterProvider? typeParameterContext)
-               {
-                       var results = new List<string> ();
-                       ParseTypeSymbol (id, ref index, typeParameterContext, results);
-                       if (results.Count == 1)
-                               return results[0];
-
-                       Debug.Assert (results.Count == 0);
-                       return null;
-               }
-
-               static void ParseTypeSymbol (string id, ref int index, IGenericParameterProvider? typeParameterContext, List<string> results)
-               {
-                       // Note: Roslyn has a special case that deviates from the language spec, which
-                       // allows context expressions embedded in a type reference => <context-definition>:<type-parameter>
-                       // We do not support this special format.
-
-                       Debug.Assert (results.Count == 0);
-
-                       if (PeekNextChar (id, index) == '`')
-                               ParseTypeParameterSymbol (id, ref index, typeParameterContext, results);
-                       else
-                               ParseNamedTypeSymbol (id, ref index, typeParameterContext, results);
-
-                       // apply any array or pointer constructions to results
-                       var startIndex = index;
-                       var endIndex = index;
-
-                       for (int i = 0; i < results.Count; i++) {
-                               index = startIndex;
-                               var typeReference = results[i];
-
-                               while (true) {
-                                       if (PeekNextChar (id, index) == '[') {
-                                               var boundsStartIndex = index;
-                                               var bounds = ParseArrayBounds (id, ref index);
-                                               var boundsEndIndex = index;
-                                               Debug.Assert (bounds > 0);
-                                               // Instead of constructing a representation of the array bounds, we
-                                               // use the original input to represent the bounds, and later match it
-                                               // against the generated strings for types in signatures.
-                                               // This ensures that we will only resolve members with supported array bounds.
-                                               typeReference += id.Substring (boundsStartIndex, boundsEndIndex - boundsStartIndex);
-                                               continue;
-                                       }
-
-                                       if (PeekNextChar (id, index) == '*') {
-                                               index++;
-                                               typeReference += '*';
-                                               continue;
-                                       }
-
-                                       break;
-                               }
-
-                               if (PeekNextChar (id, index) == '@') {
-                                       index++;
-                                       typeReference += '@';
-                               }
-
-                               results[i] = typeReference;
-                               endIndex = index;
-                       }
-
-                       index = endIndex;
-               }
-
-               static void ParseTypeParameterSymbol (string id, ref int index, IGenericParameterProvider? typeParameterContext, List<string> results)
-               {
-                       // skip the first `
-                       Debug.Assert (PeekNextChar (id, index) == '`');
-                       index++;
-
-                       Debug.Assert (
-                               typeParameterContext == null ||
-                               (typeParameterContext is MethodDefinition && typeParameterContext.GenericParameterType == GenericParameterType.Method) ||
-                               (typeParameterContext is TypeDefinition && typeParameterContext.GenericParameterType == GenericParameterType.Type)
-                       );
-
-                       if (PeekNextChar (id, index) == '`') {
-                               // `` means this is a method type parameter
-                               index++;
-                               var methodTypeParameterIndex = ReadNextInteger (id, ref index);
-
-                               if (typeParameterContext is MethodDefinition methodContext) {
-                                       var count = methodContext.HasGenericParameters ? methodContext.GenericParameters.Count : 0;
-                                       if (count > 0 && methodTypeParameterIndex < count) {
-                                               results.Add ("``" + methodTypeParameterIndex);
-                                       }
-                               }
-                       } else {
-                               // regular type parameter
-                               var typeParameterIndex = ReadNextInteger (id, ref index);
-
-                               var typeContext = typeParameterContext is MethodDefinition methodContext
-                                       ? methodContext.DeclaringType
-                                       : typeParameterContext as TypeDefinition;
-
-                               if (typeParameterIndex >= 0 ||
-                                       typeParameterIndex < typeContext?.GenericParameters.Count) {
-                                       // No need to look at declaring types like Roslyn, because type parameters are redeclared.
-                                       results.Add ("`" + typeParameterIndex);
-                               }
-                       }
-               }
-
-               static void ParseNamedTypeSymbol (string id, ref int index, IGenericParameterProvider? typeParameterContext, List<string> results)
-               {
-                       Debug.Assert (results.Count == 0);
-                       var nameBuilder = new StringBuilder ();
-                       // loop for dotted names
-                       while (true) {
-                               var name = ParseName (id, ref index);
-                               if (String.IsNullOrEmpty (name))
-                                       return;
-
-                               nameBuilder.Append (name);
-
-                               List<string>? typeArguments = null;
-                               int arity = 0;
-
-                               // type arguments
-                               if (PeekNextChar (id, index) == '{') {
-                                       typeArguments = new List<string> ();
-                                       if (!ParseTypeArguments (id, ref index, typeParameterContext, typeArguments)) {
-                                               continue;
-                                       }
-
-                                       arity = typeArguments.Count;
-                               }
-
-                               if (arity != 0) {
-                                       Debug.Assert (typeArguments != null && typeArguments.Count != 0);
-                                       nameBuilder.Append ('{');
-                                       bool needsComma = false;
-                                       foreach (var typeArg in typeArguments) {
-                                               if (needsComma) {
-                                                       nameBuilder.Append (',');
-                                               }
-                                               nameBuilder.Append (typeArg);
-                                               needsComma = true;
-                                       }
-                                       nameBuilder.Append ('}');
-                               }
-
-                               if (PeekNextChar (id, index) != '.')
-                                       break;
-
-                               index++;
-                               nameBuilder.Append ('.');
-                       }
-
-                       results.Add (nameBuilder.ToString ());
-               }
-
-               static int ParseArrayBounds (string id, ref int index)
-               {
-                       index++; // skip '['
-
-                       int bounds = 0;
-
-                       while (true) {
-                               // note: the actual bounds are ignored.
-                               // C# only supports arrays with lower bound zero.
-                               // size is not known.
-
-                               if (char.IsDigit (PeekNextChar (id, index)))
-                                       ReadNextInteger (id, ref index);
-
-                               if (PeekNextChar (id, index) == ':') {
-                                       index++;
-
-                                       // note: the spec says that omitting both the lower bounds and the size
-                                       // should omit the ':' as well, but this allows for it in the input.
-                                       if (char.IsDigit (PeekNextChar (id, index)))
-                                               ReadNextInteger (id, ref index);
-                               }
-
-                               bounds++;
-
-                               if (PeekNextChar (id, index) == ',') {
-                                       index++;
-                                       continue;
-                               }
-
-                               break;
-                       }
-
-                       // note: this allows leaving out the closing ']'
-                       if (PeekNextChar (id, index) == ']')
-                               index++;
-
-                       return bounds;
-               }
-
-               static bool ParseTypeArguments (string id, ref int index, IGenericParameterProvider? typeParameterContext, List<string> typeArguments)
-               {
-                       index++; // skip over {
-
-                       while (true) {
-                               var type = ParseTypeSymbol (id, ref index, typeParameterContext);
-
-                               if (type == null) {
-                                       // if a type argument cannot be identified, argument list is no good
-                                       return false;
-                               }
-
-                               // add first one
-                               typeArguments.Add (type);
-
-                               if (PeekNextChar (id, index) == ',') {
-                                       index++;
-                                       continue;
-                               }
-
-                               break;
-                       }
-
-                       // note: this doesn't require closing }
-                       if (PeekNextChar (id, index) == '}') {
-                               index++;
-                       }
-
-                       return true;
-               }
-
-               static void GetMatchingTypes (ModuleDefinition module, TypeDefinition? declaringType, string name, int arity, List<IMemberDefinition> results, ITryResolveMetadata resolver)
-               {
-                       Debug.Assert (module != null);
-
-                       if (declaringType == null) {
-                               var type = module.ResolveType (name, resolver);
-                               if (type != null) {
-                                       results.Add (type);
-                               }
-                               return;
-                       }
-
-                       if (!declaringType.HasNestedTypes)
-                               return;
-
-                       foreach (var nestedType in declaringType.NestedTypes) {
-                               Debug.Assert (String.IsNullOrEmpty (nestedType.Namespace));
-                               if (nestedType.Name != name)
-                                       continue;
-
-                               // Compute arity counting only the newly-introduced generic parameters
-                               var declaringArity = declaringType.HasGenericParameters ? declaringType.GenericParameters.Count : 0;
-                               int totalArity = nestedType.HasGenericParameters ? nestedType.GenericParameters.Count : 0;
-                               var nestedTypeArity = totalArity - declaringArity;
-                               if (nestedTypeArity != arity)
-                                       continue;
-
-                               results.Add (nestedType);
-                               return;
-                       }
-               }
-
-               static void GetMatchingMethods (string id, ref int index, TypeDefinition? type, string memberName, int arity, List<IMemberDefinition> results, ITryResolveMetadata resolver, bool acceptName = false)
-               {
-                       if (type == null)
-                               return;
-
-                       var parameters = new List<string> ();
-                       var startIndex = index;
-                       var endIndex = index;
-
-                       foreach (var method in type.Methods) {
-                               index = startIndex;
-                               if (method.Name != memberName)
-                                       continue;
-
-                               var methodArity = method.HasGenericParameters ? method.GenericParameters.Count : 0;
-                               if (methodArity != arity)
-                                       continue;
-
-                               parameters.Clear ();
-                               bool isNameOnly = true;
-                               if (PeekNextChar (id, index) == '(') {
-                                       isNameOnly = false;
-                                       // if the parameters cannot be identified (some error), then the symbol cannot match, try next method symbol
-                                       if (!ParseParameterList (id, ref index, method, parameters))
-                                               continue;
-                               }
-
-                               // note: this allows extra characters at the end
-
-                               if (PeekNextChar (id, index) == '~') {
-                                       isNameOnly = false;
-                                       index++;
-                                       string? returnType = ParseTypeSymbol (id, ref index, method);
-                                       if (returnType == null)
-                                               continue;
-
-                                       // if return type is specified, then it must match
-                                       if (GetSignaturePart (method.ReturnType, resolver) != returnType)
-                                               continue;
-                               }
-
-                               if (!isNameOnly || !acceptName) {
-                                       // check parameters unless we are matching a name only
-                                       if (!AllParametersMatch (method.Parameters, parameters, resolver))
-                                               continue;
-                               }
-
-                               results.Add (method);
-                               endIndex = index;
-                       }
-                       index = endIndex;
-               }
-
-               static void GetMatchingProperties (string id, ref int index, TypeDefinition? type, string memberName, List<IMemberDefinition> results, ITryResolveMetadata resolver, bool acceptName = false)
-               {
-                       if (type == null)
-                               return;
-
-                       int startIndex = index;
-                       int endIndex = index;
-
-                       List<string>? parameters = null;
-                       // Unlike Roslyn, we don't need to decode property names because we are working
-                       // directly with IL.
-                       foreach (var property in type.Properties) {
-                               index = startIndex;
-                               if (property.Name != memberName)
-                                       continue;
-                               if (PeekNextChar (id, index) == '(') {
-                                       if (parameters == null) {
-                                               parameters = new List<string> ();
-                                       } else {
-                                               parameters.Clear ();
-                                       }
-                                       if (!ParseParameterList (id, ref index, property.DeclaringType, parameters))
-                                               continue;
-                                       if (!AllParametersMatch (property.Parameters, parameters, resolver))
-                                               continue;
-                               } else {
-                                       if (!acceptName && property.Parameters.Count != 0)
-                                               continue;
-                               }
-                               results.Add (property);
-                               endIndex = index;
-                       }
-
-                       index = endIndex;
-               }
-
-               static void GetMatchingFields (TypeDefinition? type, string memberName, List<IMemberDefinition> results)
-               {
-                       if (type == null)
-                               return;
-                       foreach (var field in type.Fields) {
-                               if (field.Name != memberName)
-                                       continue;
-                               results.Add (field);
-                       }
-               }
-
-               static void GetMatchingEvents (TypeDefinition? type, string memberName, List<IMemberDefinition> results)
-               {
-                       if (type == null)
-                               return;
-                       foreach (var evt in type.Events) {
-                               if (evt.Name != memberName)
-                                       continue;
-                               results.Add (evt);
-                       }
-               }
-
-               static bool AllParametersMatch (Collection<ParameterDefinition> methodParameters, List<string> expectedParameters, ITryResolveMetadata resolver)
-               {
-                       if (methodParameters.Count != expectedParameters.Count)
-                               return false;
-
-                       for (int i = 0; i < expectedParameters.Count; i++) {
-                               if (GetSignaturePart (methodParameters[i].ParameterType, resolver) != expectedParameters[i])
-                                       return false;
-                       }
-
-                       return true;
-               }
-
-               static bool ParseParameterList (string id, ref int index, IGenericParameterProvider typeParameterContext, List<string> parameters)
-               {
-                       System.Diagnostics.Debug.Assert (typeParameterContext != null);
-
-                       index++; // skip over '('
-
-                       if (PeekNextChar (id, index) == ')') {
-                               // note: this will match parameterless methods, or methods with only varargs parameters
-                               index++;
-                               return true;
-                       }
-
-                       string? parameter = ParseTypeSymbol (id, ref index, typeParameterContext);
-                       if (parameter == null)
-                               return false;
-
-                       parameters.Add (parameter);
-
-                       while (PeekNextChar (id, index) == ',') {
-                               index++;
-
-                               parameter = ParseTypeSymbol (id, ref index, typeParameterContext);
-                               if (parameter == null)
-                                       return false;
-
-                               parameters.Add (parameter);
-                       }
-
-                       // note: this doesn't require the trailing ')'
-                       if (PeekNextChar (id, index) == ')') {
-                               index++;
-                       }
-
-                       return true;
-               }
-
-               static char PeekNextChar (string id, int index)
-               {
-                       return index >= id.Length ? '\0' : id[index];
-               }
-
-               static readonly char[] s_nameDelimiters = { ':', '.', '(', ')', '{', '}', '[', ']', ',', '\'', '@', '*', '`', '~' };
-
-               static string ParseName (string id, ref int index)
-               {
-                       string name;
-
-                       int delimiterOffset = id.IndexOfAny (s_nameDelimiters, index);
-                       if (delimiterOffset >= 0) {
-                               name = id.Substring (index, delimiterOffset - index);
-                               index = delimiterOffset;
-                       } else {
-                               name = id.Substring (index);
-                               index = id.Length;
-                       }
-
-                       return DecodeName (name);
-               }
-
-               // undoes dot encodings within names...
-               static string DecodeName (string name)
-               {
-                       return name.Replace ('#', '.');
-               }
-
-               static int ReadNextInteger (string id, ref int index)
-               {
-                       int n = 0;
-
-                       // note: this can overflow
-                       while (index < id.Length && char.IsDigit (id[index])) {
-                               n = n * 10 + (id[index] - '0');
-                               index++;
-                       }
-
-                       return n;
-               }
-       }
-}
\ No newline at end of file
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Logging/ReferenceSource/MessageContainer.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Logging/ReferenceSource/MessageContainer.cs
deleted file mode 100644 (file)
index 1133ce0..0000000
+++ /dev/null
@@ -1,362 +0,0 @@
-// 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.Diagnostics.CodeAnalysis;
-using System.Reflection;
-using System.Text;
-using ILLink.Shared;
-using Mono.Cecil;
-
-namespace Mono.Linker
-{
-       public readonly struct MessageContainer : IComparable<MessageContainer>, IEquatable<MessageContainer>
-       {
-               public static readonly MessageContainer Empty;
-
-               /// <summary>
-               /// Optional data with a filename, line and column that triggered the
-               /// linker to output an error (or warning) message.
-               /// </summary>
-               public MessageOrigin? Origin { get; }
-
-               public MessageCategory Category { get; }
-
-               /// <summary>
-               /// Further categorize the message.
-               /// </summary>
-               public string SubCategory { get; }
-
-               /// <summary>
-               /// Code identifier for errors and warnings reported by the IL linker.
-               /// </summary>
-               public int? Code { get; }
-
-               /// <summary>
-               /// User friendly text describing the error or warning.
-               /// </summary>
-               public string Text { get; }
-
-               /// <summary>
-               /// Create an error message.
-               /// </summary>
-               /// <param name="text">Humanly readable message describing the error</param>
-               /// <param name="code">Unique error ID. Please see https://github.com/dotnet/runtime/blob/main/docs/tools/illink/error-codes.md
-               /// for the list of errors and possibly add a new one</param>
-               /// <param name="subcategory">Optionally, further categorize this error</param>
-               /// <param name="origin">Filename, line, and column where the error was found</param>
-               /// <returns>New MessageContainer of 'Error' category</returns>
-               internal static MessageContainer CreateErrorMessage (string text, int code, string subcategory = MessageSubCategory.None, MessageOrigin? origin = null)
-               {
-                       if (!(code >= 1000 && code <= 2000))
-                               throw new ArgumentOutOfRangeException (nameof (code), $"The provided code '{code}' does not fall into the error category, which is in the range of 1000 to 2000 (inclusive).");
-
-                       return new MessageContainer (MessageCategory.Error, text, code, subcategory, origin);
-               }
-
-               /// <summary>
-               /// Create an error message.
-               /// </summary>
-               /// <param name="origin">Filename, line, and column where the error was found</param>
-               /// <param name="id">Unique error ID. Please see https://github.com/dotnet/runtime/blob/main/docs/tools/illink/error-codes.md
-               /// for the list of errors and possibly add a new one</param>
-               /// <param name="args">Additional arguments to form a humanly readable message describing the warning</param>
-               /// <returns>New MessageContainer of 'Error' category</returns>
-               internal static MessageContainer CreateErrorMessage (MessageOrigin? origin, DiagnosticId id, params string[] args)
-               {
-                       if (!((int) id >= 1000 && (int) id <= 2000))
-                               throw new ArgumentOutOfRangeException (nameof (id), $"The provided code '{(int) id}' does not fall into the error category, which is in the range of 1000 to 2000 (inclusive).");
-
-                       return new MessageContainer (MessageCategory.Error, id, origin: origin, args: args);
-               }
-
-               /// <summary>
-               /// Create a custom error message.
-               /// </summary>
-               /// <param name="text">Humanly readable message describing the error</param>
-               /// <param name="code">A custom error ID. This code should be greater than or equal to 6001
-               /// to avoid any collisions with existing and future linker errors</param>
-               /// <param name="subcategory">Optionally, further categorize this error</param>
-               /// <param name="origin">Filename or member where the error is coming from</param>
-               /// <returns>Custom MessageContainer of 'Error' category</returns>
-               public static MessageContainer CreateCustomErrorMessage (string text, int code, string subcategory = MessageSubCategory.None, MessageOrigin? origin = null)
-               {
-#if DEBUG
-                       Debug.Assert (Assembly.GetCallingAssembly () != typeof (MessageContainer).Assembly,
-                               "'CreateCustomErrorMessage' is intended to be used by external assemblies only. Use 'CreateErrorMessage' instead.");
-#endif
-                       if (code <= 6000)
-                               throw new ArgumentOutOfRangeException (nameof (code), $"The provided code '{code}' does not fall into the permitted range for external errors. To avoid possible collisions " +
-                                       "with existing and future {Constants.ILLink} errors, external messages should use codes starting from 6001.");
-
-                       return new MessageContainer (MessageCategory.Error, text, code, subcategory, origin);
-               }
-
-               /// <summary>
-               /// Create a warning message.
-               /// </summary>
-               /// <param name="context">Context with the relevant warning suppression info.</param>
-               /// <param name="text">Humanly readable message describing the warning</param>
-               /// <param name="code">Unique warning ID. Please see https://github.com/dotnet/runtime/blob/main/docs/tools/illink/error-codes.md
-               /// for the list of warnings and possibly add a new one</param>
-               /// /// <param name="origin">Filename or member where the warning is coming from</param>
-               /// <param name="subcategory">Optionally, further categorize this warning</param>
-               /// <param name="version">Optional warning version number. Versioned warnings can be controlled with the
-               /// warning wave option --warn VERSION. Unversioned warnings are unaffected by this option. </param>
-               /// <returns>New MessageContainer of 'Warning' category</returns>
-               internal static MessageContainer CreateWarningMessage (LinkContext context, string text, int code, MessageOrigin origin, WarnVersion version, string subcategory = MessageSubCategory.None)
-               {
-                       if (!(code > 2000 && code <= 6000))
-                               throw new ArgumentOutOfRangeException (nameof (code), $"The provided code '{code}' does not fall into the warning category, which is in the range of 2001 to 6000 (inclusive).");
-
-                       return CreateWarningMessageContainer (context, text, code, origin, version, subcategory);
-               }
-
-               /// <summary>
-               /// Create a warning message.
-               /// </summary>
-               /// <param name="context">Context with the relevant warning suppression info.</param>
-               /// <param name="origin">Filename or member where the warning is coming from</param>
-               /// <param name="id">Unique warning ID. Please see https://github.com/dotnet/runtime/blob/main/docs/tools/illink/error-codes.md
-               /// for the list of warnings and possibly add a new one</param>
-               /// <param name="version">Optional warning version number. Versioned warnings can be controlled with the
-               /// warning wave option --warn VERSION. Unversioned warnings are unaffected by this option. </param>
-               /// <param name="args">Additional arguments to form a humanly readable message describing the warning</param>
-               /// <returns>New MessageContainer of 'Warning' category</returns>
-               internal static MessageContainer CreateWarningMessage (LinkContext context, MessageOrigin origin, DiagnosticId id, WarnVersion version, params string[] args)
-               {
-                       if (!((int) id > 2000 && (int) id <= 6000))
-                               throw new ArgumentOutOfRangeException (nameof (id), $"The provided code '{(int) id}' does not fall into the warning category, which is in the range of 2001 to 6000 (inclusive).");
-
-                       return CreateWarningMessageContainer (context, origin, id, version, id.GetDiagnosticSubcategory (), args);
-               }
-
-               /// <summary>
-               /// Create a custom warning message.
-               /// </summary>
-               /// <param name="context">Context with the relevant warning suppression info.</param>
-               /// <param name="text">Humanly readable message describing the warning</param>
-               /// <param name="code">A custom warning ID. This code should be greater than or equal to 6001
-               /// to avoid any collisions with existing and future linker warnings</param>
-               /// <param name="origin">Filename or member where the warning is coming from</param>
-               /// <param name="version">Optional warning version number. Versioned warnings can be controlled with the
-               /// warning wave option --warn VERSION. Unversioned warnings are unaffected by this option</param>
-               /// <param name="subcategory"></param>
-               /// <returns>Custom MessageContainer of 'Warning' category</returns>
-               public static MessageContainer CreateCustomWarningMessage (LinkContext context, string text, int code, MessageOrigin origin, WarnVersion version, string subcategory = MessageSubCategory.None)
-               {
-#if DEBUG
-                       Debug.Assert (Assembly.GetCallingAssembly () != typeof (MessageContainer).Assembly,
-                               "'CreateCustomWarningMessage' is intended to be used by external assemblies only. Use 'CreateWarningMessage' instead.");
-#endif
-                       if (code <= 6000)
-                               throw new ArgumentOutOfRangeException (nameof (code), $"The provided code '{code}' does not fall into the permitted range for external warnings. To avoid possible collisions " +
-                                       $"with existing and future {Constants.ILLink} warnings, external messages should use codes starting from 6001.");
-
-                       return CreateWarningMessageContainer (context, text, code, origin, version, subcategory);
-               }
-
-               private static MessageContainer CreateWarningMessageContainer (LinkContext context, string text, int code, MessageOrigin origin, WarnVersion version, string subcategory = MessageSubCategory.None)
-               {
-                       if (!(version >= WarnVersion.ILLink0 && version <= WarnVersion.Latest))
-                               throw new ArgumentException ($"The provided warning version '{version}' is invalid.");
-
-                       if (context.IsWarningSuppressed (code, origin))
-                               return Empty;
-
-                       if (version > context.WarnVersion)
-                               return Empty;
-
-                       if (TryLogSingleWarning (context, code, origin, subcategory))
-                               return Empty;
-
-                       if (context.IsWarningAsError (code))
-                               return new MessageContainer (MessageCategory.WarningAsError, text, code, subcategory, origin);
-
-                       return new MessageContainer (MessageCategory.Warning, text, code, subcategory, origin);
-               }
-
-               private static MessageContainer CreateWarningMessageContainer (LinkContext context, MessageOrigin origin, DiagnosticId id, WarnVersion version, string subcategory, params string[] args)
-               {
-                       if (!(version >= WarnVersion.ILLink0 && version <= WarnVersion.Latest))
-                               throw new ArgumentException ($"The provided warning version '{version}' is invalid.");
-
-                       if (context.IsWarningSuppressed ((int) id, origin))
-                               return Empty;
-
-                       if (version > context.WarnVersion)
-                               return Empty;
-
-                       if (TryLogSingleWarning (context, (int) id, origin, subcategory))
-                               return Empty;
-
-                       if (context.IsWarningAsError ((int) id))
-                               return new MessageContainer (MessageCategory.WarningAsError, id, subcategory, origin, args);
-
-                       return new MessageContainer (MessageCategory.Warning, id, subcategory, origin, args);
-               }
-
-               public bool IsWarningMessage ([NotNullWhen (true)] out int? code)
-               {
-                       code = null;
-
-                       if (Category is MessageCategory.Warning or MessageCategory.WarningAsError) {
-                               // Warning messages always have a code.
-                               code = Code!;
-                               return true;
-                       }
-
-                       return false;
-               }
-
-               static bool TryLogSingleWarning (LinkContext context, int code, MessageOrigin origin, string subcategory)
-               {
-                       if (subcategory != MessageSubCategory.TrimAnalysis)
-                               return false;
-
-                       // There are valid cases where we can't map the message to an assembly
-                       // For example if it's caused by something in an xml file passed on the command line
-                       // In that case, give up on single-warn collapse and just print out the warning on its own.
-                       var assembly = origin.Provider switch {
-                               AssemblyDefinition asm => asm,
-                               TypeDefinition type => type.Module.Assembly,
-                               IMemberDefinition member => member.DeclaringType.Module.Assembly,
-                               _ => null
-                       };
-
-                       if (assembly == null)
-                               return false;
-
-                       // Any IL2026 warnings left in an assembly with an IsTrimmable attribute are considered intentional
-                       // and should not be collapsed, so that the user-visible RUC message gets printed.
-                       if (code == 2026 && context.IsTrimmable (assembly))
-                               return false;
-
-                       var assemblyName = assembly.Name.Name;
-                       if (!context.IsSingleWarn (assemblyName))
-                               return false;
-
-                       if (context.AssembliesWithGeneratedSingleWarning.Add (assemblyName))
-                               context.LogWarning (context.GetAssemblyLocation (assembly), DiagnosticId.AssemblyProducedTrimWarnings, assemblyName);
-
-                       return true;
-               }
-
-               /// <summary>
-               /// Create a info message.
-               /// </summary>
-               /// <param name="text">Humanly readable message</param>
-               /// <returns>New MessageContainer of 'Info' category</returns>
-               public static MessageContainer CreateInfoMessage (string text)
-               {
-                       return new MessageContainer (MessageCategory.Info, text, null);
-               }
-
-               /// <summary>
-               /// Create a diagnostics message.
-               /// </summary>
-               /// <param name="text">Humanly readable message</param>
-               /// <returns>New MessageContainer of 'Diagnostic' category</returns>
-               public static MessageContainer CreateDiagnosticMessage (string text)
-               {
-                       return new MessageContainer (MessageCategory.Diagnostic, text, null);
-               }
-
-               private MessageContainer (MessageCategory category, string text, int? code, string subcategory = MessageSubCategory.None, MessageOrigin? origin = null)
-               {
-                       Code = code;
-                       Category = category;
-                       Origin = origin;
-                       SubCategory = subcategory;
-                       Text = text;
-               }
-
-               private MessageContainer (MessageCategory category, DiagnosticId id, string subcategory = MessageSubCategory.None, MessageOrigin? origin = null, params string[] args)
-               {
-                       Code = (int) id;
-                       Category = category;
-                       Origin = origin;
-                       SubCategory = subcategory;
-                       Text = new DiagnosticString (id).GetMessage (args);
-               }
-
-               public override string ToString () => ToMSBuildString ();
-
-               public string ToMSBuildString ()
-               {
-                       const string originApp = Constants.ILLink;
-                       string origin = Origin?.ToString () ?? originApp;
-
-                       StringBuilder sb = new StringBuilder ();
-                       sb.Append (origin).Append (":");
-
-                       if (!string.IsNullOrEmpty (SubCategory))
-                               sb.Append (" ").Append (SubCategory);
-
-                       string cat;
-                       switch (Category) {
-                       case MessageCategory.Error:
-                       case MessageCategory.WarningAsError:
-                               cat = "error";
-                               break;
-                       case MessageCategory.Warning:
-                               cat = "warning";
-                               break;
-                       default:
-                               cat = "";
-                               break;
-                       }
-
-                       if (!string.IsNullOrEmpty (cat)) {
-                               sb.Append (" ")
-                                       .Append (cat)
-                                       .Append (" IL")
-                                       // Warning and error messages always have a code.
-                                       .Append (Code!.Value.ToString ("D4"))
-                                       .Append (": ");
-                       } else {
-                               sb.Append (" ");
-                       }
-
-                       if (Origin?.Provider != null) {
-                               if (Origin?.Provider is MethodDefinition method)
-                                       sb.Append (method.GetDisplayName ());
-                               else if (Origin?.Provider is MemberReference memberRef)
-                                       sb.Append (memberRef.GetDisplayName ());
-                               else if (Origin?.Provider is IMemberDefinition member)
-                                       sb.Append (member.FullName);
-                               else if (Origin?.Provider is AssemblyDefinition assembly)
-                                       sb.Append (assembly.Name.Name);
-                               else
-                                       throw new NotSupportedException ();
-
-                               sb.Append (": ");
-                       }
-
-                       // Expected output $"{FileName(SourceLine, SourceColumn)}: {SubCategory}{Category} IL{Code}: ({MemberDisplayName}: ){Text}");
-                       sb.Append (Text);
-                       return sb.ToString ();
-               }
-
-               public bool Equals (MessageContainer other) =>
-                       (Category, Text, Code, SubCategory, Origin) == (other.Category, other.Text, other.Code, other.SubCategory, other.Origin);
-
-               public override bool Equals (object? obj) => obj is MessageContainer messageContainer && Equals (messageContainer);
-               public override int GetHashCode () => (Category, Text, Code, SubCategory, Origin).GetHashCode ();
-
-               public int CompareTo (MessageContainer other)
-               {
-                       if (Origin != null && other.Origin != null) {
-                               return Origin.Value.CompareTo (other.Origin.Value);
-                       } else if (Origin == null && other.Origin == null) {
-                               return (Code < other.Code) ? -1 : 1;
-                       }
-
-                       return (Origin == null) ? 1 : -1;
-               }
-
-               public static bool operator == (MessageContainer lhs, MessageContainer rhs) => lhs.Equals (rhs);
-               public static bool operator != (MessageContainer lhs, MessageContainer rhs) => !lhs.Equals (rhs);
-       }
-}
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Logging/ReferenceSource/MessageOrigin.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Logging/ReferenceSource/MessageOrigin.cs
deleted file mode 100644 (file)
index 62de5fb..0000000
+++ /dev/null
@@ -1,163 +0,0 @@
-// 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.Linq;
-using System.Text;
-using Mono.Cecil;
-using Mono.Cecil.Cil;
-
-namespace Mono.Linker
-{
-       public readonly struct MessageOrigin : IComparable<MessageOrigin>, IEquatable<MessageOrigin>
-       {
-               public string? FileName { get; }
-               public ICustomAttributeProvider? Provider { get; }
-               readonly ICustomAttributeProvider? _suppressionContextMember;
-               public ICustomAttributeProvider? SuppressionContextMember {
-                       get {
-                               Debug.Assert (_suppressionContextMember == null || _suppressionContextMember is IMemberDefinition || _suppressionContextMember is AssemblyDefinition);
-                               return _suppressionContextMember ?? Provider;
-                       }
-               }
-
-               public int SourceLine { get; }
-               public int SourceColumn { get; }
-               public int? ILOffset { get; }
-
-               const int HiddenLineNumber = 0xfeefee;
-
-               public MessageOrigin (IMemberDefinition? memberDefinition, int? ilOffset = null)
-                       : this (memberDefinition as ICustomAttributeProvider, ilOffset)
-               {
-               }
-
-               public MessageOrigin (ICustomAttributeProvider? provider)
-                       : this (provider, null)
-               {
-               }
-
-               public MessageOrigin (string fileName, int sourceLine = 0, int sourceColumn = 0)
-                       : this (fileName, sourceLine, sourceColumn, null)
-               {
-               }
-
-               // The assembly attribute should be specified if available as it allows assigning the diagnostic
-               // to a an assembly (we group based on assembly).
-               public MessageOrigin (string fileName, int sourceLine, int sourceColumn, AssemblyDefinition? assembly)
-               {
-                       FileName = fileName;
-                       SourceLine = sourceLine;
-                       SourceColumn = sourceColumn;
-                       Provider = assembly;
-                       _suppressionContextMember = null;
-                       ILOffset = null;
-               }
-
-               public MessageOrigin (ICustomAttributeProvider? provider, int? ilOffset)
-                       : this (provider, ilOffset, null)
-               {
-               }
-
-               public MessageOrigin (ICustomAttributeProvider? provider, int? ilOffset, ICustomAttributeProvider? suppressionContextMember)
-               {
-                       Debug.Assert (provider == null || provider is IMemberDefinition || provider is AssemblyDefinition);
-                       Debug.Assert (suppressionContextMember == null || suppressionContextMember is IMemberDefinition || provider is AssemblyDefinition);
-                       FileName = null;
-                       Provider = provider;
-                       _suppressionContextMember = suppressionContextMember;
-                       SourceLine = 0;
-                       SourceColumn = 0;
-                       ILOffset = ilOffset;
-               }
-
-               public MessageOrigin (MessageOrigin other, IMemberDefinition? suppressionContextMember)
-               {
-                       FileName = other.FileName;
-                       Provider = other.Provider;
-                       _suppressionContextMember = suppressionContextMember;
-                       SourceLine = other.SourceLine;
-                       SourceColumn = other.SourceColumn;
-                       ILOffset = other.ILOffset;
-               }
-
-               public override string? ToString ()
-               {
-                       int sourceLine = SourceLine, sourceColumn = SourceColumn;
-                       string? fileName = FileName;
-                       if (Provider is MethodDefinition method &&
-                               method.DebugInformation.HasSequencePoints) {
-                               var offset = ILOffset ?? 0;
-                               SequencePoint? correspondingSequencePoint = method.DebugInformation.SequencePoints
-                                       .Where (s => s.Offset <= offset)?.Last ();
-
-                               // If the warning comes from hidden line (compiler generated code typically)
-                               // search for any sequence point with non-hidden line number and report that as a best effort.
-                               if (correspondingSequencePoint?.StartLine == HiddenLineNumber) {
-                                       correspondingSequencePoint = method.DebugInformation.SequencePoints
-                                               .Where (s => s.StartLine != HiddenLineNumber).FirstOrDefault ();
-                               }
-
-                               if (correspondingSequencePoint != null) {
-                                       fileName = correspondingSequencePoint.Document.Url;
-                                       sourceLine = correspondingSequencePoint.StartLine;
-                                       sourceColumn = correspondingSequencePoint.StartColumn;
-                               }
-                       }
-
-                       if (fileName == null)
-                               return null;
-
-                       StringBuilder sb = new StringBuilder (fileName);
-                       if (sourceLine != 0) {
-                               sb.Append ("(").Append (sourceLine);
-                               if (sourceColumn != 0)
-                                       sb.Append (",").Append (sourceColumn);
-
-                               sb.Append (")");
-                       }
-
-                       return sb.ToString ();
-               }
-
-               public bool Equals (MessageOrigin other) =>
-                       (FileName, Provider, SourceLine, SourceColumn, ILOffset) == (other.FileName, other.Provider, other.SourceLine, other.SourceColumn, other.ILOffset);
-
-               public override bool Equals (object? obj) => obj is MessageOrigin messageOrigin && Equals (messageOrigin);
-               public override int GetHashCode () => (FileName, Provider, SourceLine, SourceColumn).GetHashCode ();
-               public static bool operator == (MessageOrigin lhs, MessageOrigin rhs) => lhs.Equals (rhs);
-               public static bool operator != (MessageOrigin lhs, MessageOrigin rhs) => !lhs.Equals (rhs);
-
-               public int CompareTo (MessageOrigin other)
-               {
-                       if (Provider != null && other.Provider != null) {
-                               var thisMember = Provider as IMemberDefinition;
-                               var otherMember = other.Provider as IMemberDefinition;
-                               TypeDefinition? thisTypeDef = (Provider as TypeDefinition) ?? (Provider as IMemberDefinition)?.DeclaringType;
-                               TypeDefinition? otherTypeDef = (other.Provider as TypeDefinition) ?? (other.Provider as IMemberDefinition)?.DeclaringType;
-                               var thisAssembly = thisTypeDef?.Module.Assembly ?? Provider as AssemblyDefinition;
-                               var otherAssembly = otherTypeDef?.Module.Assembly ?? other.Provider as AssemblyDefinition;
-                               int result = (thisAssembly?.Name.Name, thisTypeDef?.Name, thisMember?.Name).CompareTo
-                                       ((otherAssembly?.Name.Name, otherTypeDef?.Name, otherMember?.Name));
-                               if (result != 0)
-                                       return result;
-
-                               if (ILOffset != null && other.ILOffset != null)
-                                       return ILOffset.Value.CompareTo (other.ILOffset);
-
-                               return ILOffset == null ? (other.ILOffset == null ? 0 : 1) : -1;
-                       } else if (Provider == null && other.Provider == null) {
-                               if (FileName != null && other.FileName != null) {
-                                       return string.Compare (FileName, other.FileName);
-                               } else if (FileName == null && other.FileName == null) {
-                                       return (SourceLine, SourceColumn).CompareTo ((other.SourceLine, other.SourceColumn));
-                               }
-
-                               return (FileName == null) ? 1 : -1;
-                       }
-
-                       return (Provider == null) ? 1 : -1;
-               }
-       }
-}
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Logging/ReferenceSource/README.md b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Logging/ReferenceSource/README.md
deleted file mode 100644 (file)
index 4fdfbf1..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Sources from the dotnet/linker repo at commit 2999a6a9dd884d554be18d3c86a4a9db4b61e156.