Skip to content

Commit deebe8b

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.
1 parent 04630a3 commit deebe8b

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
@@ -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,16 @@ 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+
if (SF.Kind != SourceFileKind::REPL &&
711+
SF.Kind != SourceFileKind::SIL &&
712+
!Ctx.LangOpts.DebuggerSupport) {
713+
Ctx.verifyAllLoadedModules();
714+
}
695715
}
696716

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

0 commit comments

Comments
 (0)