File tree 3 files changed +33
-3
lines changed
lib/SILOptimizer/Mandatory 3 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -295,9 +295,20 @@ class ApplySite {
295
295
// / Return the apply operand for the given applied argument index.
296
296
Operand &getArgumentRef (unsigned i) const { return getArgumentOperands ()[i]; }
297
297
298
+ // The apply operand at the given index into the callee's function's
299
+ // arguments.
300
+ Operand &getArgumentRefAtCalleeArgIndex (unsigned i) const {
301
+ return getArgumentRef (i - getCalleeArgIndexOfFirstAppliedArg ());
302
+ }
303
+
298
304
// / Return the ith applied argument.
299
305
SILValue getArgument (unsigned i) const { return getArguments ()[i]; }
300
306
307
+ // The argument at the given index into the callee's function's arguments.
308
+ SILValue getArgumentAtCalleeArgIndex (unsigned i) const {
309
+ return getArgument (i - getCalleeArgIndexOfFirstAppliedArg ());
310
+ }
311
+
301
312
// / Set the ith applied argument.
302
313
void setArgument (unsigned i, SILValue V) const {
303
314
getArgumentOperands ()[i].set (V);
Original file line number Diff line number Diff line change @@ -2190,14 +2190,17 @@ bool CallArgRewriter::rewriteArguments() {
2190
2190
bool changed = false ;
2191
2191
2192
2192
auto origConv = apply.getSubstCalleeConv ();
2193
- assert (apply.getNumArguments () == origConv.getNumParameters () &&
2194
- " results should not yet be rewritten" );
2193
+ assert ((apply.getNumArguments () == origConv.getNumParameters () &&
2194
+ apply.asFullApplySite ()) ||
2195
+ (apply.getNumArguments () <= origConv.getNumParameters () &&
2196
+ !apply.asFullApplySite ()) &&
2197
+ " results should not yet be rewritten" );
2195
2198
2196
2199
for (unsigned argIdx = apply.getCalleeArgIndexOfFirstAppliedArg (),
2197
2200
endArgIdx = argIdx + apply.getNumArguments ();
2198
2201
argIdx < endArgIdx; ++argIdx) {
2199
2202
2200
- Operand &operand = apply.getArgumentRef (argIdx);
2203
+ Operand &operand = apply.getArgumentRefAtCalleeArgIndex (argIdx);
2201
2204
// Ignore arguments that have already been rewritten with an address.
2202
2205
if (operand.get ()->getType ().isAddress ())
2203
2206
continue ;
Original file line number Diff line number Diff line change @@ -2619,6 +2619,22 @@ sil [ossa] @test_partial_apply_4_loadable_stack : $() -> () {
2619
2619
return %retval : $()
2620
2620
}
2621
2621
2622
+ // CHECK-LABEL: sil [ossa] @test_partial_apply_5_indexing : {{.*}} {
2623
+ // CHECK: {{bb[0-9]+}}([[C:%[^,]+]] :
2624
+ // CHECK: [[CALLEE:%[^,]+]] = function_ref @test_partial_apply_5_indexing_callee
2625
+ // CHECK: [[CLOSURE:%[^,]+]] = partial_apply [callee_guaranteed] [[CALLEE]]([[C]])
2626
+ // CHECK: destroy_value [[CLOSURE]]
2627
+ // CHECK-LABEL: } // end sil function 'test_partial_apply_5_indexing'
2628
+ sil @test_partial_apply_5_indexing_callee : $@convention(thin) (@inout Int, @guaranteed Klass) -> (@out Int)
2629
+ sil [ossa] @test_partial_apply_5_indexing : $@convention(thin) (@owned Klass) -> () {
2630
+ bb0(%c : @owned $Klass):
2631
+ %callee = function_ref @test_partial_apply_5_indexing_callee : $@convention(thin) (@inout Int, @guaranteed Klass) -> (@out Int)
2632
+ %closure = partial_apply [callee_guaranteed] %callee(%c) : $@convention(thin) (@inout Int, @guaranteed Klass) -> (@out Int)
2633
+ destroy_value %closure : $@callee_guaranteed (@inout Int) -> (@out Int)
2634
+ %retval = tuple ()
2635
+ return %retval : $()
2636
+ }
2637
+
2622
2638
// CHECK-LABEL: sil hidden [ossa] @test_store_1 : {{.*}} {
2623
2639
// CHECK: [[MAYBE_ADDR:%[^,]+]] = alloc_stack $Optional<Self>
2624
2640
// CHECK: [[LOAD_ADDR:%[^,]+]] = alloc_stack $Self
You can’t perform that action at this time.
0 commit comments