Skip to content

Commit 26fc63e

Browse files
authored
Revert "[clang] Don't add documentation comments to the AST if not requested" (#219807)
Reverts llvm/llvm-project#206363 due to huge compile-time regression.
1 parent e971feb commit 26fc63e

21 files changed

Lines changed: 98 additions & 278 deletions

clang-tools-extra/clang-doc/tool/ClangDocMain.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,7 @@ Example usage for a project using a compile commands database:
285285
llvm::outs() << "Emiting docs in " << Format << " format.\n";
286286
auto G = ExitOnErr(doc::findGeneratorByName(Format));
287287

288-
ArgumentsAdjuster ArgAdjuster = getInsertArgumentAdjuster(
289-
"-fretain-comments", tooling::ArgumentInsertPosition::END);
288+
ArgumentsAdjuster ArgAdjuster;
290289
if (!DoxygenOnly)
291290
ArgAdjuster = combineAdjusters(
292291
getInsertArgumentAdjuster("-fparse-all-comments",

clang-tools-extra/clangd/Compiler.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ buildCompilerInvocation(const ParseInputs &Inputs, clang::DiagnosticConsumer &D,
121121
// createInvocationFromCommandLine sets DisableFree.
122122
CI->getFrontendOpts().DisableFree = false;
123123
CI->getLangOpts().CommentOpts.ParseAllComments = true;
124-
CI->getLangOpts().CommentOpts.RetainComments = true;
125-
CI->getLangOpts().CommentOpts.RetainCommentsFromSystemHeaders = true;
124+
CI->getLangOpts().RetainCommentsFromSystemHeaders = true;
126125

127126
disableUnsupportedOptions(*CI);
128127
return CI;

clang-tools-extra/clangd/index/IndexAction.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ class IndexAction : public ASTFrontendAction {
167167
bool BeginInvocation(CompilerInstance &CI) override {
168168
// We want all comments, not just the doxygen ones.
169169
CI.getLangOpts().CommentOpts.ParseAllComments = true;
170-
CI.getLangOpts().CommentOpts.RetainComments = true;
171-
CI.getLangOpts().CommentOpts.RetainCommentsFromSystemHeaders = true;
170+
CI.getLangOpts().RetainCommentsFromSystemHeaders = true;
172171
// Index the whole file even if there are warnings and -Werror is set.
173172
// Avoids some analyses too. Set in two places as we're late to the party.
174173
CI.getDiagnosticOpts().IgnoreWarnings = true;

clang/docs/ReleaseNotes.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -405,12 +405,6 @@ features cannot lower the translation-unit ABI level;
405405

406406
- Improved how Unicode characters are displayed in diagnostic messages.
407407

408-
- Clang no longer retains source comments in the AST when nothing will read them
409-
back. Comments are now collected only when they may be consumed (e.g. with
410-
``-fparse-all-comments``, when ``-Wdocumentation`` is enabled, when emitting a
411-
PCH/module, or during code completion), reducing memory overhead for typical
412-
compilations.
413-
414408
- `-Wtautological-pointer-compare` and `-Wpointer-bool-conversion` now
415409
diagnose a reference to a function (e.g. of type `void (&)()`) compared
416410
against or converted to a null pointer, the same as a bare function name.

clang/include/clang/Basic/CommentOptions.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,6 @@ struct CommentOptions {
3030
/// Treat ordinary comments as documentation comments.
3131
bool ParseAllComments = false;
3232

33-
/// Force the front end to retain all documentation comments in the AST, even
34-
/// when no comment consuming diagnostic or language option is enabled. Tools
35-
/// that query comments after parsing set this.
36-
bool RetainComments = false;
37-
38-
/// Retain documentation comments from system headers in the AST.
39-
bool RetainCommentsFromSystemHeaders = false;
40-
4133
CommentOptions() = default;
4234
};
4335

clang/include/clang/Basic/Diagnostic.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -974,16 +974,6 @@ class DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> {
974974
diag::Severity::Ignored;
975975
}
976976

977-
bool areAllIgnored(StringRef Group, SourceLocation Loc) const {
978-
llvm::SmallVector<diag::kind> diagsInGroup;
979-
bool Failed = Diags->getDiagnosticsInGroup(diag::Flavor::WarningOrError,
980-
Group, diagsInGroup);
981-
assert(!Failed && "Incorrect group name?");
982-
(void)Failed;
983-
return Diags->getDiagnosticListHighestSeverity(diagsInGroup, Loc, *this) ==
984-
diag::Severity::Ignored;
985-
}
986-
987977
/// Based on the way the client configured the DiagnosticsEngine
988978
/// object, classify the specified diagnostic ID into a Level, consumable by
989979
/// the DiagnosticConsumer.

clang/include/clang/Basic/DiagnosticIDs.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -516,12 +516,6 @@ class DiagnosticIDs : public RefCountedBase<DiagnosticIDs> {
516516
getDiagnosticSeverity(unsigned DiagID, SourceLocation Loc,
517517
const DiagnosticsEngine &Diag) const LLVM_READONLY;
518518

519-
/// Given a collection of diagnostic IDs, get the 'highest' severity of them
520-
/// at the provided location for this DiagnosticsEngine.
521-
diag::Severity getDiagnosticListHighestSeverity(
522-
llvm::ArrayRef<diag::kind> DiagIDs, SourceLocation Loc,
523-
const DiagnosticsEngine &Diag) const LLVM_READONLY;
524-
525519
Class getDiagClass(unsigned DiagID) const;
526520

527521
/// Whether the diagnostic may leave the AST in a state where some

clang/include/clang/Basic/LangOptions.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,8 @@ LANGOPT(ApplePragmaPack, 1, 0, NotCompatible, "Apple gcc-compatible #pragma pack
405405

406406
LANGOPT(XLPragmaPack, 1, 0, NotCompatible, "IBM XL #pragma pack handling")
407407

408+
LANGOPT(RetainCommentsFromSystemHeaders, 1, 0, Compatible, "retain documentation comments from system headers in the AST")
409+
408410
LANGOPT(APINotes, 1, 0, NotCompatible, "use external API notes")
409411
LANGOPT(APINotesModules, 1, 0, NotCompatible, "use module-based external API notes")
410412
LANGOPT(SwiftVersionIndependentAPINotes, 1, 0, NotCompatible, "use external API notes capturing all versions")

clang/include/clang/Options/Options.td

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,12 +2221,6 @@ defm define_target_os_macros : OptInCC1FFlag<"define-target-os-macros",
22212221
def fparse_all_comments : Flag<["-"], "fparse-all-comments">, Group<f_clang_Group>,
22222222
Visibility<[ClangOption, CC1Option]>,
22232223
MarshallingInfoFlag<LangOpts<"CommentOpts.ParseAllComments">>;
2224-
def fretain_comments : Flag<["-"], "fretain-comments">, Group<f_clang_Group>,
2225-
Visibility<[ClangOption, CC1Option]>,
2226-
HelpText<"Retain documentation comments in the AST even when no diagnostic or "
2227-
"language option would otherwise require them (e.g. for tools that "
2228-
"query comments after parsing)">,
2229-
MarshallingInfoFlag<LangOpts<"CommentOpts.RetainComments">>;
22302224
def frecord_command_line : Flag<["-"], "frecord-command-line">,
22312225
DocBrief<[{Generate a section named ".GCC.command.line" containing the
22322226
driver command-line. After linking, the section may contain multiple command
@@ -3948,7 +3942,7 @@ defm implicit_modules : BoolFOption<"implicit-modules",
39483942
[NoXarchOption], [ClangOption, CLOption]>>;
39493943
def fretain_comments_from_system_headers : Flag<["-"], "fretain-comments-from-system-headers">, Group<f_Group>,
39503944
Visibility<[ClangOption, CC1Option]>,
3951-
MarshallingInfoFlag<LangOpts<"CommentOpts.RetainCommentsFromSystemHeaders">>;
3945+
MarshallingInfoFlag<LangOpts<"RetainCommentsFromSystemHeaders">>;
39523946
def fmodule_header : Flag <["-"], "fmodule-header">, Group<f_Group>,
39533947
Visibility<[ClangOption, CLOption]>,
39543948
HelpText<"Build a C++20 Header Unit from a header">;

clang/include/clang/Sema/Sema.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,11 +1126,6 @@ class Sema final : public SemaBase {
11261126

11271127
void ActOnComment(SourceRange Comment);
11281128

1129-
/// Returns true if a comment at \p Loc should be retained in the AST
1130-
/// (some consumer such as -Wdocumentation, -fparse-all-comments, code
1131-
/// completion, or AST-file serialization may read it back).
1132-
bool shouldRetainCommentsInAST(SourceLocation Loc) const;
1133-
11341129
/// Retrieve the parser's current scope.
11351130
///
11361131
/// This routine must only be used when it is certain that semantic analysis

0 commit comments

Comments
 (0)