Skip to content

Commit 5894920

Browse files
authored
Merge pull request #22540 from gottesmm/pr-39b00ff45804f7b5ef7c5ae3af4ab013c32d1ccb
2 parents 32b7c26 + c4b7019 commit 5894920

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

lib/SILOptimizer/Utils/Generics.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,6 +2292,15 @@ void swift::trySpecializeApplyOfGeneric(
22922292
if (shouldNotSpecialize(RefF, F))
22932293
return;
22942294

2295+
// If our callee has ownership, do not specialize for now. This should only
2296+
// occur with transparent referenced functions.
2297+
//
2298+
// FIXME: Support this.
2299+
if (RefF->hasOwnership()) {
2300+
assert(RefF->isTransparent());
2301+
return;
2302+
}
2303+
22952304
// If the caller and callee are both fragile, preserve the fragility when
22962305
// cloning the callee. Otherwise, strip it off so that we can optimize
22972306
// the body more.

test/SILOptimizer/specialize_ossa.sil

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %target-sil-opt -enable-sil-verify-all -generic-specializer %/s | %FileCheck %s
2+
3+
sil_stage canonical
4+
5+
import Builtin
6+
import Swift
7+
8+
sil [ossa] [transparent] @ossaTransparentCallee : $@convention(thin) <T> (@in T) -> () {
9+
bb0(%0 : $*T):
10+
destroy_addr %0 : $*T
11+
%9999 = tuple()
12+
return %9999 : $()
13+
}
14+
15+
// CHECK-LABEL: sil @caller : $@convention(thin) (@owned Builtin.NativeObject) -> () {
16+
// CHECK: [[FUNC:%.*]] = function_ref @ossaTransparentCallee : $@convention(thin) <τ_0_0> (@in τ_0_0) -> ()
17+
// CHECK: apply [[FUNC]]<Builtin.NativeObject>(
18+
// CHECK: } // end sil function 'caller'
19+
sil @caller : $@convention(thin) (@owned Builtin.NativeObject) -> () {
20+
bb0(%0 : $Builtin.NativeObject):
21+
%1 = function_ref @ossaTransparentCallee : $@convention(thin) <τ_0_0> (@in τ_0_0) -> ()
22+
%2 = alloc_stack $Builtin.NativeObject
23+
store %0 to %2 : $*Builtin.NativeObject
24+
apply %1<Builtin.NativeObject>(%2) : $@convention(thin) <τ_0_0> (@in τ_0_0) -> ()
25+
dealloc_stack %2 : $*Builtin.NativeObject
26+
%9999 = tuple()
27+
return %9999 : $()
28+
}

0 commit comments

Comments
 (0)