@@ -66,19 +66,106 @@ class ManagedValue {
66
66
public:
67
67
68
68
ManagedValue () = default ;
69
-
69
+
70
70
// / Create a managed value for a +1 rvalue.
71
+ // /
72
+ // / Please do not introduce new uses of this method! Instead use one of the
73
+ // / static constructors below.
71
74
ManagedValue (SILValue value, CleanupHandle cleanup)
72
75
: valueAndFlag(value, false ), cleanup(cleanup) {
73
- assert (value && " No value specified" );
76
+ assert (value && " No value specified?! " );
74
77
}
75
78
76
79
// / Create a managed value for a +0 rvalue.
80
+ // /
81
+ // / Please do not introduce new uses of this method! Instead use one of the
82
+ // / static constructors below!
77
83
static ManagedValue forUnmanaged (SILValue value) {
78
84
assert (value && " No value specified" );
79
85
return ManagedValue (value, false , CleanupHandle::invalid ());
80
86
}
81
87
88
+ // / Create a managed value for a +1 rvalue object.
89
+ static ManagedValue forOwnedObjectRValue (SILValue value,
90
+ CleanupHandle cleanup) {
91
+ assert (value && " No value specified" );
92
+ assert (value->getType ().isObject () &&
93
+ " Expected borrowed rvalues to be objects" );
94
+ assert (value.getOwnershipKind () != ValueOwnershipKind::Trivial);
95
+ return ManagedValue (value, false , cleanup);
96
+ }
97
+
98
+ // / Create a managed value for a +1 rvalue address.
99
+ // /
100
+ // / From a high level perspective, this consists of a temporary buffer.
101
+ static ManagedValue forOwnedAddressRValue (SILValue value,
102
+ CleanupHandle cleanup) {
103
+ assert (value && " No value specified" );
104
+ assert (value->getType ().isAddress () && " Expected value to be an address" );
105
+ assert (value.getOwnershipKind () == ValueOwnershipKind::Trivial &&
106
+ " Addresses always have trivial ownership" );
107
+ return ManagedValue (value, false , cleanup);
108
+ }
109
+
110
+ // / Create a managed value for a +1 non-trivial rvalue.
111
+ static ManagedValue forOwnedRValue (SILValue value, CleanupHandle cleanup) {
112
+ if (value->getType ().isAddress ())
113
+ return ManagedValue::forOwnedAddressRValue (value, cleanup);
114
+ return ManagedValue::forOwnedObjectRValue (value, cleanup);
115
+ }
116
+
117
+ // / Create a managed value for a +0 borrowed non-trivial rvalue object.
118
+ static ManagedValue
119
+ forBorrowedObjectRValue (SILValue value,
120
+ CleanupHandle cleanup = CleanupHandle::invalid()) {
121
+ assert (value && " No value specified" );
122
+ assert (value->getType ().isObject () &&
123
+ " Expected borrowed rvalues to be objects" );
124
+ assert (value.getOwnershipKind () != ValueOwnershipKind::Trivial);
125
+ return ManagedValue (value, false , cleanup);
126
+ }
127
+
128
+ // / Create a managed value for a +0 borrowed non-trivial rvalue address.
129
+ static ManagedValue
130
+ forBorrowedAddressRValue (SILValue value,
131
+ CleanupHandle cleanup = CleanupHandle::invalid()) {
132
+ assert (value && " No value specified" );
133
+ assert (value->getType ().isAddress () && " Expected value to be an address" );
134
+ assert (value.getOwnershipKind () == ValueOwnershipKind::Trivial &&
135
+ " Addresses always have trivial ownership" );
136
+ return ManagedValue (value, false , cleanup);
137
+ }
138
+
139
+ // / Create a managed value for a +0 guaranteed rvalue.
140
+ static ManagedValue
141
+ forBorrowedRValue (SILValue value,
142
+ CleanupHandle cleanup = CleanupHandle::invalid()) {
143
+ if (value->getType ().isAddress ())
144
+ return ManagedValue::forBorrowedAddressRValue (value, cleanup);
145
+ return ManagedValue::forBorrowedObjectRValue (value, cleanup);
146
+ }
147
+
148
+ // / Create a managed value for a +0 trivial object rvalue.
149
+ static ManagedValue forTrivialObjectRValue (SILValue value) {
150
+ assert (value->getType ().isObject () && " Expected an object" );
151
+ assert (value.getOwnershipKind () == ValueOwnershipKind::Trivial);
152
+ return ManagedValue (value, false , CleanupHandle::invalid ());
153
+ }
154
+
155
+ // / Create a managed value for a +0 trivial address rvalue.
156
+ static ManagedValue forTrivialAddressRValue (SILValue value) {
157
+ assert (value->getType ().isAddress () && " Expected an address" );
158
+ assert (value.getOwnershipKind () == ValueOwnershipKind::Trivial);
159
+ return ManagedValue (value, false , CleanupHandle::invalid ());
160
+ }
161
+
162
+ // / Create a managed value for a +0 trivial rvalue.
163
+ static ManagedValue forTrivialRValue (SILValue value) {
164
+ if (value->getType ().isObject ())
165
+ return ManagedValue::forTrivialObjectRValue (value);
166
+ return ManagedValue::forTrivialAddressRValue (value);
167
+ }
168
+
82
169
// / Create a managed value for an l-value.
83
170
static ManagedValue forLValue (SILValue value) {
84
171
assert (value && " No value specified" );
0 commit comments