Skip to content

Commit a5dcb1d

Browse files
committed
[NFC] Add a "Main Module" Bit
The constraint system will need this if it wants to disable debug mode for serialized modules
1 parent 52ddcea commit a5dcb1d

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

include/swift/AST/Decl.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ class alignas(1 << DeclAlignInBits) Decl {
575575
HasAnyUnavailableValues : 1
576576
);
577577

578-
SWIFT_INLINE_BITFIELD(ModuleDecl, TypeDecl, 1+1+1+1+1+1+1+1,
578+
SWIFT_INLINE_BITFIELD(ModuleDecl, TypeDecl, 1+1+1+1+1+1+1+1+1,
579579
/// If the module was or is being compiled with `-enable-testing`.
580580
TestingEnabled : 1,
581581

@@ -601,7 +601,10 @@ class alignas(1 << DeclAlignInBits) Decl {
601601

602602
/// Whether the module was imported from Clang (or, someday, maybe another
603603
/// language).
604-
IsNonSwiftModule : 1
604+
IsNonSwiftModule : 1,
605+
606+
/// Whether this module is the main module.
607+
IsMainModule : 1
605608
);
606609

607610
SWIFT_INLINE_BITFIELD(PrecedenceGroupDecl, Decl, 1+2,

include/swift/AST/Module.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,13 @@ class ModuleDecl : public DeclContext, public TypeDecl {
347347
return new (ctx) ModuleDecl(name, ctx, importInfo);
348348
}
349349

350+
static ModuleDecl *
351+
createMainModule(ASTContext &ctx, Identifier name, ImplicitImportInfo iinfo) {
352+
auto *Mod = ModuleDecl::create(name, ctx, iinfo);
353+
Mod->Bits.ModuleDecl.IsMainModule = true;
354+
return Mod;
355+
}
356+
350357
using Decl::getASTContext;
351358

352359
/// Retrieves information about which modules are implicitly imported by
@@ -542,6 +549,10 @@ class ModuleDecl : public DeclContext, public TypeDecl {
542549
Bits.ModuleDecl.IsNonSwiftModule = flag;
543550
}
544551

552+
bool isMainModule() const {
553+
return Bits.ModuleDecl.IsMainModule;
554+
}
555+
545556
/// Retrieve the top-level module. If this module is already top-level, this
546557
/// returns itself. If this is a submodule such as \c Foo.Bar.Baz, this
547558
/// returns the module \c Foo.

lib/AST/Module.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,16 @@ ModuleDecl::ModuleDecl(Identifier name, ASTContext &ctx,
475475
setInterfaceType(ModuleType::get(this));
476476

477477
setAccess(AccessLevel::Public);
478+
479+
Bits.ModuleDecl.TestingEnabled = 0;
480+
Bits.ModuleDecl.FailedToLoad = 0;
481+
Bits.ModuleDecl.RawResilienceStrategy = 0;
482+
Bits.ModuleDecl.HasResolvedImports = 0;
483+
Bits.ModuleDecl.PrivateImportsEnabled = 0;
484+
Bits.ModuleDecl.ImplicitDynamicEnabled = 0;
485+
Bits.ModuleDecl.IsSystemModule = 0;
486+
Bits.ModuleDecl.IsNonSwiftModule = 0;
487+
Bits.ModuleDecl.IsMainModule = 0;
478488
}
479489

480490
ArrayRef<ImplicitImport> ModuleDecl::getImplicitImports() const {

lib/Frontend/Frontend.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,8 @@ ImplicitImportInfo CompilerInstance::getImplicitImportInfo() const {
717717
ModuleDecl *CompilerInstance::getMainModule() const {
718718
if (!MainModule) {
719719
Identifier ID = Context->getIdentifier(Invocation.getModuleName());
720-
MainModule = ModuleDecl::create(ID, *Context, getImplicitImportInfo());
720+
MainModule = ModuleDecl::createMainModule(*Context, ID,
721+
getImplicitImportInfo());
721722
if (Invocation.getFrontendOptions().EnableTesting)
722723
MainModule->setTestingEnabled();
723724
if (Invocation.getFrontendOptions().EnablePrivateImports)

0 commit comments

Comments
 (0)