Skip to content

Commit 283f73b

Browse files
committed
performTypeChecking: Defer verifyAllLoadedModules in WMO mode.
Suggested by Jordan Rose. Defer per-file verification in whole-module mode. Verifying imports between files could cause the importer to cache declarations without adding them to the ASTContext. This happens when the importer registers a declaration without a valid TypeChecker instance, as is the case during verification. A subsequent file may require that declaration to be fully imported (e.g. to synthesized a function body), but since it has already been cached, it will never be added to the ASTContext. The solution is to skip verification and avoid caching it. Instead, loaded modules are now verified in WMO mode once during performWholeModuleTypeChecking. Fixes <rdar:36801676> [Edge][swift 4.1] SIL verification failed: external declarations of SILFunctions with shared visibility is not allowed. (cherry picked from commit deebe8b)
1 parent ea92fb7 commit 283f73b

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

lib/Sema/TypeChecker.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,18 @@ void swift::performTypeChecking(SourceFile &SF, TopLevelContext &TLC,
671671
verify(SF);
672672

673673
// Verify imported modules.
674+
//
675+
// Skip per-file verification in whole-module mode. Verifying imports
676+
// between files could cause the importer to cache declarations without
677+
// adding them to the ASTContext. This happens when the importer registers a
678+
// declaration without a valid TypeChecker instance, as is the case during
679+
// verification. A subsequent file may require that declaration to be fully
680+
// imported (e.g. to synthesized a function body), but since it has already
681+
// been cached, it will never be added to the ASTContext. The solution is to
682+
// skip verification and avoid caching it.
674683
#ifndef NDEBUG
675-
if (SF.Kind != SourceFileKind::REPL &&
684+
if (!(Options & TypeCheckingFlags::DelayWholeModuleChecking) &&
685+
SF.Kind != SourceFileKind::REPL &&
676686
SF.Kind != SourceFileKind::SIL &&
677687
!Ctx.LangOpts.DebuggerSupport) {
678688
Ctx.verifyAllLoadedModules();
@@ -688,6 +698,16 @@ void swift::performWholeModuleTypeChecking(SourceFile &SF) {
688698
Ctx.diagnoseObjCMethodConflicts(SF);
689699
Ctx.diagnoseObjCUnsatisfiedOptReqConflicts(SF);
690700
Ctx.diagnoseUnintendedObjCMethodOverrides(SF);
701+
702+
// In whole-module mode, import verification is deferred until all files have
703+
// been type checked. This avoids caching imported declarations when a valid
704+
// type checker is not present. The same declaration may need to be fully
705+
// imported by subsequent files.
706+
if (SF.Kind != SourceFileKind::REPL &&
707+
SF.Kind != SourceFileKind::SIL &&
708+
!Ctx.LangOpts.DebuggerSupport) {
709+
Ctx.verifyAllLoadedModules();
710+
}
691711
}
692712

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

0 commit comments

Comments
 (0)