Skip to content

Commit ddea9f6

Browse files
committed
Optimizer: switch to the new ConstantCapturePropagation pass in the pass pipeline
1 parent efa9f9e commit ddea9f6

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ static void addClosureSpecializePassPipeline(SILPassPipelinePlan &P) {
779779
// ClosureSpecialization, because constant propagation is more effective. At
780780
// least one round of SSA optimization and inlining should run after this to
781781
// take advantage of static dispatch.
782-
P.addCapturePropagation();
782+
P.addConstantCapturePropagation();
783783

784784
// Specialize closure.
785785
if (P.getOptions().EnableExperimentalSwiftBasedClosureSpecialization) {

test/Interpreter/withoutActuallyEscaping.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ struct Context {
5959

6060
WithoutEscapingSuite.test("ExpectCrash") {
6161
expectCrashLater()
62-
let context = Context()
62+
let context = _opaqueIdentity(Context())
6363
sink = letEscape(f: { print("Context: \(context.a) \(context.b)") })
6464
}
6565

test/SILOptimizer/capture_propagate_keypath.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ struct GetID<C: RandomAccessCollection, ID> {
3838
}
3939
}
4040

41+
struct GetInt<C: RandomAccessCollection> {
42+
var getInt: (C.Element) -> Int
43+
44+
@inline(__always)
45+
init(keyPath: KeyPath<C.Element, Int>, i: Int) {
46+
getInt = { $0[keyPath: keyPath] + i }
47+
}
48+
}
49+
4150
// CHECK-LABEL: sil {{.*}} @$s4test0A6SimpleyyySiAA3StrVXEXEF :
4251
// CHECK-NOT: keypath
4352
// CHECK-LABEL: } // end sil function '$s4test0A6SimpleyyySiAA3StrVXEXEF'
@@ -68,6 +77,17 @@ func testGenericEscapingClosure() -> GetID<[Str], Int> {
6877
GetID(id: \.i)
6978
}
7079

80+
// CHECK-LABEL: sil {{.*}} @$s4test0A22KeypathWithNonConstInt1iAA03GetF0VySayAA3StrVGGSi_tF :
81+
// CHECK-NOT: keypath
82+
// CHECK: [[C:%.*]] = function_ref @[[SPECIALIZED_CLOSURE2:.*]] : $@convention(thin) (@in_guaranteed Str, Int) -> Int
83+
// CHECK-NEXT: partial_apply [callee_guaranteed] [[C]](%0) : $@convention(thin) (@in_guaranteed Str, Int) -> Int
84+
// CHECK-NOT: keypath
85+
// CHECK-LABEL: } // end sil function '$s4test0A22KeypathWithNonConstInt1iAA03GetF0VySayAA3StrVGGSi_tF'
86+
@inline(never)
87+
func testKeypathWithNonConstInt(i: Int) -> GetInt<[Str]> {
88+
GetInt(keyPath: \.j, i: i)
89+
}
90+
7191
// CHECK-LABEL: sil {{.*}} @$s4test0A7GenericyyyxAA6GenStrVyxGXEXElF :
7292
// CHECK: keypath
7393
// CHECK: keypath
@@ -91,6 +111,10 @@ public func _opaqueIdentity<T>(_ x: T) -> T {
91111
// CHECK-NOT: keypath
92112
// CHECK: } // end sil function '[[SPECIALIZED_CLOSURE]]'
93113

114+
// CHECK: sil shared {{.*}}@[[SPECIALIZED_CLOSURE2]] :
115+
// CHECK-NOT: keypath
116+
// CHECK: } // end sil function '[[SPECIALIZED_CLOSURE2]]'
117+
94118
func calltests() {
95119
// CHECK-OUTPUT-LABEL: testSimple:
96120
print("testSimple:")
@@ -130,6 +154,12 @@ func calltests() {
130154

131155
// CHECK-OUTPUT-NEXT: 27
132156
print(testGenericEscapingClosure().getID(Str()))
157+
158+
// CHECK-OUTPUT-LABEL: testKeypathWithNonConstInt:
159+
print("testKeypathWithNonConstInt:")
160+
161+
// CHECK-OUTPUT-NEXT: 38
162+
print(testKeypathWithNonConstInt(i: 10).getInt(Str()))
133163
}
134164

135165
calltests()

0 commit comments

Comments
 (0)