@@ -41,24 +41,25 @@ DependencyScanningWorkerFilesystem::readFile(StringRef Filename) {
41
41
return TentativeEntry (Stat, std::move (Buffer));
42
42
}
43
43
44
- EntryRef DependencyScanningWorkerFilesystem::scanForDirectivesIfNecessary (
45
- const CachedFileSystemEntry &Entry, StringRef Filename, bool Disable) {
46
- if (Entry.isError () || Entry.isDirectory () || Disable ||
47
- !shouldScanForDirectives (Filename))
48
- return EntryRef (Filename, Entry);
44
+ bool DependencyScanningWorkerFilesystem::ensureDirectiveTokensArePopulated (
45
+ EntryRef Ref) {
46
+ auto &Entry = Ref.Entry ;
47
+
48
+ if (Entry.isError () || Entry.isDirectory ())
49
+ return false ;
49
50
50
51
CachedFileContents *Contents = Entry.getCachedContents ();
51
52
assert (Contents && " contents not initialized" );
52
53
53
54
// Double-checked locking.
54
55
if (Contents->DepDirectives .load ())
55
- return EntryRef (Filename, Entry) ;
56
+ return true ;
56
57
57
58
std::lock_guard<std::mutex> GuardLock (Contents->ValueLock );
58
59
59
60
// Double-checked locking.
60
61
if (Contents->DepDirectives .load ())
61
- return EntryRef (Filename, Entry) ;
62
+ return true ;
62
63
63
64
SmallVector<dependency_directives_scan::Directive, 64 > Directives;
64
65
// Scan the file for preprocessor directives that might affect the
@@ -69,16 +70,16 @@ EntryRef DependencyScanningWorkerFilesystem::scanForDirectivesIfNecessary(
69
70
Contents->DepDirectiveTokens .clear ();
70
71
// FIXME: Propagate the diagnostic if desired by the client.
71
72
Contents->DepDirectives .store (new std::optional<DependencyDirectivesTy>());
72
- return EntryRef (Filename, Entry) ;
73
+ return false ;
73
74
}
74
75
75
76
// This function performed double-checked locking using `DepDirectives`.
76
77
// Assigning it must be the last thing this function does, otherwise other
77
- // threads may skip the
78
- // critical section (`DepDirectives != nullptr`), leading to a data race.
78
+ // threads may skip the critical section (`DepDirectives != nullptr`), leading
79
+ // to a data race.
79
80
Contents->DepDirectives .store (
80
81
new std::optional<DependencyDirectivesTy>(std::move (Directives)));
81
- return EntryRef (Filename, Entry) ;
82
+ return true ;
82
83
}
83
84
84
85
DependencyScanningFilesystemSharedCache::
@@ -161,34 +162,11 @@ DependencyScanningFilesystemSharedCache::CacheShard::
161
162
return *EntriesByFilename.insert ({Filename, &Entry}).first ->getValue ();
162
163
}
163
164
164
- // / Whitelist file extensions that should be minimized, treating no extension as
165
- // / a source file that should be minimized.
166
- // /
167
- // / This is kinda hacky, it would be better if we knew what kind of file Clang
168
- // / was expecting instead.
169
- static bool shouldScanForDirectivesBasedOnExtension (StringRef Filename) {
170
- StringRef Ext = llvm::sys::path::extension (Filename);
171
- if (Ext.empty ())
172
- return true ; // C++ standard library
173
- return llvm::StringSwitch<bool >(Ext)
174
- .CasesLower (" .c" , " .cc" , " .cpp" , " .c++" , " .cxx" , true )
175
- .CasesLower (" .h" , " .hh" , " .hpp" , " .h++" , " .hxx" , true )
176
- .CasesLower (" .m" , " .mm" , true )
177
- .CasesLower (" .i" , " .ii" , " .mi" , " .mmi" , true )
178
- .CasesLower (" .def" , " .inc" , true )
179
- .Default (false );
180
- }
181
-
182
165
static bool shouldCacheStatFailures (StringRef Filename) {
183
166
StringRef Ext = llvm::sys::path::extension (Filename);
184
167
if (Ext.empty ())
185
168
return false ; // This may be the module cache directory.
186
- // Only cache stat failures on files that are not expected to change during
187
- // the build.
188
- StringRef FName = llvm::sys::path::filename (Filename);
189
- if (FName == " module.modulemap" || FName == " module.map" )
190
- return true ;
191
- return shouldScanForDirectivesBasedOnExtension (Filename);
169
+ return true ;
192
170
}
193
171
194
172
DependencyScanningWorkerFilesystem::DependencyScanningWorkerFilesystem (
@@ -201,11 +179,6 @@ DependencyScanningWorkerFilesystem::DependencyScanningWorkerFilesystem(
201
179
updateWorkingDirForCacheLookup ();
202
180
}
203
181
204
- bool DependencyScanningWorkerFilesystem::shouldScanForDirectives (
205
- StringRef Filename) {
206
- return shouldScanForDirectivesBasedOnExtension (Filename);
207
- }
208
-
209
182
const CachedFileSystemEntry &
210
183
DependencyScanningWorkerFilesystem::getOrEmplaceSharedEntryForUID (
211
184
TentativeEntry TEntry) {
@@ -259,7 +232,7 @@ DependencyScanningWorkerFilesystem::computeAndStoreResult(
259
232
260
233
llvm::ErrorOr<EntryRef>
261
234
DependencyScanningWorkerFilesystem::getOrCreateFileSystemEntry (
262
- StringRef OriginalFilename, bool DisableDirectivesScanning ) {
235
+ StringRef OriginalFilename) {
263
236
StringRef FilenameForLookup;
264
237
SmallString<256 > PathBuf;
265
238
if (llvm::sys::path::is_absolute_gnu (OriginalFilename)) {
@@ -276,15 +249,11 @@ DependencyScanningWorkerFilesystem::getOrCreateFileSystemEntry(
276
249
assert (llvm::sys::path::is_absolute_gnu (FilenameForLookup));
277
250
if (const auto *Entry =
278
251
findEntryByFilenameWithWriteThrough (FilenameForLookup))
279
- return scanForDirectivesIfNecessary (*Entry, OriginalFilename,
280
- DisableDirectivesScanning)
281
- .unwrapError ();
252
+ return EntryRef (OriginalFilename, *Entry).unwrapError ();
282
253
auto MaybeEntry = computeAndStoreResult (OriginalFilename, FilenameForLookup);
283
254
if (!MaybeEntry)
284
255
return MaybeEntry.getError ();
285
- return scanForDirectivesIfNecessary (*MaybeEntry, OriginalFilename,
286
- DisableDirectivesScanning)
287
- .unwrapError ();
256
+ return EntryRef (OriginalFilename, *MaybeEntry).unwrapError ();
288
257
}
289
258
290
259
llvm::ErrorOr<llvm::vfs::Status>
0 commit comments