@@ -100,36 +100,37 @@ struct BorrowScopeOperandKind {
100
100
llvm::raw_ostream &operator <<(llvm::raw_ostream &os,
101
101
BorrowScopeOperandKind kind);
102
102
103
- struct BorrowScopeIntroducingValue ;
103
+ struct BorrowedValue ;
104
104
105
105
// / An operand whose user instruction introduces a new borrow scope for the
106
- // / operand's value. The value of the operand must be considered as implicitly
107
- // / borrowed until the user's corresponding end scope instruction.
106
+ // / operand's value. By executing the given user, the operand's value becomes
107
+ // / borrowed and thus the incoming value must implicitly be borrowed until the
108
+ // / user's corresponding end scope instruction.
108
109
// /
109
110
// / NOTE: We do not require that the guaranteed scope be represented by a
110
111
// / guaranteed value in the same function: see begin_apply. In such cases, we
111
112
// / require instead an end_* instruction to mark the end of the scope's region.
112
- struct BorrowScopeOperand {
113
+ struct BorrowingOperand {
113
114
BorrowScopeOperandKind kind;
114
115
Operand *op;
115
116
116
- BorrowScopeOperand (Operand *op)
117
+ BorrowingOperand (Operand *op)
117
118
: kind(*BorrowScopeOperandKind::get (op->getUser ()->getKind())), op(op) {}
118
- BorrowScopeOperand (const BorrowScopeOperand &other)
119
+ BorrowingOperand (const BorrowingOperand &other)
119
120
: kind(other.kind), op(other.op) {}
120
- BorrowScopeOperand &operator =(const BorrowScopeOperand &other) {
121
+ BorrowingOperand &operator =(const BorrowingOperand &other) {
121
122
kind = other.kind ;
122
123
op = other.op ;
123
124
return *this ;
124
125
}
125
126
126
127
// / If value is a borrow introducer return it after doing some checks.
127
- static Optional<BorrowScopeOperand > get (Operand *op) {
128
+ static Optional<BorrowingOperand > get (Operand *op) {
128
129
auto *user = op->getUser ();
129
130
auto kind = BorrowScopeOperandKind::get (user->getKind ());
130
131
if (!kind)
131
132
return None;
132
- return BorrowScopeOperand (*kind, op);
133
+ return BorrowingOperand (*kind, op);
133
134
}
134
135
135
136
void visitEndScopeInstructions (function_ref<void (Operand *)> func) const ;
@@ -182,8 +183,8 @@ struct BorrowScopeOperand {
182
183
// / Visit all of the "results" of the user of this operand that are borrow
183
184
// / scope introducers for the specific scope that this borrow scope operand
184
185
// / summarizes.
185
- void visitBorrowIntroducingUserResults (
186
- function_ref<void (BorrowScopeIntroducingValue )> visitor);
186
+ void
187
+ visitBorrowIntroducingUserResults ( function_ref<void (BorrowedValue )> visitor);
187
188
188
189
// / Passes to visitor all of the consuming uses of this use's using
189
190
// / instruction.
@@ -200,14 +201,14 @@ struct BorrowScopeOperand {
200
201
private:
201
202
// / Internal constructor for failable static constructor. Please do not expand
202
203
// / its usage since it assumes the code passed in is well formed.
203
- BorrowScopeOperand (BorrowScopeOperandKind kind, Operand *op)
204
+ BorrowingOperand (BorrowScopeOperandKind kind, Operand *op)
204
205
: kind(kind), op(op) {}
205
206
};
206
207
207
208
llvm::raw_ostream &operator <<(llvm::raw_ostream &os,
208
- const BorrowScopeOperand &operand);
209
+ const BorrowingOperand &operand);
209
210
210
- struct BorrowScopeIntroducingValueKind {
211
+ struct BorrowedValueKind {
211
212
// / Enum we use for exhaustive pattern matching over borrow scope introducers.
212
213
enum Kind {
213
214
LoadBorrow,
@@ -216,35 +217,34 @@ struct BorrowScopeIntroducingValueKind {
216
217
Phi,
217
218
};
218
219
219
- static Optional<BorrowScopeIntroducingValueKind > get (SILValue value) {
220
+ static Optional<BorrowedValueKind > get (SILValue value) {
220
221
if (value.getOwnershipKind () != ValueOwnershipKind::Guaranteed)
221
222
return None;
222
223
switch (value->getKind ()) {
223
224
default :
224
225
return None;
225
226
case ValueKind::LoadBorrowInst:
226
- return BorrowScopeIntroducingValueKind (LoadBorrow);
227
+ return BorrowedValueKind (LoadBorrow);
227
228
case ValueKind::BeginBorrowInst:
228
- return BorrowScopeIntroducingValueKind (BeginBorrow);
229
+ return BorrowedValueKind (BeginBorrow);
229
230
case ValueKind::SILFunctionArgument:
230
- return BorrowScopeIntroducingValueKind (SILFunctionArgument);
231
+ return BorrowedValueKind (SILFunctionArgument);
231
232
case ValueKind::SILPhiArgument: {
232
233
if (llvm::any_of (value->getParentBlock ()->getPredecessorBlocks (),
233
234
[](SILBasicBlock *block) {
234
235
return !isa<BranchInst>(block->getTerminator ());
235
236
})) {
236
237
return None;
237
238
}
238
- return BorrowScopeIntroducingValueKind (Phi);
239
+ return BorrowedValueKind (Phi);
239
240
}
240
241
}
241
242
}
242
243
243
244
Kind value;
244
245
245
- BorrowScopeIntroducingValueKind (Kind newValue) : value(newValue) {}
246
- BorrowScopeIntroducingValueKind (const BorrowScopeIntroducingValueKind &other)
247
- : value(other.value) {}
246
+ BorrowedValueKind (Kind newValue) : value(newValue) {}
247
+ BorrowedValueKind (const BorrowedValueKind &other) : value(other.value) {}
248
248
operator Kind () const { return value; }
249
249
250
250
// / Is this a borrow scope that begins and ends within the same function and
@@ -255,11 +255,11 @@ struct BorrowScopeIntroducingValueKind {
255
255
// / of the scope.
256
256
bool isLocalScope () const {
257
257
switch (value) {
258
- case BorrowScopeIntroducingValueKind ::BeginBorrow:
259
- case BorrowScopeIntroducingValueKind ::LoadBorrow:
260
- case BorrowScopeIntroducingValueKind ::Phi:
258
+ case BorrowedValueKind ::BeginBorrow:
259
+ case BorrowedValueKind ::LoadBorrow:
260
+ case BorrowedValueKind ::Phi:
261
261
return true ;
262
- case BorrowScopeIntroducingValueKind ::SILFunctionArgument:
262
+ case BorrowedValueKind ::SILFunctionArgument:
263
263
return false ;
264
264
}
265
265
llvm_unreachable (" Covered switch isnt covered?!" );
@@ -269,13 +269,12 @@ struct BorrowScopeIntroducingValueKind {
269
269
SWIFT_DEBUG_DUMP { print (llvm::dbgs ()); }
270
270
};
271
271
272
- llvm::raw_ostream &operator <<(llvm::raw_ostream &os,
273
- BorrowScopeIntroducingValueKind kind);
272
+ llvm::raw_ostream &operator <<(llvm::raw_ostream &os, BorrowedValueKind kind);
274
273
275
274
struct InteriorPointerOperand ;
276
275
277
- // / A higher level construct for working with values that represent the
278
- // / introduction of a new borrow scope.
276
+ // / A higher level construct for working with values that act as a "borrow
277
+ // / introducer" for a new borrow scope.
279
278
// /
280
279
// / DISCUSSION: A "borrow introducer" is a SILValue that represents the
281
280
// / beginning of a borrow scope that the ownership verifier validates. The idea
@@ -290,19 +289,19 @@ struct InteriorPointerOperand;
290
289
// / guaranteed results are borrow introducers. In practice this means that
291
290
// / borrow introducers can not have guaranteed results that are not creating a
292
291
// / new borrow scope. No such instructions exist today.
293
- struct BorrowScopeIntroducingValue {
294
- BorrowScopeIntroducingValueKind kind;
292
+ struct BorrowedValue {
293
+ BorrowedValueKind kind;
295
294
SILValue value;
296
295
297
296
// / If value is a borrow introducer return it after doing some checks.
298
297
// /
299
298
// / This is the only way to construct a BorrowScopeIntroducingValue. We make
300
299
// / the primary constructor private for this reason.
301
- static Optional<BorrowScopeIntroducingValue > get (SILValue value) {
302
- auto kind = BorrowScopeIntroducingValueKind ::get (value);
300
+ static Optional<BorrowedValue > get (SILValue value) {
301
+ auto kind = BorrowedValueKind ::get (value);
303
302
if (!kind)
304
303
return None;
305
- return BorrowScopeIntroducingValue (*kind, value);
304
+ return BorrowedValue (*kind, value);
306
305
}
307
306
308
307
// / If this value is introducing a local scope, gather all local end scope
@@ -359,13 +358,12 @@ struct BorrowScopeIntroducingValue {
359
358
private:
360
359
// / Internal constructor for failable static constructor. Please do not expand
361
360
// / its usage since it assumes the code passed in is well formed.
362
- BorrowScopeIntroducingValue (BorrowScopeIntroducingValueKind kind,
363
- SILValue value)
361
+ BorrowedValue (BorrowedValueKind kind, SILValue value)
364
362
: kind(kind), value(value) {}
365
363
};
366
364
367
365
llvm::raw_ostream &operator <<(llvm::raw_ostream &os,
368
- const BorrowScopeIntroducingValue &value);
366
+ const BorrowedValue &value);
369
367
370
368
// / Look up the def-use graph starting at use \p inputOperand, recording any
371
369
// / "borrow" introducing values that we find into \p out. If at any point, we
@@ -376,16 +374,15 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
376
374
// / NOTE: This may return multiple borrow introducing values in cases where
377
375
// / there are phi-like nodes in the IR like any true phi block arguments or
378
376
// / aggregate literal instructions (struct, tuple, enum, etc.).
379
- bool getAllBorrowIntroducingValues (
380
- SILValue value, SmallVectorImpl<BorrowScopeIntroducingValue > &out);
377
+ bool getAllBorrowIntroducingValues (SILValue value,
378
+ SmallVectorImpl<BorrowedValue > &out);
381
379
382
380
// / Look up through the def-use chain of \p inputValue, looking for an initial
383
381
// / "borrow" introducing value. If at any point, we find two introducers or we
384
382
// / find a point in the chain we do not understand, we bail and return false. If
385
383
// / we are able to understand all of the def-use graph and only find a single
386
384
// / introducer, then we return a .some(BorrowScopeIntroducingValue).
387
- Optional<BorrowScopeIntroducingValue>
388
- getSingleBorrowIntroducingValue (SILValue inputValue);
385
+ Optional<BorrowedValue> getSingleBorrowIntroducingValue (SILValue inputValue);
389
386
390
387
struct InteriorPointerOperandKind {
391
388
enum Kind : uint8_t {
@@ -441,7 +438,7 @@ struct InteriorPointerOperand {
441
438
// / projection. Returns true if we were able to find all borrow introducing
442
439
// / values.
443
440
bool visitBaseValueScopeEndingUses (function_ref<void (Operand *)> func) const {
444
- SmallVector<BorrowScopeIntroducingValue , 4 > introducers;
441
+ SmallVector<BorrowedValue , 4 > introducers;
445
442
if (!getAllBorrowIntroducingValues (operand->get (), introducers))
446
443
return false ;
447
444
for (const auto &introducer : introducers) {
0 commit comments