Skip to content

Commit 25f90c6

Browse files
authored
Merge pull request #6542 from benlangmuir/include-tree-modules-stable
[clang][cas] include-tree support for modules
2 parents d7024c4 + 2ed7779 commit 25f90c6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+3659
-496
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,14 @@ class ASTContext : public RefCountedBase<ASTContext> {
477477
/// For module code-gen cases, this is the top-level module we are building.
478478
Module *TopLevelModule = nullptr;
479479

480+
/// The include tree that is being built, if any.
481+
/// See \c FrontendOptions::CASIncludeTreeID.
482+
std::optional<std::string> CASIncludeTreeID;
483+
484+
/// The cas-fs tree that is being built, if any.
485+
/// See \c FileSystemOptions::CASFileSystemRootID.
486+
std::optional<std::string> CASFileSystemRootID;
487+
480488
static constexpr unsigned ConstantArrayTypesLog2InitSize = 8;
481489
static constexpr unsigned GeneralTypesLog2InitSize = 9;
482490
static constexpr unsigned FunctionProtoTypesLog2InitSize = 12;
@@ -1086,6 +1094,20 @@ class ASTContext : public RefCountedBase<ASTContext> {
10861094
/// Get module under construction, nullptr if this is not a C++20 module.
10871095
Module *getModuleForCodeGen() const { return TopLevelModule; }
10881096

1097+
std::optional<std::string> getCASIncludeTreeID() const {
1098+
return CASIncludeTreeID;
1099+
}
1100+
void setCASIncludeTreeID(std::string ID) {
1101+
CASIncludeTreeID = std::move(ID);
1102+
}
1103+
1104+
std::optional<std::string> getCASFileSystemRootID() const {
1105+
return CASFileSystemRootID;
1106+
}
1107+
void setCASFileSystemRootID(std::string ID) {
1108+
CASFileSystemRootID = std::move(ID);
1109+
}
1110+
10891111
TranslationUnitDecl *getTranslationUnitDecl() const {
10901112
return TUDecl->getMostRecentDecl();
10911113
}

clang/include/clang/Basic/DiagnosticCASKinds.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ def err_cas_missing_root_id : Error<
3636
"CAS missing expected root-id '%0'">, DefaultFatal;
3737
def err_cas_cannot_parse_root_id_for_module : Error<
3838
"CAS cannot parse root-id '%0' for module '%1'">, DefaultFatal;
39+
def err_cas_cannot_parse_include_tree_id : Error<
40+
"CAS cannot parse include-tree-id '%0'">, DefaultFatal;
41+
def err_cas_missing_include_tree_id : Error<
42+
"CAS missing expected include-tree '%0'">, DefaultFatal;
3943

4044
def warn_clang_cache_disabled_caching: Warning<
4145
"caching disabled because %0">,

clang/include/clang/Basic/DiagnosticFrontendKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ def err_missing_module_name : Error<
229229
DefaultFatal;
230230
def err_missing_module : Error<
231231
"no module named '%0' declared in module map file '%1'">, DefaultFatal;
232+
def err_missing_module_include_tree : Error<
233+
"no module named '%0' declared in include-tree module map '%1'">, DefaultFatal;
232234
def err_no_submodule : Error<"no submodule named %0 in module '%1'">;
233235
def err_no_submodule_suggest : Error<
234236
"no submodule named %0 in module '%1'; did you mean '%2'?">;

clang/include/clang/Basic/DiagnosticLexKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,9 @@ def warn_defined_in_function_type_macro : Extension<
918918
"macro expansion producing 'defined' has undefined behavior">,
919919
InGroup<ExpansionToDefined>;
920920

921+
def err_pp_missing_module_include_tree : Error<
922+
"no module named '%0' declared in include-tree module map">, DefaultFatal;
923+
921924
let CategoryName = "Nullability Issue" in {
922925

923926
def err_pp_assume_nonnull_syntax : Error<"expected 'begin' or 'end'">;

clang/include/clang/Basic/Module.h

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ class alignas(8) Module {
108108
/// of header files.
109109
ModuleMapModule,
110110

111+
/// This is a module that was defined by a module map and built out
112+
/// of header files as part of an \c IncludeTree.
113+
IncludeTreeModuleMap,
114+
111115
/// This is a C++20 module interface unit.
112116
ModuleInterfaceUnit,
113117

@@ -175,7 +179,9 @@ class alignas(8) Module {
175179

176180
bool isPrivateModule() const { return Kind == PrivateModuleFragment; }
177181

178-
bool isModuleMapModule() const { return Kind == ModuleMapModule; }
182+
bool isModuleMapModule() const {
183+
return Kind == ModuleMapModule || Kind == IncludeTreeModuleMap;
184+
}
179185

180186
private:
181187
/// The submodules of this module, indexed by name.
@@ -192,10 +198,6 @@ class alignas(8) Module {
192198
/// The \c ActionCache key for this module, if any.
193199
Optional<std::string> ModuleCacheKey;
194200

195-
/// The CAS filesystem root ID for implicit modules built with the dependency
196-
/// scanner, if any.
197-
Optional<std::string> CASFileSystemRootID;
198-
199201
/// The top-level headers associated with this module.
200202
llvm::SmallSetVector<const FileEntry *, 2> TopHeaders;
201203

@@ -636,14 +638,6 @@ class alignas(8) Module {
636638
getTopLevelModule()->ModuleCacheKey = std::move(Key);
637639
}
638640

639-
Optional<std::string> getCASFileSystemRootID() const {
640-
return getTopLevelModule()->CASFileSystemRootID;
641-
}
642-
643-
void setCASFileSystemRootID(std::string ID) {
644-
assert(!getCASFileSystemRootID() || *getCASFileSystemRootID() == ID);
645-
getTopLevelModule()->CASFileSystemRootID = std::move(ID);
646-
}
647641

648642
/// Retrieve the directory for which this module serves as the
649643
/// umbrella.

0 commit comments

Comments
 (0)