@@ -93,6 +93,9 @@ public protocol Comparable {
93
93
94
94
sil [ossa] @unknown : $@convention(thin) () -> ()
95
95
sil [ossa] @getT : $@convention(thin) <T> () -> @out T
96
+ sil [ossa] @getKlass : $@convention(thin) () -> (@owned Klass)
97
+ sil [ossa] @borrowKlass : $(@in_guaranteed Klass) -> ()
98
+ sil [ossa] @borrowT : $@convention(thin) <T> (@in_guaranteed T) -> ()
96
99
sil [ossa] @getPair : $@convention(thin) <T> () -> @out Pair<T>
97
100
sil [ossa] @getOwned : $@convention(thin) <T : AnyObject> () -> (@owned T)
98
101
sil [ossa] @takeGuaranteedObject : $@convention(thin) (@guaranteed AnyObject) -> ()
@@ -2521,6 +2524,101 @@ bb0:
2521
2524
return %retval : $()
2522
2525
}
2523
2526
2527
+ // CHECK-LABEL: sil [ossa] @test_partial_apply_1_addronly_heap : {{.*}} {
2528
+ // CHECK: [[STACK:%[^,]+]] = alloc_stack $T
2529
+ // CHECK: [[GET:%[^,]+]] = function_ref @getT
2530
+ // CHECK: apply [[GET]]<T>([[STACK]])
2531
+ // CHECK: [[BORROW:%[^,]+]] = function_ref @borrowT
2532
+ // CHECK: [[CLOSURE:%[^,]+]] = partial_apply [callee_guaranteed] [[BORROW]]<T>([[STACK]])
2533
+ // CHECK: apply [[CLOSURE]]()
2534
+ // CHECK: destroy_value [[CLOSURE]]
2535
+ // CHECK: dealloc_stack [[STACK]]
2536
+ // CHECK-LABEL: } // end sil function 'test_partial_apply_1_addronly_heap'
2537
+ sil [ossa] @test_partial_apply_1_addronly_heap : $<T> () -> () {
2538
+ %get = function_ref @getT : $@convention(thin) <T> () -> (@out T)
2539
+ %instance = apply %get<T>() : $@convention(thin) <T> () -> (@out T)
2540
+ %callee = function_ref @borrowT : $@convention(thin) <T> (@in_guaranteed T) -> ()
2541
+ %closure = partial_apply [callee_guaranteed] %callee<T>(%instance) : $@convention(thin) <T> (@in_guaranteed T) -> ()
2542
+ apply %closure() : $@callee_guaranteed () -> ()
2543
+ destroy_value %closure : $@callee_guaranteed () -> ()
2544
+ %retval = tuple ()
2545
+ return %retval : $()
2546
+ }
2547
+
2548
+ // CHECK-LABEL: sil [ossa] @test_partial_apply_2_addronly_stack : {{.*}} {
2549
+ // CHECK: [[STACK:%[^,]+]] = alloc_stack $T
2550
+ // CHECK: [[GET:%[^,]+]] = function_ref @getT
2551
+ // CHECK: apply [[GET]]<T>([[STACK]])
2552
+ // CHECK: [[BORROW:%[^,]+]] = function_ref @borrowT
2553
+ // CHECK: [[CLOSURE:%[^,]+]] = partial_apply [callee_guaranteed] [on_stack] [[BORROW]]<T>([[STACK]])
2554
+ // CHECK: apply [[CLOSURE]]()
2555
+ // CHECK: destroy_value [[CLOSURE]]
2556
+ // CHECK: destroy_addr [[STACK]]
2557
+ // CHECK: dealloc_stack [[STACK]]
2558
+ // CHECK-LABEL: } // end sil function 'test_partial_apply_2_addronly_stack'
2559
+ sil [ossa] @test_partial_apply_2_addronly_stack : $<T> () -> () {
2560
+ %get = function_ref @getT : $@convention(thin) <T> () -> (@out T)
2561
+ %instance = apply %get<T>() : $@convention(thin) <T> () -> (@out T)
2562
+ %callee = function_ref @borrowT : $@convention(thin) <T> (@in_guaranteed T) -> ()
2563
+ %closure = partial_apply [on_stack] [callee_guaranteed] %callee<T>(%instance) : $@convention(thin) <T> (@in_guaranteed T) -> ()
2564
+ apply %closure() : $@noescape @callee_guaranteed () -> ()
2565
+ destroy_value %closure : $@noescape @callee_guaranteed () -> ()
2566
+ destroy_value %instance : $T
2567
+ %retval = tuple ()
2568
+ return %retval : $()
2569
+ }
2570
+
2571
+ // CHECK-LABEL: sil [ossa] @test_partial_apply_3_loadable_heap : {{.*}} {
2572
+ // CHECK: [[GET:%[^,]+]] = function_ref @getKlass
2573
+ // CHECK: [[INSTANCE:%[^,]+]] = apply [[GET]]()
2574
+ // CHECK: [[BORROW:%[^,]+]] = function_ref @borrowKlass
2575
+ // CHECK: [[ADDR:%[^,]+]] = alloc_stack $Klass
2576
+ // CHECK: store [[INSTANCE]] to [init] [[ADDR]]
2577
+ // CHECK: [[CLOSURE:%[^,]+]] = partial_apply [callee_guaranteed] [[BORROW]]([[ADDR]])
2578
+ // CHECK: dealloc_stack [[ADDR]]
2579
+ // CHECK: apply [[CLOSURE]]()
2580
+ // CHECK: destroy_value [[CLOSURE]]
2581
+ // CHECK-LABEL: } // end sil function 'test_partial_apply_3_loadable_heap'
2582
+ sil [ossa] @test_partial_apply_3_loadable_heap : $() -> () {
2583
+ %get = function_ref @getKlass : $@convention(thin) () -> (@owned Klass)
2584
+ %instance = apply %get() : $@convention(thin) () -> (@owned Klass)
2585
+ %callee = function_ref @borrowKlass : $@convention(thin) (@in_guaranteed Klass) -> ()
2586
+ %closure = partial_apply [callee_guaranteed] %callee(%instance) : $@convention(thin) (@in_guaranteed Klass) -> ()
2587
+ apply %closure() : $@callee_guaranteed () -> ()
2588
+ destroy_value %closure : $@callee_guaranteed () -> ()
2589
+ // destroy_value %instance : $Klass
2590
+ %retval = tuple ()
2591
+ return %retval : $()
2592
+ }
2593
+
2594
+ // CHECK-LABEL: sil [ossa] @test_partial_apply_4_loadable_stack : {{.*}} {
2595
+ // CHECK: [[GET:%[^,]+]] = function_ref @getKlass
2596
+ // CHECK: [[INSTANCE:%[^,]+]] = apply [[GET]]()
2597
+ // CHECK: [[BORROW:%[^,]+]] = function_ref @borrowKlass
2598
+ // CHECK: [[STACK:%[^,]+]] = alloc_stack $Klass
2599
+ // CHECK: [[LIFETIME:%[^,]+]] = begin_borrow [[INSTANCE]]
2600
+ // CHECK: [[STORAGE_LIFETIME:%[^,]+]] = store_borrow [[LIFETIME]] to [[STACK]]
2601
+ // CHECK: [[CLOSURE:%[^,]+]] = partial_apply [callee_guaranteed] [on_stack] [[BORROW]]([[STORAGE_LIFETIME]])
2602
+ // FIXME: These end_borrows must be _after_ the apply of the closure!
2603
+ // CHECK: end_borrow [[STORAGE_LIFETIME]]
2604
+ // CHECK: end_borrow [[LIFETIME]]
2605
+ // CHECK: dealloc_stack [[STACK]]
2606
+ // CHECK: apply [[CLOSURE]]() : $@noescape @callee_guaranteed () -> ()
2607
+ // CHECK: destroy_value [[CLOSURE]] : $@noescape @callee_guaranteed () -> ()
2608
+ // CHECK: destroy_value [[INSTANCE]]
2609
+ // CHECK-LABEL: } // end sil function 'test_partial_apply_4_loadable_stack'
2610
+ sil [ossa] @test_partial_apply_4_loadable_stack : $() -> () {
2611
+ %get = function_ref @getKlass : $@convention(thin) () -> (@owned Klass)
2612
+ %instance = apply %get() : $@convention(thin) () -> (@owned Klass)
2613
+ %callee = function_ref @borrowKlass : $@convention(thin) (@in_guaranteed Klass) -> ()
2614
+ %closure = partial_apply [on_stack] [callee_guaranteed] %callee(%instance) : $@convention(thin) (@in_guaranteed Klass) -> ()
2615
+ apply %closure() : $@noescape @callee_guaranteed () -> ()
2616
+ destroy_value %closure : $@noescape @callee_guaranteed () -> ()
2617
+ destroy_value %instance : $Klass
2618
+ %retval = tuple ()
2619
+ return %retval : $()
2620
+ }
2621
+
2524
2622
// CHECK-LABEL: sil hidden [ossa] @test_store_1 : {{.*}} {
2525
2623
// CHECK: [[MAYBE_ADDR:%[^,]+]] = alloc_stack $Optional<Self>
2526
2624
// CHECK: [[LOAD_ADDR:%[^,]+]] = alloc_stack $Self
0 commit comments