Skip to content

Commit 028cc70

Browse files
authored
Merge pull request #31222 from brentdax/pathfinder-5.3
[5.3] Fix layering of cross-import and clang overlays
2 parents bf71b42 + 557abcb commit 028cc70

File tree

12 files changed

+110
-2
lines changed

12 files changed

+110
-2
lines changed

include/swift/AST/SourceFile.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ class SourceFile final : public FileUnit {
395395
overlays.append(value.begin(), value.end());
396396
}
397397

398+
SWIFT_DEBUG_DUMPER(dumpSeparatelyImportedOverlays());
399+
398400
void cacheVisibleDecls(SmallVectorImpl<ValueDecl *> &&globals) const;
399401
const SmallVectorImpl<ValueDecl *> &getCachedVisibleDecls() const;
400402

lib/AST/ASTDumper.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,10 @@ namespace {
12591259

12601260
void visitModuleDecl(ModuleDecl *MD) {
12611261
printCommon(MD, "module");
1262+
1263+
if (MD->isNonSwiftModule())
1264+
OS << " non_swift";
1265+
12621266
PrintWithColorRAII(OS, ParenthesisColor) << ')';
12631267
}
12641268

lib/AST/Module.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,22 @@ SourceFile::getImportedModules(SmallVectorImpl<ModuleDecl::ImportedModule> &modu
14181418
}
14191419
}
14201420

1421+
void SourceFile::dumpSeparatelyImportedOverlays() const {
1422+
for (auto &pair : separatelyImportedOverlays) {
1423+
auto &underlying = std::get<0>(pair);
1424+
auto &overlays = std::get<1>(pair);
1425+
1426+
llvm::errs() << (void*)underlying << " ";
1427+
underlying->dump(llvm::errs());
1428+
1429+
for (auto overlay : overlays) {
1430+
llvm::errs() << "- ";
1431+
llvm::errs() << (void*)overlay << " ";
1432+
overlay->dump(llvm::errs());
1433+
}
1434+
}
1435+
}
1436+
14211437
void ModuleDecl::getImportedModulesForLookup(
14221438
SmallVectorImpl<ImportedModule> &modules) const {
14231439
FORWARD(getImportedModulesForLookup, (modules));

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)