@@ -706,13 +706,15 @@ LoadedFile *SerializedModuleLoaderBase::loadAST(
706
706
std::move (moduleDocInputBuffer),
707
707
std::move (moduleSourceInfoInputBuffer),
708
708
isFramework, loadedModuleFileCore);
709
+ SerializedASTFile *fileUnit = nullptr ;
710
+
709
711
if (loadInfo.status == serialization::Status::Valid) {
710
712
loadedModuleFile =
711
713
std::make_unique<ModuleFile>(std::move (loadedModuleFileCore));
712
714
M.setResilienceStrategy (loadedModuleFile->getResilienceStrategy ());
713
715
714
716
// We've loaded the file. Now try to bring it into the AST.
715
- auto fileUnit = new (Ctx) SerializedASTFile (M, *loadedModuleFile);
717
+ fileUnit = new (Ctx) SerializedASTFile (M, *loadedModuleFile);
716
718
if (loadedModuleFile->isTestable ())
717
719
M.setTestingEnabled ();
718
720
if (loadedModuleFile->arePrivateImportsEnabled ())
@@ -723,8 +725,8 @@ LoadedFile *SerializedModuleLoaderBase::loadAST(
723
725
M.setHasIncrementalInfo ();
724
726
725
727
auto diagLocOrInvalid = diagLoc.getValueOr (SourceLoc ());
726
- loadInfo.status =
727
- loadedModuleFile-> associateWithFileContext ( fileUnit, diagLocOrInvalid);
728
+ loadInfo.status = loadedModuleFile-> associateWithFileContext (
729
+ fileUnit, diagLocOrInvalid, Ctx. LangOpts . AllowModuleWithCompilerErrors );
728
730
729
731
// FIXME: This seems wrong. Overlay for system Clang module doesn't
730
732
// necessarily mean it's "system" module. User can make their own overlay
@@ -734,31 +736,36 @@ LoadedFile *SerializedModuleLoaderBase::loadAST(
734
736
if (shadowed->isSystemModule ())
735
737
M.setIsSystemModule (true );
736
738
737
- if (loadInfo.status == serialization::Status::Valid) {
739
+ if (loadInfo.status == serialization::Status::Valid ||
740
+ (Ctx.LangOpts .AllowModuleWithCompilerErrors &&
741
+ (loadInfo.status == serialization::Status::TargetTooNew ||
742
+ loadInfo.status == serialization::Status::TargetIncompatible))) {
738
743
Ctx.bumpGeneration ();
739
744
LoadedModuleFiles.emplace_back (std::move (loadedModuleFile),
740
745
Ctx.getCurrentGeneration ());
741
746
findOverlayFiles (diagLoc.getValueOr (SourceLoc ()), &M, fileUnit);
742
- return fileUnit;
747
+ } else {
748
+ fileUnit = nullptr ;
743
749
}
744
750
}
745
751
746
- // From here on is the failure path.
747
-
748
- if (diagLoc)
749
- serialization::diagnoseSerializedASTLoadFailure (
750
- Ctx, *diagLoc, loadInfo, moduleBufferID,
751
- moduleDocBufferID, loadedModuleFile.get (), M.getName ());
752
-
753
- // Even though the module failed to load, it's possible its contents include
754
- // a source buffer that need to survive because it's already been used for
755
- // diagnostics.
756
- // Note this is only necessary in case a bridging header failed to load
757
- // during the `associateWithFileContext()` call.
758
- if (loadedModuleFile && loadedModuleFile->mayHaveDiagnosticsPointingAtBuffer ())
759
- OrphanedModuleFiles.push_back (std::move (loadedModuleFile));
752
+ if (loadInfo.status != serialization::Status::Valid) {
753
+ if (diagLoc)
754
+ serialization::diagnoseSerializedASTLoadFailure (
755
+ Ctx, *diagLoc, loadInfo, moduleBufferID, moduleDocBufferID,
756
+ loadedModuleFile.get (), M.getName ());
757
+
758
+ // Even though the module failed to load, it's possible its contents
759
+ // include a source buffer that need to survive because it's already been
760
+ // used for diagnostics.
761
+ // Note this is only necessary in case a bridging header failed to load
762
+ // during the `associateWithFileContext()` call.
763
+ if (loadedModuleFile &&
764
+ loadedModuleFile->mayHaveDiagnosticsPointingAtBuffer ())
765
+ OrphanedModuleFiles.push_back (std::move (loadedModuleFile));
766
+ }
760
767
761
- return nullptr ;
768
+ return fileUnit ;
762
769
}
763
770
764
771
void swift::serialization::diagnoseSerializedASTLoadFailure (
@@ -908,7 +915,8 @@ void swift::serialization::diagnoseSerializedASTLoadFailure(
908
915
// FIXME: This doesn't handle a non-debugger REPL, which should also treat
909
916
// this as a non-fatal error.
910
917
auto diagKind = diag::serialization_target_incompatible;
911
- if (Ctx.LangOpts .DebuggerSupport )
918
+ if (Ctx.LangOpts .DebuggerSupport ||
919
+ Ctx.LangOpts .AllowModuleWithCompilerErrors )
912
920
diagKind = diag::serialization_target_incompatible_repl;
913
921
Ctx.Diags .diagnose (diagLoc, diagKind, ModuleName, loadInfo.targetTriple ,
914
922
moduleBufferID);
@@ -926,7 +934,8 @@ void swift::serialization::diagnoseSerializedASTLoadFailure(
926
934
// FIXME: This doesn't handle a non-debugger REPL, which should also treat
927
935
// this as a non-fatal error.
928
936
auto diagKind = diag::serialization_target_too_new;
929
- if (Ctx.LangOpts .DebuggerSupport )
937
+ if (Ctx.LangOpts .DebuggerSupport ||
938
+ Ctx.LangOpts .AllowModuleWithCompilerErrors )
930
939
diagKind = diag::serialization_target_too_new_repl;
931
940
Ctx.Diags .diagnose (diagLoc, diagKind, compilationOSInfo.first ,
932
941
compilationOSInfo.second , ModuleName,
0 commit comments