@@ -1150,19 +1150,11 @@ static Language getLanguageFromOptions(const LangOptions &LangOpts) {
1150
1150
return LangOpts.CPlusPlus ? Language::CXX : Language::C;
1151
1151
}
1152
1152
1153
- // / Creates a \c CompilerInstance for compiling a module.
1154
- // /
1155
- // / This expects a properly initialized \c FrontendInputFile.
1156
- static std::unique_ptr<CompilerInstance>
1157
- createCompilerInstanceForModuleCompileImpl (CompilerInstance &ImportingInstance,
1158
- SourceLocation ImportLoc,
1159
- StringRef ModuleName,
1160
- FrontendInputFile Input,
1161
- StringRef OriginalModuleMapFile,
1162
- StringRef ModuleFileName) {
1153
+ std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompileImpl (
1154
+ SourceLocation ImportLoc, StringRef ModuleName, FrontendInputFile Input,
1155
+ StringRef OriginalModuleMapFile, StringRef ModuleFileName) {
1163
1156
// Construct a compiler invocation for creating this module.
1164
- auto Invocation =
1165
- std::make_shared<CompilerInvocation>(ImportingInstance.getInvocation ());
1157
+ auto Invocation = std::make_shared<CompilerInvocation>(getInvocation ());
1166
1158
1167
1159
PreprocessorOptions &PPOpts = Invocation->getPreprocessorOpts ();
1168
1160
@@ -1182,7 +1174,7 @@ createCompilerInstanceForModuleCompileImpl(CompilerInstance &ImportingInstance,
1182
1174
1183
1175
// If the original compiler invocation had -fmodule-name, pass it through.
1184
1176
Invocation->getLangOpts ().ModuleName =
1185
- ImportingInstance. getInvocation ().getLangOpts ().ModuleName ;
1177
+ getInvocation ().getLangOpts ().ModuleName ;
1186
1178
1187
1179
// Note the name of the module we're building.
1188
1180
Invocation->getLangOpts ().CurrentModule = std::string (ModuleName);
@@ -1206,82 +1198,70 @@ createCompilerInstanceForModuleCompileImpl(CompilerInstance &ImportingInstance,
1206
1198
DiagnosticOptions &DiagOpts = Invocation->getDiagnosticOpts ();
1207
1199
1208
1200
DiagOpts.VerifyDiagnostics = 0 ;
1209
- assert (ImportingInstance. getInvocation ().getModuleHash () ==
1210
- Invocation-> getModuleHash () && " Module hash mismatch!" );
1201
+ assert (getInvocation ().getModuleHash () == Invocation-> getModuleHash () &&
1202
+ " Module hash mismatch!" );
1211
1203
1212
1204
// Construct a compiler instance that will be used to actually create the
1213
1205
// module. Since we're sharing an in-memory module cache,
1214
1206
// CompilerInstance::CompilerInstance is responsible for finalizing the
1215
1207
// buffers to prevent use-after-frees.
1216
1208
auto InstancePtr = std::make_unique<CompilerInstance>(
1217
- ImportingInstance.getPCHContainerOperations (),
1218
- &ImportingInstance.getModuleCache ());
1209
+ getPCHContainerOperations (), &getModuleCache ());
1219
1210
auto &Instance = *InstancePtr;
1220
1211
1221
1212
auto &Inv = *Invocation;
1222
1213
Instance.setInvocation (std::move (Invocation));
1223
1214
1224
1215
Instance.createDiagnostics (
1225
- ImportingInstance. getVirtualFileSystem (),
1226
- new ForwardingDiagnosticConsumer (ImportingInstance. getDiagnosticClient ()),
1216
+ getVirtualFileSystem (),
1217
+ new ForwardingDiagnosticConsumer (getDiagnosticClient ()),
1227
1218
/* ShouldOwnClient=*/ true );
1228
1219
1229
1220
if (llvm::is_contained (DiagOpts.SystemHeaderWarningsModules , ModuleName))
1230
1221
Instance.getDiagnostics ().setSuppressSystemWarnings (false );
1231
1222
1232
1223
if (FrontendOpts.ModulesShareFileManager ) {
1233
- Instance.setFileManager (&ImportingInstance. getFileManager ());
1224
+ Instance.setFileManager (&getFileManager ());
1234
1225
} else {
1235
- Instance.createFileManager (&ImportingInstance. getVirtualFileSystem ());
1226
+ Instance.createFileManager (&getVirtualFileSystem ());
1236
1227
}
1237
1228
Instance.createSourceManager (Instance.getFileManager ());
1238
1229
SourceManager &SourceMgr = Instance.getSourceManager ();
1239
1230
1240
1231
// Note that this module is part of the module build stack, so that we
1241
1232
// can detect cycles in the module graph.
1242
- SourceMgr.setModuleBuildStack (
1243
- ImportingInstance.getSourceManager ().getModuleBuildStack ());
1233
+ SourceMgr.setModuleBuildStack (getSourceManager ().getModuleBuildStack ());
1244
1234
SourceMgr.pushModuleBuildStack (ModuleName,
1245
- FullSourceLoc (ImportLoc, ImportingInstance. getSourceManager ()));
1235
+ FullSourceLoc (ImportLoc, getSourceManager ()));
1246
1236
1247
- // Make sure that the failed-module structure has been allocated in
1248
- // the importing instance, and propagate the pointer to the newly-created
1249
- // instance.
1250
- if (!ImportingInstance.hasFailedModulesSet ())
1251
- ImportingInstance.createFailedModulesSet ();
1252
- Instance.setFailedModulesSet (ImportingInstance.getFailedModulesSetPtr ());
1237
+ // Make a copy for the new instance.
1238
+ Instance.FailedModules = FailedModules;
1253
1239
1254
1240
// If we're collecting module dependencies, we need to share a collector
1255
1241
// between all of the module CompilerInstances. Other than that, we don't
1256
1242
// want to produce any dependency output from the module build.
1257
- Instance.setModuleDepCollector (ImportingInstance. getModuleDepCollector ());
1243
+ Instance.setModuleDepCollector (getModuleDepCollector ());
1258
1244
Inv.getDependencyOutputOpts () = DependencyOutputOptions ();
1259
1245
1260
1246
return InstancePtr;
1261
1247
}
1262
1248
1263
- // / Compile a module file for the given module, using the options
1264
- // / provided by the importing compiler instance. Returns true if the module
1265
- // / was built without errors.
1266
- static bool compileModule (CompilerInstance &ImportingInstance,
1267
- SourceLocation ImportLoc, StringRef ModuleName,
1268
- StringRef ModuleFileName,
1269
- CompilerInstance &Instance) {
1249
+ bool CompilerInstance::compileModule (SourceLocation ImportLoc,
1250
+ StringRef ModuleName,
1251
+ StringRef ModuleFileName,
1252
+ CompilerInstance &Instance) {
1270
1253
llvm::TimeTraceScope TimeScope (" Module Compile" , ModuleName);
1271
1254
1272
1255
// Never compile a module that's already finalized - this would cause the
1273
1256
// existing module to be freed, causing crashes if it is later referenced
1274
- if (ImportingInstance.getModuleCache ().getInMemoryModuleCache ().isPCMFinal (
1275
- ModuleFileName)) {
1276
- ImportingInstance.getDiagnostics ().Report (
1277
- ImportLoc, diag::err_module_rebuild_finalized)
1257
+ if (getModuleCache ().getInMemoryModuleCache ().isPCMFinal (ModuleFileName)) {
1258
+ getDiagnostics ().Report (ImportLoc, diag::err_module_rebuild_finalized)
1278
1259
<< ModuleName;
1279
1260
return false ;
1280
1261
}
1281
1262
1282
- ImportingInstance.getDiagnostics ().Report (ImportLoc,
1283
- diag::remark_module_build)
1284
- << ModuleName << ModuleFileName;
1263
+ getDiagnostics ().Report (ImportLoc, diag::remark_module_build)
1264
+ << ModuleName << ModuleFileName;
1285
1265
1286
1266
// Execute the action to actually build the module in-place. Use a separate
1287
1267
// thread so that we get a stack large enough.
@@ -1292,13 +1272,15 @@ static bool compileModule(CompilerInstance &ImportingInstance,
1292
1272
},
1293
1273
DesiredStackSize);
1294
1274
1295
- ImportingInstance.getDiagnostics ().Report (ImportLoc,
1296
- diag::remark_module_build_done)
1297
- << ModuleName;
1275
+ getDiagnostics ().Report (ImportLoc, diag::remark_module_build_done)
1276
+ << ModuleName;
1298
1277
1299
1278
// Propagate the statistics to the parent FileManager.
1300
- if (!ImportingInstance.getFrontendOpts ().ModulesShareFileManager )
1301
- ImportingInstance.getFileManager ().AddStats (Instance.getFileManager ());
1279
+ if (!getFrontendOpts ().ModulesShareFileManager )
1280
+ getFileManager ().AddStats (Instance.getFileManager ());
1281
+
1282
+ // Propagate the failed modules to the parent instance.
1283
+ FailedModules = std::move (Instance.FailedModules );
1302
1284
1303
1285
if (Crashed) {
1304
1286
// Clear the ASTConsumer if it hasn't been already, in case it owns streams
@@ -1312,8 +1294,8 @@ static bool compileModule(CompilerInstance &ImportingInstance,
1312
1294
1313
1295
// We've rebuilt a module. If we're allowed to generate or update the global
1314
1296
// module index, record that fact in the importing compiler instance.
1315
- if (ImportingInstance. getFrontendOpts ().GenerateGlobalModuleIndex ) {
1316
- ImportingInstance. setBuildGlobalModuleIndex (true );
1297
+ if (getFrontendOpts ().GenerateGlobalModuleIndex ) {
1298
+ setBuildGlobalModuleIndex (true );
1317
1299
}
1318
1300
1319
1301
// If \p AllowPCMWithCompilerErrors is set return 'success' even if errors
@@ -1378,8 +1360,8 @@ std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompile(
1378
1360
bool IsSystem = isSystem (SLoc.getFile ().getFileCharacteristic ());
1379
1361
1380
1362
// Use the module map where this module resides.
1381
- return createCompilerInstanceForModuleCompileImpl (
1382
- * this , ImportLoc, ModuleName,
1363
+ return cloneForModuleCompileImpl (
1364
+ ImportLoc, ModuleName,
1383
1365
FrontendInputFile (ModuleMapFilePath, IK, IsSystem),
1384
1366
ModMap.getModuleMapFileForUniquing (Module)->getName (), ModuleFileName);
1385
1367
}
@@ -1395,8 +1377,8 @@ std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompile(
1395
1377
llvm::raw_string_ostream OS (InferredModuleMapContent);
1396
1378
Module->print (OS);
1397
1379
1398
- auto Instance = createCompilerInstanceForModuleCompileImpl (
1399
- * this , ImportLoc, ModuleName,
1380
+ auto Instance = cloneForModuleCompileImpl (
1381
+ ImportLoc, ModuleName,
1400
1382
FrontendInputFile (FakeModuleMapFile, IK, +Module->IsSystem ),
1401
1383
ModMap.getModuleMapFileForUniquing (Module)->getName (), ModuleFileName);
1402
1384
@@ -1460,9 +1442,9 @@ static bool compileModuleAndReadASTImpl(CompilerInstance &ImportingInstance,
1460
1442
auto Instance = ImportingInstance.cloneForModuleCompile (ModuleNameLoc, Module,
1461
1443
ModuleFileName);
1462
1444
1463
- if (!compileModule (ImportingInstance, ModuleNameLoc,
1464
- Module->getTopLevelModuleName (), ModuleFileName ,
1465
- *Instance)) {
1445
+ if (!ImportingInstance. compileModule (ModuleNameLoc,
1446
+ Module->getTopLevelModuleName (),
1447
+ ModuleFileName, *Instance)) {
1466
1448
ImportingInstance.getDiagnostics ().Report (ModuleNameLoc,
1467
1449
diag::err_module_not_built)
1468
1450
<< Module->Name << SourceRange (ImportLoc, ModuleNameLoc);
@@ -2002,7 +1984,7 @@ ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST(
2002
1984
}
2003
1985
2004
1986
// Check whether we have already attempted to build this module (but failed).
2005
- if (FailedModules && FailedModules-> hasAlreadyFailed (ModuleName)) {
1987
+ if (FailedModules. contains (ModuleName)) {
2006
1988
getDiagnostics ().Report (ModuleNameLoc, diag::err_module_not_built)
2007
1989
<< ModuleName << SourceRange (ImportLoc, ModuleNameLoc);
2008
1990
return nullptr ;
@@ -2013,8 +1995,7 @@ ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST(
2013
1995
ModuleFilename)) {
2014
1996
assert (getDiagnostics ().hasErrorOccurred () &&
2015
1997
" undiagnosed error in compileModuleAndReadAST" );
2016
- if (FailedModules)
2017
- FailedModules->addFailed (ModuleName);
1998
+ FailedModules.insert (ModuleName);
2018
1999
return nullptr ;
2019
2000
}
2020
2001
@@ -2238,8 +2219,8 @@ void CompilerInstance::createModuleFromSource(SourceLocation ImportLoc,
2238
2219
2239
2220
std::string NullTerminatedSource (Source.str ());
2240
2221
2241
- auto Other = createCompilerInstanceForModuleCompileImpl (
2242
- * this , ImportLoc, ModuleName, Input, StringRef (), ModuleFileName);
2222
+ auto Other = cloneForModuleCompileImpl (ImportLoc, ModuleName, Input,
2223
+ StringRef (), ModuleFileName);
2243
2224
2244
2225
// Create a virtual file containing our desired source.
2245
2226
// FIXME: We shouldn't need to do this.
@@ -2252,8 +2233,7 @@ void CompilerInstance::createModuleFromSource(SourceLocation ImportLoc,
2252
2233
Other->DeleteBuiltModules = false ;
2253
2234
2254
2235
// Build the module, inheriting any modules that we've built locally.
2255
- bool Success =
2256
- compileModule (*this , ImportLoc, ModuleName, ModuleFileName, *Other);
2236
+ bool Success = compileModule (ImportLoc, ModuleName, ModuleFileName, *Other);
2257
2237
2258
2238
BuiltModules = std::move (Other->BuiltModules );
2259
2239
0 commit comments