mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
It used to be done with a library intrinsic which returns the array and an element address pointer. A `mark_dependence` was used to "connect" the two results. But this resulted in completely wrong OSSA after inlining. It just didn't get caught be the verifier because the SIL was obfuscated by address-pointer conversions. Now we don't use the second result (= the element address) of the intrinsic but generate a correct borrow scope from the first (= array) result. Within that borrow scope we project out the element address with a `ref_tail_addr` instruction. This relies on knowledge of the internal Array data structures. However those data structures are baked into the ABI since a long time and will not change.
26 lines
1.0 KiB
Swift
26 lines
1.0 KiB
Swift
|
|
// RUN: %target-swift-emit-silgen -module-name array_literal_abstraction %s | %FileCheck %s
|
|
|
|
// Verify that reabstraction happens when forming container literals.
|
|
// <rdar://problem/16039286>
|
|
|
|
// CHECK-LABEL: sil hidden [ossa] @$s25array_literal_abstraction0A9_of_funcsSayyycGyF
|
|
// CHECK: ref_tail_addr %{{[0-9]+}}, $@callee_guaranteed @substituted <τ_0_0> () -> @out τ_0_0 for <()>
|
|
func array_of_funcs() -> [(() -> ())] {
|
|
return [{}, {}]
|
|
}
|
|
|
|
// CHECK-LABEL: sil hidden [ossa] @$s25array_literal_abstraction13dict_of_funcsSDySiyycGyF
|
|
// CHECK: ref_tail_addr %{{[0-9]+}}, $(Int, @callee_guaranteed @substituted <τ_0_0> () -> @out τ_0_0 for <()>)
|
|
func dict_of_funcs() -> Dictionary<Int, () -> ()> {
|
|
return [0: {}, 1: {}]
|
|
}
|
|
|
|
func vararg_funcs(_ fs: (() -> ())...) {}
|
|
|
|
// CHECK-LABEL: sil hidden [ossa] @$s25array_literal_abstraction17call_vararg_funcsyyF
|
|
// CHECK: ref_tail_addr %{{[0-9]+}}, $@callee_guaranteed @substituted <τ_0_0> () -> @out τ_0_0 for <()>
|
|
func call_vararg_funcs() {
|
|
vararg_funcs({}, {})
|
|
}
|