diff --git a/lib/IRGen/GenDecl.cpp b/lib/IRGen/GenDecl.cpp index 42ba9ef647285..15e88148e0afe 100644 --- a/lib/IRGen/GenDecl.cpp +++ b/lib/IRGen/GenDecl.cpp @@ -34,6 +34,7 @@ #include "swift/SIL/FormalLinkage.h" #include "swift/SIL/SILDebugScope.h" #include "swift/SIL/SILModule.h" +#include "swift/Subsystems.h" #include "clang/AST/ASTContext.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/GlobalDecl.h" @@ -443,7 +444,10 @@ class PrettySynthesizedFileUnitEmission : public llvm::PrettyStackTraceEntry { /// Emit all the top-level code in the source file. void IRGenModule::emitSourceFile(SourceFile &SF) { - assert(SF.ASTStage == SourceFile::TypeChecked); + // Type-check the file if we haven't already (this may be necessary for .sil + // files, which don't get fully type-checked by parsing). + performTypeChecking(SF); + PrettySourceFileEmission StackEntry(SF); // Emit types and other global decls. diff --git a/lib/IRGen/IRGen.cpp b/lib/IRGen/IRGen.cpp index d91af32ed620d..16621cc104274 100644 --- a/lib/IRGen/IRGen.cpp +++ b/lib/IRGen/IRGen.cpp @@ -1447,12 +1447,6 @@ GeneratedModule OptimizedIRRequest::evaluate(Evaluator &evaluator, bindExtensions(*parentMod); - // Type-check the files that need emitting. - for (auto *file : desc.getFiles()) { - if (auto *SF = dyn_cast(file)) - performTypeChecking(*SF); - } - if (ctx.hadError()) return GeneratedModule::null(); diff --git a/lib/SILGen/SILGen.cpp b/lib/SILGen/SILGen.cpp index 4943330220262..a684026797bc8 100644 --- a/lib/SILGen/SILGen.cpp +++ b/lib/SILGen/SILGen.cpp @@ -1884,7 +1884,8 @@ class SILGenModuleRAII { public: void emitSourceFile(SourceFile *sf) { - assert(sf->ASTStage == SourceFile::TypeChecked); + // Type-check the file if we haven't already. + performTypeChecking(*sf); SourceFileScope scope(SGM, sf); for (Decl *D : sf->getTopLevelDecls()) {