@@ -72,6 +72,9 @@ sil @useNE : $@convention(thin) (@guaranteed NE) -> ()
72
72
73
73
sil [ossa] @Wrapper_init : $@convention(method) (@owned NE, @thin Wrapper.Type) -> @lifetime(copy 0) @owned Wrapper
74
74
75
+ sil @yieldWrapper : $@yield_once @convention(method) (@guaranteed NCContainer) -> @lifetime(borrow 0) @yields @guaranteed Wrapper
76
+ sil @yieldNE : $@yield_once @convention(method) (@guaranteed Wrapper) -> @lifetime(copy 0) @yields @guaranteed NE
77
+
75
78
sil [ossa] @NCContainer_ne_read : $@yield_once @convention(method) (@guaranteed NCContainer) -> @lifetime(borrow 0) @yields @guaranteed NE
76
79
77
80
sil @yieldRawSpan : $@yield_once @convention(method) (@in_guaranteed A) -> @lifetime(borrow address_for_deps 0) @yields @guaranteed RawSpan
@@ -554,3 +557,59 @@ bb0(%0 : $*Holder):
554
557
destroy_value %holder
555
558
return %md
556
559
}
560
+
561
+ // Test a nested dependent coroutine. The inner coroutine yields a
562
+ // value (NE) that inherits its dependency from the outer yield
563
+ // (Wrapper). All copies of the inner yield must be used within the
564
+ // scope of the outer coroutine. The outer end_apply must be extended
565
+ // below the call to 'useNE'.
566
+ //
567
+ // CHECK-LABEL: sil hidden [ossa] @testCopiedYield : $@convention(thin) (@owned NCContainer) -> () {
568
+ // CHECK: bb0(%0 : @owned $NCContainer):
569
+ // CHECK: [[BOX:%[0-9]+]] = alloc_box ${ var NCContainer }, var, name "nc"
570
+ // CHECK: [[ACCESS:%[0-9]+]] = begin_access [read] [unknown]
571
+ // CHECK: [[LB:%[0-9]+]] = load_borrow [unchecked]
572
+ // CHECK: ([[YIELD:%[0-9]+]], [[TOKEN:%[0-9]+]]) = begin_apply %7(%6) : $@yield_once @convention(method) (@guaranteed NCContainer) -> @lifetime(borrow 0) @yields @guaranteed Wrapper
573
+ // CHECK: mark_dependence [unresolved] [[YIELD]] on [[TOKEN]]
574
+ // CHECK: ([[NE:%[0-9]+]], %{{.*}}) = begin_apply %13(%12) : $@yield_once @convention(method) (@guaranteed Wrapper) -> @lifetime(copy 0) @yields @guaranteed NE
575
+ // CHECK: destroy_value
576
+ // CHECK: apply %{{.*}}(%{{.*}}) : $@convention(thin) (@guaranteed NE) -> ()
577
+ // CHECK: destroy_value %{{.*}}
578
+ // CHECK: end_apply [[TOKEN]] as $()
579
+ // CHECK: end_borrow [[LB]]
580
+ // CHECK: end_access [[ACCESS]]
581
+ // CHECK: destroy_value [[BOX]]
582
+ // CHECK-LABEL: } // end sil function 'testCopiedYield'
583
+ sil hidden [ossa] @testCopiedYield : $@convention(thin) (@owned NCContainer) -> () {
584
+ bb0(%0 : @owned $NCContainer):
585
+ %1 = alloc_box ${ var NCContainer }, var, name "nc"
586
+ %2 = begin_borrow [lexical] [var_decl] %1
587
+ %3 = project_box %2, 0
588
+ store %0 to [init] %3
589
+ %5 = begin_access [read] [unknown] %3
590
+ %7 = load_borrow [unchecked] %5
591
+
592
+ %8 = function_ref @yieldWrapper : $@yield_once @convention(method) (@guaranteed NCContainer) -> @lifetime(borrow 0) @yields @guaranteed Wrapper
593
+ (%9, %10) = begin_apply %8(%7) : $@yield_once @convention(method) (@guaranteed NCContainer) -> @lifetime(borrow 0) @yields @guaranteed Wrapper
594
+ %11 = mark_dependence [unresolved] %9 on %10
595
+ %12 = copy_value %11
596
+ %13 = end_apply %10 as $()
597
+ end_borrow %7
598
+ end_access %5
599
+ %16 = move_value [var_decl] %12
600
+
601
+ %18 = function_ref @yieldNE : $@yield_once @convention(method) (@guaranteed Wrapper) -> @lifetime(copy 0) @yields @guaranteed NE
602
+ (%19, %20) = begin_apply %18(%16) : $@yield_once @convention(method) (@guaranteed Wrapper) -> @lifetime(copy 0) @yields @guaranteed NE
603
+ %21 = copy_value %19
604
+ %22 = end_apply %20 as $()
605
+ destroy_value %16
606
+ %23 = move_value [var_decl] %21
607
+
608
+ %25 = function_ref @useNE : $@convention(thin) (@guaranteed NE) -> ()
609
+ %26 = apply %25(%23) : $@convention(thin) (@guaranteed NE) -> ()
610
+ destroy_value %23
611
+ end_borrow %2
612
+ destroy_value %1
613
+ %31 = tuple ()
614
+ return %31
615
+ }
0 commit comments