[Serialization] Import incompatible targets when allowing errors

If allowing modules to be output with compile errors
(-experimental-allow-module-with-errors), import targets regardless of
whether they are compatible or not, and still output the module. The
error diagnostic will still be output (preventing SILGen), but the AST
will be available for various editor functionality.
This commit is contained in:
Ben Barham
2021-02-23 15:26:28 +10:00
parent 44ed14e646
commit f410958c9c
6 changed files with 66 additions and 30 deletions

View File

@@ -118,12 +118,14 @@ ModuleFile::ModuleFile(std::shared_ptr<const ModuleFileSharedCore> core)
allocateBuffer(Identifiers, core->Identifiers);
}
Status ModuleFile::associateWithFileContext(FileUnit *file, SourceLoc diagLoc) {
Status ModuleFile::associateWithFileContext(FileUnit *file, SourceLoc diagLoc,
bool recoverFromIncompatibility) {
PrettyStackTraceModuleFile stackEntry(*this);
assert(!hasError() && "error already detected; should not call this");
assert(!FileContext && "already associated with an AST module");
FileContext = file;
Status status = Status::Valid;
ModuleDecl *M = file->getParentModule();
if (M->getName().str() != Core->Name)
@@ -134,12 +136,14 @@ Status ModuleFile::associateWithFileContext(FileUnit *file, SourceLoc diagLoc) {
llvm::Triple moduleTarget(llvm::Triple::normalize(Core->TargetTriple));
if (!areCompatibleArchitectures(moduleTarget, ctx.LangOpts.Target) ||
!areCompatibleOSs(moduleTarget, ctx.LangOpts.Target)) {
return error(Status::TargetIncompatible);
}
if (ctx.LangOpts.EnableTargetOSChecking &&
!M->isResilient() &&
isTargetTooNew(moduleTarget, ctx.LangOpts.Target)) {
return error(Status::TargetTooNew);
status = Status::TargetIncompatible;
if (!recoverFromIncompatibility)
return error(status);
} else if (ctx.LangOpts.EnableTargetOSChecking && !M->isResilient() &&
isTargetTooNew(moduleTarget, ctx.LangOpts.Target)) {
status = Status::TargetTooNew;
if (!recoverFromIncompatibility)
return error(status);
}
for (const auto &searchPath : Core->SearchPaths)
@@ -240,7 +244,7 @@ Status ModuleFile::associateWithFileContext(FileUnit *file, SourceLoc diagLoc) {
None);
}
return Status::Valid;
return status;
}
bool ModuleFile::mayHaveDiagnosticsPointingAtBuffer() const {