Skip to content

Commit af19e54

Browse files
committed
[silgen] Make NormalCaseHandler and DefaultCaseHandler take SwitchCaseFullExpr as movable rvalues.
This fits more with the notion of the API, that the user is being given a scope that was already setup for them and that they must decide when to pop.
1 parent 7a6c880 commit af19e54

File tree

6 files changed

+13
-13
lines changed

6 files changed

+13
-13
lines changed

lib/SILGen/SILGenConvert.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ SILGenFunction::emitOptionalToOptional(SILLocation loc,
393393

394394
SEBuilder.addCase(
395395
getASTContext().getOptionalSomeDecl(), isPresentBB, contBB,
396-
[&](ManagedValue input, SwitchCaseFullExpr &scope) {
396+
[&](ManagedValue input, SwitchCaseFullExpr &&scope) {
397397
// If we have an address only type, we want to match the old behavior of
398398
// transforming the underlying type instead of the optional type. This
399399
// ensures that we use the more efficient non-generic code paths when
@@ -422,7 +422,7 @@ SILGenFunction::emitOptionalToOptional(SILLocation loc,
422422

423423
SEBuilder.addCase(
424424
getASTContext().getOptionalNoneDecl(), isNotPresentBB, contBB,
425-
[&](ManagedValue input, SwitchCaseFullExpr &scope) {
425+
[&](ManagedValue input, SwitchCaseFullExpr &&scope) {
426426
if (!(resultTL.isAddressOnly() && silConv.useLoweredAddresses())) {
427427
SILValue none =
428428
B.createManagedOptionalNone(loc, resultTy).forward(*this);

lib/SILGen/SILGenDecl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ void EnumElementPatternInitialization::emitEnumMatch(
779779
// path, causing a use (the destroy on the negative path) to be created that
780780
// does not dominate its definition (in the positive path).
781781
auto handler = [&SGF, &loc, &failureDest](ManagedValue mv,
782-
SwitchCaseFullExpr &expr) {
782+
SwitchCaseFullExpr &&expr) {
783783
expr.exit();
784784
SGF.Cleanups.emitBranchAndCleanups(failureDest, loc);
785785
};
@@ -804,7 +804,7 @@ void EnumElementPatternInitialization::emitEnumMatch(
804804
switchBuilder.addCase(
805805
eltDecl, someBlock, contBlock,
806806
[&SGF, &loc, &eltDecl, &subInit, &value](ManagedValue mv,
807-
SwitchCaseFullExpr &expr) {
807+
SwitchCaseFullExpr &&expr) {
808808
// If the enum case has no bound value, we're done.
809809
if (!eltDecl->hasAssociatedValues()) {
810810
assert(

lib/SILGen/SILGenExpr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4255,7 +4255,7 @@ static ManagedValue flattenOptional(SILGenFunction &SGF, SILLocation loc,
42554255

42564256
auto *someDecl = SGF.getASTContext().getOptionalSomeDecl();
42574257
SEB.addCase(someDecl, isPresentBB, contBB, [&](ManagedValue input,
4258-
SwitchCaseFullExpr &scope) {
4258+
SwitchCaseFullExpr &&scope) {
42594259
if (resultTL.isAddressOnly()) {
42604260
SILValue addr =
42614261
addrOnlyResultBuf->getAddressForInPlaceInitialization(SGF, loc);
@@ -4270,7 +4270,7 @@ static ManagedValue flattenOptional(SILGenFunction &SGF, SILLocation loc,
42704270
});
42714271
SEB.addCase(
42724272
SGF.getASTContext().getOptionalNoneDecl(), isNotPresentBB, contBB,
4273-
[&](ManagedValue input, SwitchCaseFullExpr &scope) {
4273+
[&](ManagedValue input, SwitchCaseFullExpr &&scope) {
42744274
if (resultTL.isAddressOnly()) {
42754275
SILValue addr =
42764276
addrOnlyResultBuf->getAddressForInPlaceInitialization(SGF, loc);

lib/SILGen/SILGenStmt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ void StmtEmitter::visitForEachStmt(ForEachStmt *S) {
819819
switchEnumBuilder.addCase(
820820
SGF.getASTContext().getOptionalSomeDecl(), createBasicBlock(),
821821
loopDest.getBlock(),
822-
[&](ManagedValue inputValue, SwitchCaseFullExpr &scope) {
822+
[&](ManagedValue inputValue, SwitchCaseFullExpr &&scope) {
823823
SGF.emitProfilerIncrement(S->getBody());
824824

825825
// Emit the loop body.
@@ -884,7 +884,7 @@ void StmtEmitter::visitForEachStmt(ForEachStmt *S) {
884884
switchEnumBuilder.addCase(
885885
SGF.getASTContext().getOptionalNoneDecl(), createBasicBlock(),
886886
failExitingBlock,
887-
[&](ManagedValue inputValue, SwitchCaseFullExpr &scope) {
887+
[&](ManagedValue inputValue, SwitchCaseFullExpr &&scope) {
888888
assert(!inputValue && "None should not be passed an argument!");
889889
scope.exitAndBranch(S);
890890
},

lib/SILGen/SwitchEnumBuilder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void SwitchEnumBuilder::emit() && {
105105
if (!isAddressOnly) {
106106
input = builder.createOwnedPHIArgument(optional.getType());
107107
}
108-
handler(input, presentScope);
108+
handler(input, std::move(presentScope));
109109
builder.clearInsertionPoint();
110110
}
111111

@@ -132,7 +132,7 @@ void SwitchEnumBuilder::emit() && {
132132
input = builder.createOwnedPHIArgument(inputType);
133133
}
134134
}
135-
handler(input, presentScope);
135+
handler(input, std::move(presentScope));
136136
builder.clearInsertionPoint();
137137
}
138138

@@ -153,7 +153,7 @@ void SwitchEnumBuilder::emit() && {
153153
if (!isAddressOnly) {
154154
input = builder.createOwnedPHIArgument(optional.getType());
155155
}
156-
handler(input, presentScope);
156+
handler(input, std::move(presentScope));
157157
builder.clearInsertionPoint();
158158
}
159159
}

lib/SILGen/SwitchEnumBuilder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ class SwitchCaseFullExpr {
5858
class SwitchEnumBuilder {
5959
public:
6060
using NormalCaseHandler =
61-
std::function<void(ManagedValue, SwitchCaseFullExpr &)>;
61+
std::function<void(ManagedValue, SwitchCaseFullExpr &&)>;
6262
using DefaultCaseHandler =
63-
std::function<void(ManagedValue, SwitchCaseFullExpr &)>;
63+
std::function<void(ManagedValue, SwitchCaseFullExpr &&)>;
6464

6565
enum class DefaultDispatchTime { BeforeNormalCases, AfterNormalCases };
6666

0 commit comments

Comments
 (0)