@@ -1428,7 +1428,6 @@ bool InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleN
1428
1428
}
1429
1429
1430
1430
struct ExplicitSwiftModuleLoader ::Implementation {
1431
-
1432
1431
// Information about explicitly specified Swift module files.
1433
1432
struct ExplicitModuleInfo {
1434
1433
// Path of the .swiftmodule file.
@@ -1451,44 +1450,48 @@ struct ExplicitSwiftModuleLoader::Implementation {
1451
1450
return Saver.save (cast<llvm::yaml::ScalarNode>(N)->getValue (Buffer));
1452
1451
}
1453
1452
1454
- bool parseSingleModuleEntry (llvm::yaml::KeyValueNode &node) {
1453
+ bool parseSingleModuleEntry (llvm::yaml::Node &node) {
1455
1454
using namespace llvm ::yaml;
1456
- auto moduleName = getScalaNodeText (node.getKey ());
1457
- auto insertRes = ExplicitModuleMap.insert ({moduleName,
1458
- ExplicitModuleInfo ()});
1459
- if (!insertRes.second ) {
1460
- return true ;
1461
- }
1462
- auto moduleDetails = dyn_cast<MappingNode>(node.getValue ());
1463
- if (!moduleDetails)
1455
+ auto *mapNode = dyn_cast<MappingNode>(&node);
1456
+ if (!mapNode)
1464
1457
return true ;
1465
- for (auto &entry: *moduleDetails) {
1458
+ StringRef moduleName;
1459
+ ExplicitModuleInfo result;
1460
+ for (auto &entry: *mapNode) {
1466
1461
auto key = getScalaNodeText (entry.getKey ());
1467
1462
auto val = getScalaNodeText (entry.getValue ());
1468
- if (key == " SwiftModulePath" ) {
1469
- insertRes.first ->second .modulePath = val;
1463
+ if (key == " SwiftModule" ) {
1464
+ moduleName = val;
1465
+ } else if (key == " SwiftModulePath" ) {
1466
+ result.modulePath = val;
1470
1467
} else if (key == " SwiftDocPath" ) {
1471
- insertRes. first -> second .moduleDocPath = val;
1468
+ result .moduleDocPath = val;
1472
1469
} else if (key == " SwiftSourceInfoPath" ) {
1473
- insertRes. first -> second .moduleSourceInfoPath = val;
1470
+ result .moduleSourceInfoPath = val;
1474
1471
} else {
1475
- return true ;
1472
+ // Being forgiving for future fields.
1473
+ continue ;
1476
1474
}
1477
1475
}
1476
+ if (moduleName.empty ())
1477
+ return true ;
1478
+ ExplicitModuleMap[moduleName] = std::move (result);
1478
1479
return false ;
1479
1480
}
1480
- // {
1481
- // "A": {
1481
+ // [
1482
+ // {
1483
+ // "SwiftModule": "A",
1482
1484
// "SwiftModulePath": "A.swiftmodule",
1483
1485
// "SwiftDocPath": "A.swiftdoc",
1484
1486
// "SwiftSourceInfoPath": "A.swiftsourceinfo"
1485
1487
// },
1486
- // "B": {
1488
+ // {
1489
+ // "SwiftModule": "B",
1487
1490
// "SwiftModulePath": "B.swiftmodule",
1488
1491
// "SwiftDocPath": "B.swiftdoc",
1489
1492
// "SwiftSourceInfoPath": "B.swiftsourceinfo"
1490
1493
// }
1491
- // }
1494
+ // ]
1492
1495
void parseSwiftExplicitModuleMap (StringRef fileName) {
1493
1496
using namespace llvm ::yaml;
1494
1497
// Load the input file.
@@ -1504,7 +1507,7 @@ struct ExplicitSwiftModuleLoader::Implementation {
1504
1507
Ctx.SourceMgr .getLLVMSourceMgr ());
1505
1508
for (auto DI = Stream.begin (); DI != Stream.end (); ++ DI) {
1506
1509
assert (DI != Stream.end () && " Failed to read a document" );
1507
- if (auto *MN = dyn_cast_or_null<MappingNode >(DI->getRoot ())) {
1510
+ if (auto *MN = dyn_cast_or_null<SequenceNode >(DI->getRoot ())) {
1508
1511
for (auto &entry: *MN) {
1509
1512
if (parseSingleModuleEntry (entry)) {
1510
1513
Ctx.Diags .diagnose (SourceLoc (),
@@ -1559,8 +1562,12 @@ std::error_code ExplicitSwiftModuleLoader::findModuleFilesInDirectory(
1559
1562
auto &fs = *Ctx.SourceMgr .getFileSystem ();
1560
1563
// Open .swiftmodule file
1561
1564
auto moduleBuf = fs.getBufferForFile (moduleInfo.modulePath );
1562
- if (!moduleBuf)
1565
+ if (!moduleBuf) {
1566
+ // We cannot read the module content, diagnose.
1567
+ Ctx.Diags .diagnose (SourceLoc (), diag::error_opening_explicit_module_file,
1568
+ moduleInfo.modulePath );
1563
1569
return moduleBuf.getError ();
1570
+ }
1564
1571
*ModuleBuffer = std::move (moduleBuf.get ());
1565
1572
1566
1573
// Open .swiftdoc file
0 commit comments