From a5dcb1d400a8d0d6d341b19d0579e8280c41fdbf Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Mon, 11 May 2020 16:44:28 -0700 Subject: [PATCH] [NFC] Add a "Main Module" Bit The constraint system will need this if it wants to disable debug mode for serialized modules --- include/swift/AST/Decl.h | 7 +++++-- include/swift/AST/Module.h | 11 +++++++++++ lib/AST/Module.cpp | 10 ++++++++++ lib/Frontend/Frontend.cpp | 3 ++- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/include/swift/AST/Decl.h b/include/swift/AST/Decl.h index 288a6f805ad..eb6af822e7a 100644 --- a/include/swift/AST/Decl.h +++ b/include/swift/AST/Decl.h @@ -575,7 +575,7 @@ protected: HasAnyUnavailableValues : 1 ); - SWIFT_INLINE_BITFIELD(ModuleDecl, TypeDecl, 1+1+1+1+1+1+1+1, + SWIFT_INLINE_BITFIELD(ModuleDecl, TypeDecl, 1+1+1+1+1+1+1+1+1, /// If the module was or is being compiled with `-enable-testing`. TestingEnabled : 1, @@ -601,7 +601,10 @@ protected: /// Whether the module was imported from Clang (or, someday, maybe another /// language). - IsNonSwiftModule : 1 + IsNonSwiftModule : 1, + + /// Whether this module is the main module. + IsMainModule : 1 ); SWIFT_INLINE_BITFIELD(PrecedenceGroupDecl, Decl, 1+2, diff --git a/include/swift/AST/Module.h b/include/swift/AST/Module.h index 936bf83f5df..c5a70a6e667 100644 --- a/include/swift/AST/Module.h +++ b/include/swift/AST/Module.h @@ -347,6 +347,13 @@ public: return new (ctx) ModuleDecl(name, ctx, importInfo); } + static ModuleDecl * + createMainModule(ASTContext &ctx, Identifier name, ImplicitImportInfo iinfo) { + auto *Mod = ModuleDecl::create(name, ctx, iinfo); + Mod->Bits.ModuleDecl.IsMainModule = true; + return Mod; + } + using Decl::getASTContext; /// Retrieves information about which modules are implicitly imported by @@ -542,6 +549,10 @@ public: Bits.ModuleDecl.IsNonSwiftModule = flag; } + bool isMainModule() const { + return Bits.ModuleDecl.IsMainModule; + } + /// Retrieve the top-level module. If this module is already top-level, this /// returns itself. If this is a submodule such as \c Foo.Bar.Baz, this /// returns the module \c Foo. diff --git a/lib/AST/Module.cpp b/lib/AST/Module.cpp index a766aafebf3..c8a667ebe38 100644 --- a/lib/AST/Module.cpp +++ b/lib/AST/Module.cpp @@ -475,6 +475,16 @@ ModuleDecl::ModuleDecl(Identifier name, ASTContext &ctx, setInterfaceType(ModuleType::get(this)); setAccess(AccessLevel::Public); + + Bits.ModuleDecl.TestingEnabled = 0; + Bits.ModuleDecl.FailedToLoad = 0; + Bits.ModuleDecl.RawResilienceStrategy = 0; + Bits.ModuleDecl.HasResolvedImports = 0; + Bits.ModuleDecl.PrivateImportsEnabled = 0; + Bits.ModuleDecl.ImplicitDynamicEnabled = 0; + Bits.ModuleDecl.IsSystemModule = 0; + Bits.ModuleDecl.IsNonSwiftModule = 0; + Bits.ModuleDecl.IsMainModule = 0; } ArrayRef ModuleDecl::getImplicitImports() const { diff --git a/lib/Frontend/Frontend.cpp b/lib/Frontend/Frontend.cpp index ce81e02c40d..b9192a13c45 100644 --- a/lib/Frontend/Frontend.cpp +++ b/lib/Frontend/Frontend.cpp @@ -717,7 +717,8 @@ ImplicitImportInfo CompilerInstance::getImplicitImportInfo() const { ModuleDecl *CompilerInstance::getMainModule() const { if (!MainModule) { Identifier ID = Context->getIdentifier(Invocation.getModuleName()); - MainModule = ModuleDecl::create(ID, *Context, getImplicitImportInfo()); + MainModule = ModuleDecl::createMainModule(*Context, ID, + getImplicitImportInfo()); if (Invocation.getFrontendOptions().EnableTesting) MainModule->setTestingEnabled(); if (Invocation.getFrontendOptions().EnablePrivateImports)