Skip to content

Commit 1926cc7

Browse files
committed
Optimize ASTContext::getOpenedArchetypeSignature
Avoid computing and caching a new signature for a plain protocol type when when we can grab the protocol's own identical canonical generic signature
1 parent 421bce3 commit 1926cc7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/AST/ASTContext.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4551,12 +4551,18 @@ CanGenericSignature ASTContext::getSingleGenericParameterSignature() const {
45514551
// constraints while existential values do.
45524552
CanGenericSignature ASTContext::getOpenedArchetypeSignature(CanType existential,
45534553
ModuleDecl *mod) {
4554+
assert(existential.isExistentialType());
4555+
4556+
// The opened archetype signature for a protocol type is identical
4557+
// to the protocol's own canonical generic signature.
4558+
if (const auto protoTy = dyn_cast<ProtocolType>(existential)) {
4559+
return protoTy->getDecl()->getGenericSignature()->getCanonicalSignature();
4560+
}
4561+
45544562
auto found = getImpl().ExistentialSignatures.find(existential);
45554563
if (found != getImpl().ExistentialSignatures.end())
45564564
return found->second;
45574565

4558-
assert(existential.isExistentialType());
4559-
45604566
auto genericParam = GenericTypeParamType::get(0, 0, *this);
45614567
Requirement requirement(RequirementKind::Conformance, genericParam,
45624568
existential);

0 commit comments

Comments
 (0)