Skip to content

Commit 0a72d02

Browse files
committed
[TypeChecker] Rename 'typeCheckAbstractFunctionBodyUntil()'
to 'typeCheckAbstractFunctionBodyNodeAt()' because that only typecheck a statement at the position.
1 parent a22fd6f commit 0a72d02

File tree

10 files changed

+29
-36
lines changed

10 files changed

+29
-36
lines changed

include/swift/AST/TypeCheckRequests.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -872,8 +872,8 @@ class LazyStoragePropertyRequest :
872872
///
873873
/// Produces true if an error occurred, false otherwise.
874874
/// FIXME: it would be far better to return the type-checked body.
875-
class TypeCheckFunctionBodyUntilRequest :
876-
public SimpleRequest<TypeCheckFunctionBodyUntilRequest,
875+
class TypeCheckFunctionBodyRequest :
876+
public SimpleRequest<TypeCheckFunctionBodyRequest,
877877
bool(AbstractFunctionDecl *, SourceLoc),
878878
RequestFlags::Cached|RequestFlags::DependencySource> {
879879
public:

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ SWIFT_REQUEST(TypeChecker, SuperclassTypeRequest,
196196
SWIFT_REQUEST(TypeChecker, SynthesizeAccessorRequest,
197197
AccessorDecl *(AbstractStorageDecl *, AccessorKind),
198198
SeparatelyCached, NoLocationInfo)
199-
SWIFT_REQUEST(TypeChecker, TypeCheckFunctionBodyUntilRequest,
199+
SWIFT_REQUEST(TypeChecker, TypeCheckFunctionBodyRequest,
200200
bool(AbstractFunctionDecl *, SourceLoc),
201201
Cached, NoLocationInfo)
202202
SWIFT_REQUEST(TypeChecker, UnderlyingTypeRequest, Type(TypeAliasDecl *),

include/swift/Sema/IDETypeChecking.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ namespace swift {
134134
bool typeCheckExpression(DeclContext *DC, Expr *&parsedExpr);
135135

136136
/// Partially typecheck the specified function body.
137-
bool typeCheckAbstractFunctionBodyUntil(AbstractFunctionDecl *AFD,
138-
SourceLoc EndTypeCheckLoc);
137+
bool typeCheckAbstractFunctionBodyNodeAt(AbstractFunctionDecl *AFD,
138+
SourceLoc TargetLoc);
139139

140140
/// Typecheck top-level code parsed during code completion.
141141
///

lib/AST/TypeCheckRequests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,11 +1455,11 @@ void TypeCheckSourceFileRequest::cacheResult(evaluator::SideEffect) const {
14551455
}
14561456

14571457
//----------------------------------------------------------------------------//
1458-
// TypeCheckFunctionBodyUntilRequest computation.
1458+
// TypeCheckFunctionBodyRequest computation.
14591459
//----------------------------------------------------------------------------//
14601460

14611461
evaluator::DependencySource
1462-
TypeCheckFunctionBodyUntilRequest::readDependencySource(
1462+
TypeCheckFunctionBodyRequest::readDependencySource(
14631463
const evaluator::DependencyRecorder &e) const {
14641464
// We're going under a function body scope, unconditionally flip the scope
14651465
// to private.

lib/IDE/ExprContextAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void typeCheckContextImpl(DeclContext *DC, SourceLoc Loc) {
7979
auto &SM = DC->getASTContext().SourceMgr;
8080
auto bodyRange = AFD->getBodySourceRange();
8181
if (SM.rangeContainsTokenLoc(bodyRange, Loc)) {
82-
swift::typeCheckAbstractFunctionBodyUntil(AFD, Loc);
82+
swift::typeCheckAbstractFunctionBodyNodeAt(AFD, Loc);
8383
} else {
8484
assert(bodyRange.isInvalid() && "The body should not be parsed if the "
8585
"completion happens in the signature");

lib/Sema/TypeCheckStmt.cpp

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
318318
CaseStmt /*nullable*/ *FallthroughDest = nullptr;
319319
FallthroughStmt /*nullable*/ *PreviousFallthrough = nullptr;
320320

321-
SourceLoc EndTypeCheckLoc;
321+
SourceLoc TargetTypeCheckLoc;
322322

323323
/// Used to distinguish the first BraceStmt that starts a TopLevelCodeDecl.
324324
bool IsBraceStmtFromTopLevelDecl;
@@ -501,7 +501,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
501501

502502
TypeCheckExprOptions options = {};
503503

504-
if (EndTypeCheckLoc.isValid()) {
504+
if (TargetTypeCheckLoc.isValid()) {
505505
assert(DiagnosticSuppression::isEnabled(getASTContext().Diags) &&
506506
"Diagnosing and AllowUnresolvedTypeVariables don't seem to mix");
507507
options |= TypeCheckExprFlags::AllowUnresolvedTypeVariables;
@@ -1557,15 +1557,15 @@ Stmt *StmtChecker::visitBraceStmt(BraceStmt *BS) {
15571557
}
15581558

15591559
for (auto &elem : BS->getElements()) {
1560-
if (EndTypeCheckLoc.isValid()) {
1561-
if (SM.isBeforeInBuffer(EndTypeCheckLoc, elem.getStartLoc()))
1560+
if (TargetTypeCheckLoc.isValid()) {
1561+
if (SM.isBeforeInBuffer(TargetTypeCheckLoc, elem.getStartLoc()))
15621562
break;
15631563

15641564
// NOTE: We need to check the character loc here because the target loc
15651565
// can be inside the last token of the node. i.e. string interpolation.
15661566
SourceLoc endLoc = Lexer::getLocForEndOfToken(SM, elem.getEndLoc());
1567-
if (endLoc == EndTypeCheckLoc ||
1568-
SM.isBeforeInBuffer(endLoc, EndTypeCheckLoc))
1567+
if (endLoc == TargetTypeCheckLoc ||
1568+
SM.isBeforeInBuffer(endLoc, TargetTypeCheckLoc))
15691569
continue;
15701570
}
15711571

@@ -1577,7 +1577,7 @@ Stmt *StmtChecker::visitBraceStmt(BraceStmt *BS) {
15771577
if (isDiscarded)
15781578
options |= TypeCheckExprFlags::IsDiscarded;
15791579

1580-
if (EndTypeCheckLoc.isValid()) {
1580+
if (TargetTypeCheckLoc.isValid()) {
15811581
assert(DiagnosticSuppression::isEnabled(getASTContext().Diags) &&
15821582
"Diagnosing and AllowUnresolvedTypeVariables don't seem to mix");
15831583
options |= TypeCheckExprFlags::AllowUnresolvedTypeVariables;
@@ -1635,7 +1635,9 @@ static Type getFunctionBuilderType(FuncDecl *FD) {
16351635
}
16361636

16371637
bool TypeChecker::typeCheckAbstractFunctionBody(AbstractFunctionDecl *AFD) {
1638-
auto res = TypeChecker::typeCheckAbstractFunctionBodyUntil(AFD, SourceLoc());
1638+
auto res =
1639+
evaluateOrDefault(AFD->getASTContext().evaluator,
1640+
TypeCheckFunctionBodyRequest{AFD, SourceLoc()}, true);
16391641
TypeChecker::checkFunctionErrorHandling(AFD);
16401642
TypeChecker::computeCaptures(AFD);
16411643
return res;
@@ -1835,9 +1837,9 @@ static void checkClassConstructorBody(ClassDecl *classDecl,
18351837
}
18361838

18371839
bool
1838-
TypeCheckFunctionBodyUntilRequest::evaluate(Evaluator &evaluator,
1839-
AbstractFunctionDecl *AFD,
1840-
SourceLoc endTypeCheckLoc) const {
1840+
TypeCheckFunctionBodyRequest::evaluate(Evaluator &evaluator,
1841+
AbstractFunctionDecl *AFD,
1842+
SourceLoc targetTypeCheckLoc) const {
18411843
ASTContext &ctx = AFD->getASTContext();
18421844

18431845
Optional<FunctionBodyTimer> timer;
@@ -1894,7 +1896,7 @@ TypeCheckFunctionBodyUntilRequest::evaluate(Evaluator &evaluator,
18941896
bool hadError = false;
18951897
if (!alreadyTypeChecked) {
18961898
StmtChecker SC(AFD);
1897-
SC.EndTypeCheckLoc = endTypeCheckLoc;
1899+
SC.TargetTypeCheckLoc = targetTypeCheckLoc;
18981900
hadError = SC.typeCheckBody(body);
18991901
}
19001902

@@ -1925,20 +1927,12 @@ TypeCheckFunctionBodyUntilRequest::evaluate(Evaluator &evaluator,
19251927
AFD->setBody(body, AbstractFunctionDecl::BodyKind::TypeChecked);
19261928

19271929
// If nothing went wrong yet, perform extra checking.
1928-
if (!hadError && endTypeCheckLoc.isInvalid())
1930+
if (!hadError && targetTypeCheckLoc.isInvalid())
19291931
performAbstractFuncDeclDiagnostics(AFD);
19301932

19311933
return hadError;
19321934
}
19331935

1934-
bool TypeChecker::typeCheckAbstractFunctionBodyUntil(AbstractFunctionDecl *AFD,
1935-
SourceLoc EndTypeCheckLoc) {
1936-
return evaluateOrDefault(
1937-
AFD->getASTContext().evaluator,
1938-
TypeCheckFunctionBodyUntilRequest{AFD, EndTypeCheckLoc},
1939-
true);
1940-
}
1941-
19421936
bool TypeChecker::typeCheckClosureBody(ClosureExpr *closure) {
19431937
checkParameterAttributes(closure->getParameters());
19441938

lib/Sema/TypeChecker.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,11 +540,12 @@ bool swift::typeCheckExpression(DeclContext *DC, Expr *&parsedExpr) {
540540
return !resultTy;
541541
}
542542

543-
bool swift::typeCheckAbstractFunctionBodyUntil(AbstractFunctionDecl *AFD,
544-
SourceLoc EndTypeCheckLoc) {
543+
bool swift::typeCheckAbstractFunctionBodyNodeAt(AbstractFunctionDecl *AFD,
544+
SourceLoc TargetLoc) {
545545
auto &Ctx = AFD->getASTContext();
546546
DiagnosticSuppression suppression(Ctx.Diags);
547-
return !TypeChecker::typeCheckAbstractFunctionBodyUntil(AFD, EndTypeCheckLoc);
547+
return !evaluateOrDefault(Ctx.evaluator,
548+
TypeCheckFunctionBodyRequest{AFD, TargetLoc}, true);
548549
}
549550

550551
bool swift::typeCheckTopLevelCodeDecl(TopLevelCodeDecl *TLCD) {

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,6 @@ bool typesSatisfyConstraint(Type t1, Type t2, bool openArchetypes,
547547
/// of the function, set the result type of the expression to that sugar type.
548548
Expr *substituteInputSugarTypeForResult(ApplyExpr *E);
549549

550-
bool typeCheckAbstractFunctionBodyUntil(AbstractFunctionDecl *AFD,
551-
SourceLoc EndTypeCheckLoc);
552550
bool typeCheckAbstractFunctionBody(AbstractFunctionDecl *AFD);
553551

554552
/// Try to apply the function builder transform of the given builder type

test/Misc/stats_dir_profiler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// RUN: %FileCheck -check-prefix=ENTITIES -input-file %t/stats-entities/*.dir/Time.User.entities %s
88

99
// EVENTS: {{perform-sema;.*;typecheck-decl.* [0-9]+}}
10-
// ENTITIES: {{perform-sema;.*;TypeCheckFunctionBodyUntilRequest bar\(\);typecheck-stmt.* [0-9]+}}
10+
// ENTITIES: {{perform-sema;.*;TypeCheckFunctionBodyRequest bar\(\);typecheck-stmt.* [0-9]+}}
1111

1212
public func foo() {
1313
print("hello")

validation-test/compiler_scale/scale_neighbouring_getset.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %scale-test --sum-multi --begin 5 --end 16 --step 5 --select TypeCheckFunctionBodyUntilRequest %s
1+
// RUN: %scale-test --sum-multi --begin 5 --end 16 --step 5 --select TypeCheckFunctionBodyRequest %s
22
// REQUIRES: asserts
33

44
struct Struct${N} {

0 commit comments

Comments
 (0)