@@ -423,10 +423,6 @@ class ASTWorker {
423
423
Deadline scheduleLocked ();
424
424
// / Should the first task in the queue be skipped instead of run?
425
425
bool shouldSkipHeadLocked () const ;
426
- // / This is private because `FileInputs.FS` is not thread-safe and thus not
427
- // / safe to share. Callers should make sure not to expose `FS` via a public
428
- // / interface.
429
- std::shared_ptr<const ParseInputs> getCurrentFileInputs () const ;
430
426
431
427
struct Request {
432
428
llvm::unique_function<void ()> Action;
@@ -458,9 +454,9 @@ class ASTWorker {
458
454
// / Guards members used by both TUScheduler and the worker thread.
459
455
mutable std::mutex Mutex;
460
456
// / File inputs, currently being used by the worker.
461
- // / Inputs are written and read by the worker thread, compile command can also
462
- // / be consumed by clients of ASTWorker .
463
- std::shared_ptr< const ParseInputs> FileInputs; /* GUARDED_BY(Mutex) */
457
+ // / Writes and reads from unknown threads are locked. Reads from the worker
458
+ // / thread are not locked, as it's the only writer .
459
+ ParseInputs FileInputs; /* GUARDED_BY(Mutex) */
464
460
// / Times of recent AST rebuilds, used for UpdateDebounce computation.
465
461
llvm::SmallVector<DebouncePolicy::clock::duration, 8 >
466
462
RebuildTimes; /* GUARDED_BY(Mutex) */
@@ -556,12 +552,10 @@ ASTWorker::ASTWorker(PathRef FileName, const GlobalCompilationDatabase &CDB,
556
552
// FIXME: Run PreamblePeer asynchronously once ast patching
557
553
// is available.
558
554
/* RunSync=*/ true , Status, *this ) {
559
- auto Inputs = std::make_shared<ParseInputs>();
560
555
// Set a fallback command because compile command can be accessed before
561
556
// `Inputs` is initialized. Other fields are only used after initialization
562
557
// from client inputs.
563
- Inputs->CompileCommand = CDB.getFallbackCommand (FileName);
564
- FileInputs = std::move (Inputs);
558
+ FileInputs.CompileCommand = CDB.getFallbackCommand (FileName);
565
559
}
566
560
567
561
ASTWorker::~ASTWorker () {
@@ -590,7 +584,7 @@ void ASTWorker::update(ParseInputs Inputs, WantDiagnostics WantDiags) {
590
584
Inputs.CompileCommand = CDB.getFallbackCommand (FileName);
591
585
592
586
bool InputsAreTheSame =
593
- std::tie (FileInputs-> CompileCommand , FileInputs-> Contents ) ==
587
+ std::tie (FileInputs. CompileCommand , FileInputs. Contents ) ==
594
588
std::tie (Inputs.CompileCommand , Inputs.Contents );
595
589
// Cached AST is invalidated.
596
590
if (!InputsAreTheSame) {
@@ -601,7 +595,7 @@ void ASTWorker::update(ParseInputs Inputs, WantDiagnostics WantDiags) {
601
595
// Update current inputs so that subsequent reads can see them.
602
596
{
603
597
std::lock_guard<std::mutex> Lock (Mutex);
604
- FileInputs = std::make_shared<ParseInputs>( Inputs) ;
598
+ FileInputs = Inputs;
605
599
}
606
600
607
601
log (" ASTWorker building file {0} version {1} with command {2}\n [{3}]\n {4}" ,
@@ -655,21 +649,20 @@ void ASTWorker::runWithAST(
655
649
if (isCancelled ())
656
650
return Action (llvm::make_error<CancelledError>());
657
651
llvm::Optional<std::unique_ptr<ParsedAST>> AST = IdleASTs.take (this );
658
- auto CurrentInputs = getCurrentFileInputs ();
659
652
if (!AST) {
660
653
StoreDiags CompilerInvocationDiagConsumer;
661
- std::unique_ptr<CompilerInvocation> Invocation = buildCompilerInvocation (
662
- *CurrentInputs , CompilerInvocationDiagConsumer);
654
+ std::unique_ptr<CompilerInvocation> Invocation =
655
+ buildCompilerInvocation (FileInputs , CompilerInvocationDiagConsumer);
663
656
// Try rebuilding the AST.
664
657
vlog (" ASTWorker rebuilding evicted AST to run {0}: {1} version {2}" , Name,
665
- FileName, CurrentInputs-> Version );
658
+ FileName, FileInputs. Version );
666
659
// FIXME: We might need to build a patched ast once preamble thread starts
667
660
// running async. Currently getPossiblyStalePreamble below will always
668
661
// return a compatible preamble as ASTWorker::update blocks.
669
662
llvm::Optional<ParsedAST> NewAST =
670
663
Invocation ? buildAST (FileName, std::move (Invocation),
671
664
CompilerInvocationDiagConsumer.take (),
672
- *CurrentInputs , getPossiblyStalePreamble ())
665
+ FileInputs , getPossiblyStalePreamble ())
673
666
: None;
674
667
AST = NewAST ? std::make_unique<ParsedAST>(std::move (*NewAST)) : nullptr ;
675
668
}
@@ -681,8 +674,8 @@ void ASTWorker::runWithAST(
681
674
return Action (llvm::make_error<llvm::StringError>(
682
675
" invalid AST" , llvm::errc::invalid_argument));
683
676
vlog (" ASTWorker running {0} on version {2} of {1}" , Name, FileName,
684
- CurrentInputs-> Version );
685
- Action (InputsAndAST{*CurrentInputs , **AST});
677
+ FileInputs. Version );
678
+ Action (InputsAndAST{FileInputs , **AST});
686
679
};
687
680
startTask (Name, std::move (Task), /* UpdateType=*/ None, Invalidation);
688
681
}
@@ -782,7 +775,7 @@ void ASTWorker::generateDiagnostics(
782
775
}
783
776
// Used to check whether we can update AST cache.
784
777
bool InputsAreLatest =
785
- std::tie (FileInputs-> CompileCommand , FileInputs-> Contents ) ==
778
+ std::tie (FileInputs. CompileCommand , FileInputs. Contents ) ==
786
779
std::tie (Inputs.CompileCommand , Inputs.Contents );
787
780
// Take a shortcut and don't report the diagnostics, since they should be the
788
781
// same. All the clients should handle the lack of OnUpdated() call anyway to
@@ -899,14 +892,9 @@ void ASTWorker::getCurrentPreamble(
899
892
900
893
void ASTWorker::waitForFirstPreamble () const { BuiltFirstPreamble.wait (); }
901
894
902
- std::shared_ptr<const ParseInputs> ASTWorker::getCurrentFileInputs () const {
903
- std::unique_lock<std::mutex> Lock (Mutex);
904
- return FileInputs;
905
- }
906
-
907
895
tooling::CompileCommand ASTWorker::getCurrentCompileCommand () const {
908
896
std::unique_lock<std::mutex> Lock (Mutex);
909
- return FileInputs-> CompileCommand ;
897
+ return FileInputs. CompileCommand ;
910
898
}
911
899
912
900
std::size_t ASTWorker::getUsedBytes () const {
0 commit comments