Skip to content

Commit adf1e2e

Browse files
authored
[Serialization] Use the correct module for the nested type fast path. (#11018)
Fix-up for 03e1e3b, which fixes the crash caused by the new test case. More https://bugs.swift.org/browse/SR-5284
1 parent cab6ec6 commit adf1e2e

File tree

5 files changed

+39
-12
lines changed

5 files changed

+39
-12
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,9 +1343,13 @@ ModuleFile::resolveCrossReference(ModuleDecl *baseModule, uint32_t pathLen) {
13431343
nestedType = containingFile->lookupNestedType(memberName, baseType);
13441344
}
13451345
} else {
1346-
// Fault in extensions, then ask every serialized AST in the module.
1346+
// Fault in extensions, then ask every file in the module.
1347+
ModuleDecl *extensionModule = M;
1348+
if (!extensionModule)
1349+
extensionModule = baseType->getModuleContext();
1350+
13471351
(void)baseType->getExtensions();
1348-
for (FileUnit *file : baseType->getModuleContext()->getFiles()) {
1352+
for (FileUnit *file : extensionModule->getFiles()) {
13491353
if (file == getFile())
13501354
continue;
13511355
nestedType = file->lookupNestedType(memberName, baseType);

test/Serialization/Inputs/xref-nested-clang-type/NestedClangTypes.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "NestedClangTypesHelper.h"
2+
13
struct Outer {
24
int value;
35
};
@@ -6,6 +8,12 @@ struct __attribute__((swift_name("Outer.InterestingValue"))) Inner {
68
int value;
79
};
810

11+
struct OuterFromOtherModule;
12+
struct __attribute__((swift_name("OuterFromOtherModule.InterestingValue"))) InnerCrossModule {
13+
int value;
14+
};
15+
16+
917
#if __OBJC__
1018

1119
@import Foundation;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
struct OuterFromOtherModule {
2+
int value;
3+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
module NestedClangTypes {
22
header "NestedClangTypes.h"
3+
export *
4+
}
5+
6+
module NestedClangTypesHelper {
7+
header "NestedClangTypesHelper.h"
8+
export *
39
}

test/Serialization/xref-nested-clang-type.swift

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,25 @@
44

55
// RUN: %empty-directory(%t)
66
// RUN: cp %S/Inputs/xref-nested-clang-type/NestedClangTypes.h %t
7-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-module -o %t -import-objc-header %t/NestedClangTypes.h %s -module-name Lib -DNO_MODULE
8-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -I %t -import-objc-header %t/NestedClangTypes.h %s -DCLIENT -verify
7+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-module -o %t -import-objc-header %t/NestedClangTypes.h -I %S/Inputs/xref-nested-clang-type/ %s -module-name Lib -DNO_MODULE
8+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -I %t -I %S/Inputs/xref-nested-clang-type/ -import-objc-header %t/NestedClangTypes.h %s -DCLIENT -verify
99

1010
// RUN: %empty-directory(%t)
1111
// RUN: cp %S/Inputs/xref-nested-clang-type/NestedClangTypes.h %t
12-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-module -o %t -import-objc-header %t/NestedClangTypes.h -pch-output-dir %t/PCHCache %s -module-name Lib -DNO_MODULE
13-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -I %t -pch-output-dir %t/PCHCache -import-objc-header %t/NestedClangTypes.h %s -DCLIENT -verify
12+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-module -o %t -import-objc-header %t/NestedClangTypes.h -I %S/Inputs/xref-nested-clang-type/ -pch-output-dir %t/PCHCache %s -module-name Lib -DNO_MODULE
13+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -I %t -I %S/Inputs/xref-nested-clang-type/ -pch-output-dir %t/PCHCache -import-objc-header %t/NestedClangTypes.h %s -DCLIENT -verify
14+
15+
#if _runtime(_ObjC)
16+
import Foundation
17+
#endif // ObjC
1418

1519
#if CLIENT
1620

1721
import Lib
1822

1923
func test(x: MyInner) {}
20-
21-
#if _runtime(_ObjC)
22-
import Foundation
24+
func test(x: MyOtherInner) {}
2325
func test(x: MyCode) {}
24-
#endif // ObjC
2526

2627
#else // CLIENT
2728

@@ -36,13 +37,18 @@ extension MyOuter {
3637
public func use(inner: MyInner) {}
3738
}
3839

39-
#if _runtime(_ObjC)
40-
import Foundation
40+
public typealias MyOtherInner = OuterFromOtherModule.InterestingValue
41+
extension OuterFromOtherModule {
42+
public func use(inner: MyOtherInner) {}
43+
}
4144

45+
#if _runtime(_ObjC)
4246
public typealias MyCode = ErrorCodeEnum.Code
4347
extension ErrorCodeEnum {
4448
public func whatever(code: MyCode) {}
4549
}
50+
#else
51+
public typealias MyCode = Int
4652
#endif // ObjC
4753

4854
#endif // CLIENT

0 commit comments

Comments
 (0)