mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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:
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user