Skip to content

Commit

Permalink
Generate single interface dispatch map per canonical form (#76362)
Browse files Browse the repository at this point in the history
The dispatch maps are identical because canonically-equivalent types have the same vtable layouts.
  • Loading branch information
MichalStrehovsky authored Sep 29, 2022
1 parent ed9afa8 commit e5d2c3e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit e5d2c3e

Please sign in to comment.