diff --git a/src/coreclr/tools/Common/Compiler/DependencyAnalysis/CompilerComparer.cs b/src/coreclr/tools/Common/Compiler/DependencyAnalysis/CompilerComparer.cs index 632d8f55ff2b4..46f9e704a848b 100644 --- a/src/coreclr/tools/Common/Compiler/DependencyAnalysis/CompilerComparer.cs +++ b/src/coreclr/tools/Common/Compiler/DependencyAnalysis/CompilerComparer.cs @@ -11,6 +11,8 @@ namespace ILCompiler.DependencyAnalysis { public class CompilerComparer : TypeSystemComparer, IComparer { + public static new CompilerComparer Instance { get; } = new CompilerComparer(); + public int Compare(ISortableNode x, ISortableNode y) { if (x == y) diff --git a/src/coreclr/tools/Common/TypeSystem/Sorting/TypeSystemComparer.cs b/src/coreclr/tools/Common/TypeSystem/Sorting/TypeSystemComparer.cs index f648411312cf6..add498968abb1 100644 --- a/src/coreclr/tools/Common/TypeSystem/Sorting/TypeSystemComparer.cs +++ b/src/coreclr/tools/Common/TypeSystem/Sorting/TypeSystemComparer.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Collections.Generic; + using Debug = System.Diagnostics.Debug; namespace Internal.TypeSystem @@ -23,8 +25,10 @@ namespace Internal.TypeSystem // to sort itself with respect to other instances of the same type. // Comparisons between different categories of types are centralized to a single location that // can provide rules to sort them. - public class TypeSystemComparer + public class TypeSystemComparer : IComparer, IComparer, IComparer, IComparer { + public static TypeSystemComparer Instance { get; } = new TypeSystemComparer(); + public int Compare(TypeDesc x, TypeDesc y) { if (x == y) diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/DynamicInvokeTemplateDataNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/DynamicInvokeTemplateDataNode.cs index 87be95102005d..334b73adbddf3 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/DynamicInvokeTemplateDataNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/DynamicInvokeTemplateDataNode.cs @@ -55,12 +55,9 @@ public int GetIdForMethod(MethodDesc dynamicInvokeMethod, NodeFactory factory) private void BuildMethodToIdMap(NodeFactory factory) { + // Get a sorted list of generated stubs List methods = new List(factory.MetadataManager.GetDynamicInvokeTemplateMethods()); - // Sort the stubs - var typeSystemComparer = new TypeSystemComparer(); - methods.Sort((first, second) => typeSystemComparer.Compare(first, second)); - // Assign each stub an ID var methodToTemplateIndex = new Dictionary(); foreach (MethodDesc method in methods) diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/TypeGVMEntriesNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/TypeGVMEntriesNode.cs index fe9d0cd8b8927..47f03b1d824e3 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/TypeGVMEntriesNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/TypeGVMEntriesNode.cs @@ -44,6 +44,8 @@ internal class InterfaceGVMEntryInfo : TypeGVMEntryInfo private readonly TypeDesc _associatedType; private DependencyList _staticDependencies; + public TypeDesc AssociatedType => _associatedType; + public TypeGVMEntriesNode(TypeDesc associatedType) { Debug.Assert(associatedType.IsTypeDefinition); diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/MetadataManager.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/MetadataManager.cs index e655b209a7ac8..a8b7f04e7886a 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/MetadataManager.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/MetadataManager.cs @@ -47,17 +47,18 @@ public abstract class MetadataManager : ICompilationRootProvider protected readonly ManifestResourceBlockingPolicy _resourceBlockingPolicy; protected readonly DynamicInvokeThunkGenerationPolicy _dynamicInvokeThunkGenerationPolicy; - private List _cctorContextsGenerated = new List(); - private readonly HashSet _typesWithEETypesGenerated = new HashSet(); - private readonly HashSet _typesWithConstructedEETypesGenerated = new HashSet(); - private HashSet _methodsGenerated = new HashSet(); - private HashSet _reflectableMethods = new HashSet(); - private HashSet _genericDictionariesGenerated = new HashSet(); - private HashSet _methodBodiesGenerated = new HashSet(); - private List _typeGVMEntries = new List(); - private HashSet _typesWithDelegateMarshalling = new HashSet(); - private HashSet _typesWithStructMarshalling = new HashSet(); - private HashSet _dynamicInvokeTemplates = new HashSet(); + private readonly SortedSet _cctorContextsGenerated = new SortedSet(CompilerComparer.Instance); + private readonly SortedSet _typesWithEETypesGenerated = new SortedSet(TypeSystemComparer.Instance); + private readonly SortedSet _typesWithConstructedEETypesGenerated = new SortedSet(TypeSystemComparer.Instance); + private readonly SortedSet _methodsGenerated = new SortedSet(TypeSystemComparer.Instance); + private readonly SortedSet _reflectableMethods = new SortedSet(TypeSystemComparer.Instance); + private readonly SortedSet _genericDictionariesGenerated = new SortedSet(CompilerComparer.Instance); + private readonly SortedSet _methodBodiesGenerated = new SortedSet(CompilerComparer.Instance); + private readonly SortedSet _typeGVMEntries + = new SortedSet(Comparer.Create((a, b) => TypeSystemComparer.Instance.Compare(a.AssociatedType, b.AssociatedType))); + private readonly SortedSet _typesWithDelegateMarshalling = new SortedSet(TypeSystemComparer.Instance); + private readonly SortedSet _typesWithStructMarshalling = new SortedSet(TypeSystemComparer.Instance); + private readonly SortedSet _dynamicInvokeTemplates = new SortedSet(TypeSystemComparer.Instance); private HashSet _templateMethodEntries = new HashSet(); internal NativeLayoutInfoNode NativeLayoutInfo { get; private set; }