Skip to content

Commit ff7c331

Browse files
authored
Merge pull request #78555 from eeckstein/witness-table-linkage
embedded: make sure to generate witness tables which are imported from other modules
2 parents 0f9e4fc + 9d0fc8b commit ff7c331

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
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

lib/SILOptimizer/Mandatory/IRGenPrepare.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class IRGenPrepare : public SILFunctionTransform {
9292
// Even de-serialized functions must be code-gen'd.
9393
SILLinkage linkage = F->getLinkage();
9494
if (isAvailableExternally(linkage)) {
95-
F->setLinkage(stripExternalFromLinkage(linkage));
95+
F->setLinkage(SILLinkage::Hidden);
9696
}
9797
}
9898

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)