1
- // RUN: %target-swift-frontend %s -emit-sil -verify -enable-experimental-feature ManualOwnership
1
+ // RUN: %target-swift-frontend %s -emit-sil -verify \
2
+ // RUN: -enable-experimental-feature ManualOwnership \
3
+ // RUN: -enable-copy-propagation=always
2
4
3
5
// REQUIRES: swift_feature_ManualOwnership
4
6
@@ -12,6 +14,7 @@ public struct Pair {
12
14
var x : Int
13
15
var y : Int
14
16
17
+ @_manualOwnership
15
18
consuming func midpoint( _ other: borrowing Pair ) -> Pair {
16
19
return Pair ( x: ( x + other. x) / 2 , y: ( y + other. y) / 2 )
17
20
}
@@ -24,7 +27,10 @@ public class Triangle {
24
27
25
28
var nontrivial = Whatever ( )
26
29
30
+ @_manualOwnership
27
31
consuming func consuming( ) { }
32
+
33
+ @_manualOwnership
28
34
borrowing func borrowing( ) { }
29
35
}
30
36
@@ -33,14 +39,8 @@ public class Triangle {
33
39
@_manualOwnership
34
40
public func basic_return1( ) -> Triangle {
35
41
let x = Triangle ( )
36
- return x // expected-error {{explicit 'copy' required here}}
42
+ return x
37
43
}
38
- @_manualOwnership
39
- public func basic_return1_fixed( ) -> Triangle {
40
- let x = Triangle ( )
41
- return copy x
42
- }
43
-
44
44
45
45
@_manualOwnership
46
46
public func basic_return2( t: Triangle ) -> Triangle {
@@ -56,24 +56,39 @@ public func basic_return3() -> Triangle {
56
56
return Triangle ( )
57
57
}
58
58
59
- // FIXME: we need copy propagation in -Onone to eliminate all these copies
60
59
@_manualOwnership
61
60
func reassign_with_lets( ) -> Triangle {
62
61
let x = Triangle ( )
63
- let y = x // expected-error {{explicit 'copy' required here}}
64
- let z = y // expected-error {{explicit 'copy' required here}}
65
- return z // expected-error {{explicit 'copy' required here}}
62
+ let y = x
63
+ let z = y
64
+ return z
66
65
}
67
66
68
- // FIXME: we need copy propagation in -Onone to eliminate all but the copies for returning
69
67
@_manualOwnership
70
68
func renamed_return( _ cond: Bool , _ a: Triangle ) -> Triangle {
71
- let b = a // expected-error {{explicit 'copy' required here}}
72
- let c = b // expected-error {{explicit 'copy' required here}}
69
+ let b = a
70
+ let c = b
73
71
if cond { return b } // expected-error {{explicit 'copy' required here}}
74
72
return c // expected-error {{explicit 'copy' required here}}
75
73
}
76
74
75
+ @_manualOwnership
76
+ func renamed_return_fix1( _ cond: Bool , _ a: Triangle ) -> Triangle {
77
+ let b = copy a
78
+ let c = copy b // FIXME: not needed! Is explicit_copy_value is blocking propagation?
79
+ if cond { return b }
80
+ return c
81
+ }
82
+
83
+ // FIXME: this crashes CopyPropagation!
84
+ //@_manualOwnership
85
+ //func renamed_return_fix2(_ cond: Bool, _ a: Triangle) -> Triangle {
86
+ // let b = a
87
+ // let c = b
88
+ // if cond { return copy b }
89
+ // return copy c
90
+ //}
91
+
77
92
/// MARK: method calls
78
93
79
94
@_manualOwnership
@@ -87,7 +102,7 @@ func basic_methods_borrowing(_ t1: Triangle) {
87
102
func basic_methods_consuming( _ t1: Triangle ) {
88
103
let t2 = Triangle ( )
89
104
t1. consuming ( ) // expected-error {{explicit 'copy' required here}}
90
- t2. consuming ( ) // expected-error {{explicit 'copy' required here}}
105
+ t2. consuming ( )
91
106
}
92
107
@_manualOwnership
93
108
func basic_methods_consuming_fixed( _ t1: Triangle ) {
@@ -96,7 +111,7 @@ func basic_methods_consuming_fixed(_ t1: Triangle) {
96
111
t3 = Triangle ( )
97
112
98
113
( copy t1 ) . consuming ( )
99
- ( copy t2 ) . consuming ( )
114
+ ( copy t2 ) . consuming ( ) // FIXME: why is this not propagated?
100
115
( copy t3 ) . consuming ( )
101
116
}
102
117
@@ -113,12 +128,12 @@ func basic_function_call(_ t1: Triangle) {
113
128
/// MARK: control-flow
114
129
115
130
116
- // FIXME: var's and assignments are a little busted
131
+ // FIXME: var assignments are somtimes impossible to satisfy with 'copy'
117
132
118
133
// @_manualOwnership
119
134
// func reassignments_1() {
120
135
// var t3 = Triangle()
121
- // t3 = Triangle()
136
+ // t3 = copy Triangle() // FIXME: should not be needed
122
137
// t3.borrowing()
123
138
// }
124
139
// @_manualOwnership
0 commit comments