Skip to content

Commit 557abcb

Browse files
committed
Fix layering of cross-import and clang overlays
If a clang module declares a cross-import overlay, but it also has a traditional overlay, we want the cross-import overlay to be registered with the SourceFile as sitting atop the traditional overlay. Otherwise module-qualified name lookups will bypass the cross-import overlay. Fixes rdar://62139656.
1 parent 131797d commit 557abcb

File tree

9 files changed

+88
-2
lines changed

9 files changed

+88
-2
lines changed

lib/Sema/ImportResolution.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -803,9 +803,17 @@ void ImportResolver::crossImport(ModuleDecl *M, UnboundImport &I) {
803803
if (!SF.shouldCrossImport())
804804
return;
805805

806-
if (I.getUnderlyingModule())
806+
if (I.getUnderlyingModule()) {
807+
auto underlying = I.getUnderlyingModule().get();
808+
809+
// If this is a clang module, and it has a clang overlay, we want the
810+
// separately-imported overlay to sit on top of the clang overlay.
811+
if (underlying->isNonSwiftModule())
812+
underlying = underlying->getTopLevelModule(true);
813+
807814
// FIXME: Should we warn if M doesn't reexport underlyingModule?
808-
SF.addSeparatelyImportedOverlay(M, I.getUnderlyingModule().get());
815+
SF.addSeparatelyImportedOverlay(M, underlying);
816+
}
809817

810818
auto newImports = crossImportableModules.getArrayRef()
811819
.drop_front(nextModuleToCrossImport);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
%YAML 1.2
2+
---
3+
version: 1
4+
modules:
5+
- name: _ClangFramework_BystandingLibrary
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
%YAML 1.2
2+
---
3+
version: 1
4+
modules:
5+
- name: _OverlaidClangFramework_BystandingLibrary
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
%YAML 1.2
2+
---
3+
version: 1
4+
modules:
5+
- name: _SwiftFramework_BystandingLibrary
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// swift-interface-format-version: 1.0
2+
// swift-module-flags: -swift-version 5 -enable-library-evolution -module-name _ClangFramework_BystandingLibrary
3+
4+
import Swift
5+
@_exported import ClangFramework
6+
7+
public func fromClangFrameworkCrossImport()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// swift-interface-format-version: 1.0
2+
// swift-module-flags: -swift-version 5 -enable-library-evolution -module-name _OverlaidClangFramework_BystandingLibrary
3+
4+
import Swift
5+
@_exported import OverlaidClangFramework
6+
7+
public func fromOverlaidClangFrameworkCrossImport()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// swift-interface-format-version: 1.0
2+
// swift-module-flags: -swift-version 5 -enable-library-evolution -module-name _SwiftFramework_BystandingLibrary
3+
4+
import Swift
5+
@_exported import SwiftFramework
6+
7+
public func fromSwiftFrameworkCrossImport()

test/CrossImport/Inputs/lib-templates/lib/swift/OverlaidClangFramework.swiftmodule/module-triple-here.swiftinterface

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33

44
import Swift
55
@_exported import OverlaidClangFramework
6+
7+
public func fromOverlaidClangFrameworkOverlay()

test/CrossImport/common-case.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// This explicitly tests "common" cases with well-constructed cross-import
2+
// overlays. Some behaviors here are poorly covered by other tests.
3+
4+
// RUN: %empty-directory(%t)
5+
// RUN: cp -r %S/Inputs/lib-templates/* %t/
6+
// RUN: %{python} %S/Inputs/rewrite-module-triples.py %t %module-target-triple
7+
8+
// RUN: %target-typecheck-verify-swift -enable-cross-import-overlays -I %t/include -I %t/lib/swift -F %t/Frameworks
9+
10+
// Each framework has a cross-import overlay with this library:
11+
import BystandingLibrary
12+
13+
// 1. A Swift framework
14+
15+
import SwiftFramework
16+
17+
fromSwiftFramework()
18+
fromSwiftFrameworkCrossImport()
19+
SwiftFramework.fromSwiftFramework()
20+
SwiftFramework.fromSwiftFrameworkCrossImport()
21+
22+
// 2. A Clang framework
23+
24+
import ClangFramework
25+
26+
fromClangFramework()
27+
fromClangFrameworkCrossImport()
28+
ClangFramework.fromClangFramework()
29+
ClangFramework.fromClangFrameworkCrossImport()
30+
31+
// 3. A Swift-overlaid Clang framework
32+
33+
import OverlaidClangFramework
34+
35+
fromOverlaidClangFramework()
36+
fromOverlaidClangFrameworkOverlay()
37+
fromOverlaidClangFrameworkCrossImport()
38+
OverlaidClangFramework.fromOverlaidClangFramework()
39+
OverlaidClangFramework.fromOverlaidClangFrameworkOverlay()
40+
OverlaidClangFramework.fromOverlaidClangFrameworkCrossImport()

0 commit comments

Comments
 (0)