Skip to content

Commit cc308c9

Browse files
committed
embedded: make sure to generate witness tables which are imported from other modules
In embedded swift all the code is generated in the top-level module. De-serialized witness tables for class existentials must be code-gen'd and therefore made non-external. Fixes an unresolved symbol linker error. rdar://142561676
1 parent 1573344 commit cc308c9

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

lib/SIL/IR/Linker.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,17 @@ void SILLinkerVisitor::visitProtocolConformance(
324324
return;
325325
}
326326

327+
if (Mod.getASTContext().LangOpts.hasFeature(Feature::Embedded) &&
328+
isAvailableExternally(WT->getLinkage()) &&
329+
WT->getProtocol()->requiresClass()) {
330+
// In embedded swift all the code is generated in the top-level module.
331+
// De-serialized tables (= public_external) must be code-gen'd and
332+
// therefore made non-external.
333+
// Note: for functions we do that at the end of the pipeline in the
334+
// IRGenPrepare pass to be able to eliminate dead functions.
335+
WT->setLinkage(SILLinkage::Hidden);
336+
}
337+
327338
auto maybeVisitRelatedConformance = [&](ProtocolConformanceRef c) {
328339
// Formally all conformances referenced by a used conformance are used.
329340
// However, eagerly visiting them all at this point leads to a large blowup
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %{python} %utils/split_file.py -o %t %s
3+
4+
// RUN: %target-swift-frontend -emit-module -o %t/MyModule.swiftmodule %t/MyModule.swift -enable-experimental-feature Embedded -parse-as-library
5+
// RUN: %target-swift-frontend -c -I %t %t/Main.swift -enable-experimental-feature Embedded -parse-as-library -o %t/a.o
6+
// RUN: %target-clang -x c -c %S/Inputs/print.c -o %t/print.o
7+
// RUN: %target-clang %t/a.o %t/print.o -o %t/a.out
8+
// RUN: %target-run %t/a.out | %FileCheck %s
9+
10+
// REQUIRES: swift_in_compiler
11+
// REQUIRES: executable_test
12+
// REQUIRES: OS=macosx || OS=linux-gnu
13+
// REQUIRES: swift_feature_Embedded
14+
15+
// BEGIN MyModule.swift
16+
17+
public protocol Foo: AnyObject {
18+
func run()
19+
}
20+
21+
public class Hello: Foo {
22+
public init() {}
23+
public func run() {
24+
print("Hello from MyLibrary!")
25+
}
26+
}
27+
28+
// BEGIN Main.swift
29+
30+
import MyModule
31+
32+
@main
33+
struct MyApp {
34+
static func main() {
35+
let ex: Foo = Hello()
36+
print("Hello from main!")
37+
ex.run()
38+
}
39+
}
40+
41+
// CHECK: Hello from main!

0 commit comments

Comments
 (0)