Skip to content

Commit 98b595e

Browse files
committed
[Runtime] Short-circuit search for context descriptor for protocol extensions
When looking for a context descriptor for a protocol extension, we search based on the mangled name--"x", a generic type parameter with depth and index 0--and are guaranteed to fail because there is no such concrete type. However, _findContextDescriptor will fail very slowly, spinning through all of the types and conformances in all of the loaded images. Moreover, negative results aren't cached, so this can happen repeatedly. Short-circuit _findContextDescriptor when it receives a dependent generic type parameter type, avoiding the expensive search when it will find nothing. Potential fix for rdar://problem/53560010.
1 parent 252a072 commit 98b595e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

stdlib/public/runtime/MetadataLookup.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,9 +613,14 @@ _findContextDescriptor(Demangle::NodePointer node,
613613
NodePointer symbolicNode = node;
614614
if (symbolicNode->getKind() == Node::Kind::Type)
615615
symbolicNode = symbolicNode->getChild(0);
616-
if (symbolicNode->getKind() == Node::Kind::TypeSymbolicReference)
616+
if (symbolicNode->getKind() == Node::Kind::TypeSymbolicReference) {
617617
return cast<TypeContextDescriptor>(
618618
(const ContextDescriptor *)symbolicNode->getIndex());
619+
}
620+
621+
// Nothing to resolve if have a generic parameter.
622+
if (symbolicNode->getKind() == Node::Kind::DependentGenericParamType)
623+
return nullptr;
619624

620625
StringRef mangledName =
621626
Demangle::mangleNode(node, ExpandResolvedSymbolicReferences(Dem), Dem);

0 commit comments

Comments
 (0)