Skip to content

Commit 2965c8f

Browse files
authored
Merge pull request #14250 from atrick/fix-wmo-import
2 parents 238b876 + d885078 commit 2965c8f

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

lib/Sema/TypeChecker.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,8 +675,18 @@ void swift::performTypeChecking(SourceFile &SF, TopLevelContext &TLC,
675675
verify(SF);
676676

677677
// 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.
678687
#ifndef NDEBUG
679-
if (SF.Kind != SourceFileKind::REPL &&
688+
if (!(Options & TypeCheckingFlags::DelayWholeModuleChecking) &&
689+
SF.Kind != SourceFileKind::REPL &&
680690
SF.Kind != SourceFileKind::SIL &&
681691
!Ctx.LangOpts.DebuggerSupport) {
682692
Ctx.verifyAllLoadedModules();
@@ -692,6 +702,21 @@ void swift::performWholeModuleTypeChecking(SourceFile &SF) {
692702
Ctx.diagnoseObjCMethodConflicts(SF);
693703
Ctx.diagnoseObjCUnsatisfiedOptReqConflicts(SF);
694704
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
695720
}
696721

697722
bool swift::performTypeLocChecking(ASTContext &Ctx, TypeLoc &T,

0 commit comments

Comments
 (0)