Skip to content

Commit a3be846

Browse files
committed
[SILGen] NFC: Moved EndBorrowCleanup to header.
Previously the declaration and definition of EndBorrowCleanup were both within SILGenExpr.cpp. That prevented the usage of cleanups which end borrow scopes within other files. Here, the declaration is moved to Cleanup.h. The necessary changes are made to SILGenExpr.cpp to keep the definition of member functions in place.
1 parent 028b964 commit a3be846

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

lib/SILGen/Cleanup.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ class LLVM_LIBRARY_VISIBILITY Cleanup {
133133
}
134134
};
135135

136+
struct EndBorrowCleanup final : Cleanup {
137+
SILValue borrowedValue;
138+
EndBorrowCleanup(SILValue borrowedValue);
139+
void emit(SILGenFunction &SGF, CleanupLocation l,
140+
ForUnwind_t forUnwind) override;
141+
void dump(SILGenFunction &) const override;
142+
};
143+
136144
/// A cleanup depth is generally used to denote the set of cleanups
137145
/// between the given cleanup (and not including it) and the top of
138146
/// the stack.

lib/SILGen/SILGenExpr.cpp

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -158,34 +158,30 @@ SILGenFunction::emitManagedBeginBorrow(SILLocation loc, SILValue v,
158158
return emitManagedBorrowedRValueWithCleanup(v, bbi, lowering);
159159
}
160160

161-
namespace {
162-
163-
struct EndBorrowCleanup : Cleanup {
164-
SILValue borrowedValue;
165-
166-
EndBorrowCleanup(SILValue borrowedValue) : borrowedValue(borrowedValue) {
167-
if (auto *arg = dyn_cast<SILPhiArgument>(borrowedValue)) {
168-
if (auto *ti = arg->getSingleTerminator()) {
169-
assert(!ti->isTransformationTerminator() &&
170-
"Transforming terminators do not have end_borrow");
171-
}
161+
EndBorrowCleanup::EndBorrowCleanup(SILValue borrowedValue)
162+
: borrowedValue(borrowedValue) {
163+
if (auto *arg = dyn_cast<SILPhiArgument>(borrowedValue)) {
164+
if (auto *ti = arg->getSingleTerminator()) {
165+
assert(!ti->isTransformationTerminator() &&
166+
"Transforming terminators do not have end_borrow");
172167
}
173168
}
169+
}
174170

175-
void emit(SILGenFunction &SGF, CleanupLocation l,
176-
ForUnwind_t forUnwind) override {
177-
SGF.B.createEndBorrow(l, borrowedValue);
178-
}
171+
void EndBorrowCleanup::emit(SILGenFunction &SGF, CleanupLocation l,
172+
ForUnwind_t forUnwind) {
173+
SGF.B.createEndBorrow(l, borrowedValue);
174+
}
179175

180-
void dump(SILGenFunction &) const override {
176+
void EndBorrowCleanup::dump(SILGenFunction &) const {
181177
#ifndef NDEBUG
182-
llvm::errs() << "EndBorrowCleanup "
183-
<< "State:" << getState() << "\n"
184-
<< "borrowed:" << borrowedValue
185-
<< "\n";
178+
llvm::errs() << "EndBorrowCleanup "
179+
<< "State:" << getState() << "\n"
180+
<< "borrowed:" << borrowedValue << "\n";
186181
#endif
187-
}
188-
};
182+
}
183+
184+
namespace {
189185

190186
struct FormalEvaluationEndBorrowCleanup : Cleanup {
191187
FormalEvaluationContext::stable_iterator Depth;

0 commit comments

Comments
 (0)