@@ -108,7 +108,7 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type,
108
108
109
109
// Look for the file entry. This only fails if the expected size or
110
110
// modification time differ.
111
- OptionalFileEntryRefDegradesToFileEntryPtr Entry;
111
+ OptionalFileEntryRef Entry;
112
112
if (Type == MK_ExplicitModule || Type == MK_PrebuiltModule) {
113
113
// If we're not expecting to pull this file out of the module cache, it
114
114
// might have a different mtime due to being moved across filesystems in
@@ -123,7 +123,7 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type,
123
123
return OutOfDate;
124
124
}
125
125
126
- if (!Entry && FileName != " - " ) {
126
+ if (!Entry) {
127
127
ErrorStr = " module file not found" ;
128
128
return Missing;
129
129
}
@@ -150,7 +150,7 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type,
150
150
};
151
151
152
152
// Check whether we already loaded this module, before
153
- if (ModuleFile *ModuleEntry = Modules.lookup (Entry)) {
153
+ if (ModuleFile *ModuleEntry = Modules.lookup (* Entry)) {
154
154
if (implicitModuleNamesMatch (Type, ModuleEntry, *Entry)) {
155
155
// Check the stored signature.
156
156
if (checkSignature (ModuleEntry->Signature , ExpectedSignature, ErrorStr))
@@ -163,10 +163,9 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type,
163
163
}
164
164
165
165
// Allocate a new module.
166
- auto NewModule = std::make_unique<ModuleFile>(Type, Generation);
166
+ auto NewModule = std::make_unique<ModuleFile>(Type, *Entry, Generation);
167
167
NewModule->Index = Chain.size ();
168
168
NewModule->FileName = FileName.str ();
169
- NewModule->File = Entry;
170
169
NewModule->ImportLoc = ImportLoc;
171
170
NewModule->InputFilesValidationTimestamp = 0 ;
172
171
@@ -198,21 +197,15 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type,
198
197
Entry->closeFile ();
199
198
return OutOfDate;
200
199
} else {
201
- // Open the AST file.
202
- llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Buf ((std::error_code ()));
203
- if (FileName == " -" ) {
204
- Buf = llvm::MemoryBuffer::getSTDIN ();
205
- } else {
206
- // Get a buffer of the file and close the file descriptor when done.
207
- // The file is volatile because in a parallel build we expect multiple
208
- // compiler processes to use the same module file rebuilding it if needed.
209
- //
210
- // RequiresNullTerminator is false because module files don't need it, and
211
- // this allows the file to still be mmapped.
212
- Buf = FileMgr.getBufferForFile (*NewModule->File ,
213
- /* IsVolatile=*/ true ,
214
- /* RequiresNullTerminator=*/ false );
215
- }
200
+ // Get a buffer of the file and close the file descriptor when done.
201
+ // The file is volatile because in a parallel build we expect multiple
202
+ // compiler processes to use the same module file rebuilding it if needed.
203
+ //
204
+ // RequiresNullTerminator is false because module files don't need it, and
205
+ // this allows the file to still be mmapped.
206
+ auto Buf = FileMgr.getBufferForFile (NewModule->File ,
207
+ /* IsVolatile=*/ true ,
208
+ /* RequiresNullTerminator=*/ false );
216
209
217
210
if (!Buf) {
218
211
ErrorStr = Buf.getError ().message ();
@@ -232,7 +225,7 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type,
232
225
return OutOfDate;
233
226
234
227
// We're keeping this module. Store it everywhere.
235
- Module = Modules[Entry] = NewModule.get ();
228
+ Module = Modules[* Entry] = NewModule.get ();
236
229
237
230
updateModuleImports (*NewModule, ImportedBy, ImportLoc);
238
231
@@ -441,22 +434,19 @@ void ModuleManager::visit(llvm::function_ref<bool(ModuleFile &M)> Visitor,
441
434
bool ModuleManager::lookupModuleFile (StringRef FileName, off_t ExpectedSize,
442
435
time_t ExpectedModTime,
443
436
OptionalFileEntryRef &File) {
444
- File = std::nullopt;
445
- if (FileName == " - " )
437
+ if (FileName == " - " ) {
438
+ File = expectedToOptional (FileMgr. getSTDIN ());
446
439
return false ;
440
+ }
447
441
448
442
// Open the file immediately to ensure there is no race between stat'ing and
449
443
// opening the file.
450
- OptionalFileEntryRef FileOrErr =
451
- expectedToOptional (FileMgr.getFileRef (FileName, /* OpenFile=*/ true ,
452
- /* CacheFailure=*/ false ));
453
- if (!FileOrErr)
454
- return false ;
455
-
456
- File = *FileOrErr;
444
+ File = FileMgr.getOptionalFileRef (FileName, /* OpenFile=*/ true ,
445
+ /* CacheFailure=*/ false );
457
446
458
- if ((ExpectedSize && ExpectedSize != File->getSize ()) ||
459
- (ExpectedModTime && ExpectedModTime != File->getModificationTime ()))
447
+ if (File &&
448
+ ((ExpectedSize && ExpectedSize != File->getSize ()) ||
449
+ (ExpectedModTime && ExpectedModTime != File->getModificationTime ())))
460
450
// Do not destroy File, as it may be referenced. If we need to rebuild it,
461
451
// it will be destroyed by removeModules.
462
452
return true ;
0 commit comments