Skip to content

[Serialization] Use the correct module for the nested type fast path. #11018

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/Serialization/Deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1343,9 +1343,13 @@ ModuleFile::resolveCrossReference(ModuleDecl *baseModule, uint32_t pathLen) {
nestedType = containingFile->lookupNestedType(memberName, baseType);
}
} else {
// Fault in extensions, then ask every serialized AST in the module.
// Fault in extensions, then ask every file in the module.
ModuleDecl *extensionModule = M;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

M here is the module specified by the cross-reference path; it's omitted if you're supposed to look in the same module. This will be made clearer in the future when everything gets refactored as @milseman suggested.

if (!extensionModule)
extensionModule = baseType->getModuleContext();

(void)baseType->getExtensions();
for (FileUnit *file : baseType->getModuleContext()->getFiles()) {
for (FileUnit *file : extensionModule->getFiles()) {
if (file == getFile())
continue;
nestedType = file->lookupNestedType(memberName, baseType);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "NestedClangTypesHelper.h"

struct Outer {
int value;
};
Expand All @@ -6,6 +8,12 @@ struct __attribute__((swift_name("Outer.InterestingValue"))) Inner {
int value;
};

struct OuterFromOtherModule;
struct __attribute__((swift_name("OuterFromOtherModule.InterestingValue"))) InnerCrossModule {
int value;
};


#if __OBJC__

@import Foundation;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
struct OuterFromOtherModule {
int value;
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
module NestedClangTypes {
header "NestedClangTypes.h"
export *
}

module NestedClangTypesHelper {
header "NestedClangTypesHelper.h"
export *
}
26 changes: 16 additions & 10 deletions test/Serialization/xref-nested-clang-type.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@

// RUN: %empty-directory(%t)
// RUN: cp %S/Inputs/xref-nested-clang-type/NestedClangTypes.h %t
// 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
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -I %t -import-objc-header %t/NestedClangTypes.h %s -DCLIENT -verify
// 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
// 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

// RUN: %empty-directory(%t)
// RUN: cp %S/Inputs/xref-nested-clang-type/NestedClangTypes.h %t
// 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
// 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
// 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
// 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

#if _runtime(_ObjC)
import Foundation
#endif // ObjC

#if CLIENT

import Lib

func test(x: MyInner) {}

#if _runtime(_ObjC)
import Foundation
func test(x: MyOtherInner) {}
func test(x: MyCode) {}
#endif // ObjC

#else // CLIENT

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

#if _runtime(_ObjC)
import Foundation
public typealias MyOtherInner = OuterFromOtherModule.InterestingValue
extension OuterFromOtherModule {
public func use(inner: MyOtherInner) {}
}

#if _runtime(_ObjC)
public typealias MyCode = ErrorCodeEnum.Code
extension ErrorCodeEnum {
public func whatever(code: MyCode) {}
}
#else
public typealias MyCode = Int
#endif // ObjC

#endif // CLIENT