From c9cc8035eb4fbf5d20a73ec7e0870e6195012a71 Mon Sep 17 00:00:00 2001 From: Iain Sandoe Date: Mon, 29 Nov 2021 08:05:56 +0000 Subject: [PATCH] [C++20][Modules][2/8] Add enumerations for partition modules and stream them. This is an initial enabling patch for module partition support. We add enumerations for partition interfaces/implementations. This means that the module kind enumeration now occupies three bits, so the AST streamer is adjusted for this. Adding one bit there seems preferable to trying to overload the meanings of existing kinds (and we will also want to add a C++20 header unit case later). Differential Revision: https://reviews.llvm.org/D114714 --- clang/include/clang/Basic/Module.h | 15 +++++++++++++-- clang/lib/AST/Decl.cpp | 2 ++ clang/lib/Sema/SemaModule.cpp | 2 ++ clang/lib/Serialization/ASTWriter.cpp | 2 +- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/clang/include/clang/Basic/Module.h b/clang/include/clang/Basic/Module.h index de7857347bc2..b05d3c654e72 100644 --- a/clang/include/clang/Basic/Module.h +++ b/clang/include/clang/Basic/Module.h @@ -106,9 +106,15 @@ public: /// of header files. ModuleMapModule, - /// This is a C++ Modules TS module interface unit. + /// This is a C++20 module interface unit. ModuleInterfaceUnit, + /// This is a C++ 20 module partition interface. + ModulePartitionInterface, + + /// This is a C++ 20 module partition implementation. + ModulePartitionImplementation, + /// This is a fragment of the global module within some C++ module. GlobalModuleFragment, @@ -150,7 +156,9 @@ public: /// Does this Module scope describe part of the purview of a named C++ module? bool isModulePurview() const { - return Kind == ModuleInterfaceUnit || Kind == PrivateModuleFragment; + return Kind == ModuleInterfaceUnit || Kind == ModulePartitionInterface || + Kind == ModulePartitionImplementation || + Kind == PrivateModuleFragment; } /// Does this Module scope describe a fragment of the global module within @@ -506,6 +514,9 @@ public: Parent->SubModules.push_back(this); } + /// Is this a module partition. + bool isModulePartition() const { return Name.find(':') != std::string::npos; } + /// Retrieve the full name of this module, including the path from /// its top-level module. /// \param AllowStringLiterals If \c true, components that might not be diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 030da7f55fac..82c4412296db 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -1550,6 +1550,8 @@ Module *Decl::getOwningModuleForLinkage(bool IgnoreLinkage) const { return nullptr; case Module::ModuleInterfaceUnit: + case Module::ModulePartitionInterface: + case Module::ModulePartitionImplementation: return M; case Module::GlobalModuleFragment: { diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp index 9bed3cb769f7..bd5b900e5d38 100644 --- a/clang/lib/Sema/SemaModule.cpp +++ b/clang/lib/Sema/SemaModule.cpp @@ -261,6 +261,8 @@ Sema::ActOnPrivateModuleFragmentDecl(SourceLocation ModuleLoc, : ModuleScopes.back().Module->Kind) { case Module::ModuleMapModule: case Module::GlobalModuleFragment: + case Module::ModulePartitionImplementation: + case Module::ModulePartitionInterface: Diag(PrivateLoc, diag::err_private_module_fragment_not_module); return nullptr; diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index a126e12bcbd9..cf42e529a8d6 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -2674,7 +2674,7 @@ void ASTWriter::WriteSubmodules(Module *WritingModule) { Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_DEFINITION)); Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Parent - Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Kind + Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Kind Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExplicit Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsSystem