Skip to content

Commit 30cdd3c

Browse files
authored
Merge pull request #69563 from CodaFi/weak-in-the-knees
Weak-Link the Immediate Re-Exports of a Weak-Linked Module
2 parents 86365cd + 17f5864 commit 30cdd3c

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

lib/AST/Module.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3441,6 +3441,16 @@ bool SourceFile::importsModuleAsWeakLinked(const ModuleDecl *module) const {
34413441
importedModule->getUnderlyingModuleIfOverlay();
34423442
if (module == clangModule)
34433443
return true;
3444+
3445+
// Traverse the exported modules of this weakly-linked module to ensure
3446+
// that we weak-link declarations from its exported peers.
3447+
SmallVector<ImportedModule, 8> reexportedModules;
3448+
importedModule->getImportedModules(reexportedModules,
3449+
ModuleDecl::ImportFilterKind::Exported);
3450+
for (const ImportedModule &reexportedModule : reexportedModules) {
3451+
if (module == reexportedModule.importedModule)
3452+
return true;
3453+
}
34443454
}
34453455
return false;
34463456
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
extern void clang_fn(void);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module weaklinked_import_helper_clang {
2+
header "weaklinked_import_helper_clang.h"
3+
export *
4+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %empty-directory(%t)
2+
//
3+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/weaklinked_import_helper.swiftmodule -parse-as-library %S/Inputs/weaklinked_import_helper.swift -enable-library-evolution
4+
//
5+
// RUN: echo '@_exported import weaklinked_import_helper' > %t/intermediate.swift
6+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/intermediate.swiftmodule -parse-as-library %t/intermediate.swift -I %t -enable-library-evolution
7+
//
8+
// RUN: echo '@_exported import weaklinked_import_helper_clang' > %t/intermediate_clang.swift
9+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/intermediate_clang.swiftmodule -parse-as-library %t/intermediate_clang.swift -I %t -enable-library-evolution -Xcc -fmodule-map-file=%S/Inputs/weaklinked_import_helper_clang.modulemap
10+
//
11+
// RUN: %target-swift-frontend -primary-file %s -I %t -emit-ir -Xcc -fmodule-map-file=%S/Inputs/weaklinked_import_helper_clang.modulemap | %FileCheck %s
12+
13+
// UNSUPPORTED: OS=windows-msvc
14+
15+
@_weakLinked import intermediate
16+
@_weakLinked import intermediate_clang
17+
18+
// CHECK-DAG: declare extern_weak swiftcc {{.+}} @"$s24weaklinked_import_helper2fnyyF"()
19+
fn()
20+
// CHECK-DAG: declare extern_weak void @clang_fn()
21+
clang_fn()

0 commit comments

Comments
 (0)