[serialization] Record dependencies on other modules.

When loading a module, we now try to load its dependencies as well.
If one of those dependencies can't be loaded, we emit an error message.

Swift SVN r5796
This commit is contained in:
Jordan Rose
2013-06-25 00:47:48 +00:00
parent 8deec52b17
commit 0e4f6c6a12
9 changed files with 156 additions and 16 deletions

View File

@@ -757,6 +757,10 @@ ModuleFile::ModuleFile(llvm::OwningPtr<llvm::MemoryBuffer> &&input)
assert(scratch.empty());
SourcePaths.push_back(blobData);
break;
case input_block::IMPORTED_MODULE:
assert(scratch.empty());
Dependencies.push_back(blobData);
break;
default:
// Unknown input kind, possibly for use by a future version of the
// module format.
@@ -885,6 +889,30 @@ ModuleFile::ModuleFile(llvm::OwningPtr<llvm::MemoryBuffer> &&input)
return error();
}
bool ModuleFile::associateWithModule(Module *module) {
assert(!ModuleContext && "already associated with an AST module");
assert(Status == ModuleStatus::Valid && "invalid module file");
ASTContext &ctx = module->Ctx;
bool missingDependency = false;
for (auto &dependency : Dependencies) {
assert(!dependency.Mod && "already loaded?");
Identifier ID = ctx.getIdentifier(dependency.Name);
// FIXME: Provide a proper source location.
dependency.Mod = ctx.getModule(std::make_pair(ID, SourceLoc()));
if (!dependency.Mod)
missingDependency = true;
}
if (missingDependency) {
error(ModuleStatus::MissingDependency);
return false;
}
ModuleContext = module;
return true;
}
void ModuleFile::buildTopLevelDeclMap() {
// FIXME: be more lazy about deserialization by encoding this some other way.
for (DeclID ID : RawTopLevelIDs) {