Skip to content

Commit 9222b91

Browse files
committed
Add a test case for generic specialization and addressableForDeps.
(cherry picked from commit f5d7c03)
1 parent 4608c06 commit 9222b91

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// RUN: %target-sil-opt \
2+
// RUN: -generic-specializer \
3+
// RUN: -sil-verify-all \
4+
// RUN: -enable-experimental-feature LifetimeDependence \
5+
// RUN: -enable-experimental-feature AddressableParameters \
6+
// RUN: -enable-experimental-feature AddressableTypes \
7+
// RUN: %s | %FileCheck %s
8+
9+
// REQUIRES: swift_in_compiler
10+
// REQUIRES: swift_feature_LifetimeDependence
11+
// REQUIRES: swift_feature_AddressableParameters
12+
// REQUIRES: swift_feature_AddressableTypes
13+
14+
// Test the SIL representation for lifetime dependence scope fixup.
15+
16+
sil_stage raw
17+
18+
import Builtin
19+
import Swift
20+
21+
sil @makeSpan : $@convention(method) <τ_0_0 where τ_0_0 : ~Copyable> (UnsafePointer<τ_0_0>, Int, @thin Span<τ_0_0>.Type) -> @lifetime(borrow 0) @owned Span<τ_0_0>
22+
23+
// Ensure that the addressable argument is not deleted.
24+
//
25+
// CHECK-LABEL: sil shared [ossa] @$s12getSpanOfOneSi_Tg5 : $@convention(thin) (@in_guaranteed CollectionOfOne<Int>) -> @lifetime(borrow address_for_deps 0) @owned Span<Int> {
26+
sil shared [ossa] @getSpanOfOne : $@convention(thin) <Element> (@in_guaranteed CollectionOfOne<Element>) -> @lifetime(borrow address_for_deps 0) @owned Span<Element> {
27+
[global: ]
28+
bb0(%0 : $*CollectionOfOne<Element>):
29+
%1 = address_to_pointer [stack_protection] %0 : $*CollectionOfOne<Element> to $Builtin.RawPointer
30+
%2 = struct $UnsafePointer<Element> (%1 : $Builtin.RawPointer)
31+
%3 = metatype $@thin Span<Element>.Type
32+
%4 = integer_literal $Builtin.Int64, 1
33+
%5 = struct $Int (%4 : $Builtin.Int64)
34+
%6 = function_ref @makeSpan : $@convention(method) <τ_0_0 where τ_0_0 : ~Copyable> (UnsafePointer<τ_0_0>, Int, @thin Span<τ_0_0>.Type) -> @lifetime(borrow 0) @owned Span<τ_0_0>
35+
%7 = apply %6<Element>(%2, %5, %3) : $@convention(method) <τ_0_0 where τ_0_0 : ~Copyable> (UnsafePointer<τ_0_0>, Int, @thin Span<τ_0_0>.Type) -> @lifetime(borrow 0) @owned Span<τ_0_0>
36+
return %7 : $Span<Element>
37+
}
38+
39+
sil hidden [ossa] @testGetSpanOfOne : $@convention(thin) (@in_guaranteed CollectionOfOne<Int>) -> () {
40+
bb0(%0 : $*CollectionOfOne<Int>):
41+
%temp = alloc_stack $CollectionOfOne<Int>
42+
%load = load [trivial] %0 : $*CollectionOfOne<Int>
43+
%borrow = store_borrow %load to %temp : $*CollectionOfOne<Int>
44+
45+
%fget = function_ref @getSpanOfOne : $@convention(thin) <Element> (@in_guaranteed CollectionOfOne<Element>) -> @lifetime(borrow address_for_deps 0) @owned Span<Element>
46+
%span = apply %fget<Int>(%borrow) : $@convention(thin) <τ_0_0> (@in_guaranteed CollectionOfOne<τ_0_0>) -> @lifetime(borrow address_for_deps 0) @owned Span<τ_0_0>
47+
48+
destroy_value %span : $Span<Int>
49+
end_borrow %borrow : $*CollectionOfOne<Int>
50+
dealloc_stack %temp : $*CollectionOfOne<Int>
51+
52+
%99 = tuple ()
53+
return %99 : $()
54+
}

0 commit comments

Comments
 (0)