[Serialization] Filter Decl to deserialize by their attributes

Add an alternative to getTopLevelDecls and getDeclChecked to limit which
decls are deserialized by first looking at their attributes. If the
attributes are accepted by a function passed as argument the decl is
fully deserialized, otherwise it is ignored.

The filter is included in the signature of existing functions in the
Serilalization services, but I’ve added new methods for it in FileUnit
and its subclasses to leave existing implementations untouched.
This commit is contained in:
Alexis Laferrière
2019-11-19 09:52:18 -08:00
parent f240867732
commit e9abba2eab
9 changed files with 135 additions and 10 deletions

View File

@@ -2539,11 +2539,20 @@ ModuleFile::collectLinkLibraries(ModuleDecl::LinkLibraryCallback callback) const
callback(LinkLibrary(Name, LibraryKind::Framework));
}
void ModuleFile::getTopLevelDecls(SmallVectorImpl<Decl *> &results) {
void ModuleFile::getTopLevelDecls(
SmallVectorImpl<Decl *> &results,
llvm::function_ref<bool(DeclAttributes)> matchAttributes) {
PrettyStackTraceModuleFile stackEntry(*this);
for (DeclID entry : OrderedTopLevelDecls) {
Expected<Decl *> declOrError = getDeclChecked(entry);
Expected<Decl *> declOrError = getDeclChecked(entry, matchAttributes);
if (!declOrError) {
if (declOrError.errorIsA<DeclAttributesDidNotMatch>()) {
// Decl rejected by matchAttributes, ignore it.
assert(matchAttributes);
consumeError(declOrError.takeError());
continue;
}
if (!getContext().LangOpts.EnableDeserializationRecovery)
fatal(declOrError.takeError());
consumeError(declOrError.takeError());