@@ -45,9 +45,11 @@ class ModuleDependenciesCacheDeserializer {
45
45
std::vector<LinkLibrary> LinkLibraries;
46
46
std::vector<std::vector<uint64_t >> ArraysOfLinkLibraryIDs;
47
47
std::vector<std::pair<std::string, MacroPluginDependency>> MacroDependencies;
48
+ std::vector<serialization::SearchPath> SearchPaths;
48
49
std::vector<std::vector<uint64_t >> ArraysOfMacroDependenciesIDs;
49
50
std::vector<ScannerImportStatementInfo> ImportStatements;
50
51
std::vector<std::vector<uint64_t >> ArraysOfImportStatementIDs;
52
+ std::vector<std::vector<uint64_t >> ArraysOfSearchPathIDs;
51
53
std::vector<std::vector<uint64_t >> ArraysOfOptionalImportStatementIDs;
52
54
53
55
llvm::BitstreamCursor Cursor;
@@ -66,6 +68,8 @@ class ModuleDependenciesCacheDeserializer {
66
68
std::optional<std::vector<LinkLibrary>> getLinkLibraryArray (unsigned n);
67
69
std::optional<std::vector<std::pair<std::string, MacroPluginDependency>>>
68
70
getMacroDependenciesArray (unsigned n);
71
+ std::optional<std::vector<serialization::SearchPath>>
72
+ getSearchPathArray (unsigned n);
69
73
std::optional<std::vector<ScannerImportStatementInfo>>
70
74
getImportStatementInfoArray (unsigned n);
71
75
std::optional<std::vector<ScannerImportStatementInfo>>
@@ -389,6 +393,24 @@ bool ModuleDependenciesCacheDeserializer::readGraph(
389
393
break ;
390
394
}
391
395
396
+ case SEARCH_PATH_NODE: {
397
+ unsigned pathStrID;
398
+ bool isFramework, isSystem;
399
+ SearchPathLayout::readRecord (Scratch, pathStrID, isFramework, isSystem);
400
+ auto pathStr = getIdentifier (pathStrID);
401
+ if (!pathStr)
402
+ llvm::report_fatal_error (" Bad search path: no path string" );
403
+ SearchPaths.push_back ({*pathStr, isFramework, isSystem});
404
+ break ;
405
+ }
406
+
407
+ case SEARCH_PATH_ARRAY_NODE: {
408
+ ArrayRef<uint64_t > identifierIDs;
409
+ SearchPathArrayLayout::readRecord (Scratch, identifierIDs);
410
+ ArraysOfSearchPathIDs.push_back (identifierIDs.vec ());
411
+ break ;
412
+ }
413
+
392
414
case IMPORT_STATEMENT_NODE: {
393
415
unsigned importIdentifierID, bufferIdentifierID;
394
416
unsigned lineNumber, columnNumber;
@@ -653,14 +675,15 @@ bool ModuleDependenciesCacheDeserializer::readGraph(
653
675
llvm::report_fatal_error (
654
676
" Unexpected SWIFT_BINARY_MODULE_DETAILS_NODE record" );
655
677
unsigned compiledModulePathID, moduleDocPathID, moduleSourceInfoPathID,
656
- headerImportID, definingInterfacePathID,
678
+ headerImportID, definingInterfacePathID, searchPathArrayID,
657
679
headerModuleDependenciesArrayID, headerImportsSourceFilesArrayID,
658
680
isFramework, isStatic, moduleCacheKeyID, userModuleVersionID;
659
681
SwiftBinaryModuleDetailsLayout::readRecord (
660
682
Scratch, compiledModulePathID, moduleDocPathID,
661
683
moduleSourceInfoPathID, headerImportID, definingInterfacePathID,
662
684
headerModuleDependenciesArrayID, headerImportsSourceFilesArrayID,
663
- isFramework, isStatic, moduleCacheKeyID, userModuleVersionID);
685
+ searchPathArrayID, isFramework, isStatic, moduleCacheKeyID,
686
+ userModuleVersionID);
664
687
665
688
auto compiledModulePath = getIdentifier (compiledModulePathID);
666
689
if (!compiledModulePath)
@@ -685,14 +708,17 @@ bool ModuleDependenciesCacheDeserializer::readGraph(
685
708
if (!definingInterfacePath)
686
709
llvm::report_fatal_error (
687
710
" Bad binary direct dependencies: no defining interface path" );
711
+ auto searchPaths = getSearchPathArray (searchPathArrayID);
712
+ if (!searchPaths)
713
+ llvm::report_fatal_error (
714
+ " Bad binary direct dependencies: no serialized search paths" );
688
715
689
716
// Form the dependencies storage object
690
717
auto moduleDep = ModuleDependencyInfo::forSwiftBinaryModule (
691
718
*compiledModulePath, *moduleDocPath, *moduleSourceInfoPath,
692
719
importStatements, optionalImportStatements, linkLibraries,
693
- {}, // TODO: serialized search path serialization
694
- *headerImport, *definingInterfacePath, isFramework, isStatic,
695
- *moduleCacheKey, *userModuleVersion);
720
+ *searchPaths, *headerImport, *definingInterfacePath, isFramework,
721
+ isStatic, *moduleCacheKey, *userModuleVersion);
696
722
697
723
addCommonDependencyInfo (moduleDep);
698
724
addSwiftCommonDependencyInfo (moduleDep);
@@ -909,6 +935,25 @@ ModuleDependenciesCacheDeserializer::getMacroDependenciesArray(unsigned n) {
909
935
return result;
910
936
}
911
937
938
+ std::optional<std::vector<serialization::SearchPath>>
939
+ ModuleDependenciesCacheDeserializer::getSearchPathArray (unsigned n) {
940
+ if (n == 0 )
941
+ return std::vector<serialization::SearchPath>();
942
+
943
+ --n;
944
+ if (n >= ArraysOfSearchPathIDs.size ())
945
+ return std::nullopt;
946
+
947
+ auto &llIDs = ArraysOfSearchPathIDs[n];
948
+
949
+ auto IDtoLLMap = [this ](unsigned index) { return SearchPaths[index]; };
950
+ std::vector<serialization::SearchPath> result;
951
+ result.reserve (llIDs.size ());
952
+ std::transform (llIDs.begin (), llIDs.end (), std::back_inserter (result),
953
+ IDtoLLMap);
954
+ return result;
955
+ }
956
+
912
957
std::optional<std::vector<ScannerImportStatementInfo>>
913
958
ModuleDependenciesCacheDeserializer::getImportStatementInfoArray (unsigned n) {
914
959
if (n == 0 )
@@ -1084,6 +1129,7 @@ class ModuleDependenciesCacheSerializer {
1084
1129
1085
1130
std::unordered_map<ModuleDependencyID, unsigned > LinkLibraryArrayIDsMap;
1086
1131
std::unordered_map<ModuleDependencyID, unsigned > MacroDependenciesArrayIDsMap;
1132
+ std::unordered_map<ModuleDependencyID, unsigned > SearchPathArrayIDsMap;
1087
1133
std::unordered_map<ModuleDependencyID, unsigned > ImportInfosArrayIDsMap;
1088
1134
std::unordered_map<ModuleDependencyID, unsigned >
1089
1135
OptionalImportInfosArrayIDsMap;
@@ -1110,6 +1156,7 @@ class ModuleDependenciesCacheSerializer {
1110
1156
ModuleIdentifierArrayKind arrayKind) const ;
1111
1157
unsigned getLinkLibrariesArrayID (ModuleDependencyID moduleID) const ;
1112
1158
unsigned getMacroDependenciesArrayID (ModuleDependencyID moduleID) const ;
1159
+ unsigned getSearchPathArrayID (ModuleDependencyID moduleID) const ;
1113
1160
unsigned getImportStatementsArrayID (ModuleDependencyID moduleID) const ;
1114
1161
unsigned
1115
1162
getOptionalImportStatementsArrayID (ModuleDependencyID moduleID) const ;
@@ -1146,6 +1193,10 @@ class ModuleDependenciesCacheSerializer {
1146
1193
unsigned writeMacroDependencies (const ModuleDependencyInfo &dependencyInfo);
1147
1194
void writeMacroDependenciesArray (unsigned startIndex, unsigned count);
1148
1195
1196
+ void writeSearchPaths (const ModuleDependenciesCache &cache);
1197
+ unsigned writeSearchPaths (const SwiftBinaryModuleDependencyStorage &dependencyInfo);
1198
+ void writeSearchPathsArray (unsigned startIndex, unsigned count);
1199
+
1149
1200
void writeImportStatementInfos (const ModuleDependenciesCache &cache);
1150
1201
unsigned writeImportStatementInfos (const ModuleDependencyInfo &dependencyInfo,
1151
1202
bool optional);
@@ -1206,6 +1257,8 @@ void ModuleDependenciesCacheSerializer::writeBlockInfoBlock() {
1206
1257
BLOCK_RECORD (graph_block, LINK_LIBRARY_ARRAY_NODE);
1207
1258
BLOCK_RECORD (graph_block, MACRO_DEPENDENCY_NODE);
1208
1259
BLOCK_RECORD (graph_block, MACRO_DEPENDENCY_ARRAY_NODE);
1260
+ BLOCK_RECORD (graph_block, SEARCH_PATH_NODE);
1261
+ BLOCK_RECORD (graph_block, SEARCH_PATH_ARRAY_NODE);
1209
1262
BLOCK_RECORD (graph_block, IMPORT_STATEMENT_NODE);
1210
1263
BLOCK_RECORD (graph_block, IMPORT_STATEMENT_ARRAY_NODE);
1211
1264
BLOCK_RECORD (graph_block, OPTIONAL_IMPORT_STATEMENT_ARRAY_NODE);
@@ -1367,6 +1420,52 @@ void ModuleDependenciesCacheSerializer::writeMacroDependenciesArray(
1367
1420
Out, ScratchRecord, AbbrCodes[MacroDependencyArrayLayout::Code], vec);
1368
1421
}
1369
1422
1423
+ void ModuleDependenciesCacheSerializer::writeSearchPaths (const ModuleDependenciesCache &cache) {
1424
+ unsigned lastSPIndex = 0 ;
1425
+ std::map<ModuleDependencyID, std::pair<unsigned , unsigned >>
1426
+ moduleSearchPathArrayMap;
1427
+
1428
+ auto modMap = cache.getDependenciesMap (ModuleDependencyKind::SwiftBinary);
1429
+ for (const auto &entry : modMap) {
1430
+ ModuleDependencyID moduleID = {entry.getKey ().str (), ModuleDependencyKind::SwiftBinary};
1431
+ auto optionalDependencyInfo = cache.findDependency (moduleID);
1432
+ assert (optionalDependencyInfo && " Expected dependency info." );
1433
+ auto dependencyInfo = *optionalDependencyInfo;
1434
+ unsigned numSPs = writeSearchPaths (*dependencyInfo->getAsSwiftBinaryModule ());
1435
+ moduleSearchPathArrayMap.insert ({moduleID, std::make_pair (lastSPIndex, numSPs)});
1436
+ lastSPIndex += numSPs;
1437
+ }
1438
+
1439
+ unsigned lastSPArrayIndex = 1 ;
1440
+ for (const auto &entry : modMap) {
1441
+ ModuleDependencyID moduleID = {entry.getKey ().str (), ModuleDependencyKind::SwiftBinary};
1442
+ auto entries = moduleSearchPathArrayMap.at (moduleID);
1443
+ if (entries.second == 0 )
1444
+ continue ;
1445
+ writeSearchPathsArray (entries.first , entries.second );
1446
+ SearchPathArrayIDsMap.insert ({moduleID, lastSPArrayIndex++});
1447
+ }
1448
+ }
1449
+ unsigned ModuleDependenciesCacheSerializer::writeSearchPaths (const SwiftBinaryModuleDependencyStorage &dependencyInfo) {
1450
+ using namespace graph_block ;
1451
+ for (const auto &searchPath : dependencyInfo.serializedSearchPaths ) {
1452
+ SearchPathLayout::emitRecord (
1453
+ Out, ScratchRecord, AbbrCodes[SearchPathLayout::Code],
1454
+ getIdentifier (searchPath.Path ),
1455
+ searchPath.IsFramework ,
1456
+ searchPath.IsSystem );
1457
+ }
1458
+ return dependencyInfo.serializedSearchPaths .size ();
1459
+ }
1460
+
1461
+ void ModuleDependenciesCacheSerializer::writeSearchPathsArray (unsigned startIndex, unsigned count) {
1462
+ using namespace graph_block ;
1463
+ std::vector<unsigned > vec (count);
1464
+ std::iota (vec.begin (), vec.end (), startIndex);
1465
+ SearchPathArrayLayout::emitRecord (
1466
+ Out, ScratchRecord, AbbrCodes[SearchPathArrayLayout::Code], vec);
1467
+ }
1468
+
1370
1469
void ModuleDependenciesCacheSerializer::writeImportStatementInfos (
1371
1470
const ModuleDependenciesCache &cache) {
1372
1471
unsigned lastImportInfoIndex = 0 ;
@@ -1559,10 +1658,10 @@ void ModuleDependenciesCacheSerializer::writeModuleInfo(
1559
1658
getIdentifierArrayID (
1560
1659
moduleID,
1561
1660
ModuleIdentifierArrayKind::HeaderInputDependencySourceFiles),
1661
+ getSearchPathArrayID (moduleID),
1562
1662
swiftBinDeps->isFramework , swiftBinDeps->isStatic ,
1563
1663
getIdentifier (swiftBinDeps->moduleCacheKey ),
1564
1664
getIdentifier (swiftBinDeps->userModuleVersion ));
1565
-
1566
1665
break ;
1567
1666
}
1568
1667
case swift::ModuleDependencyKind::SwiftPlaceholder: {
@@ -1699,6 +1798,15 @@ unsigned ModuleDependenciesCacheSerializer::getMacroDependenciesArrayID(
1699
1798
return iter->second ;
1700
1799
}
1701
1800
1801
+ unsigned ModuleDependenciesCacheSerializer::getSearchPathArrayID (
1802
+ ModuleDependencyID moduleID) const {
1803
+ auto iter = SearchPathArrayIDsMap.find (moduleID);
1804
+ if (iter == SearchPathArrayIDsMap.end ())
1805
+ return 0 ;
1806
+
1807
+ return iter->second ;
1808
+ }
1809
+
1702
1810
unsigned ModuleDependenciesCacheSerializer::getImportStatementsArrayID (
1703
1811
ModuleDependencyID moduleID) const {
1704
1812
auto iter = ImportInfosArrayIDsMap.find (moduleID);
@@ -1820,6 +1928,8 @@ void ModuleDependenciesCacheSerializer::collectStringsAndArrays(
1820
1928
moduleID,
1821
1929
ModuleIdentifierArrayKind::HeaderInputDependencySourceFiles,
1822
1930
swiftBinDeps->headerSourceFiles );
1931
+ llvm::for_each (swiftBinDeps->serializedSearchPaths ,
1932
+ [this ](auto &sp) { addIdentifier (sp.Path ); });
1823
1933
break ;
1824
1934
}
1825
1935
case swift::ModuleDependencyKind::SwiftPlaceholder: {
@@ -1899,6 +2009,8 @@ void ModuleDependenciesCacheSerializer::writeInterModuleDependenciesCache(
1899
2009
registerRecordAbbr<LinkLibraryArrayLayout>();
1900
2010
registerRecordAbbr<MacroDependencyLayout>();
1901
2011
registerRecordAbbr<MacroDependencyArrayLayout>();
2012
+ registerRecordAbbr<SearchPathLayout>();
2013
+ registerRecordAbbr<SearchPathArrayLayout>();
1902
2014
registerRecordAbbr<ImportStatementLayout>();
1903
2015
registerRecordAbbr<ImportStatementArrayLayout>();
1904
2016
registerRecordAbbr<ModuleInfoLayout>();
@@ -1933,6 +2045,9 @@ void ModuleDependenciesCacheSerializer::writeInterModuleDependenciesCache(
1933
2045
// Write all the arrays of macro dependency infos for this graph
1934
2046
writeMacroDependencies (cache);
1935
2047
2048
+ // Write all the arrays of binary-module-serialized search paths
2049
+ writeSearchPaths (cache);
2050
+
1936
2051
// Write the core graph
1937
2052
for (auto kind = ModuleDependencyKind::FirstKind;
1938
2053
kind != ModuleDependencyKind::LastKind; ++kind) {
0 commit comments