Skip to content

Commit 41ef194

Browse files
committed
[embedded] Allow serialization of SILLinkage::shared functions without promoting them to public
1 parent 859dabd commit 41ef194

File tree

2 files changed

+58
-4
lines changed

2 files changed

+58
-4
lines changed

lib/SILOptimizer/IPO/CrossModuleOptimization.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ void CrossModuleOptimization::serializeFunction(SILFunction *function,
491491
if (function->isSerialized())
492492
return;
493493

494-
if (!canSerializeFlags.lookup(function))
494+
if (!everything && !canSerializeFlags.lookup(function))
495495
return;
496496

497497
function->setSerialized(IsSerialized);
@@ -588,9 +588,14 @@ void CrossModuleOptimization::keepMethodAlive(SILDeclRef method) {
588588

589589
void CrossModuleOptimization::makeFunctionUsableFromInline(SILFunction *function) {
590590
assert(canUseFromInline(function));
591-
if (!isAvailableExternally(function->getLinkage()) &&
592-
function->getLinkage() != SILLinkage::Public) {
593-
function->setLinkage(SILLinkage::Public);
591+
if (!isAvailableExternally(function->getLinkage())) {
592+
bool shouldPromoteToPublic = function->getLinkage() != SILLinkage::Public;
593+
if (everything)
594+
shouldPromoteToPublic = function->getLinkage() != SILLinkage::Public &&
595+
function->getLinkage() != SILLinkage::Shared;
596+
if (shouldPromoteToPublic) {
597+
function->setLinkage(SILLinkage::Public);
598+
}
594599
}
595600
}
596601

test/embedded/shared-linkage.swift

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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/Module.swiftmodule %t/Module.swift -enable-experimental-feature Embedded
5+
// RUN: %target-swift-frontend -emit-ir %t/Main.swift -I%t -enable-experimental-feature Embedded
6+
7+
// RUN: %target-swift-frontend -O -emit-module -o %t/Module.swiftmodule %t/Module.swift -enable-experimental-feature Embedded
8+
// RUN: %target-swift-frontend -O -emit-ir %t/Main.swift -I%t -enable-experimental-feature Embedded
9+
10+
// RUN: %target-swift-frontend -Osize -emit-module -o %t/Module.swiftmodule %t/Module.swift -enable-experimental-feature Embedded
11+
// RUN: %target-swift-frontend -Osize -emit-ir %t/Main.swift -I%t -enable-experimental-feature Embedded
12+
13+
// REQUIRES: swift_in_compiler
14+
// REQUIRES: VENDOR=apple
15+
// REQUIRES: OS=macosx
16+
17+
// BEGIN Module.swift
18+
19+
public func bar<R>(count: Int, _ body: (UnsafeMutableBufferPointer<Int>) -> R) -> R {
20+
let pointer = UnsafeMutablePointer<Int>(bitPattern: 42)!
21+
let inoutBufferPointer = UnsafeMutableBufferPointer(start: pointer, count: count)
22+
return body(inoutBufferPointer)
23+
}
24+
25+
public func foo<R>(_ body: () -> R) -> R {
26+
bar(count: 10) { p in
27+
body()
28+
}
29+
}
30+
31+
public func module_func() {
32+
foo {
33+
return 0
34+
}
35+
}
36+
37+
// BEGIN Main.swift
38+
39+
import Module
40+
41+
public func test() {
42+
module_func()
43+
}
44+
45+
public func client_func() {
46+
foo {
47+
return 0
48+
}
49+
}

0 commit comments

Comments
 (0)