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