mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Serialization] Preserve source order in serialization (#18361)
We previously shied away from this in order to not /accidentally/ depend on it, but it becomes interesting again with textual interfaces, which can certainly be read by humans. The cross-file order is the order of input files, which is at least controllable by users.
This commit is contained in:
@@ -828,6 +828,9 @@ bool ModuleFile::readIndexBlock(llvm::BitstreamCursor &cursor) {
|
||||
assert(blobData.empty());
|
||||
setEntryPointClassID(scratch.front());
|
||||
break;
|
||||
case index_block::ORDERED_TOP_LEVEL_DECLS:
|
||||
OrderedTopLevelDecls.assign(scratch.begin(), scratch.end());
|
||||
break;
|
||||
case index_block::LOCAL_TYPE_DECLS:
|
||||
LocalTypeDecls = readLocalDeclTable(scratch, blobData);
|
||||
break;
|
||||
@@ -1980,48 +1983,15 @@ ModuleFile::collectLinkLibraries(ModuleDecl::LinkLibraryCallback callback) const
|
||||
|
||||
void ModuleFile::getTopLevelDecls(SmallVectorImpl<Decl *> &results) {
|
||||
PrettyStackTraceModuleFile stackEntry(*this);
|
||||
if (PrecedenceGroupDecls) {
|
||||
for (auto entry : PrecedenceGroupDecls->data()) {
|
||||
for (auto item : entry)
|
||||
results.push_back(getDecl(item.second));
|
||||
}
|
||||
}
|
||||
|
||||
if (OperatorDecls) {
|
||||
for (auto entry : OperatorDecls->data()) {
|
||||
for (auto item : entry)
|
||||
results.push_back(getDecl(item.second));
|
||||
}
|
||||
}
|
||||
|
||||
if (TopLevelDecls) {
|
||||
for (auto entry : TopLevelDecls->data()) {
|
||||
for (auto item : entry) {
|
||||
Expected<Decl *> declOrError = getDeclChecked(item.second);
|
||||
if (!declOrError) {
|
||||
if (!getContext().LangOpts.EnableDeserializationRecovery)
|
||||
fatal(declOrError.takeError());
|
||||
llvm::consumeError(declOrError.takeError());
|
||||
continue;
|
||||
}
|
||||
results.push_back(declOrError.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ExtensionDecls) {
|
||||
for (auto entry : ExtensionDecls->data()) {
|
||||
for (auto item : entry) {
|
||||
Expected<Decl *> declOrError = getDeclChecked(item.second);
|
||||
if (!declOrError) {
|
||||
if (!getContext().LangOpts.EnableDeserializationRecovery)
|
||||
fatal(declOrError.takeError());
|
||||
llvm::consumeError(declOrError.takeError());
|
||||
continue;
|
||||
}
|
||||
results.push_back(declOrError.get());
|
||||
}
|
||||
for (DeclID entry : OrderedTopLevelDecls) {
|
||||
Expected<Decl *> declOrError = getDeclChecked(entry);
|
||||
if (!declOrError) {
|
||||
if (!getContext().LangOpts.EnableDeserializationRecovery)
|
||||
fatal(declOrError.takeError());
|
||||
llvm::consumeError(declOrError.takeError());
|
||||
continue;
|
||||
}
|
||||
results.push_back(declOrError.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user