@@ -675,8 +675,18 @@ void swift::performTypeChecking(SourceFile &SF, TopLevelContext &TLC,
675
675
verify (SF);
676
676
677
677
// Verify imported modules.
678
+ //
679
+ // Skip per-file verification in whole-module mode. Verifying imports
680
+ // between files could cause the importer to cache declarations without
681
+ // adding them to the ASTContext. This happens when the importer registers a
682
+ // declaration without a valid TypeChecker instance, as is the case during
683
+ // verification. A subsequent file may require that declaration to be fully
684
+ // imported (e.g. to synthesized a function body), but since it has already
685
+ // been cached, it will never be added to the ASTContext. The solution is to
686
+ // skip verification and avoid caching it.
678
687
#ifndef NDEBUG
679
- if (SF.Kind != SourceFileKind::REPL &&
688
+ if (!(Options & TypeCheckingFlags::DelayWholeModuleChecking) &&
689
+ SF.Kind != SourceFileKind::REPL &&
680
690
SF.Kind != SourceFileKind::SIL &&
681
691
!Ctx.LangOpts .DebuggerSupport ) {
682
692
Ctx.verifyAllLoadedModules ();
@@ -692,6 +702,21 @@ void swift::performWholeModuleTypeChecking(SourceFile &SF) {
692
702
Ctx.diagnoseObjCMethodConflicts (SF);
693
703
Ctx.diagnoseObjCUnsatisfiedOptReqConflicts (SF);
694
704
Ctx.diagnoseUnintendedObjCMethodOverrides (SF);
705
+
706
+ // In whole-module mode, import verification is deferred until all files have
707
+ // been type checked. This avoids caching imported declarations when a valid
708
+ // type checker is not present. The same declaration may need to be fully
709
+ // imported by subsequent files.
710
+ //
711
+ // FIXME: some playgrounds tests (playground_lvalues.swift) fail with
712
+ // verification enabled.
713
+ #if 0
714
+ if (SF.Kind != SourceFileKind::REPL &&
715
+ SF.Kind != SourceFileKind::SIL &&
716
+ !Ctx.LangOpts.DebuggerSupport) {
717
+ Ctx.verifyAllLoadedModules();
718
+ }
719
+ #endif
695
720
}
696
721
697
722
bool swift::performTypeLocChecking (ASTContext &Ctx, TypeLoc &T,
0 commit comments