Skip to content

Commit dc4d8bd

Browse files
authored
---
yaml --- r: 349190 b: refs/heads/master-next c: c0a57b6 h: refs/heads/master
1 parent 139e176 commit dc4d8bd

40 files changed

+1203
-487
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 3574c513bbc5578dd9346b4ea9ab5995c5927bb5
3-
refs/heads/master-next: 44827bbde4d856199c528b9743b4c6b86fb4e6f7
3+
refs/heads/master-next: c0a57b6e17831e2c4e399c4a61b342f5b077245c
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea
66
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-b: 66d897bfcf64a82cb9a87f5e663d889189d06d07

branches/master-next/include/swift/AST/DiagnosticsSema.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,8 @@ ERROR(missing_argument_named,none,
11161116
"missing argument for parameter %0 in call", (Identifier))
11171117
ERROR(missing_argument_positional,none,
11181118
"missing argument for parameter #%0 in call", (unsigned))
1119+
ERROR(missing_arguments_in_call,none,
1120+
"missing arguments for parameters %0 in call", (StringRef))
11191121
ERROR(extra_argument_named,none,
11201122
"extra argument %0 in call", (Identifier))
11211123
ERROR(extra_argument_positional,none,
@@ -3493,6 +3495,10 @@ ERROR(single_tuple_parameter_mismatch_normal,none,
34933495
(DescriptiveDeclKind, DeclBaseName, Type, StringRef))
34943496
ERROR(unknown_single_tuple_parameter_mismatch,none,
34953497
"single parameter of type %0 is expected in call", (Type))
3498+
ERROR(cannot_convert_single_tuple_into_multiple_arguments,none,
3499+
"%0 %select{%1 |}2expects %3 separate arguments"
3500+
"%select{|; remove extra parentheses to change tuple into separate arguments}4",
3501+
(DescriptiveDeclKind, DeclName, bool, unsigned, bool))
34963502

34973503
ERROR(enum_element_pattern_assoc_values_mismatch,none,
34983504
"pattern with associated values does not match enum case %0",

branches/master-next/include/swift/SIL/OwnershipUtils.h

Lines changed: 98 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,86 @@ bool isOwnershipForwardingInst(SILInstruction *i);
200200

201201
bool isGuaranteedForwardingInst(SILInstruction *i);
202202

203-
struct BorrowScopeIntroducerKind {
203+
struct BorrowScopeOperandKind {
204+
using UnderlyingKindTy = std::underlying_type<SILInstructionKind>::type;
205+
206+
enum Kind : UnderlyingKindTy {
207+
BeginBorrow = UnderlyingKindTy(SILInstructionKind::BeginBorrowInst),
208+
BeginApply = UnderlyingKindTy(SILInstructionKind::BeginApplyInst),
209+
};
210+
211+
Kind value;
212+
213+
BorrowScopeOperandKind(Kind newValue) : value(newValue) {}
214+
BorrowScopeOperandKind(const BorrowScopeOperandKind &other)
215+
: value(other.value) {}
216+
operator Kind() const { return value; }
217+
218+
static Optional<BorrowScopeOperandKind> get(SILInstructionKind kind) {
219+
switch (kind) {
220+
default:
221+
return None;
222+
case SILInstructionKind::BeginBorrowInst:
223+
return BorrowScopeOperandKind(BeginBorrow);
224+
case SILInstructionKind::BeginApplyInst:
225+
return BorrowScopeOperandKind(BeginApply);
226+
}
227+
}
228+
229+
void print(llvm::raw_ostream &os) const;
230+
LLVM_ATTRIBUTE_DEPRECATED(void dump() const, "only for use in the debugger");
231+
};
232+
233+
/// An operand whose user instruction introduces a new borrow scope for the
234+
/// operand's value. The value of the operand must be considered as implicitly
235+
/// borrowed until the user's corresponding end scope instruction.
236+
struct BorrowScopeOperand {
237+
BorrowScopeOperandKind kind;
238+
Operand *op;
239+
240+
BorrowScopeOperand(Operand *op)
241+
: kind(*BorrowScopeOperandKind::get(op->getUser()->getKind())), op(op) {}
242+
243+
/// If value is a borrow introducer return it after doing some checks.
244+
static Optional<BorrowScopeOperand> get(Operand *op) {
245+
auto *user = op->getUser();
246+
auto kind = BorrowScopeOperandKind::get(user->getKind());
247+
if (!kind)
248+
return None;
249+
return BorrowScopeOperand(*kind, op);
250+
}
251+
252+
void visitEndScopeInstructions(function_ref<void(Operand *)> func) const {
253+
switch (kind) {
254+
case BorrowScopeOperandKind::BeginBorrow:
255+
for (auto *use : cast<BeginBorrowInst>(op->getUser())->getUses()) {
256+
if (isa<EndBorrowInst>(use->getUser())) {
257+
func(use);
258+
}
259+
}
260+
return;
261+
case BorrowScopeOperandKind::BeginApply: {
262+
auto *user = cast<BeginApplyInst>(op->getUser());
263+
for (auto *use : user->getTokenResult()->getUses()) {
264+
func(use);
265+
}
266+
return;
267+
}
268+
}
269+
llvm_unreachable("Covered switch isn't covered");
270+
}
271+
272+
private:
273+
/// Internal constructor for failable static constructor. Please do not expand
274+
/// its usage since it assumes the code passed in is well formed.
275+
BorrowScopeOperand(BorrowScopeOperandKind kind, Operand *op)
276+
: kind(kind), op(op) {}
277+
};
278+
279+
llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
280+
BorrowScopeOperandKind kind);
281+
282+
struct BorrowScopeIntroducingValueKind {
204283
using UnderlyingKindTy = std::underlying_type<ValueKind>::type;
205284

206285
/// Enum we use for exhaustive pattern matching over borrow scope introducers.
@@ -210,23 +289,23 @@ struct BorrowScopeIntroducerKind {
210289
SILFunctionArgument = UnderlyingKindTy(ValueKind::SILFunctionArgument),
211290
};
212291

213-
static Optional<BorrowScopeIntroducerKind> get(ValueKind kind) {
292+
static Optional<BorrowScopeIntroducingValueKind> get(ValueKind kind) {
214293
switch (kind) {
215294
default:
216295
return None;
217296
case ValueKind::LoadBorrowInst:
218-
return BorrowScopeIntroducerKind(LoadBorrow);
297+
return BorrowScopeIntroducingValueKind(LoadBorrow);
219298
case ValueKind::BeginBorrowInst:
220-
return BorrowScopeIntroducerKind(BeginBorrow);
299+
return BorrowScopeIntroducingValueKind(BeginBorrow);
221300
case ValueKind::SILFunctionArgument:
222-
return BorrowScopeIntroducerKind(SILFunctionArgument);
301+
return BorrowScopeIntroducingValueKind(SILFunctionArgument);
223302
}
224303
}
225304

226305
Kind value;
227306

228-
BorrowScopeIntroducerKind(Kind newValue) : value(newValue) {}
229-
BorrowScopeIntroducerKind(const BorrowScopeIntroducerKind &other)
307+
BorrowScopeIntroducingValueKind(Kind newValue) : value(newValue) {}
308+
BorrowScopeIntroducingValueKind(const BorrowScopeIntroducingValueKind &other)
230309
: value(other.value) {}
231310
operator Kind() const { return value; }
232311

@@ -238,10 +317,10 @@ struct BorrowScopeIntroducerKind {
238317
/// of the scope.
239318
bool isLocalScope() const {
240319
switch (value) {
241-
case BorrowScopeIntroducerKind::BeginBorrow:
242-
case BorrowScopeIntroducerKind::LoadBorrow:
320+
case BorrowScopeIntroducingValueKind::BeginBorrow:
321+
case BorrowScopeIntroducingValueKind::LoadBorrow:
243322
return true;
244-
case BorrowScopeIntroducerKind::SILFunctionArgument:
323+
case BorrowScopeIntroducingValueKind::SILFunctionArgument:
245324
return false;
246325
}
247326
llvm_unreachable("Covered switch isnt covered?!");
@@ -252,7 +331,7 @@ struct BorrowScopeIntroducerKind {
252331
};
253332

254333
llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
255-
BorrowScopeIntroducerKind kind);
334+
BorrowScopeIntroducingValueKind kind);
256335

257336
/// A higher level construct for working with values that represent the
258337
/// introduction of a new borrow scope.
@@ -271,26 +350,26 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
271350
/// borrow introducers can not have guaranteed results that are not creating a
272351
/// new borrow scope. No such instructions exist today.
273352
struct BorrowScopeIntroducingValue {
274-
BorrowScopeIntroducerKind kind;
353+
BorrowScopeIntroducingValueKind kind;
275354
SILValue value;
276355

277356
BorrowScopeIntroducingValue(LoadBorrowInst *lbi)
278-
: kind(BorrowScopeIntroducerKind::LoadBorrow), value(lbi) {}
357+
: kind(BorrowScopeIntroducingValueKind::LoadBorrow), value(lbi) {}
279358
BorrowScopeIntroducingValue(BeginBorrowInst *bbi)
280-
: kind(BorrowScopeIntroducerKind::BeginBorrow), value(bbi) {}
359+
: kind(BorrowScopeIntroducingValueKind::BeginBorrow), value(bbi) {}
281360
BorrowScopeIntroducingValue(SILFunctionArgument *arg)
282-
: kind(BorrowScopeIntroducerKind::SILFunctionArgument), value(arg) {
361+
: kind(BorrowScopeIntroducingValueKind::SILFunctionArgument), value(arg) {
283362
assert(arg->getOwnershipKind() == ValueOwnershipKind::Guaranteed);
284363
}
285364

286365
BorrowScopeIntroducingValue(SILValue v)
287-
: kind(*BorrowScopeIntroducerKind::get(v->getKind())), value(v) {
366+
: kind(*BorrowScopeIntroducingValueKind::get(v->getKind())), value(v) {
288367
assert(v.getOwnershipKind() == ValueOwnershipKind::Guaranteed);
289368
}
290369

291370
/// If value is a borrow introducer return it after doing some checks.
292371
static Optional<BorrowScopeIntroducingValue> get(SILValue value) {
293-
auto kind = BorrowScopeIntroducerKind::get(value->getKind());
372+
auto kind = BorrowScopeIntroducingValueKind::get(value->getKind());
294373
if (!kind || value.getOwnershipKind() != ValueOwnershipKind::Guaranteed)
295374
return None;
296375
return BorrowScopeIntroducingValue(*kind, value);
@@ -334,7 +413,8 @@ struct BorrowScopeIntroducingValue {
334413
private:
335414
/// Internal constructor for failable static constructor. Please do not expand
336415
/// its usage since it assumes the code passed in is well formed.
337-
BorrowScopeIntroducingValue(BorrowScopeIntroducerKind kind, SILValue value)
416+
BorrowScopeIntroducingValue(BorrowScopeIntroducingValueKind kind,
417+
SILValue value)
338418
: kind(kind), value(value) {}
339419
};
340420

branches/master-next/lib/SIL/OwnershipUtils.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,22 @@ bool swift::isOwnershipForwardingInst(SILInstruction *i) {
8181
// Borrow Introducers
8282
//===----------------------------------------------------------------------===//
8383

84-
void BorrowScopeIntroducerKind::print(llvm::raw_ostream &os) const {
84+
void BorrowScopeIntroducingValueKind::print(llvm::raw_ostream &os) const {
8585
switch (value) {
86-
case BorrowScopeIntroducerKind::SILFunctionArgument:
86+
case BorrowScopeIntroducingValueKind::SILFunctionArgument:
8787
os << "SILFunctionArgument";
8888
return;
89-
case BorrowScopeIntroducerKind::BeginBorrow:
89+
case BorrowScopeIntroducingValueKind::BeginBorrow:
9090
os << "BeginBorrowInst";
9191
return;
92-
case BorrowScopeIntroducerKind::LoadBorrow:
92+
case BorrowScopeIntroducingValueKind::LoadBorrow:
9393
os << "LoadBorrowInst";
9494
return;
9595
}
9696
llvm_unreachable("Covered switch isn't covered?!");
9797
}
9898

99-
void BorrowScopeIntroducerKind::dump() const {
99+
void BorrowScopeIntroducingValueKind::dump() const {
100100
#ifndef NDEBUG
101101
print(llvm::dbgs());
102102
#endif
@@ -107,13 +107,13 @@ void BorrowScopeIntroducingValue::getLocalScopeEndingInstructions(
107107
assert(isLocalScope() && "Should only call this given a local scope");
108108

109109
switch (kind) {
110-
case BorrowScopeIntroducerKind::SILFunctionArgument:
110+
case BorrowScopeIntroducingValueKind::SILFunctionArgument:
111111
llvm_unreachable("Should only call this with a local scope");
112-
case BorrowScopeIntroducerKind::BeginBorrow:
112+
case BorrowScopeIntroducingValueKind::BeginBorrow:
113113
llvm::copy(cast<BeginBorrowInst>(value)->getEndBorrows(),
114114
std::back_inserter(scopeEndingInsts));
115115
return;
116-
case BorrowScopeIntroducerKind::LoadBorrow:
116+
case BorrowScopeIntroducingValueKind::LoadBorrow:
117117
llvm::copy(cast<LoadBorrowInst>(value)->getEndBorrows(),
118118
std::back_inserter(scopeEndingInsts));
119119
return;
@@ -125,17 +125,17 @@ void BorrowScopeIntroducingValue::visitLocalScopeEndingUses(
125125
function_ref<void(Operand *)> visitor) const {
126126
assert(isLocalScope() && "Should only call this given a local scope");
127127
switch (kind) {
128-
case BorrowScopeIntroducerKind::SILFunctionArgument:
128+
case BorrowScopeIntroducingValueKind::SILFunctionArgument:
129129
llvm_unreachable("Should only call this with a local scope");
130-
case BorrowScopeIntroducerKind::BeginBorrow:
131-
for (auto *use : cast<BeginBorrowInst>(value)->getUses()) {
130+
case BorrowScopeIntroducingValueKind::BeginBorrow:
131+
for (auto *use : value->getUses()) {
132132
if (isa<EndBorrowInst>(use->getUser())) {
133133
visitor(use);
134134
}
135135
}
136136
return;
137-
case BorrowScopeIntroducerKind::LoadBorrow:
138-
for (auto *use : cast<LoadBorrowInst>(value)->getUses()) {
137+
case BorrowScopeIntroducingValueKind::LoadBorrow:
138+
for (auto *use : value->getUses()) {
139139
if (isa<EndBorrowInst>(use->getUser())) {
140140
visitor(use);
141141
}
@@ -182,7 +182,7 @@ bool swift::getUnderlyingBorrowIntroducingValues(
182182
}
183183

184184
llvm::raw_ostream &swift::operator<<(llvm::raw_ostream &os,
185-
BorrowScopeIntroducerKind kind) {
185+
BorrowScopeIntroducingValueKind kind) {
186186
kind.print(os);
187187
return os;
188188
}

branches/master-next/lib/SIL/SILOwnershipVerifier.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,10 @@ bool SILValueOwnershipChecker::gatherUsers(
278278
// For correctness reasons we use indices to make sure that we can
279279
// append to NonLifetimeEndingUsers without needing to deal with
280280
// iterator invalidation.
281-
for (unsigned i : indices(nonLifetimeEndingUsers)) {
282-
if (auto *bbi = dyn_cast<BeginBorrowInst>(
283-
nonLifetimeEndingUsers[i]->getUser())) {
284-
for (auto *use : bbi->getUses()) {
285-
if (isa<EndBorrowInst>(use->getUser())) {
286-
implicitRegularUsers.push_back(use);
287-
}
288-
}
281+
for (auto *op : nonLifetimeEndingUsers) {
282+
if (auto scopedOperand = BorrowScopeOperand::get(op)) {
283+
scopedOperand->visitEndScopeInstructions(
284+
[&](Operand *op) { implicitRegularUsers.push_back(op); });
289285
}
290286
}
291287
}

0 commit comments

Comments
 (0)