Skip to content

Commit 3ee209d

Browse files
committed
AST: Add a fast path for IterableDeclContext::getBodyFingerprint()
getParsedMembers() on imported and deserialized contexts has to pull in all the members. This is wasteful. Imported contexts do not have fingerprints at all, and fingerprints of deserialized contexts are serialized separately. The fast path handles these cases, only calling down to getParsedMembers() if the parent FileUnit is a SourceFile.
1 parent 325ca87 commit 3ee209d

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

lib/AST/DeclContext.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,11 +1038,22 @@ IterableDeclContext::castDeclToIterableDeclContext(const Decl *D) {
10381038
}
10391039

10401040
Optional<Fingerprint> IterableDeclContext::getBodyFingerprint() const {
1041-
auto mutableThis = const_cast<IterableDeclContext *>(this);
1042-
return evaluateOrDefault(getASTContext().evaluator,
1043-
ParseMembersRequest{mutableThis},
1044-
FingerprintAndMembers())
1045-
.fingerprint;
1041+
auto fileUnit = dyn_cast<FileUnit>(getAsGenericContext()->getModuleScopeContext());
1042+
if (!fileUnit)
1043+
return None;
1044+
1045+
if (isa<SourceFile>(fileUnit)) {
1046+
auto mutableThis = const_cast<IterableDeclContext *>(this);
1047+
return evaluateOrDefault(getASTContext().evaluator,
1048+
ParseMembersRequest{mutableThis},
1049+
FingerprintAndMembers())
1050+
.fingerprint;
1051+
}
1052+
1053+
if (getDecl()->isImplicit())
1054+
return None;
1055+
1056+
return fileUnit->loadFingerprint(this);
10461057
}
10471058

10481059
/// Return the DeclContext to compare when checking private access in

0 commit comments

Comments
 (0)