@@ -308,12 +308,20 @@ class ASTBuildOperation
308
308
// / can be determined at construction time of the \c ASTBuildOperation.
309
309
const std::vector<FileContent> FileContents;
310
310
311
+ // / Guards \c DependencyStamps. This prevents reading from \c DependencyStamps
312
+ // / while it is being modified. It does not provide any ordering gurantees
313
+ // / that \c DependencyStamps have been computed in \c buildASTUnit before they
314
+ // / are accessed in \c matchesSourceState but that's fine (see comment on
315
+ // / \c DependencyStamps).
316
+ llvm::sys::Mutex DependencyStampsMtx;
317
+
311
318
// / \c DependencyStamps contains the stamps of all module depenecies needed
312
319
// / for the AST build. These stamps are only known after the AST is built.
313
320
// / Before the AST has been built, we thus assume that all dependency stamps
314
321
// / match. This seems to be a reasonable assumption since the dependencies
315
322
// / shouldn't change (much) in the time between an \c ASTBuildOperation is
316
323
// / created and until it produced an AST.
324
+ // / Must only be accessed if \c DependencyStampsMtx has been claimed.
317
325
SmallVector<std::pair<std::string, BufferStamp>, 8 > DependencyStamps = {};
318
326
319
327
// / The ASTManager from which this operation got scheduled. Used to update
@@ -898,6 +906,8 @@ bool ASTBuildOperation::matchesSourceState(
898
906
}
899
907
}
900
908
909
+ llvm::sys::ScopedLock L (DependencyStampsMtx);
910
+
901
911
for (auto &Dependency : DependencyStamps) {
902
912
if (Dependency.second !=
903
913
ASTManager->Impl .getBufferStamp (Dependency.first , OtherFileSystem))
@@ -1070,9 +1080,12 @@ ASTUnitRef ASTBuildOperation::buildASTUnit(std::string &Error) {
1070
1080
collectModuleDependencies (CompIns.getMainModule (), Visited, Filenames);
1071
1081
// FIXME: There exists a small window where the module file may have been
1072
1082
// modified after compilation finished and before we get its stamp.
1073
- for (auto &Filename : Filenames) {
1074
- DependencyStamps.push_back (std::make_pair (
1075
- Filename, ASTManager->Impl .getBufferStamp (Filename, FileSystem)));
1083
+ {
1084
+ llvm::sys::ScopedLock L (DependencyStampsMtx);
1085
+ for (auto &Filename : Filenames) {
1086
+ DependencyStamps.push_back (std::make_pair (
1087
+ Filename, ASTManager->Impl .getBufferStamp (Filename, FileSystem)));
1088
+ }
1076
1089
}
1077
1090
1078
1091
// Since we only typecheck the primary file (plus referenced constructs
0 commit comments