@@ -264,9 +264,11 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs,
264
264
StoreDiags ASTDiags;
265
265
266
266
llvm::Optional<PreamblePatch> Patch;
267
+ bool PreserveDiags = true ;
267
268
if (Preamble) {
268
269
Patch = PreamblePatch::create (Filename, Inputs, *Preamble);
269
270
Patch->apply (*CI);
271
+ PreserveDiags = Patch->preserveDiagnostics ();
270
272
}
271
273
auto Clang = prepareCompilerInstance (
272
274
std::move (CI), PreamblePCH,
@@ -441,14 +443,20 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs,
441
443
// CompilerInstance won't run this callback, do it directly.
442
444
ASTDiags.EndSourceFile ();
443
445
444
- std::vector<Diag> Diags = CompilerInvocationDiags;
445
- // Add diagnostics from the preamble, if any.
446
- if (Preamble)
447
- Diags.insert (Diags.end (), Preamble->Diags .begin (), Preamble->Diags .end ());
448
- // Finally, add diagnostics coming from the AST.
449
- {
450
- std::vector<Diag> D = ASTDiags.take (CTContext.getPointer ());
451
- Diags.insert (Diags.end (), D.begin (), D.end ());
446
+ llvm::Optional<std::vector<Diag>> Diags;
447
+ // FIXME: Also skip generation of diagnostics alltogether to speed up ast
448
+ // builds when we are patching a stale preamble.
449
+ if (PreserveDiags) {
450
+ Diags = CompilerInvocationDiags;
451
+ // Add diagnostics from the preamble, if any.
452
+ if (Preamble)
453
+ Diags->insert (Diags->end (), Preamble->Diags .begin (),
454
+ Preamble->Diags .end ());
455
+ // Finally, add diagnostics coming from the AST.
456
+ {
457
+ std::vector<Diag> D = ASTDiags.take (CTContext.getPointer ());
458
+ Diags->insert (Diags->end (), D.begin (), D.end ());
459
+ }
452
460
}
453
461
return ParsedAST (Inputs.Version , std::move (Preamble), std::move (Clang),
454
462
std::move (Action), std::move (Tokens), std::move (Macros),
@@ -493,14 +501,12 @@ llvm::ArrayRef<Decl *> ParsedAST::getLocalTopLevelDecls() {
493
501
494
502
const MainFileMacros &ParsedAST::getMacros () const { return Macros; }
495
503
496
- const std::vector<Diag> &ParsedAST::getDiagnostics () const { return Diags; }
497
-
498
504
std::size_t ParsedAST::getUsedBytes () const {
499
505
auto &AST = getASTContext ();
500
506
// FIXME(ibiryukov): we do not account for the dynamically allocated part of
501
507
// Message and Fixes inside each diagnostic.
502
- std::size_t Total =
503
- clangd::getUsedBytes (LocalTopLevelDecls) + clangd::getUsedBytes (Diags);
508
+ std::size_t Total = clangd::getUsedBytes (LocalTopLevelDecls) +
509
+ (Diags ? clangd::getUsedBytes (* Diags) : 0 );
504
510
505
511
// FIXME: the rest of the function is almost a direct copy-paste from
506
512
// libclang's clang_getCXTUResourceUsage. We could share the implementation.
@@ -541,8 +547,8 @@ ParsedAST::ParsedAST(llvm::StringRef Version,
541
547
std::unique_ptr<FrontendAction> Action,
542
548
syntax::TokenBuffer Tokens, MainFileMacros Macros,
543
549
std::vector<Decl *> LocalTopLevelDecls,
544
- std::vector<Diag> Diags, IncludeStructure Includes ,
545
- CanonicalIncludes CanonIncludes)
550
+ llvm::Optional< std::vector<Diag>> Diags,
551
+ IncludeStructure Includes, CanonicalIncludes CanonIncludes)
546
552
: Version(Version), Preamble(std::move(Preamble)), Clang(std::move(Clang)),
547
553
Action (std::move(Action)), Tokens(std::move(Tokens)),
548
554
Macros(std::move(Macros)), Diags(std::move(Diags)),
0 commit comments