@@ -46,24 +46,25 @@ DependencyScanningWorkerFilesystem::readFile(StringRef Filename) {
46
46
return TentativeEntry (Stat, std::move (Buffer), std::move (CASContents));
47
47
}
48
48
49
- EntryRef DependencyScanningWorkerFilesystem::scanForDirectivesIfNecessary (
50
- const CachedFileSystemEntry &Entry, StringRef Filename, bool Disable) {
51
- if (Entry.isError () || Entry.isDirectory () || Disable ||
52
- !shouldScanForDirectives (Filename))
53
- return EntryRef (Filename, Entry);
49
+ bool DependencyScanningWorkerFilesystem::ensureDirectiveTokensArePopulated (
50
+ EntryRef Ref) {
51
+ auto &Entry = Ref.Entry ;
52
+
53
+ if (Entry.isError () || Entry.isDirectory ())
54
+ return false ;
54
55
55
56
CachedFileContents *Contents = Entry.getCachedContents ();
56
57
assert (Contents && " contents not initialized" );
57
58
58
59
// Double-checked locking.
59
60
if (Contents->DepDirectives .load ())
60
- return EntryRef (Filename, Entry) ;
61
+ return true ;
61
62
62
63
std::lock_guard<std::mutex> GuardLock (Contents->ValueLock );
63
64
64
65
// Double-checked locking.
65
66
if (Contents->DepDirectives .load ())
66
- return EntryRef (Filename, Entry) ;
67
+ return true ;
67
68
68
69
SmallVector<dependency_directives_scan::Directive, 64 > Directives;
69
70
// Scan the file for preprocessor directives that might affect the
@@ -74,16 +75,16 @@ EntryRef DependencyScanningWorkerFilesystem::scanForDirectivesIfNecessary(
74
75
Contents->DepDirectiveTokens .clear ();
75
76
// FIXME: Propagate the diagnostic if desired by the client.
76
77
Contents->DepDirectives .store (new std::optional<DependencyDirectivesTy>());
77
- return EntryRef (Filename, Entry) ;
78
+ return false ;
78
79
}
79
80
80
81
// This function performed double-checked locking using `DepDirectives`.
81
82
// Assigning it must be the last thing this function does, otherwise other
82
- // threads may skip the
83
- // critical section (`DepDirectives != nullptr`), leading to a data race.
83
+ // threads may skip the critical section (`DepDirectives != nullptr`), leading
84
+ // to a data race.
84
85
Contents->DepDirectives .store (
85
86
new std::optional<DependencyDirectivesTy>(std::move (Directives)));
86
- return EntryRef (Filename, Entry) ;
87
+ return true ;
87
88
}
88
89
89
90
DependencyScanningFilesystemSharedCache::
@@ -167,34 +168,11 @@ DependencyScanningFilesystemSharedCache::CacheShard::
167
168
return *EntriesByFilename.insert ({Filename, &Entry}).first ->getValue ();
168
169
}
169
170
170
- // / Whitelist file extensions that should be minimized, treating no extension as
171
- // / a source file that should be minimized.
172
- // /
173
- // / This is kinda hacky, it would be better if we knew what kind of file Clang
174
- // / was expecting instead.
175
- static bool shouldScanForDirectivesBasedOnExtension (StringRef Filename) {
176
- StringRef Ext = llvm::sys::path::extension (Filename);
177
- if (Ext.empty ())
178
- return true ; // C++ standard library
179
- return llvm::StringSwitch<bool >(Ext)
180
- .CasesLower (" .c" , " .cc" , " .cpp" , " .c++" , " .cxx" , true )
181
- .CasesLower (" .h" , " .hh" , " .hpp" , " .h++" , " .hxx" , true )
182
- .CasesLower (" .m" , " .mm" , true )
183
- .CasesLower (" .i" , " .ii" , " .mi" , " .mmi" , true )
184
- .CasesLower (" .def" , " .inc" , true )
185
- .Default (false );
186
- }
187
-
188
171
static bool shouldCacheStatFailures (StringRef Filename) {
189
172
StringRef Ext = llvm::sys::path::extension (Filename);
190
173
if (Ext.empty ())
191
174
return false ; // This may be the module cache directory.
192
- // Only cache stat failures on files that are not expected to change during
193
- // the build.
194
- StringRef FName = llvm::sys::path::filename (Filename);
195
- if (FName == " module.modulemap" || FName == " module.map" )
196
- return true ;
197
- return shouldScanForDirectivesBasedOnExtension (Filename);
175
+ return true ;
198
176
}
199
177
200
178
DependencyScanningWorkerFilesystem::DependencyScanningWorkerFilesystem (
@@ -207,11 +185,6 @@ DependencyScanningWorkerFilesystem::DependencyScanningWorkerFilesystem(
207
185
updateWorkingDirForCacheLookup ();
208
186
}
209
187
210
- bool DependencyScanningWorkerFilesystem::shouldScanForDirectives (
211
- StringRef Filename) {
212
- return shouldScanForDirectivesBasedOnExtension (Filename);
213
- }
214
-
215
188
const CachedFileSystemEntry &
216
189
DependencyScanningWorkerFilesystem::getOrEmplaceSharedEntryForUID (
217
190
TentativeEntry TEntry) {
@@ -265,7 +238,7 @@ DependencyScanningWorkerFilesystem::computeAndStoreResult(
265
238
266
239
llvm::ErrorOr<EntryRef>
267
240
DependencyScanningWorkerFilesystem::getOrCreateFileSystemEntry (
268
- StringRef OriginalFilename, bool DisableDirectivesScanning ) {
241
+ StringRef OriginalFilename) {
269
242
StringRef FilenameForLookup;
270
243
SmallString<256 > PathBuf;
271
244
if (llvm::sys::path::is_absolute_gnu (OriginalFilename)) {
@@ -282,15 +255,11 @@ DependencyScanningWorkerFilesystem::getOrCreateFileSystemEntry(
282
255
assert (llvm::sys::path::is_absolute_gnu (FilenameForLookup));
283
256
if (const auto *Entry =
284
257
findEntryByFilenameWithWriteThrough (FilenameForLookup))
285
- return scanForDirectivesIfNecessary (*Entry, OriginalFilename,
286
- DisableDirectivesScanning)
287
- .unwrapError ();
258
+ return EntryRef (OriginalFilename, *Entry).unwrapError ();
288
259
auto MaybeEntry = computeAndStoreResult (OriginalFilename, FilenameForLookup);
289
260
if (!MaybeEntry)
290
261
return MaybeEntry.getError ();
291
- return scanForDirectivesIfNecessary (*MaybeEntry, OriginalFilename,
292
- DisableDirectivesScanning)
293
- .unwrapError ();
262
+ return EntryRef (OriginalFilename, *MaybeEntry).unwrapError ();
294
263
}
295
264
296
265
llvm::ErrorOr<llvm::vfs::Status>
0 commit comments