Skip to content

Commit e0cf515

Browse files
authored
Merge pull request #7417 from slavapestov/fix-closure-specialization-in-fragile-functions
SILOptimizer: Fix bug in closure specialization with resilient build
2 parents 6c52b67 + 890958e commit e0cf515

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/SILOptimizer/IPO/ClosureSpecializer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,13 @@ void ClosureSpecializer::gatherCallSites(
744744
if (!ApplyCallee || ApplyCallee->isExternalDeclaration())
745745
continue;
746746

747+
// Don't specialize non-fragile callees if the caller is fragile;
748+
// the specialized callee will have shared linkage, and thus cannot
749+
// be referenced from the fragile caller.
750+
if (Caller->isFragile() &&
751+
!ApplyCallee->hasValidLinkageForFragileInline())
752+
continue;
753+
747754
// Ok, we know that we can perform the optimization but not whether or
748755
// not the optimization is profitable. Find the index of the argument
749756
// corresponding to our partial apply.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %target-swift-frontend -Xllvm -new-mangling-for-tests %s -emit-sil -O -o - -verify | %FileCheck %s
2+
3+
// Make sure we do not specialize resilientCallee.
4+
5+
// CHECK-LABEL: sil [fragile] [always_inline] @_T026closure_specialize_fragile0C6CalleryyF : $@convention(thin) () -> ()
6+
// CHECK: function_ref @_T026closure_specialize_fragile15resilientCalleeyyyc2fn_tF : $@convention(thin) (@owned @callee_owned () -> ()) -> ()
7+
// CHECK: return
8+
9+
@inline(__always) public func fragileCaller() {
10+
resilientCallee {
11+
print("Hi")
12+
}
13+
}
14+
15+
// CHECK-LABEL: sil @_T026closure_specialize_fragile15resilientCalleeyyyc2fn_tF : $@convention(thin) (@owned @callee_owned () -> ()) -> ()
16+
17+
public func resilientCallee(fn: () -> ()) {
18+
fn()
19+
}

0 commit comments

Comments
 (0)