[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:
Jordan Rose
2018-07-31 13:15:07 -07:00
committed by GitHub
parent 3439333f79
commit 2dfa303975
12 changed files with 229 additions and 238 deletions

View File

@@ -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());
}
}