Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions src/coreclr/tools/Common/TypeSystem/Ecma/EcmaModule.Sorting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Reflection;

using Debug = System.Diagnostics.Debug;

Expand All @@ -14,11 +15,30 @@ public int CompareTo(EcmaModule other)
if (this == other)
return 0;

Guid thisMvid = _metadataReader.GetGuid(_metadataReader.GetModuleDefinition().Mvid);
Guid otherMvid = other._metadataReader.GetGuid(other.MetadataReader.GetModuleDefinition().Mvid);
IAssemblyDesc thisAssembly = Assembly;
IAssemblyDesc otherAssembly = other.Assembly;
if (thisAssembly != otherAssembly)
{
// Each module comes from a different assembly: compare the assemblies
AssemblyName thisAssemblyName = thisAssembly.GetName();
AssemblyName otherAssemblyName = otherAssembly.GetName();

Debug.Assert(thisMvid.CompareTo(otherMvid) != 0, "Different instance of EcmaModule but same MVID?");
return thisMvid.CompareTo(otherMvid);
int compare = StringComparer.Ordinal.Compare(thisAssemblyName.Name, otherAssemblyName.Name);
if (compare != 0)
return compare;

compare = StringComparer.Ordinal.Compare(thisAssemblyName.CultureName, otherAssemblyName.CultureName);
Debug.Assert(compare != 0);
return compare;
}
else
{
// Multi-module assembly: compare two modules that are part of same assembly
string thisName = _metadataReader.GetString(_metadataReader.GetModuleDefinition().Name);
string otherName = other._metadataReader.GetString(other._metadataReader.GetModuleDefinition().Name);
Debug.Assert(StringComparer.Ordinal.Compare(thisName, otherName) != 0);
return StringComparer.Ordinal.Compare(thisName, otherName);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the Debug.Assert get removed for release builds of the compiler? Above you capture the comparison result and use it in the Assert.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, the entire thing in the assert gets removed in non-debug builds. It didn't feel worth it to add the extra line here.

}
}
}
}