Skip to content

Commit 4a7be42

Browse files
committed
[C++20] [Modules] Remove unmaintained Header Module
Currently there is a -emit-header-module mode, which can combine several headers together as a module interface. However, this breaks our assumption (for standard c++ modules) about module interface. The module interface should come from a module interface unit. And if it is a header, it should be a header unit. And currently we have no ideas to combine several headers together. So I think this mode is an experimental one and it is not maintained and it is not used. So it will be better to remove them. Reviewed By: Bigcheese, dblaikie, bruno Differential Revision: https://reviews.llvm.org/D137609
1 parent cab9c02 commit 4a7be42

File tree

21 files changed

+9
-361
lines changed

21 files changed

+9
-361
lines changed

clang/include/clang/Driver/Action.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -436,26 +436,6 @@ class PrecompileJobAction : public JobAction {
436436
}
437437
};
438438

439-
class HeaderModulePrecompileJobAction : public PrecompileJobAction {
440-
void anchor() override;
441-
442-
const char *ModuleName;
443-
444-
public:
445-
HeaderModulePrecompileJobAction(Action *Input, types::ID OutputType,
446-
const char *ModuleName);
447-
448-
static bool classof(const Action *A) {
449-
return A->getKind() == HeaderModulePrecompileJobClass;
450-
}
451-
452-
void addModuleHeaderInput(Action *Input) {
453-
getInputs().push_back(Input);
454-
}
455-
456-
const char *getModuleName() const { return ModuleName; }
457-
};
458-
459439
class ExtractAPIJobAction : public JobAction {
460440
void anchor() override;
461441

clang/include/clang/Driver/Options.td

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5934,8 +5934,6 @@ def emit_module : Flag<["-"], "emit-module">,
59345934
HelpText<"Generate pre-compiled module file from a module map">;
59355935
def emit_module_interface : Flag<["-"], "emit-module-interface">,
59365936
HelpText<"Generate pre-compiled module file from a C++ module interface">;
5937-
def emit_header_module : Flag<["-"], "emit-header-module">,
5938-
HelpText<"Generate pre-compiled module file from a set of header files">;
59395937
def emit_header_unit : Flag<["-"], "emit-header-unit">,
59405938
HelpText<"Generate C++20 header units from header files">;
59415939
def emit_pch : Flag<["-"], "emit-pch">,

clang/include/clang/Frontend/FrontendActions.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -155,19 +155,6 @@ class GenerateModuleInterfaceAction : public GenerateModuleAction {
155155
CreateOutputFile(CompilerInstance &CI, StringRef InFile) override;
156156
};
157157

158-
class GenerateHeaderModuleAction : public GenerateModuleAction {
159-
/// The synthesized module input buffer for the current compilation.
160-
std::unique_ptr<llvm::MemoryBuffer> Buffer;
161-
std::vector<std::string> ModuleHeaders;
162-
163-
private:
164-
bool PrepareToExecuteAction(CompilerInstance &CI) override;
165-
bool BeginSourceFileAction(CompilerInstance &CI) override;
166-
167-
std::unique_ptr<raw_pwrite_stream>
168-
CreateOutputFile(CompilerInstance &CI, StringRef InFile) override;
169-
};
170-
171158
class GenerateHeaderUnitAction : public GenerateModuleAction {
172159

173160
private:

clang/include/clang/Frontend/FrontendOptions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ enum ActionKind {
8787
/// Generate pre-compiled module from a C++ module interface file.
8888
GenerateModuleInterface,
8989

90-
/// Generate pre-compiled module from a set of header files.
91-
GenerateHeaderModule,
92-
9390
/// Generate a C++20 header unit module from a header file.
9491
GenerateHeaderUnit,
9592

clang/include/clang/Lex/ModuleMap.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,9 +566,6 @@ class ModuleMap {
566566
/// \returns The newly-created module.
567567
Module *createModuleForInterfaceUnit(SourceLocation Loc, StringRef Name);
568568

569-
/// Create a header module from the specified list of headers.
570-
Module *createHeaderModule(StringRef Name, ArrayRef<Module::Header> Headers);
571-
572569
/// Create a C++20 header unit.
573570
Module *createHeaderUnit(SourceLocation Loc, StringRef Name,
574571
Module::Header H);

clang/lib/Driver/Action.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const char *Action::getClassName(ActionClass AC) {
2525
return "offload";
2626
case PreprocessJobClass: return "preprocessor";
2727
case PrecompileJobClass: return "precompiler";
28-
case HeaderModulePrecompileJobClass: return "header-module-precompiler";
2928
case ExtractAPIJobClass:
3029
return "api-extractor";
3130
case AnalyzeJobClass: return "analyzer";
@@ -352,13 +351,6 @@ PrecompileJobAction::PrecompileJobAction(ActionClass Kind, Action *Input,
352351
assert(isa<PrecompileJobAction>((Action*)this) && "invalid action kind");
353352
}
354353

355-
void HeaderModulePrecompileJobAction::anchor() {}
356-
357-
HeaderModulePrecompileJobAction::HeaderModulePrecompileJobAction(
358-
Action *Input, types::ID OutputType, const char *ModuleName)
359-
: PrecompileJobAction(HeaderModulePrecompileJobClass, Input, OutputType),
360-
ModuleName(ModuleName) {}
361-
362354
void ExtractAPIJobAction::anchor() {}
363355

364356
ExtractAPIJobAction::ExtractAPIJobAction(Action *Inputs, types::ID OutputType)

clang/lib/Driver/Driver.cpp

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3957,7 +3957,6 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
39573957
: nullptr;
39583958

39593959
// Construct the actions to perform.
3960-
HeaderModulePrecompileJobAction *HeaderModuleAction = nullptr;
39613960
ExtractAPIJobAction *ExtractAPIAction = nullptr;
39623961
ActionList LinkerInputs;
39633962
ActionList MergerInputs;
@@ -4012,16 +4011,6 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
40124011
break;
40134012
}
40144013

4015-
// Each precompiled header file after a module file action is a module
4016-
// header of that same module file, rather than being compiled to a
4017-
// separate PCH.
4018-
if (Phase == phases::Precompile && HeaderModuleAction &&
4019-
getPrecompiledType(InputType) == types::TY_PCH) {
4020-
HeaderModuleAction->addModuleHeaderInput(Current);
4021-
Current = nullptr;
4022-
break;
4023-
}
4024-
40254014
if (Phase == phases::Precompile && ExtractAPIAction) {
40264015
ExtractAPIAction->addHeaderInput(Current);
40274016
Current = nullptr;
@@ -4038,9 +4027,7 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
40384027
if (NewCurrent == Current)
40394028
continue;
40404029

4041-
if (auto *HMA = dyn_cast<HeaderModulePrecompileJobAction>(NewCurrent))
4042-
HeaderModuleAction = HMA;
4043-
else if (auto *EAA = dyn_cast<ExtractAPIJobAction>(NewCurrent))
4030+
if (auto *EAA = dyn_cast<ExtractAPIJobAction>(NewCurrent))
40444031
ExtractAPIAction = EAA;
40454032

40464033
Current = NewCurrent;
@@ -4524,9 +4511,6 @@ Action *Driver::ConstructPhaseAction(
45244511
OutputTy = types::TY_Nothing;
45254512
}
45264513

4527-
if (ModName)
4528-
return C.MakeAction<HeaderModulePrecompileJobAction>(Input, OutputTy,
4529-
ModName);
45304514
return C.MakeAction<PrecompileJobAction>(Input, OutputTy);
45314515
}
45324516
case phases::Compile: {
@@ -5303,10 +5287,6 @@ InputInfoList Driver::BuildJobsForActionNoCache(
53035287
if (JA->getType() == types::TY_dSYM)
53045288
BaseInput = InputInfos[0].getFilename();
53055289

5306-
// ... and in header module compilations, which use the module name.
5307-
if (auto *ModuleJA = dyn_cast<HeaderModulePrecompileJobAction>(JA))
5308-
BaseInput = ModuleJA->getModuleName();
5309-
53105290
// Append outputs of offload device jobs to the input list
53115291
if (!OffloadDependencesInputInfo.empty())
53125292
InputInfos.append(OffloadDependencesInputInfo.begin(),

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4539,7 +4539,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
45394539
bool IsHIP = JA.isOffloading(Action::OFK_HIP);
45404540
bool IsHIPDevice = JA.isDeviceOffloading(Action::OFK_HIP);
45414541
bool IsOpenMPDevice = JA.isDeviceOffloading(Action::OFK_OpenMP);
4542-
bool IsHeaderModulePrecompile = isa<HeaderModulePrecompileJobAction>(JA);
45434542
bool IsExtractAPI = isa<ExtractAPIJobAction>(JA);
45444543
bool IsDeviceOffloadAction = !(JA.isDeviceOffloading(Action::OFK_None) ||
45454544
JA.isDeviceOffloading(Action::OFK_Host));
@@ -4554,44 +4553,24 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
45544553
bool IsUsingLTO = D.isUsingLTO(IsDeviceOffloadAction);
45554554
auto LTOMode = D.getLTOMode(IsDeviceOffloadAction);
45564555

4557-
// A header module compilation doesn't have a main input file, so invent a
4558-
// fake one as a placeholder.
4559-
const char *ModuleName = [&] {
4560-
auto *ModuleNameArg = Args.getLastArg(options::OPT_fmodule_name_EQ);
4561-
return ModuleNameArg ? ModuleNameArg->getValue() : "";
4562-
}();
4563-
InputInfo HeaderModuleInput(Inputs[0].getType(), ModuleName, ModuleName);
4564-
45654556
// Extract API doesn't have a main input file, so invent a fake one as a
45664557
// placeholder.
45674558
InputInfo ExtractAPIPlaceholderInput(Inputs[0].getType(), "extract-api",
45684559
"extract-api");
45694560

45704561
const InputInfo &Input = [&]() -> const InputInfo & {
4571-
if (IsHeaderModulePrecompile)
4572-
return HeaderModuleInput;
45734562
if (IsExtractAPI)
45744563
return ExtractAPIPlaceholderInput;
45754564
return Inputs[0];
45764565
}();
45774566

4578-
InputInfoList ModuleHeaderInputs;
45794567
InputInfoList ExtractAPIInputs;
45804568
InputInfoList HostOffloadingInputs;
45814569
const InputInfo *CudaDeviceInput = nullptr;
45824570
const InputInfo *OpenMPDeviceInput = nullptr;
45834571
for (const InputInfo &I : Inputs) {
45844572
if (&I == &Input || I.getType() == types::TY_Nothing) {
45854573
// This is the primary input or contains nothing.
4586-
} else if (IsHeaderModulePrecompile &&
4587-
types::getPrecompiledType(I.getType()) == types::TY_PCH) {
4588-
types::ID Expected = HeaderModuleInput.getType();
4589-
if (I.getType() != Expected) {
4590-
D.Diag(diag::err_drv_module_header_wrong_kind)
4591-
<< I.getFilename() << types::getTypeName(I.getType())
4592-
<< types::getTypeName(Expected);
4593-
}
4594-
ModuleHeaderInputs.push_back(I);
45954574
} else if (IsExtractAPI) {
45964575
auto ExpectedInputType = ExtractAPIPlaceholderInput.getType();
45974576
if (I.getType() != ExpectedInputType) {
@@ -4779,9 +4758,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
47794758
if (JA.getType() == types::TY_Nothing)
47804759
CmdArgs.push_back("-fsyntax-only");
47814760
else if (JA.getType() == types::TY_ModuleFile)
4782-
CmdArgs.push_back(IsHeaderModulePrecompile
4783-
? "-emit-header-module"
4784-
: "-emit-module-interface");
4761+
CmdArgs.push_back("-emit-module-interface");
47854762
else if (JA.getType() == types::TY_HeaderUnit)
47864763
CmdArgs.push_back("-emit-header-unit");
47874764
else
@@ -7376,9 +7353,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
73767353
addDashXForInput(Args, Input, CmdArgs);
73777354

73787355
ArrayRef<InputInfo> FrontendInputs = Input;
7379-
if (IsHeaderModulePrecompile)
7380-
FrontendInputs = ModuleHeaderInputs;
7381-
else if (IsExtractAPI)
7356+
if (IsExtractAPI)
73827357
FrontendInputs = ExtractAPIInputs;
73837358
else if (Input.isNothing())
73847359
FrontendInputs = {};

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,7 +2469,6 @@ static const auto &getFrontendActionTable() {
24692469

24702470
{frontend::GenerateModule, OPT_emit_module},
24712471
{frontend::GenerateModuleInterface, OPT_emit_module_interface},
2472-
{frontend::GenerateHeaderModule, OPT_emit_header_module},
24732472
{frontend::GenerateHeaderUnit, OPT_emit_header_unit},
24742473
{frontend::GeneratePCH, OPT_emit_pch},
24752474
{frontend::GenerateInterfaceStubs, OPT_emit_interface_stubs},
@@ -4129,7 +4128,6 @@ static bool isStrictlyPreprocessorAction(frontend::ActionKind Action) {
41294128
case frontend::FixIt:
41304129
case frontend::GenerateModule:
41314130
case frontend::GenerateModuleInterface:
4132-
case frontend::GenerateHeaderModule:
41334131
case frontend::GenerateHeaderUnit:
41344132
case frontend::GeneratePCH:
41354133
case frontend::GenerateInterfaceStubs:

clang/lib/Frontend/FrontendActions.cpp

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -265,77 +265,6 @@ GenerateModuleInterfaceAction::CreateOutputFile(CompilerInstance &CI,
265265
return CI.createDefaultOutputFile(/*Binary=*/true, InFile, "pcm");
266266
}
267267

268-
bool GenerateHeaderModuleAction::PrepareToExecuteAction(
269-
CompilerInstance &CI) {
270-
if (!CI.getLangOpts().Modules) {
271-
CI.getDiagnostics().Report(diag::err_header_module_requires_modules);
272-
return false;
273-
}
274-
275-
auto &Inputs = CI.getFrontendOpts().Inputs;
276-
if (Inputs.empty())
277-
return GenerateModuleAction::BeginInvocation(CI);
278-
279-
auto Kind = Inputs[0].getKind();
280-
281-
// Convert the header file inputs into a single module input buffer.
282-
SmallString<256> HeaderContents;
283-
ModuleHeaders.reserve(Inputs.size());
284-
for (const FrontendInputFile &FIF : Inputs) {
285-
// FIXME: We should support re-compiling from an AST file.
286-
if (FIF.getKind().getFormat() != InputKind::Source || !FIF.isFile()) {
287-
CI.getDiagnostics().Report(diag::err_module_header_file_not_found)
288-
<< (FIF.isFile() ? FIF.getFile()
289-
: FIF.getBuffer().getBufferIdentifier());
290-
return true;
291-
}
292-
293-
HeaderContents += "#include \"";
294-
HeaderContents += FIF.getFile();
295-
HeaderContents += "\"\n";
296-
ModuleHeaders.push_back(std::string(FIF.getFile()));
297-
}
298-
Buffer = llvm::MemoryBuffer::getMemBufferCopy(
299-
HeaderContents, Module::getModuleInputBufferName());
300-
301-
// Set that buffer up as our "real" input.
302-
Inputs.clear();
303-
Inputs.push_back(
304-
FrontendInputFile(Buffer->getMemBufferRef(), Kind, /*IsSystem*/ false));
305-
306-
return GenerateModuleAction::PrepareToExecuteAction(CI);
307-
}
308-
309-
bool GenerateHeaderModuleAction::BeginSourceFileAction(
310-
CompilerInstance &CI) {
311-
CI.getLangOpts().setCompilingModule(LangOptions::CMK_HeaderModule);
312-
313-
// Synthesize a Module object for the given headers.
314-
auto &HS = CI.getPreprocessor().getHeaderSearchInfo();
315-
SmallVector<Module::Header, 16> Headers;
316-
for (StringRef Name : ModuleHeaders) {
317-
Optional<FileEntryRef> FE = HS.LookupFile(
318-
Name, SourceLocation(), /*Angled*/ false, nullptr, nullptr, None,
319-
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
320-
if (!FE) {
321-
CI.getDiagnostics().Report(diag::err_module_header_file_not_found)
322-
<< Name;
323-
continue;
324-
}
325-
Headers.push_back(
326-
{std::string(Name), std::string(Name), &FE->getFileEntry()});
327-
}
328-
HS.getModuleMap().createHeaderModule(CI.getLangOpts().CurrentModule, Headers);
329-
330-
return GenerateModuleAction::BeginSourceFileAction(CI);
331-
}
332-
333-
std::unique_ptr<raw_pwrite_stream>
334-
GenerateHeaderModuleAction::CreateOutputFile(CompilerInstance &CI,
335-
StringRef InFile) {
336-
return CI.createDefaultOutputFile(/*Binary=*/true, InFile, "pcm");
337-
}
338-
339268
bool GenerateHeaderUnitAction::BeginSourceFileAction(CompilerInstance &CI) {
340269
if (!CI.getLangOpts().CPlusPlusModules) {
341270
CI.getDiagnostics().Report(diag::err_module_interface_requires_cpp_modules);

clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ CreateFrontendBaseAction(CompilerInstance &CI) {
6565
return std::make_unique<GenerateModuleFromModuleMapAction>();
6666
case GenerateModuleInterface:
6767
return std::make_unique<GenerateModuleInterfaceAction>();
68-
case GenerateHeaderModule:
69-
return std::make_unique<GenerateHeaderModuleAction>();
7068
case GenerateHeaderUnit:
7169
return std::make_unique<GenerateHeaderUnitAction>();
7270
case GeneratePCH: return std::make_unique<GeneratePCHAction>();

clang/lib/Lex/ModuleMap.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -899,29 +899,6 @@ Module *ModuleMap::createModuleForInterfaceUnit(SourceLocation Loc,
899899
return Result;
900900
}
901901

902-
Module *ModuleMap::createHeaderModule(StringRef Name,
903-
ArrayRef<Module::Header> Headers) {
904-
assert(LangOpts.CurrentModule == Name && "module name mismatch");
905-
assert(!Modules[Name] && "redefining existing module");
906-
907-
auto *Result =
908-
new Module(Name, SourceLocation(), nullptr, /*IsFramework*/ false,
909-
/*IsExplicit*/ false, NumCreatedModules++);
910-
Result->Kind = Module::ModuleInterfaceUnit;
911-
Modules[Name] = SourceModule = Result;
912-
913-
for (const Module::Header &H : Headers) {
914-
auto *M = new Module(H.NameAsWritten, SourceLocation(), Result,
915-
/*IsFramework*/ false,
916-
/*IsExplicit*/ true, NumCreatedModules++);
917-
// Header modules are implicitly 'export *'.
918-
M->Exports.push_back(Module::ExportDecl(nullptr, true));
919-
addHeader(M, H, NormalHeader);
920-
}
921-
922-
return Result;
923-
}
924-
925902
Module *ModuleMap::createHeaderUnit(SourceLocation Loc, StringRef Name,
926903
Module::Header H) {
927904
assert(LangOpts.CurrentModule == Name && "module name mismatch");

clang/test/CXX/cpp/cpp.module/Inputs/attrs.h

Lines changed: 0 additions & 1 deletion
This file was deleted.

clang/test/CXX/cpp/cpp.module/Inputs/empty.h

Whitespace-only changes.

clang/test/CXX/cpp/cpp.module/p1.cpp

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)