@@ -1332,10 +1332,12 @@ bool ModuleInterfaceLoader::buildSwiftModuleFromSwiftInterface(
1332
1332
SearchPathOpts.CandidateCompiledModules );
1333
1333
}
1334
1334
1335
- static bool readSwiftInterfaceVersionAndArgs (
1336
- SourceManager &SM, DiagnosticEngine &Diags, llvm::StringSaver &ArgSaver,
1337
- SmallVectorImpl<const char *> &SubArgs, std::string &CompilerVersion,
1338
- StringRef interfacePath, SourceLoc diagnosticLoc) {
1335
+ static bool readSwiftInterfaceVersionAndArgs (SourceManager &SM,
1336
+ DiagnosticEngine &Diags,
1337
+ llvm::StringSaver &ArgSaver,
1338
+ SwiftInterfaceInfo &interfaceInfo,
1339
+ StringRef interfacePath,
1340
+ SourceLoc diagnosticLoc) {
1339
1341
llvm::vfs::FileSystem &fs = *SM.getFileSystem ();
1340
1342
auto FileOrError = swift::vfs::getFileOrSTDIN (fs, interfacePath);
1341
1343
if (!FileOrError) {
@@ -1348,7 +1350,7 @@ static bool readSwiftInterfaceVersionAndArgs(
1348
1350
auto SB = FileOrError.get ()->getBuffer ();
1349
1351
auto VersRe = getSwiftInterfaceFormatVersionRegex ();
1350
1352
auto CompRe = getSwiftInterfaceCompilerVersionRegex ();
1351
- SmallVector<StringRef, 1 > VersMatches, CompMatches;
1353
+ SmallVector<StringRef, 2 > VersMatches, CompMatches;
1352
1354
1353
1355
if (!VersRe.match (SB, &VersMatches)) {
1354
1356
InterfaceSubContextDelegateImpl::diagnose (
@@ -1357,7 +1359,8 @@ static bool readSwiftInterfaceVersionAndArgs(
1357
1359
return true ;
1358
1360
}
1359
1361
1360
- if (extractCompilerFlagsFromInterface (interfacePath, SB, ArgSaver, SubArgs)) {
1362
+ if (extractCompilerFlagsFromInterface (interfacePath, SB, ArgSaver,
1363
+ interfaceInfo.Arguments )) {
1361
1364
InterfaceSubContextDelegateImpl::diagnose (
1362
1365
interfacePath, diagnosticLoc, SM, &Diags,
1363
1366
diag::error_extracting_version_from_module_interface);
@@ -1377,10 +1380,20 @@ static bool readSwiftInterfaceVersionAndArgs(
1377
1380
1378
1381
if (CompRe.match (SB, &CompMatches)) {
1379
1382
assert (CompMatches.size () == 2 );
1380
- CompilerVersion = ArgSaver.save (CompMatches[1 ]).str ();
1383
+ interfaceInfo.CompilerVersion = ArgSaver.save (CompMatches[1 ]).str ();
1384
+
1385
+ // For now, successfully parsing the tools version out of the interface is
1386
+ // optional.
1387
+ auto ToolsVersRe = getSwiftInterfaceCompilerToolsVersionRegex ();
1388
+ SmallVector<StringRef, 2 > VendorToolsVersMatches;
1389
+ if (ToolsVersRe.match (interfaceInfo.CompilerVersion ,
1390
+ &VendorToolsVersMatches)) {
1391
+ interfaceInfo.CompilerToolsVersion = VersionParser::parseVersionString (
1392
+ VendorToolsVersMatches[1 ], SourceLoc (), nullptr );
1393
+ }
1381
1394
} else {
1382
1395
// Don't diagnose; handwritten module interfaces don't include this field.
1383
- CompilerVersion = " (unspecified, file possibly handwritten)" ;
1396
+ interfaceInfo. CompilerVersion = " (unspecified, file possibly handwritten)" ;
1384
1397
}
1385
1398
1386
1399
// For now: we support anything with the same "major version" and assume
@@ -1421,23 +1434,18 @@ bool ModuleInterfaceLoader::buildExplicitSwiftModuleFromSwiftInterface(
1421
1434
// Read out the compiler version.
1422
1435
llvm::BumpPtrAllocator alloc;
1423
1436
llvm::StringSaver ArgSaver (alloc);
1424
- std::string CompilerVersion;
1425
- SmallVector<const char *, 64 > InterfaceArgs;
1426
- readSwiftInterfaceVersionAndArgs (Instance.getSourceMgr (),
1427
- Instance.getDiags (),
1428
- ArgSaver,
1429
- InterfaceArgs,
1430
- CompilerVersion,
1431
- interfacePath,
1437
+ SwiftInterfaceInfo InterfaceInfo;
1438
+ readSwiftInterfaceVersionAndArgs (Instance.getSourceMgr (), Instance.getDiags (),
1439
+ ArgSaver, InterfaceInfo, interfacePath,
1432
1440
SourceLoc ());
1433
-
1441
+
1434
1442
auto Builder = ExplicitModuleInterfaceBuilder (
1435
1443
Instance, &Instance.getDiags (), Instance.getSourceMgr (),
1436
1444
moduleCachePath, backupInterfaceDir, prebuiltCachePath,
1437
1445
ABIDescriptorPath, {});
1438
1446
auto error = Builder.buildSwiftModuleFromInterface (
1439
1447
interfacePath, outputPath, ShouldSerializeDeps, /* ModuleBuffer*/ nullptr ,
1440
- CompiledCandidates, CompilerVersion);
1448
+ CompiledCandidates, InterfaceInfo. CompilerVersion );
1441
1449
if (!error)
1442
1450
return false ;
1443
1451
else
@@ -1563,18 +1571,14 @@ void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface(
1563
1571
}
1564
1572
1565
1573
bool InterfaceSubContextDelegateImpl::extractSwiftInterfaceVersionAndArgs (
1566
- CompilerInvocation &subInvocation,
1567
- SmallVectorImpl<const char *> &SubArgs,
1568
- std::string &CompilerVersion,
1569
- StringRef interfacePath,
1570
- SourceLoc diagnosticLoc) {
1571
- if (readSwiftInterfaceVersionAndArgs (SM, *Diags, ArgSaver, SubArgs,
1572
- CompilerVersion, interfacePath,
1573
- diagnosticLoc))
1574
+ CompilerInvocation &subInvocation, SwiftInterfaceInfo &interfaceInfo,
1575
+ StringRef interfacePath, SourceLoc diagnosticLoc) {
1576
+ if (readSwiftInterfaceVersionAndArgs (SM, *Diags, ArgSaver, interfaceInfo,
1577
+ interfacePath, diagnosticLoc))
1574
1578
return true ;
1575
1579
1576
1580
SmallString<32 > ExpectedModuleName = subInvocation.getModuleName ();
1577
- if (subInvocation.parseArgs (SubArgs , *Diags)) {
1581
+ if (subInvocation.parseArgs (interfaceInfo. Arguments , *Diags)) {
1578
1582
return true ;
1579
1583
}
1580
1584
@@ -1834,24 +1838,28 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
1834
1838
.setMainAndSupplementaryOutputs (outputFiles, ModuleOutputPaths);
1835
1839
1836
1840
SmallVector<const char *, 64 > SubArgs;
1837
-
1838
- // If the interface was emitted by a compiler that didn't print
1839
- // `-target-min-inlining-version` into it, default to using the version from
1840
- // the target triple, emulating previous behavior.
1841
- SubArgs.push_back (" -target-min-inlining-version" );
1842
- SubArgs.push_back (" target" );
1843
-
1844
- std::string CompilerVersion;
1841
+ SwiftInterfaceInfo interfaceInfo;
1845
1842
// Extract compiler arguments from the interface file and use them to configure
1846
1843
// the compiler invocation.
1847
- if (extractSwiftInterfaceVersionAndArgs (subInvocation,
1848
- SubArgs,
1849
- CompilerVersion,
1850
- interfacePath,
1851
- diagLoc)) {
1844
+ if (extractSwiftInterfaceVersionAndArgs (subInvocation, interfaceInfo,
1845
+ interfacePath, diagLoc)) {
1852
1846
return std::make_error_code (std::errc::not_supported);
1853
1847
}
1854
1848
1849
+ // Prior to Swift 5.9, swiftinterfaces were always built (accidentally) with
1850
+ // `-target-min-inlining-version target` prepended to the argument list. To
1851
+ // preserve compatibility we must continue to prepend those flags to the
1852
+ // invocation when the interface was generated by an older compiler.
1853
+ if (auto toolsVersion = interfaceInfo.CompilerToolsVersion ) {
1854
+ if (toolsVersion < version::Version{5 , 9 }) {
1855
+ SubArgs.push_back (" -target-min-inlining-version" );
1856
+ SubArgs.push_back (" target" );
1857
+ }
1858
+ }
1859
+
1860
+ SubArgs.insert (SubArgs.end (), interfaceInfo.Arguments .begin (),
1861
+ interfaceInfo.Arguments .end ());
1862
+
1855
1863
// Insert arguments collected from the interface file.
1856
1864
BuildArgs.insert (BuildArgs.end (), SubArgs.begin (), SubArgs.end ());
1857
1865
if (subInvocation.parseArgs (SubArgs, *Diags)) {
@@ -1880,7 +1888,7 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
1880
1888
CompilerInstance subInstance;
1881
1889
SubCompilerInstanceInfo info;
1882
1890
info.Instance = &subInstance;
1883
- info.CompilerVersion = CompilerVersion;
1891
+ info.CompilerVersion = interfaceInfo. CompilerVersion ;
1884
1892
1885
1893
subInstance.getSourceMgr ().setFileSystem (SM.getFileSystem ());
1886
1894
0 commit comments