Skip to content

Commit 2820deb

Browse files
committed
NFC: Pass through an ASTContext to IsSingleValueStmtRequest
1 parent 378fbe2 commit 2820deb

File tree

5 files changed

+21
-19
lines changed

5 files changed

+21
-19
lines changed

include/swift/AST/Stmt.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ class alignas(8) Stmt : public ASTAllocated<Stmt> {
144144

145145
/// Whether the statement can produce a single value, and as such may be
146146
/// treated as an expression.
147-
IsSingleValueStmtResult mayProduceSingleValue(Evaluator &eval) const;
148147
IsSingleValueStmtResult mayProduceSingleValue(ASTContext &ctx) const;
149148

150149
/// isImplicit - Determines whether this statement was implicitly-generated,

include/swift/AST/TypeCheckRequests.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3997,18 +3997,21 @@ class IsSingleValueStmtResult {
39973997
};
39983998

39993999
/// Computes whether a given statement can be treated as a SingleValueStmtExpr.
4000+
///
4001+
// TODO: We ought to consider storing a reference to the ASTContext on the
4002+
// evaluator.
40004003
class IsSingleValueStmtRequest
40014004
: public SimpleRequest<IsSingleValueStmtRequest,
4002-
IsSingleValueStmtResult(const Stmt *),
4005+
IsSingleValueStmtResult(const Stmt *, ASTContext *),
40034006
RequestFlags::Cached> {
40044007
public:
40054008
using SimpleRequest::SimpleRequest;
40064009

40074010
private:
40084011
friend SimpleRequest;
40094012

4010-
IsSingleValueStmtResult
4011-
evaluate(Evaluator &evaluator, const Stmt *stmt) const;
4013+
IsSingleValueStmtResult evaluate(Evaluator &evaluator, const Stmt *stmt,
4014+
ASTContext *ctx) const;
40124015

40134016
public:
40144017
bool isCached() const { return true; }

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ SWIFT_REQUEST(TypeChecker, PreCheckReturnStmtRequest,
443443
Stmt *(ReturnStmt *, DeclContext *),
444444
Cached, NoLocationInfo)
445445
SWIFT_REQUEST(TypeChecker, IsSingleValueStmtRequest,
446-
IsSingleValueStmtResult(const Stmt *),
446+
IsSingleValueStmtResult(const Stmt *, ASTContext *),
447447
Cached, NoLocationInfo)
448448
SWIFT_REQUEST(TypeChecker, MacroDefinitionRequest,
449449
MacroDefinition(MacroDecl *),

lib/AST/Stmt.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,13 +333,9 @@ Stmt *BraceStmt::getSingleActiveStatement() const {
333333
return getSingleActiveElement().dyn_cast<Stmt *>();
334334
}
335335

336-
IsSingleValueStmtResult Stmt::mayProduceSingleValue(Evaluator &eval) const {
337-
return evaluateOrDefault(eval, IsSingleValueStmtRequest{this},
338-
IsSingleValueStmtResult::circularReference());
339-
}
340-
341336
IsSingleValueStmtResult Stmt::mayProduceSingleValue(ASTContext &ctx) const {
342-
return mayProduceSingleValue(ctx.evaluator);
337+
return evaluateOrDefault(ctx.evaluator, IsSingleValueStmtRequest{this, &ctx},
338+
IsSingleValueStmtResult::circularReference());
343339
}
344340

345341
SourceLoc ReturnStmt::getStartLoc() const {

lib/Sema/TypeCheckStmt.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2669,7 +2669,7 @@ PreCheckFunctionBodyRequest::evaluate(Evaluator &evaluator,
26692669
// single expression return, do so now.
26702670
if (!func->getResultInterfaceType()->isVoid()) {
26712671
if (auto *S = body->getSingleActiveStatement()) {
2672-
if (S->mayProduceSingleValue(evaluator)) {
2672+
if (S->mayProduceSingleValue(ctx)) {
26732673
auto *SVE = SingleValueStmtExpr::createWithWrappedBranches(
26742674
ctx, S, /*DC*/ func, /*mustBeExpr*/ false);
26752675
auto *RS = new (ctx) ReturnStmt(SourceLoc(), SVE);
@@ -2914,7 +2914,7 @@ static bool doesBraceEndWithThrow(BraceStmt *BS) {
29142914

29152915
/// Whether the given brace statement is considered to produce a result for
29162916
/// an if/switch expression.
2917-
static bool doesBraceProduceResult(BraceStmt *BS, Evaluator &eval) {
2917+
static bool doesBraceProduceResult(BraceStmt *BS, ASTContext &ctx) {
29182918
if (BS->empty())
29192919
return false;
29202920

@@ -2926,14 +2926,14 @@ static bool doesBraceProduceResult(BraceStmt *BS, Evaluator &eval) {
29262926
return true;
29272927

29282928
if (auto *S = BS->getSingleActiveStatement()) {
2929-
if (S->mayProduceSingleValue(eval))
2929+
if (S->mayProduceSingleValue(ctx))
29302930
return true;
29312931
}
29322932
return SingleValueStmtExpr::hasResult(BS);
29332933
}
29342934

29352935
IsSingleValueStmtResult
2936-
areBranchesValidForSingleValueStmt(Evaluator &eval, ArrayRef<Stmt *> branches) {
2936+
areBranchesValidForSingleValueStmt(ASTContext &ctx, ArrayRef<Stmt *> branches) {
29372937
TinyPtrVector<Stmt *> invalidJumps;
29382938
TinyPtrVector<Stmt *> unterminatedBranches;
29392939
JumpOutOfContextFinder jumpFinder(invalidJumps);
@@ -2950,7 +2950,7 @@ areBranchesValidForSingleValueStmt(Evaluator &eval, ArrayRef<Stmt *> branches) {
29502950
BS->walk(jumpFinder);
29512951

29522952
// Check to see if a result is produced from the branch.
2953-
if (doesBraceProduceResult(BS, eval)) {
2953+
if (doesBraceProduceResult(BS, ctx)) {
29542954
hadResult = true;
29552955
continue;
29562956
}
@@ -2976,7 +2976,11 @@ areBranchesValidForSingleValueStmt(Evaluator &eval, ArrayRef<Stmt *> branches) {
29762976
}
29772977

29782978
IsSingleValueStmtResult
2979-
IsSingleValueStmtRequest::evaluate(Evaluator &eval, const Stmt *S) const {
2979+
IsSingleValueStmtRequest::evaluate(Evaluator &eval, const Stmt *S,
2980+
ASTContext *_ctx) const {
2981+
assert(_ctx);
2982+
auto &ctx = *_ctx;
2983+
29802984
if (!isa<IfStmt>(S) && !isa<SwitchStmt>(S))
29812985
return IsSingleValueStmtResult::unhandledStmt();
29822986

@@ -2991,11 +2995,11 @@ IsSingleValueStmtRequest::evaluate(Evaluator &eval, const Stmt *S) const {
29912995
return IsSingleValueStmtResult::nonExhaustiveIf();
29922996

29932997
SmallVector<Stmt *, 4> scratch;
2994-
return areBranchesValidForSingleValueStmt(eval, IS->getBranches(scratch));
2998+
return areBranchesValidForSingleValueStmt(ctx, IS->getBranches(scratch));
29952999
}
29963000
if (auto *SS = dyn_cast<SwitchStmt>(S)) {
29973001
SmallVector<Stmt *, 4> scratch;
2998-
return areBranchesValidForSingleValueStmt(eval, SS->getBranches(scratch));
3002+
return areBranchesValidForSingleValueStmt(ctx, SS->getBranches(scratch));
29993003
}
30003004
llvm_unreachable("Unhandled case");
30013005
}

0 commit comments

Comments
 (0)