From cfd03623af5b18e1518521abef482bb77ba71fab Mon Sep 17 00:00:00 2001 From: Hamish Knight Date: Sun, 10 May 2020 19:56:12 -0700 Subject: [PATCH 1/4] [SIL] NFC: Remove a dead declaration --- include/swift/SIL/SILModule.h | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/include/swift/SIL/SILModule.h b/include/swift/SIL/SILModule.h index 096103060b7bd..531dbe15c8c55 100644 --- a/include/swift/SIL/SILModule.h +++ b/include/swift/SIL/SILModule.h @@ -280,8 +280,6 @@ class SILModule { /// invalidation message is sent. llvm::SetVector NotificationHandlers; - // Intentionally marked private so that we need to use 'constructSIL()' - // to construct a SILModule. SILModule(ModuleDecl *M, Lowering::TypeConverter &TC, const SILOptions &Options, const DeclContext *associatedDC, bool wholeModule); @@ -355,17 +353,6 @@ class SILModule { /// Erase a global SIL variable from the module. void eraseGlobalVariable(SILGlobalVariable *G); - /// Construct a SIL module from an AST module. - /// - /// The module will be constructed in the Raw stage. The provided AST module - /// should contain source files. - /// - /// If a source file is provided, SIL will only be emitted for decls in that - /// source file. - static std::unique_ptr - constructSIL(ModuleDecl *M, Lowering::TypeConverter &TC, - const SILOptions &Options, FileUnit *sf = nullptr); - /// Create and return an empty SIL module that we can /// later parse SIL bodies directly into, without converting from an AST. static std::unique_ptr From 2d9b63ed118464058ed33a27d427873f6e2ebf98 Mon Sep 17 00:00:00 2001 From: Hamish Knight Date: Sun, 10 May 2020 19:56:12 -0700 Subject: [PATCH 2/4] A SILModule Always Has An Associated Context Now that the integrated REPL has been removed, there is always an associated decl context, and we can assert as such. --- include/swift/SIL/SILModule.h | 6 +++--- lib/IRGen/IRGenModule.cpp | 11 +++-------- lib/SIL/IR/SIL.cpp | 6 ------ lib/SIL/IR/SILModule.cpp | 2 ++ lib/SILGen/SILGenExpr.cpp | 2 -- .../Transforms/SpeculativeDevirtualizer.cpp | 9 +-------- lib/SILOptimizer/Utils/Devirtualize.cpp | 16 +--------------- lib/SILOptimizer/Utils/InstOptUtils.cpp | 12 ++---------- lib/Serialization/SerializeSIL.cpp | 3 --- 9 files changed, 12 insertions(+), 55 deletions(-) diff --git a/include/swift/SIL/SILModule.h b/include/swift/SIL/SILModule.h index 531dbe15c8c55..9725dae819bf9 100644 --- a/include/swift/SIL/SILModule.h +++ b/include/swift/SIL/SILModule.h @@ -366,15 +366,15 @@ class SILModule { ASTContext &getASTContext() const; SourceManager &getSourceManager() const { return getASTContext().SourceMgr; } - /// Get the Swift DeclContext associated with this SIL module. + /// Get the Swift DeclContext associated with this SIL module. This is never + /// null. /// /// All AST declarations within this context are assumed to have been fully /// processed as part of generating this module. This allows certain passes /// to make additional assumptions about these declarations. /// /// If this is the same as TheSwiftModule, the entire module is being - /// compiled as a single unit. If this is null, no context-based assumptions - /// can be made. + /// compiled as a single unit. const DeclContext *getAssociatedContext() const { return AssociatedDeclContext; } diff --git a/lib/IRGen/IRGenModule.cpp b/lib/IRGen/IRGenModule.cpp index 57c45e86706e0..defef6ecbbc21 100644 --- a/lib/IRGen/IRGenModule.cpp +++ b/lib/IRGen/IRGenModule.cpp @@ -1203,14 +1203,9 @@ static bool isFirstObjectFileInModule(IRGenModule &IGM) { if (IGM.getSILModule().isWholeModule()) return IGM.IRGen.getPrimaryIGM() == &IGM; - const DeclContext *DC = IGM.getSILModule().getAssociatedContext(); - if (!DC) - return false; - - assert(!isa(DC) && "that would be a whole module build"); - assert(isa(DC) && "compiling something smaller than a file?"); - ModuleDecl *containingModule = cast(DC)->getParentModule(); - return containingModule->getFiles().front() == DC; + auto *file = cast(IGM.getSILModule().getAssociatedContext()); + auto *containingModule = file->getParentModule(); + return containingModule->getFiles().front() == file; } void IRGenModule::emitAutolinkInfo() { diff --git a/lib/SIL/IR/SIL.cpp b/lib/SIL/IR/SIL.cpp index 3cf225f96d411..e9c739af20805 100644 --- a/lib/SIL/IR/SIL.cpp +++ b/lib/SIL/IR/SIL.cpp @@ -127,12 +127,6 @@ bool SILModule::isTypeMetadataAccessible(CanType type) { // Private declarations are inaccessible from different files unless // this is WMO and we're in the same module. case FormalLinkage::Private: { - // The only time we don't have an associated DC is in the - // integrated REPL, where we also don't have a concept of other - // source files within the current module. - if (!AssociatedDeclContext) - return (decl->getModuleContext() != getSwiftModule()); - // The associated DC should be either a SourceFile or, in WMO mode, // a ModuleDecl. In the WMO modes, IRGen will ensure that private // declarations are usable throughout the module. Therefore, in diff --git a/lib/SIL/IR/SILModule.cpp b/lib/SIL/IR/SILModule.cpp index b061f08484d08..d285021c14071 100644 --- a/lib/SIL/IR/SILModule.cpp +++ b/lib/SIL/IR/SILModule.cpp @@ -99,6 +99,8 @@ SILModule::SILModule(ModuleDecl *SwiftModule, TypeConverter &TC, AssociatedDeclContext(associatedDC), Stage(SILStage::Raw), wholeModule(wholeModule), Options(Options), serialized(false), SerializeSILAction(), Types(TC) { + assert(AssociatedDeclContext); + // We always add the base SILModule serialization callback. std::unique_ptr callback( new SILModule::SerializationCallback()); diff --git a/lib/SILGen/SILGenExpr.cpp b/lib/SILGen/SILGenExpr.cpp index d04d6aa71cdfa..633949e32d568 100644 --- a/lib/SILGen/SILGenExpr.cpp +++ b/lib/SILGen/SILGenExpr.cpp @@ -4099,8 +4099,6 @@ static bool isVerbatimNullableTypeInC(SILModule &M, Type ty) { // Other types like UnsafePointer can also be nullable. const DeclContext *DC = M.getAssociatedContext(); - if (!DC) - DC = M.getSwiftModule(); ty = OptionalType::get(ty); return ty->isTriviallyRepresentableIn(ForeignLanguage::C, DC); } diff --git a/lib/SILOptimizer/Transforms/SpeculativeDevirtualizer.cpp b/lib/SILOptimizer/Transforms/SpeculativeDevirtualizer.cpp index 6913c3a3c94ee..1991379ee6481 100644 --- a/lib/SILOptimizer/Transforms/SpeculativeDevirtualizer.cpp +++ b/lib/SILOptimizer/Transforms/SpeculativeDevirtualizer.cpp @@ -285,8 +285,6 @@ static bool isDefaultCaseKnown(ClassHierarchyAnalysis *CHA, auto *Method = CMI->getMember().getAbstractFunctionDecl(); assert(Method && "not a function"); - const DeclContext *DC = AI.getModule().getAssociatedContext(); - if (CD->isFinal()) return true; @@ -295,13 +293,8 @@ static bool isDefaultCaseKnown(ClassHierarchyAnalysis *CHA, if (CD->checkAncestry(AncestryFlags::ObjC)) return false; - // Without an associated context we cannot perform any - // access-based optimizations. - if (!DC) - return false; - // Only handle classes defined within the SILModule's associated context. - if (!CD->isChildContextOf(DC)) + if (!CD->isChildContextOf(AI.getModule().getAssociatedContext())) return false; if (!CD->hasAccess()) diff --git a/lib/SILOptimizer/Utils/Devirtualize.cpp b/lib/SILOptimizer/Utils/Devirtualize.cpp index f07a35cf7d47e..498a4ea2d3b59 100644 --- a/lib/SILOptimizer/Utils/Devirtualize.cpp +++ b/lib/SILOptimizer/Utils/Devirtualize.cpp @@ -89,13 +89,6 @@ static bool isEffectivelyFinalMethod(FullApplySite applySite, CanType classType, if (cd && cd->isFinal()) return true; - const DeclContext *dc = applySite.getModule().getAssociatedContext(); - - // Without an associated context we cannot perform any - // access-based optimizations. - if (!dc) - return false; - auto *cmi = cast(applySite.getCallee()); if (!calleesAreStaticallyKnowable(applySite.getModule(), cmi->getMember())) @@ -149,18 +142,11 @@ static bool isEffectivelyFinalMethod(FullApplySite applySite, CanType classType, /// it is a whole-module compilation. static bool isKnownFinalClass(ClassDecl *cd, SILModule &module, ClassHierarchyAnalysis *cha) { - const DeclContext *dc = module.getAssociatedContext(); - if (cd->isFinal()) return true; - // Without an associated context we cannot perform any - // access-based optimizations. - if (!dc) - return false; - // Only handle classes defined within the SILModule's associated context. - if (!cd->isChildContextOf(dc)) + if (!cd->isChildContextOf(module.getAssociatedContext())) return false; if (!cd->hasAccess()) diff --git a/lib/SILOptimizer/Utils/InstOptUtils.cpp b/lib/SILOptimizer/Utils/InstOptUtils.cpp index dfef347c29333..46ff29ceffe3b 100644 --- a/lib/SILOptimizer/Utils/InstOptUtils.cpp +++ b/lib/SILOptimizer/Utils/InstOptUtils.cpp @@ -1815,12 +1815,8 @@ bool swift::calleesAreStaticallyKnowable(SILModule &module, SILDeclRef decl) { /// knowable based on the Decl and the compilation mode? bool swift::calleesAreStaticallyKnowable(SILModule &module, AbstractFunctionDecl *afd) { - const DeclContext *assocDC = module.getAssociatedContext(); - if (!assocDC) - return false; - // Only handle members defined within the SILModule's associated context. - if (!afd->isChildContextOf(assocDC)) + if (!afd->isChildContextOf(module.getAssociatedContext())) return false; if (afd->isDynamic()) { @@ -1859,12 +1855,8 @@ bool swift::calleesAreStaticallyKnowable(SILModule &module, // FIXME: Merge this with calleesAreStaticallyKnowable above bool swift::calleesAreStaticallyKnowable(SILModule &module, EnumElementDecl *eed) { - const DeclContext *assocDC = module.getAssociatedContext(); - if (!assocDC) - return false; - // Only handle members defined within the SILModule's associated context. - if (!eed->isChildContextOf(assocDC)) + if (!eed->isChildContextOf(module.getAssociatedContext())) return false; if (eed->isDynamic()) { diff --git a/lib/Serialization/SerializeSIL.cpp b/lib/Serialization/SerializeSIL.cpp index 3a6b090eba568..891996197c063 100644 --- a/lib/Serialization/SerializeSIL.cpp +++ b/lib/Serialization/SerializeSIL.cpp @@ -2645,9 +2645,6 @@ void SILSerializer::writeSILBlock(const SILModule *SILMod) { // Go through all SILVTables in SILMod and write them if we should // serialize everything. // FIXME: Resilience: could write out vtable for fragile classes. - const DeclContext *assocDC = SILMod->getAssociatedContext(); - assert(assocDC && "cannot serialize SIL without an associated DeclContext"); - (void)assocDC; for (const SILVTable &vt : SILMod->getVTables()) { if ((ShouldSerializeAll || vt.isSerialized()) && SILMod->shouldSerializeEntitiesAssociatedWithDeclContext(vt.getClass())) From 27ed8b0b436c50fda7cfe4296fbddb6c57f68c03 Mon Sep 17 00:00:00 2001 From: Hamish Knight Date: Sun, 10 May 2020 19:56:12 -0700 Subject: [PATCH 3/4] [SIL] Infer isWholeModule() from associated context Rather than maintain a separate bit, check if the associated decl context is for the ModuleDecl. --- include/swift/AST/SILGenRequests.h | 3 --- include/swift/SIL/SILModule.h | 12 +++--------- lib/SIL/IR/SILModule.cpp | 14 ++++++-------- lib/SIL/Parser/ParseSIL.cpp | 6 ++---- lib/SILGen/SILGen.cpp | 4 ++-- lib/SILGen/SILGenRequests.cpp | 4 ---- 6 files changed, 13 insertions(+), 30 deletions(-) diff --git a/include/swift/AST/SILGenRequests.h b/include/swift/AST/SILGenRequests.h index c20c014838308..e54723170b74a 100644 --- a/include/swift/AST/SILGenRequests.h +++ b/include/swift/AST/SILGenRequests.h @@ -81,9 +81,6 @@ struct SILGenDescriptor { /// If the module or file contains SIL that needs parsing, returns the file /// to be parsed, or \c nullptr if parsing isn't required. SourceFile *getSourceFileToParse() const; - - /// Whether the SIL is being emitted for a whole module. - bool isWholeModule() const; }; void simple_display(llvm::raw_ostream &out, const SILGenDescriptor &d); diff --git a/include/swift/SIL/SILModule.h b/include/swift/SIL/SILModule.h index 9725dae819bf9..b34456473956e 100644 --- a/include/swift/SIL/SILModule.h +++ b/include/swift/SIL/SILModule.h @@ -262,10 +262,6 @@ class SILModule { /// The indexed profile data to be used for PGO, or nullptr. std::unique_ptr PGOReader; - /// True if this SILModule really contains the whole module, i.e. - /// optimizations can assume that they see the whole module. - bool wholeModule; - /// The options passed into this SILModule. const SILOptions &Options; @@ -281,8 +277,7 @@ class SILModule { llvm::SetVector NotificationHandlers; SILModule(ModuleDecl *M, Lowering::TypeConverter &TC, - const SILOptions &Options, const DeclContext *associatedDC, - bool wholeModule); + const SILOptions &Options, const DeclContext *associatedDC); SILModule(const SILModule&) = delete; void operator=(const SILModule&) = delete; @@ -357,8 +352,7 @@ class SILModule { /// later parse SIL bodies directly into, without converting from an AST. static std::unique_ptr createEmptyModule(ModuleDecl *M, Lowering::TypeConverter &TC, - const SILOptions &Options, - bool WholeModule = false); + const SILOptions &Options); /// Get the Swift module associated with this SIL module. ModuleDecl *getSwiftModule() const { return TheSwiftModule; } @@ -382,7 +376,7 @@ class SILModule { /// Returns true if this SILModule really contains the whole module, i.e. /// optimizations can assume that they see the whole module. bool isWholeModule() const { - return wholeModule; + return isa(AssociatedDeclContext); } bool isStdlibModule() const; diff --git a/lib/SIL/IR/SILModule.cpp b/lib/SIL/IR/SILModule.cpp index d285021c14071..1d5e4974dd382 100644 --- a/lib/SIL/IR/SILModule.cpp +++ b/lib/SIL/IR/SILModule.cpp @@ -93,12 +93,11 @@ class SILModule::SerializationCallback final }; SILModule::SILModule(ModuleDecl *SwiftModule, TypeConverter &TC, - const SILOptions &Options, const DeclContext *associatedDC, - bool wholeModule) + const SILOptions &Options, const DeclContext *associatedDC) : TheSwiftModule(SwiftModule), AssociatedDeclContext(associatedDC), - Stage(SILStage::Raw), wholeModule(wholeModule), Options(Options), - serialized(false), SerializeSILAction(), Types(TC) { + Stage(SILStage::Raw), Options(Options), serialized(false), + SerializeSILAction(), Types(TC) { assert(AssociatedDeclContext); // We always add the base SILModule serialization callback. @@ -125,10 +124,9 @@ SILModule::~SILModule() { } std::unique_ptr -SILModule::createEmptyModule(ModuleDecl *M, TypeConverter &TC, const SILOptions &Options, - bool WholeModule) { - return std::unique_ptr( - new SILModule(M, TC, Options, M, WholeModule)); +SILModule::createEmptyModule(ModuleDecl *M, TypeConverter &TC, + const SILOptions &Options) { + return std::unique_ptr(new SILModule(M, TC, Options, M)); } ASTContext &SILModule::getASTContext() const { diff --git a/lib/SIL/Parser/ParseSIL.cpp b/lib/SIL/Parser/ParseSIL.cpp index 63a9a97a3ad2f..734478829c471 100644 --- a/lib/SIL/Parser/ParseSIL.cpp +++ b/lib/SIL/Parser/ParseSIL.cpp @@ -116,8 +116,7 @@ ParseSILModuleRequest::evaluate(Evaluator &evaluator, assert(bufferID); auto *mod = SF->getParentModule(); - auto silMod = SILModule::createEmptyModule(mod, desc.conv, desc.opts, - desc.isWholeModule()); + auto silMod = SILModule::createEmptyModule(mod, desc.conv, desc.opts); SILParserState parserState(silMod.get()); Parser parser(*bufferID, *SF, parserState.Impl.get()); PrettyStackTraceParser StackTrace(parser); @@ -126,8 +125,7 @@ ParseSILModuleRequest::evaluate(Evaluator &evaluator, if (hadError) { // The rest of the SIL pipeline expects well-formed SIL, so if we encounter // a parsing error, just return an empty SIL module. - return SILModule::createEmptyModule(mod, desc.conv, desc.opts, - desc.isWholeModule()); + return SILModule::createEmptyModule(mod, desc.conv, desc.opts); } return silMod; } diff --git a/lib/SILGen/SILGen.cpp b/lib/SILGen/SILGen.cpp index 7beb6644996d0..7db276a2fc338 100644 --- a/lib/SILGen/SILGen.cpp +++ b/lib/SILGen/SILGen.cpp @@ -1868,7 +1868,7 @@ SILGenSourceFileRequest::evaluate(Evaluator &evaluator, auto *unit = desc.context.get(); auto *mod = unit->getParentModule(); auto M = std::unique_ptr( - new SILModule(mod, desc.conv, desc.opts, unit, /*wholeModule*/ false)); + new SILModule(mod, desc.conv, desc.opts, unit)); SILGenModuleRAII scope(*M, mod); if (auto *file = dyn_cast(unit)) { @@ -1891,7 +1891,7 @@ SILGenWholeModuleRequest::evaluate(Evaluator &evaluator, auto *mod = desc.context.get(); auto M = std::unique_ptr( - new SILModule(mod, desc.conv, desc.opts, mod, /*wholeModule*/ true)); + new SILModule(mod, desc.conv, desc.opts, mod)); SILGenModuleRAII scope(*M, mod); for (auto file : mod->getFiles()) { diff --git a/lib/SILGen/SILGenRequests.cpp b/lib/SILGen/SILGenRequests.cpp index 96a17359ec328..97af944495768 100644 --- a/lib/SILGen/SILGenRequests.cpp +++ b/lib/SILGen/SILGenRequests.cpp @@ -65,10 +65,6 @@ ArrayRef SILGenDescriptor::getFiles() const { return llvm::makeArrayRef(*context.getAddrOfPtr1()); } -bool SILGenDescriptor::isWholeModule() const { - return context.is(); -} - SourceFile *SILGenDescriptor::getSourceFileToParse() const { #ifndef NDEBUG auto sfCount = llvm::count_if(getFiles(), [](FileUnit *file) { From 574dd2bbf9d3de9f0dcfb2be2d7b4cda5effeedf Mon Sep 17 00:00:00 2001 From: Hamish Knight Date: Sun, 10 May 2020 19:56:13 -0700 Subject: [PATCH 4/4] Use correct associated context for SIL parsing Adjust `SILModule::createEmptyModule` to accept a FileUnit or ModuleDecl, and pass the corresponding context for SIL generation and parsing. This change means that SIL parsing will now correctly use a SourceFile associated context when in single-file mode. --- include/swift/SIL/SILModule.h | 17 +++++++++-------- lib/SIL/IR/SILModule.cpp | 24 ++++++++++++++---------- lib/SIL/Parser/ParseSIL.cpp | 6 +++--- lib/SILGen/SILGen.cpp | 6 ++---- test/IRGen/multi_file_resilience.swift | 5 +++++ 5 files changed, 33 insertions(+), 25 deletions(-) diff --git a/include/swift/SIL/SILModule.h b/include/swift/SIL/SILModule.h index b34456473956e..86183e7a8ea1f 100644 --- a/include/swift/SIL/SILModule.h +++ b/include/swift/SIL/SILModule.h @@ -107,8 +107,6 @@ enum class SILStage { /// when a Swift compilation context is lowered to SIL. class SILModule { friend class SILFunctionBuilder; - friend class SILGenSourceFileRequest; - friend class SILGenWholeModuleRequest; public: using FunctionListType = llvm::ilist; @@ -276,8 +274,8 @@ class SILModule { /// invalidation message is sent. llvm::SetVector NotificationHandlers; - SILModule(ModuleDecl *M, Lowering::TypeConverter &TC, - const SILOptions &Options, const DeclContext *associatedDC); + SILModule(llvm::PointerUnion context, + Lowering::TypeConverter &TC, const SILOptions &Options); SILModule(const SILModule&) = delete; void operator=(const SILModule&) = delete; @@ -348,11 +346,14 @@ class SILModule { /// Erase a global SIL variable from the module. void eraseGlobalVariable(SILGlobalVariable *G); - /// Create and return an empty SIL module that we can - /// later parse SIL bodies directly into, without converting from an AST. + /// Create and return an empty SIL module suitable for generating or parsing + /// SIL into. + /// + /// \param context The associated decl context. This should be a FileUnit in + /// single-file mode, and a ModuleDecl in whole-module mode. static std::unique_ptr - createEmptyModule(ModuleDecl *M, Lowering::TypeConverter &TC, - const SILOptions &Options); + createEmptyModule(llvm::PointerUnion context, + Lowering::TypeConverter &TC, const SILOptions &Options); /// Get the Swift module associated with this SIL module. ModuleDecl *getSwiftModule() const { return TheSwiftModule; } diff --git a/lib/SIL/IR/SILModule.cpp b/lib/SIL/IR/SILModule.cpp index 1d5e4974dd382..50aadb293da66 100644 --- a/lib/SIL/IR/SILModule.cpp +++ b/lib/SIL/IR/SILModule.cpp @@ -92,13 +92,17 @@ class SILModule::SerializationCallback final } }; -SILModule::SILModule(ModuleDecl *SwiftModule, TypeConverter &TC, - const SILOptions &Options, const DeclContext *associatedDC) - : TheSwiftModule(SwiftModule), - AssociatedDeclContext(associatedDC), - Stage(SILStage::Raw), Options(Options), serialized(false), +SILModule::SILModule(llvm::PointerUnion context, + Lowering::TypeConverter &TC, const SILOptions &Options) + : Stage(SILStage::Raw), Options(Options), serialized(false), SerializeSILAction(), Types(TC) { - assert(AssociatedDeclContext); + assert(!context.isNull()); + if (auto *file = context.dyn_cast()) { + AssociatedDeclContext = file; + } else { + AssociatedDeclContext = context.get(); + } + TheSwiftModule = AssociatedDeclContext->getParentModule(); // We always add the base SILModule serialization callback. std::unique_ptr callback( @@ -123,10 +127,10 @@ SILModule::~SILModule() { } } -std::unique_ptr -SILModule::createEmptyModule(ModuleDecl *M, TypeConverter &TC, - const SILOptions &Options) { - return std::unique_ptr(new SILModule(M, TC, Options, M)); +std::unique_ptr SILModule::createEmptyModule( + llvm::PointerUnion context, + Lowering::TypeConverter &TC, const SILOptions &Options) { + return std::unique_ptr(new SILModule(context, TC, Options)); } ASTContext &SILModule::getASTContext() const { diff --git a/lib/SIL/Parser/ParseSIL.cpp b/lib/SIL/Parser/ParseSIL.cpp index 734478829c471..1ed4354feaca8 100644 --- a/lib/SIL/Parser/ParseSIL.cpp +++ b/lib/SIL/Parser/ParseSIL.cpp @@ -115,8 +115,8 @@ ParseSILModuleRequest::evaluate(Evaluator &evaluator, auto bufferID = SF->getBufferID(); assert(bufferID); - auto *mod = SF->getParentModule(); - auto silMod = SILModule::createEmptyModule(mod, desc.conv, desc.opts); + auto silMod = SILModule::createEmptyModule(desc.context, desc.conv, + desc.opts); SILParserState parserState(silMod.get()); Parser parser(*bufferID, *SF, parserState.Impl.get()); PrettyStackTraceParser StackTrace(parser); @@ -125,7 +125,7 @@ ParseSILModuleRequest::evaluate(Evaluator &evaluator, if (hadError) { // The rest of the SIL pipeline expects well-formed SIL, so if we encounter // a parsing error, just return an empty SIL module. - return SILModule::createEmptyModule(mod, desc.conv, desc.opts); + return SILModule::createEmptyModule(desc.context, desc.conv, desc.opts); } return silMod; } diff --git a/lib/SILGen/SILGen.cpp b/lib/SILGen/SILGen.cpp index 7db276a2fc338..1e6a4bcbb4fe2 100644 --- a/lib/SILGen/SILGen.cpp +++ b/lib/SILGen/SILGen.cpp @@ -1867,8 +1867,7 @@ SILGenSourceFileRequest::evaluate(Evaluator &evaluator, auto *unit = desc.context.get(); auto *mod = unit->getParentModule(); - auto M = std::unique_ptr( - new SILModule(mod, desc.conv, desc.opts, unit)); + auto M = SILModule::createEmptyModule(desc.context, desc.conv, desc.opts); SILGenModuleRAII scope(*M, mod); if (auto *file = dyn_cast(unit)) { @@ -1890,8 +1889,7 @@ SILGenWholeModuleRequest::evaluate(Evaluator &evaluator, } auto *mod = desc.context.get(); - auto M = std::unique_ptr( - new SILModule(mod, desc.conv, desc.opts, mod)); + auto M = SILModule::createEmptyModule(desc.context, desc.conv, desc.opts); SILGenModuleRAII scope(*M, mod); for (auto file : mod->getFiles()) { diff --git a/test/IRGen/multi_file_resilience.swift b/test/IRGen/multi_file_resilience.swift index aaadb088feec4..2a898f8bb41e1 100644 --- a/test/IRGen/multi_file_resilience.swift +++ b/test/IRGen/multi_file_resilience.swift @@ -7,6 +7,11 @@ // RUN: %target-swift-frontend -module-name main -I %t -emit-ir -primary-file %s %S/Inputs/OtherModule.swift | %FileCheck %s -DINT=i%target-ptrsize +// Check that we correctly handle resilience when parsing as SIL + SIB. +// RUN: %target-swift-frontend -emit-sib -module-name main %S/Inputs/OtherModule.swift -I %t -o %t/other.sib +// RUN: %target-swift-frontend -emit-silgen -module-name main -primary-file %s %S/Inputs/OtherModule.swift -I %t -o %t/main.sil +// RUN: %target-swift-frontend -emit-ir -module-name main -primary-file %t/main.sil %t/other.sib -I %t | %FileCheck %s -DINT=i%target-ptrsize + // This is a single-module version of the test case in // multi_module_resilience. // rdar://39763787