@@ -852,7 +852,7 @@ class ModuleInterfaceLoaderImpl {
852
852
/* serializeDependencyHashes*/ false ,
853
853
trackSystemDependencies);
854
854
// Set up a builder if we need to build the module. It'll also set up
855
- // the subinvocation we'll need to use to compute the cache paths.
855
+ // the genericSubInvocation we'll need to use to compute the cache paths.
856
856
ModuleInterfaceBuilder builder (
857
857
ctx.SourceMgr , ctx.Diags , astDelegate, interfacePath, moduleName, cacheDir,
858
858
prebuiltCacheDir,
@@ -1118,68 +1118,69 @@ void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface(
1118
1118
const SearchPathOptions &SearchPathOpts,
1119
1119
const LangOptions &LangOpts) {
1120
1120
GenericArgs.push_back (" -frontend" );
1121
- // Start with a SubInvocation that copies various state from our
1121
+ // Start with a genericSubInvocation that copies various state from our
1122
1122
// invoking ASTContext.
1123
1123
GenericArgs.push_back (" -compile-module-from-interface" );
1124
- subInvocation .setTargetTriple (LangOpts.Target );
1124
+ genericSubInvocation .setTargetTriple (LangOpts.Target );
1125
1125
1126
- auto triple = ArgSaver.save (subInvocation .getTargetTriple ());
1126
+ auto triple = ArgSaver.save (genericSubInvocation .getTargetTriple ());
1127
1127
if (!triple.empty ()) {
1128
1128
GenericArgs.push_back (" -target" );
1129
1129
GenericArgs.push_back (triple);
1130
1130
}
1131
1131
1132
1132
// Inherit the Swift language version
1133
- subInvocation .getLangOptions ().EffectiveLanguageVersion =
1133
+ genericSubInvocation .getLangOptions ().EffectiveLanguageVersion =
1134
1134
LangOpts.EffectiveLanguageVersion ;
1135
1135
GenericArgs.push_back (" -swift-version" );
1136
- GenericArgs.push_back (ArgSaver.save (subInvocation .getLangOptions ()
1136
+ GenericArgs.push_back (ArgSaver.save (genericSubInvocation .getLangOptions ()
1137
1137
.EffectiveLanguageVersion .asAPINotesVersionString ()));
1138
1138
1139
- subInvocation .setImportSearchPaths (SearchPathOpts.ImportSearchPaths );
1139
+ genericSubInvocation .setImportSearchPaths (SearchPathOpts.ImportSearchPaths );
1140
1140
llvm::for_each (SearchPathOpts.ImportSearchPaths ,
1141
1141
[&](const std::string &path) {
1142
1142
GenericArgs.push_back (" -I" );
1143
1143
GenericArgs.push_back (path);
1144
1144
});
1145
- subInvocation .setFrameworkSearchPaths (SearchPathOpts.FrameworkSearchPaths );
1145
+ genericSubInvocation .setFrameworkSearchPaths (SearchPathOpts.FrameworkSearchPaths );
1146
1146
llvm::for_each (SearchPathOpts.FrameworkSearchPaths ,
1147
1147
[&](const SearchPathOptions::FrameworkSearchPath &path) {
1148
1148
GenericArgs.push_back (path.IsSystem ? " -Fsystem" : " -F" );
1149
1149
GenericArgs.push_back (path.Path );
1150
1150
});
1151
1151
if (!SearchPathOpts.SDKPath .empty ()) {
1152
- subInvocation .setSDKPath (SearchPathOpts.SDKPath );
1152
+ genericSubInvocation .setSDKPath (SearchPathOpts.SDKPath );
1153
1153
GenericArgs.push_back (" -sdk" );
1154
1154
GenericArgs.push_back (SearchPathOpts.SDKPath );
1155
1155
}
1156
1156
1157
- subInvocation .setInputKind (InputFileKind::SwiftModuleInterface);
1157
+ genericSubInvocation .setInputKind (InputFileKind::SwiftModuleInterface);
1158
1158
if (!SearchPathOpts.RuntimeResourcePath .empty ()) {
1159
- subInvocation .setRuntimeResourcePath (SearchPathOpts.RuntimeResourcePath );
1159
+ genericSubInvocation .setRuntimeResourcePath (SearchPathOpts.RuntimeResourcePath );
1160
1160
GenericArgs.push_back (" -resource-dir" );
1161
1161
GenericArgs.push_back (SearchPathOpts.RuntimeResourcePath );
1162
1162
}
1163
1163
1164
- // Inhibit warnings from the SubInvocation since we are assuming the user
1164
+ // Inhibit warnings from the genericSubInvocation since we are assuming the user
1165
1165
// is not in a position to fix them.
1166
- subInvocation .getDiagnosticOptions ().SuppressWarnings = true ;
1166
+ genericSubInvocation .getDiagnosticOptions ().SuppressWarnings = true ;
1167
1167
GenericArgs.push_back (" -suppress-warnings" );
1168
1168
1169
1169
// Inherit this setting down so that it can affect error diagnostics (mostly
1170
1170
// by making them non-fatal).
1171
- subInvocation .getLangOptions ().DebuggerSupport = LangOpts.DebuggerSupport ;
1171
+ genericSubInvocation .getLangOptions ().DebuggerSupport = LangOpts.DebuggerSupport ;
1172
1172
if (LangOpts.DebuggerSupport ) {
1173
1173
GenericArgs.push_back (" -debugger-support" );
1174
1174
}
1175
1175
1176
1176
// Disable this; deinitializers always get printed with `@objc` even in
1177
1177
// modules that don't import Foundation.
1178
- subInvocation .getLangOptions ().EnableObjCAttrRequiresFoundation = false ;
1178
+ genericSubInvocation .getLangOptions ().EnableObjCAttrRequiresFoundation = false ;
1179
1179
GenericArgs.push_back (" -disable-objc-attr-requires-foundation-module" );
1180
1180
}
1181
1181
1182
1182
bool InterfaceSubContextDelegateImpl::extractSwiftInterfaceVersionAndArgs (
1183
+ CompilerInvocation &subInvocation,
1183
1184
SmallVectorImpl<const char *> &SubArgs,
1184
1185
std::string &CompilerVersion,
1185
1186
StringRef interfacePath,
@@ -1251,7 +1252,7 @@ bool InterfaceSubContextDelegateImpl::extractSwiftInterfaceVersionAndArgs(
1251
1252
}
1252
1253
1253
1254
void InterfaceSubContextDelegateImpl::addExtraClangArg (StringRef arg) {
1254
- subInvocation .getClangImporterOptions ().ExtraArgs .push_back (arg);
1255
+ genericSubInvocation .getClangImporterOptions ().ExtraArgs .push_back (arg);
1255
1256
GenericArgs.push_back (" -Xcc" );
1256
1257
GenericArgs.push_back (ArgSaver.save (arg));
1257
1258
}
@@ -1268,36 +1269,36 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
1268
1269
StringRef prebuiltCachePath,
1269
1270
bool serializeDependencyHashes,
1270
1271
bool trackSystemDependencies): SM(SM), Diags(Diags), ArgSaver(Allocator) {
1271
- subInvocation .setMainExecutablePath (LoaderOpts.mainExecutablePath );
1272
+ genericSubInvocation .setMainExecutablePath (LoaderOpts.mainExecutablePath );
1272
1273
inheritOptionsForBuildingInterface (searchPathOpts, langOpts);
1273
1274
// Configure front-end input.
1274
- auto &SubFEOpts = subInvocation .getFrontendOptions ();
1275
+ auto &SubFEOpts = genericSubInvocation .getFrontendOptions ();
1275
1276
SubFEOpts.RequestedAction = FrontendOptions::ActionType::EmitModuleOnly;
1276
1277
if (!moduleCachePath.empty ()) {
1277
- subInvocation .setClangModuleCachePath (moduleCachePath);
1278
+ genericSubInvocation .setClangModuleCachePath (moduleCachePath);
1278
1279
GenericArgs.push_back (" -module-cache-path" );
1279
1280
GenericArgs.push_back (moduleCachePath);
1280
1281
}
1281
1282
if (!prebuiltCachePath.empty ()) {
1282
- subInvocation .getFrontendOptions ().PrebuiltModuleCachePath =
1283
+ genericSubInvocation .getFrontendOptions ().PrebuiltModuleCachePath =
1283
1284
prebuiltCachePath.str ();
1284
1285
GenericArgs.push_back (" -prebuilt-module-cache-path" );
1285
1286
GenericArgs.push_back (prebuiltCachePath);
1286
1287
}
1287
1288
if (trackSystemDependencies) {
1288
- subInvocation .getFrontendOptions ().IntermoduleDependencyTracking =
1289
+ genericSubInvocation .getFrontendOptions ().IntermoduleDependencyTracking =
1289
1290
IntermoduleDepTrackingMode::IncludeSystem;
1290
1291
GenericArgs.push_back (" -track-system-dependencies" );
1291
1292
} else {
1292
1293
// Always track at least the non-system dependencies for interface building.
1293
- subInvocation .getFrontendOptions ().IntermoduleDependencyTracking =
1294
+ genericSubInvocation .getFrontendOptions ().IntermoduleDependencyTracking =
1294
1295
IntermoduleDepTrackingMode::ExcludeSystem;
1295
1296
}
1296
1297
if (LoaderOpts.disableImplicitSwiftModule ) {
1297
- subInvocation .getFrontendOptions ().DisableImplicitModules = true ;
1298
+ genericSubInvocation .getFrontendOptions ().DisableImplicitModules = true ;
1298
1299
GenericArgs.push_back (" -disable-implicit-swift-modules" );
1299
1300
}
1300
- subInvocation .getSearchPathOptions ().ExplicitSwiftModules =
1301
+ genericSubInvocation .getSearchPathOptions ().ExplicitSwiftModules =
1301
1302
searchPathOpts.ExplicitSwiftModules ;
1302
1303
// Dependencies scanner shouldn't know any explict Swift modules to use.
1303
1304
// Adding these argumnets may not be necessary.
@@ -1309,7 +1310,7 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
1309
1310
// Pass down -explicit-swift-module-map-file
1310
1311
// FIXME: we shouldn't need this. Remove it?
1311
1312
StringRef explictSwiftModuleMap = searchPathOpts.ExplicitSwiftModuleMap ;
1312
- subInvocation .getSearchPathOptions ().ExplicitSwiftModuleMap =
1313
+ genericSubInvocation .getSearchPathOptions ().ExplicitSwiftModuleMap =
1313
1314
explictSwiftModuleMap;
1314
1315
if (!explictSwiftModuleMap.empty ()) {
1315
1316
GenericArgs.push_back (" -explicit-swift-module-map-file" );
@@ -1329,19 +1330,19 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
1329
1330
// required by sourcekitd.
1330
1331
auto &Opts = clangImporter->getClangInstance ().getPreprocessorOpts ();
1331
1332
if (Opts.DetailedRecord ) {
1332
- subInvocation .getClangImporterOptions ().DetailedPreprocessingRecord = true ;
1333
+ genericSubInvocation .getClangImporterOptions ().DetailedPreprocessingRecord = true ;
1333
1334
}
1334
1335
}
1335
1336
1336
- // Tell the subinvocation to serialize dependency hashes if asked to do so.
1337
- auto &frontendOpts = subInvocation .getFrontendOptions ();
1337
+ // Tell the genericSubInvocation to serialize dependency hashes if asked to do so.
1338
+ auto &frontendOpts = genericSubInvocation .getFrontendOptions ();
1338
1339
frontendOpts.SerializeModuleInterfaceDependencyHashes =
1339
1340
serializeDependencyHashes;
1340
1341
if (serializeDependencyHashes) {
1341
1342
GenericArgs.push_back (" -serialize-module-interface-dependency-hashes" );
1342
1343
}
1343
1344
1344
- // Tell the subinvocation to remark on rebuilds from an interface if asked
1345
+ // Tell the genericSubInvocation to remark on rebuilds from an interface if asked
1345
1346
// to do so.
1346
1347
frontendOpts.RemarkOnRebuildFromModuleInterface =
1347
1348
LoaderOpts.remarkOnRebuildFromInterface ;
@@ -1355,14 +1356,14 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
1355
1356
(void )llvm::sys::fs::create_directories (moduleCachePath);
1356
1357
}
1357
1358
1358
- // / Calculate an output filename in \p SubInvocation 's cache path that
1359
+ // / Calculate an output filename in \p genericSubInvocation 's cache path that
1359
1360
// / includes a hash of relevant key data.
1360
1361
StringRef InterfaceSubContextDelegateImpl::computeCachedOutputPath (
1361
1362
StringRef moduleName,
1362
1363
StringRef useInterfacePath,
1363
1364
llvm::SmallString<256 > &OutPath,
1364
1365
StringRef &CacheHash) {
1365
- OutPath = subInvocation .getClangModuleCachePath ();
1366
+ OutPath = genericSubInvocation .getClangModuleCachePath ();
1366
1367
llvm::sys::path::append (OutPath, moduleName);
1367
1368
OutPath.append (" -" );
1368
1369
auto hashStart = OutPath.size ();
@@ -1387,7 +1388,7 @@ StringRef InterfaceSubContextDelegateImpl::computeCachedOutputPath(
1387
1388
std::string
1388
1389
InterfaceSubContextDelegateImpl::getCacheHash (StringRef useInterfacePath) {
1389
1390
auto normalizedTargetTriple =
1390
- getTargetSpecificModuleTriple (subInvocation .getLangOptions ().Target );
1391
+ getTargetSpecificModuleTriple (genericSubInvocation .getLangOptions ().Target );
1391
1392
1392
1393
llvm::hash_code H = hash_combine (
1393
1394
// Start with the compiler version (which will be either tag names or
@@ -1411,11 +1412,11 @@ InterfaceSubContextDelegateImpl::getCacheHash(StringRef useInterfacePath) {
1411
1412
1412
1413
// The SDK path is going to affect how this module is imported, so
1413
1414
// include it.
1414
- subInvocation .getSDKPath (),
1415
+ genericSubInvocation .getSDKPath (),
1415
1416
1416
1417
// Whether or not we're tracking system dependencies affects the
1417
1418
// invalidation behavior of this cache item.
1418
- subInvocation .getFrontendOptions ().shouldTrackSystemDependencies ());
1419
+ genericSubInvocation .getFrontendOptions ().shouldTrackSystemDependencies ());
1419
1420
1420
1421
return llvm::APInt (64 , H).toString (36 , /* Signed=*/ false );
1421
1422
}
@@ -1424,11 +1425,13 @@ bool InterfaceSubContextDelegateImpl::runInSubContext(StringRef moduleName,
1424
1425
StringRef interfacePath,
1425
1426
StringRef outputPath,
1426
1427
SourceLoc diagLoc,
1427
- llvm::function_ref<bool (ASTContext&, ArrayRef<StringRef>,
1428
+ llvm::function_ref<bool (ASTContext&, ModuleDecl*, ArrayRef<StringRef>,
1428
1429
ArrayRef<StringRef>, StringRef)> action) {
1429
1430
return runInSubCompilerInstance (moduleName, interfacePath, outputPath, diagLoc,
1430
1431
[&](SubCompilerInstanceInfo &info){
1431
- return action (info.Instance ->getASTContext (), info.BuildArguments ,
1432
+ return action (info.Instance ->getASTContext (),
1433
+ info.Instance ->getMainModule (),
1434
+ info.BuildArguments ,
1432
1435
info.ExtraPCMArgs ,
1433
1436
info.Hash );
1434
1437
});
@@ -1439,6 +1442,10 @@ bool InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleN
1439
1442
StringRef outputPath,
1440
1443
SourceLoc diagLoc,
1441
1444
llvm::function_ref<bool (SubCompilerInstanceInfo&)> action) {
1445
+ // We are about to mess up the compiler invocation by using the compiler
1446
+ // arguments in the textual interface file. So copy to use a new compiler
1447
+ // invocation.
1448
+ CompilerInvocation subInvocation = genericSubInvocation;
1442
1449
std::vector<StringRef> BuildArgs (GenericArgs.begin (), GenericArgs.end ());
1443
1450
assert (BuildArgs.size () == GenericArgs.size ());
1444
1451
// Configure inputs
@@ -1473,7 +1480,8 @@ bool InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleN
1473
1480
std::string CompilerVersion;
1474
1481
// Extract compiler arguments from the interface file and use them to configure
1475
1482
// the compiler invocation.
1476
- if (extractSwiftInterfaceVersionAndArgs (SubArgs,
1483
+ if (extractSwiftInterfaceVersionAndArgs (subInvocation,
1484
+ SubArgs,
1477
1485
CompilerVersion,
1478
1486
interfacePath,
1479
1487
diagLoc)) {
0 commit comments