Skip to content

Commit 1d6f149

Browse files
authored
Merge pull request swiftlang#12787 from slavapestov/simpler-apply-lowering
Simplify SILGenApply some more
2 parents cbee90c + 5fd8e71 commit 1d6f149

File tree

106 files changed

+715
-823
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+715
-823
lines changed

lib/SILGen/ArgumentSource.cpp

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ void ArgumentSource::rewriteType(CanType newType) & {
5555
case Kind::Tuple:
5656
llvm_unreachable("cannot rewrite type of tuple");
5757
case Kind::RValue:
58-
case Kind::DelayedBorrowedRValue:
5958
Storage.get<RValueStorage>(StoredKind).Value.rewriteType(newType);
6059
return;
6160
case Kind::Expr:
@@ -89,7 +88,6 @@ bool ArgumentSource::requiresCalleeToEvaluate() const {
8988
case Kind::Invalid:
9089
llvm_unreachable("argument source is invalid");
9190
case Kind::RValue:
92-
case Kind::DelayedBorrowedRValue:
9391
case Kind::LValue:
9492
return false;
9593
case Kind::Expr:
@@ -138,9 +136,6 @@ RValue ArgumentSource::getAsRValue(SILGenFunction &SGF, SGFContext C) && {
138136
llvm_unreachable("argument source is invalid");
139137
case Kind::LValue:
140138
llvm_unreachable("cannot get l-value as r-value");
141-
case Kind::DelayedBorrowedRValue:
142-
return std::move(*this).asKnownRValue(SGF).borrow(SGF,
143-
getKnownRValueLocation());
144139
case Kind::RValue:
145140
return std::move(*this).asKnownRValue(SGF);
146141
case Kind::Expr:
@@ -195,15 +190,6 @@ ManagedValue ArgumentSource::getAsSingleValue(SILGenFunction &SGF,
195190
return SGF.emitAddressOfLValue(loc, std::move(*this).asKnownLValue(),
196191
AccessKind::ReadWrite);
197192
}
198-
case Kind::DelayedBorrowedRValue: {
199-
assert(!C.getEmitInto() &&
200-
"Can not put a delayed borrowed rvalue into an initialization");
201-
auto loc = getKnownRValueLocation();
202-
return std::move(*this)
203-
.asKnownRValue(SGF)
204-
.getAsSingleValue(SGF, loc)
205-
.borrow(SGF, loc);
206-
}
207193
case Kind::RValue: {
208194
auto loc = getKnownRValueLocation();
209195
if (auto init = C.getEmitInto()) {
@@ -250,9 +236,6 @@ ManagedValue ArgumentSource::getConverted(SILGenFunction &SGF,
250236
llvm_unreachable("argument source is invalid");
251237
case Kind::LValue:
252238
llvm_unreachable("cannot get converted l-value");
253-
case Kind::DelayedBorrowedRValue:
254-
// TODO: We probably can, but we would need to introduce a copy.
255-
llvm_unreachable("cannot get converted borrowed r-value");
256239
case Kind::RValue:
257240
case Kind::Expr:
258241
case Kind::Tuple:
@@ -270,8 +253,6 @@ void ArgumentSource::forwardInto(SILGenFunction &SGF, Initialization *dest) && {
270253
llvm_unreachable("argument source is invalid");
271254
case Kind::LValue:
272255
llvm_unreachable("cannot forward an l-value");
273-
case Kind::DelayedBorrowedRValue:
274-
llvm_unreachable("cannot forward a delayed borrowed r-value");
275256
case Kind::RValue: {
276257
auto loc = getKnownRValueLocation();
277258
std::move(*this).asKnownRValue(SGF).forwardInto(SGF, loc, dest);
@@ -299,26 +280,12 @@ ArgumentSource::ArgumentSource(SILLocation loc, RValue &&rv, Kind kind)
299280
Storage.emplaceAggregate<RValueStorage>(StoredKind, std::move(rv), loc);
300281
}
301282

302-
ArgumentSource ArgumentSource::delayedBorrow(SILGenFunction &SGF) const & {
303-
assert(isRValue() && "Can only perform a delayed borrow on an rvalue");
304-
// We are doing something evil here since we know that we are going to perform
305-
// a borrow.
306-
//
307-
// Once uncurrying is removed from the compiler, we will no longer need to
308-
// perform delayed borrows and this evilness can be expunged.
309-
const RValue &rv = asKnownRValue();
310-
return ArgumentSource(getKnownRValueLocation(),
311-
RValue(&SGF, rv.values, rv.type),
312-
Kind::DelayedBorrowedRValue);
313-
}
314-
315283
ArgumentSource ArgumentSource::borrow(SILGenFunction &SGF) const & {
316284
switch (StoredKind) {
317285
case Kind::Invalid:
318286
llvm_unreachable("argument source is invalid");
319287
case Kind::LValue:
320288
llvm_unreachable("cannot borrow an l-value");
321-
case Kind::DelayedBorrowedRValue:
322289
case Kind::RValue: {
323290
auto loc = getKnownRValueLocation();
324291
return ArgumentSource(loc, asKnownRValue().borrow(SGF, loc));
@@ -449,7 +416,6 @@ void ArgumentSource::dump(raw_ostream &out, unsigned indent) const {
449416
return;
450417
}
451418
case Kind::RValue:
452-
case Kind::DelayedBorrowedRValue:
453419
out << "RValue\n";
454420
Storage.get<RValueStorage>(StoredKind).Value.dump(out, indent + 2);
455421
return;

lib/SILGen/ArgumentSource.h

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ class ArgumentSource {
5252
enum class Kind : unsigned char {
5353
Invalid,
5454
RValue,
55-
// An RValue that will be borrowed when emitted.
56-
DelayedBorrowedRValue,
5755
LValue,
5856
Expr,
5957
Tuple,
@@ -91,7 +89,6 @@ class ArgumentSource {
9189
switch (kind) {
9290
case Kind::Invalid: return StorageMembers::indexOf<void>();
9391
case Kind::RValue:
94-
case Kind::DelayedBorrowedRValue:
9592
return StorageMembers::indexOf<RValueStorage>();
9693
case Kind::LValue: return StorageMembers::indexOf<LValueStorage>();
9794
case Kind::Expr: return StorageMembers::indexOf<Expr*>();
@@ -147,7 +144,6 @@ class ArgumentSource {
147144
case Kind::Invalid:
148145
return false;
149146
case Kind::RValue:
150-
case Kind::DelayedBorrowedRValue:
151147
return !asKnownRValue().isNull();
152148
case Kind::LValue:
153149
return asKnownLValue().isValid();
@@ -164,7 +160,6 @@ class ArgumentSource {
164160
case Kind::Invalid:
165161
llvm_unreachable("argument source is invalid");
166162
case Kind::RValue:
167-
case Kind::DelayedBorrowedRValue:
168163
return asKnownRValue().getType();
169164
case Kind::LValue:
170165
return CanInOutType::get(asKnownLValue().getSubstFormalType());
@@ -183,7 +178,6 @@ class ArgumentSource {
183178
case Kind::Invalid:
184179
llvm_unreachable("argument source is invalid");
185180
case Kind::RValue:
186-
case Kind::DelayedBorrowedRValue:
187181
return asKnownRValue().getType();
188182
case Kind::LValue:
189183
return asKnownLValue().getSubstFormalType();
@@ -201,7 +195,6 @@ class ArgumentSource {
201195
switch (StoredKind) {
202196
case Kind::Invalid: llvm_unreachable("argument source is invalid");
203197
case Kind::RValue:
204-
case Kind::DelayedBorrowedRValue:
205198
return false;
206199
case Kind::LValue: return true;
207200
case Kind::Expr: return asKnownExpr()->isSemanticallyInOutExpr();
@@ -215,7 +208,6 @@ class ArgumentSource {
215208
case Kind::Invalid:
216209
llvm_unreachable("argument source is invalid");
217210
case Kind::RValue:
218-
case Kind::DelayedBorrowedRValue:
219211
return getKnownRValueLocation();
220212
case Kind::LValue:
221213
return getKnownLValueLocation();
@@ -228,21 +220,13 @@ class ArgumentSource {
228220
}
229221

230222
bool isExpr() const & { return StoredKind == Kind::Expr; }
231-
bool isRValue() const & {
232-
return StoredKind == Kind::RValue ||
233-
StoredKind == Kind::DelayedBorrowedRValue;
234-
}
223+
bool isRValue() const & { return StoredKind == Kind::RValue; }
235224
bool isLValue() const & { return StoredKind == Kind::LValue; }
236225
bool isTuple() const & { return StoredKind == Kind::Tuple; }
237226

238227
/// Given that this source is storing an RValue, extract and clear
239228
/// that value.
240229
RValue &&asKnownRValue(SILGenFunction &SGF) && {
241-
if (isDelayedBorrowedRValue()) {
242-
std::move(Storage.get<RValueStorage>(StoredKind).Value)
243-
.borrow(SGF, getKnownRValueLocation());
244-
}
245-
246230
return std::move(Storage.get<RValueStorage>(StoredKind).Value);
247231
}
248232

@@ -313,15 +297,6 @@ class ArgumentSource {
313297
/// return the ArgumentSource. Otherwise, assert.
314298
ArgumentSource borrow(SILGenFunction &SGF) const &;
315299

316-
/// If we have an rvalue, return an Argument Source that when the RValue is
317-
/// retrieved, the RValue is always borrowed first.
318-
///
319-
/// This allows us to specify when creating callees that a value must be
320-
/// borrowed, but emit the actual borrow once the callee is evaluated later in
321-
/// SILGenApply. Ideally, the callee would always eagerly borrow, but since we
322-
/// still have uncurrying, we can not do that.
323-
ArgumentSource delayedBorrow(SILGenFunction &SGF) const &;
324-
325300
ManagedValue materialize(SILGenFunction &SGF) &&;
326301

327302
/// Emit this value to memory so that it follows the abstraction
@@ -346,14 +321,6 @@ class ArgumentSource {
346321
/// Private helper constructor for delayed borrowed rvalues.
347322
ArgumentSource(SILLocation loc, RValue &&rv, Kind kind);
348323

349-
/// Returns true if this ArgumentSource stores a delayed borrowed RValue.
350-
///
351-
/// This is private since we do not want users to be able to determine if the
352-
/// given ArgumentSource is a normal RValue or a delayed borrow rvalue.
353-
bool isDelayedBorrowedRValue() const & {
354-
return StoredKind == Kind::DelayedBorrowedRValue;
355-
}
356-
357324
// Make the non-move accessors private to make it more difficult
358325
// to accidentally re-emit values.
359326
const RValue &asKnownRValue() const & {

0 commit comments

Comments
 (0)