From e5d2c3e7fe8576c6904c9cc4e47acd9c97817f87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Thu, 29 Sep 2022 23:17:23 +0900 Subject: [PATCH] Generate single interface dispatch map per canonical form (#76362) The dispatch maps are identical because canonically-equivalent types have the same vtable layouts. --- .../Compiler/DependencyAnalysis/ConstructedEETypeNode.cs | 3 ++- .../Compiler/DependencyAnalysis/EETypeNode.cs | 3 ++- .../Compiler/DependencyAnalysis/InterfaceDispatchMapNode.cs | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ConstructedEETypeNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ConstructedEETypeNode.cs index 01205d68e86aa..6d734d92ee6e0 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ConstructedEETypeNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ConstructedEETypeNode.cs @@ -38,7 +38,8 @@ protected override DependencyList ComputeNonRelocationBasedDependencies(NodeFact if (MightHaveInterfaceDispatchMap(factory)) { - dependencyList.Add(factory.InterfaceDispatchMap(_type), "Interface dispatch map"); + TypeDesc canonType = _type.ConvertToCanonForm(CanonicalFormKind.Specific); + dependencyList.Add(factory.InterfaceDispatchMap(canonType), "Interface dispatch map"); } if (_type.IsArray) diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/EETypeNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/EETypeNode.cs index 3395c4882ad0f..e159318becaa2 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/EETypeNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/EETypeNode.cs @@ -1056,7 +1056,8 @@ protected internal virtual void ComputeOptionalEETypeFields(NodeFactory factory, { if (!relocsOnly && MightHaveInterfaceDispatchMap(factory)) { - _optionalFieldsBuilder.SetFieldValue(EETypeOptionalFieldTag.DispatchMap, checked((uint)factory.InterfaceDispatchMapIndirection(Type).IndexFromBeginningOfArray)); + TypeDesc canonType = _type.ConvertToCanonForm(CanonicalFormKind.Specific); + _optionalFieldsBuilder.SetFieldValue(EETypeOptionalFieldTag.DispatchMap, checked((uint)factory.InterfaceDispatchMapIndirection(canonType).IndexFromBeginningOfArray)); } ComputeRareFlags(factory, relocsOnly); diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/InterfaceDispatchMapNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/InterfaceDispatchMapNode.cs index 4390f46cfa9f5..08fc5523091d4 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/InterfaceDispatchMapNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/InterfaceDispatchMapNode.cs @@ -22,6 +22,7 @@ public InterfaceDispatchMapNode(NodeFactory factory, TypeDesc type) // Pointer arrays also follow the same path Debug.Assert(!type.IsArrayTypeWithoutGenericInterfaces()); Debug.Assert(MightHaveInterfaceDispatchMap(type, factory)); + Debug.Assert(type.ConvertToCanonForm(CanonicalFormKind.Specific) == type); _type = type; }