Skip to content

Commit 12a915f

Browse files
committed
OpaqueValues: resurrect closure test
This effectively reverts 8ca5c83
1 parent 78a7df8 commit 12a915f

File tree

2 files changed

+29
-36
lines changed

2 files changed

+29
-36
lines changed

test/SILGen/assign_or_init_without_opaque_sil.swift

Lines changed: 0 additions & 35 deletions
This file was deleted.

test/SILGen/opaque_values_closures.swift

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ struct G<T> {}
4343
struct MOG<T> : ~Copyable {}
4444
func getMOG<T>(_ t: T.Type) -> MOG<T> { return MOG<T>() }
4545
func borrow<T>(_ t: T) {}
46+
@propertyWrapper struct BoxWrapper<T> { var wrappedValue: T }
4647

4748
// CaptureKind::Immutable, canGuarantee=true, isPack=true
4849
// CHECK-LABEL: sil {{.*}}[ossa] @$s22opaque_values_closures30captureImmutablePackGuaranteed1tyxxQp_tRvzlF6$deferL_yyRvzlF : {{.*}} {
@@ -356,4 +357,31 @@ func captureBoxNonopaqueOwnedEscaping() {
356357
}
357358
}
358359
func captureBoxNonopaqueOwnedEscaping_callee<T>(_ t: T, _ c: @escaping (T) -> ()) {}
359-
func captureBoxNonopaqueOwnedEscaping_vend() -> C { return C() }
360+
func captureBoxNonopaqueOwnedEscaping_vend() -> C { return C() }
361+
362+
// CaptureKind::Box, non-opaque, canGuarantee=false, captureCanEscape=false
363+
// CHECK-LABEL: sil {{.*}}[ossa] @$s22opaque_values_closures35captureBoxNonopaqueOwnedNonescapingyyxyXElF : {{.*}} {
364+
// CHECK: bb0([[GET:%[^,]+]] :
365+
// CHECK: [[BOX:%[^,]+]] = alloc_box $<τ_0_0> { var BoxWrapper<τ_0_0> } <U>, var
366+
// CHECK: [[VAR:%[^,]+]] = mark_uninitialized [var] [[BOX]]
367+
// CHECK: [[VAR_LIFETIME:%[^,]+]] = begin_borrow [lexical] [var_decl] [[VAR]]
368+
// CHECK: [[VAR_ADDR:%[^,]+]] = project_box [[VAR_LIFETIME]]
369+
// TODO: DETERMINE: Considering that captureCanEscape is false, should this mark_function_escape be emitted?
370+
// CHECK: mark_function_escape [[VAR_ADDR]]
371+
// CHECK: [[LOCAL:%[^,]+]] = function_ref @$s22opaque_values_closures35captureBoxNonopaqueOwnedNonescapingyyxyXElF5localL_yylF
372+
// CHECK: apply [[LOCAL]]<U>([[VAR_LIFETIME]], [[GET]])
373+
// CHECK: end_borrow [[VAR_LIFETIME]]
374+
// CHECK: destroy_value [[VAR]]
375+
// CHECK-LABEL: } // end sil function '$s22opaque_values_closures35captureBoxNonopaqueOwnedNonescapingyyxyXElF'
376+
// CHECK-LABEL: sil {{.*}}[ossa] @$s22opaque_values_closures35captureBoxNonopaqueOwnedNonescapingyyxyXElF5localL_yylF : {{.*}}
377+
// CHECK: bb0(%0 : @closureCapture @guaranteed $<τ_0_0> { var BoxWrapper<τ_0_0> } <U>,
378+
// CHECK-SAME: %1 :
379+
// CHECK-LABEL: } // end sil function '$s22opaque_values_closures35captureBoxNonopaqueOwnedNonescapingyyxyXElF5localL_yylF'
380+
func captureBoxNonopaqueOwnedNonescaping<U>(_ get: () -> U) {
381+
@BoxWrapper var u: U
382+
383+
func local() {
384+
u = get()
385+
}
386+
local()
387+
}

0 commit comments

Comments
 (0)