Skip to content

Commit 098b170

Browse files
committed
Just autolink every imported module, public or private
This is unfortunate in that it makes the linker do extra work, but in practice it probably doesn't matter much, and meanwhile it handles all our problems with @inlinable. Alternate solution to rdar://problem/39338239
1 parent 0e5100d commit 098b170

9 files changed

+60
-7
lines changed

lib/AST/Module.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,13 +1214,15 @@ void ModuleDecl::collectLinkLibraries(LinkLibraryCallback callback) {
12141214

12151215
void
12161216
SourceFile::collectLinkLibraries(ModuleDecl::LinkLibraryCallback callback) const {
1217-
1218-
const_cast<SourceFile *>(this)->forAllVisibleModules([&](swift::ModuleDecl::ImportedModule import) {
1217+
forAllImportedModules<false>(getParentModule(), /*thisPath*/{},
1218+
/*includePrivateTopLevelImports*/false,
1219+
[=](ModuleDecl::ImportedModule import) -> bool {
12191220
swift::ModuleDecl *next = import.second;
12201221
if (next->getName() == getParentModule()->getName())
1221-
return;
1222+
return true;
12221223

12231224
next->collectLinkLibraries(callback);
1225+
return true;
12241226
});
12251227
}
12261228

test/ClangImporter/autolinking.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
// RUN: %FileCheck %s < %t/with-adapter.ll
88
// RUN: %FileCheck -check-prefix CHECK-WITH-SWIFT %s < %t/with-adapter.ll
99

10-
// RUN: %target-swift-frontend %s -sdk %S/Inputs -I %S/Inputs/custom-modules -emit-ir -disable-autolink-framework LinkFramework -o - | %FileCheck -check-prefix CHECK-WITH-DISABLED %s
10+
// RUN: %target-swift-frontend %s -sdk %S/Inputs -I %S/Inputs/custom-modules -emit-ir -disable-autolink-framework LinkFramework -o - > %t/with-disabled.ll
11+
// RUN: %FileCheck -check-prefix CHECK-WITH-DISABLED %s < %t/with-disabled.ll
12+
// RUN: %FileCheck -check-prefix NEGATIVE-WITH-DISABLED %s < %t/with-disabled.ll
1113

1214
// Linux uses a different autolinking mechanism, based on
1315
// swift-autolink-extract. This file tests the Darwin mechanism.
@@ -37,6 +39,6 @@ UsesSubmodule.useSomethingFromSubmodule()
3739

3840
// CHECK-WITH-SWIFT: !{{[0-9]+}} = !{!"-lSwiftAdapter"}
3941

40-
// CHECK-WITH-DISABLED: !{!"-framework", !"Barrel"}
41-
// CHECK-WITH-DISABLED-NOT: !{!"-framework", !"LinkFramework"}
42-
// CHECK-WITH-DISABLED: !{!"-framework", !"Indirect"}
42+
// CHECK-WITH-DISABLED-DAG: !{!"-framework", !"Barrel"}
43+
// CHECK-WITH-DISABLED-DAG: !{!"-framework", !"Indirect"}
44+
// NEGATIVE-WITH-DISABLED-NOT: !"LinkFramework"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@_exported import autolinking_other2
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@_exported import autolinking_public
2+
import autolinking_other
3+
import autolinking_indirect
4+
import autolinking_private
5+
6+
public func bfunc(x: Int = afunc(), y: Int = afunc2()) {
7+
cfunc()
8+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public func afunc() -> Int { return 0 }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public func afunc2() -> Int { return 0 }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public func cfunc() {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Empty module
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-swift-frontend -emit-module %S/Inputs/autolinking_public.swift -emit-module-path %t/autolinking_public.swiftmodule -module-link-name autolinking_public -swift-version 4
4+
// RUN: %target-swift-frontend -emit-module %S/Inputs/autolinking_other.swift -emit-module-path %t/autolinking_other.swiftmodule -module-link-name autolinking_other -swift-version 4
5+
// RUN: %target-swift-frontend -emit-module %S/Inputs/autolinking_private.swift -emit-module-path %t/autolinking_private.swiftmodule -module-link-name autolinking_private -I %t -swift-version 4
6+
// RUN: %target-swift-frontend -emit-module %S/Inputs/autolinking_other2.swift -emit-module-path %t/autolinking_other2.swiftmodule -module-link-name autolinking_other2 -swift-version 4
7+
// RUN: %target-swift-frontend -emit-module %S/Inputs/autolinking_indirect.swift -emit-module-path %t/autolinking_indirect.swiftmodule -module-link-name autolinking_indirect -I %t -swift-version 4
8+
9+
// RUN: %target-swift-frontend -emit-module %S/Inputs/autolinking_module_inferred.swift -emit-module-path %t/autolinking_module_inferred.swiftmodule -module-link-name autolinking_module_inferred -I %t -swift-version 4
10+
// RUN: %target-swift-frontend -emit-ir %s -I %t -swift-version 4 | %FileCheck %s
11+
12+
// Linux uses a different autolinking mechanism, based on
13+
// swift-autolink-extract. This file tests the Darwin mechanism.
14+
// UNSUPPORTED: OS=linux-gnu
15+
// UNSUPPORTED: OS=linux-gnueabihf
16+
// UNSUPPORTED: OS=freebsd
17+
// UNSUPPORTED: OS=linux-androideabi
18+
19+
import autolinking_module_inferred
20+
21+
bfunc()
22+
23+
// CHECK: !llvm.linker.options = !{[[MODULE:![0-9]+]], [[PUBLIC:![0-9]+]], [[SWIFTONONESUPPORT:![0-9]+]], [[SWIFTCORE:![0-9]+]], [[PRIVATE:![0-9]+]], [[OTHER:![0-9]+]], [[INDIRECT:![0-9]+]], [[OTHER2:![0-9]+]], [[OBJC:![0-9]+]]}
24+
25+
// CHECK-DAG: [[SWIFTCORE]] = !{!"-lswiftCore"}
26+
// CHECK-DAG: [[SWIFTONONESUPPORT]] = !{!"-lswiftSwiftOnoneSupport"}
27+
// CHECK-DAG: [[MODULE]] = !{!"-lautolinking_module_inferred"}
28+
// CHECK-DAG: [[PUBLIC]] = !{!"-lautolinking_public"}
29+
// CHECK-DAG: [[OTHER]] = !{!"-lautolinking_other"}
30+
// CHECK-DAG: [[OTHER2]] = !{!"-lautolinking_other2"}
31+
// CHECK-DAG: [[OBJC]] = !{!"-lobjc"}
32+
33+
// We don't actually care about these two. As long as we autolink the libraries
34+
// that get used, we're okay.
35+
// CHECK-DAG: [[PRIVATE]] = !{!"-lautolinking_private"}
36+
// CHECK-DAG: [[INDIRECT]] = !{!"-lautolinking_indirect"}

0 commit comments

Comments
 (0)