Skip to content

Commit 053aaac

Browse files
committed
Fix crash in merge-modules involving a file with extension of nested type
rdar://74062542
1 parent d8502ac commit 053aaac

File tree

5 files changed

+41
-2
lines changed

5 files changed

+41
-2
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,7 @@ static void filterValues(Type expectedTy, ModuleDecl *expectedModule,
12411241
values.erase(newEnd, values.end());
12421242
}
12431243

1244+
/// Look for nested types in all files of \p extensionModule except from the \p thisFile.
12441245
static TypeDecl *
12451246
findNestedTypeDeclInModule(FileUnit *thisFile, ModuleDecl *extensionModule,
12461247
Identifier name, NominalTypeDecl *parent) {
@@ -1256,6 +1257,13 @@ findNestedTypeDeclInModule(FileUnit *thisFile, ModuleDecl *extensionModule,
12561257
return nullptr;
12571258
}
12581259

1260+
/// Look for nested types in all files of \p extensionModule.
1261+
static TypeDecl *
1262+
findNestedTypeDeclInModule(ModuleDecl *extensionModule,
1263+
Identifier name, NominalTypeDecl *parent) {
1264+
return findNestedTypeDeclInModule(nullptr, extensionModule, name, parent);
1265+
}
1266+
12591267
Expected<Decl *>
12601268
ModuleFile::resolveCrossReference(ModuleID MID, uint32_t pathLen) {
12611269
using namespace decls_block;
@@ -1502,10 +1510,11 @@ ModuleFile::resolveCrossReference(ModuleID MID, uint32_t pathLen) {
15021510
extensionModule = baseType->getModuleContext();
15031511

15041512
// Fault in extensions, then ask every file in the module.
1513+
// We include the current file in the search because the cross reference
1514+
// may involve a nested type of this file.
15051515
(void)baseType->getExtensions();
15061516
auto *nestedType =
1507-
findNestedTypeDeclInModule(getFile(), extensionModule,
1508-
memberName, baseType);
1517+
findNestedTypeDeclInModule(extensionModule, memberName, baseType);
15091518

15101519
// For clang module units, also search tables in the overlays.
15111520
if (!nestedType) {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class MyCls {
2+
public static func doIt(_: Inner1.Inner2) {}
3+
4+
public struct Inner1 {}
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public extension MyCls.Inner1 {
2+
struct Inner2 {}
3+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"./f1.swift": {
3+
"swift-dependencies": "./f1.swiftdeps",
4+
"swiftmodule": "./f1~partial.swiftmodule"
5+
},
6+
"./f2.swift": {
7+
"swift-dependencies": "./f2.swiftdeps",
8+
"swiftmodule": "./f2~partial.swiftmodule"
9+
},
10+
"": {
11+
"swift-dependencies": "./main~buildrecord.swiftdeps"
12+
}
13+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: cp -r %S/Inputs/crash-nested-extension/* %t
3+
// RUN: cd %t
4+
// RUN: %swiftc_driver -output-file-map %t/output.json -incremental ./f1.swift ./f2.swift -module-name MyMod -j1 -disable-batch-mode -emit-module -emit-module-path MyMod.swiftmodule -v
5+
6+
// RUN: %empty-directory(%t)
7+
// RUN: cp -r %S/Inputs/crash-nested-extension/* %t
8+
// RUN: cd %t
9+
// RUN: %swiftc_driver -output-file-map %t/output.json -incremental -Xfrontend -experimental-skip-all-function-bodies -Xfrontend -experimental-allow-module-with-compiler-errors ./f1.swift ./f2.swift -module-name MyMod -j1 -disable-batch-mode -emit-module -emit-module-path MyMod.swiftmodule -v

0 commit comments

Comments
 (0)