Skip to content

Commit cf9612b

Browse files
committed
---
yaml --- r: 341759 b: refs/heads/rxwei-patch-1 c: 1aa19b7 h: refs/heads/master i: 341757: eafc04d 341755: cb57bdf 341751: 8c7b393 341743: a5b2615 341727: 01d02b2 341695: 2266551 341631: 0ddde77 341503: efde5ca
1 parent 70c7774 commit cf9612b

File tree

4 files changed

+24
-36
lines changed

4 files changed

+24
-36
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-08-18-a: b10b1fce14385faa6d44f6b933e95
10151015
refs/heads/rdar-43033749-fix-batch-mode-no-diags-swift-5.0-branch: a14e64eaad30de89f0f5f0b2a782eed7ecdcb255
10161016
refs/heads/revert-19006-error-bridging-integer-type: 8a9065a3696535305ea53fe9b71f91cbe6702019
10171017
refs/heads/revert-19050-revert-19006-error-bridging-integer-type: ecf752d54b05dd0a20f510f0bfa54a3fec3bcaca
1018-
refs/heads/rxwei-patch-1: 3c4b5b4dcb124d531675b71b4dc49da0ec0ec6f1
1018+
refs/heads/rxwei-patch-1: 1aa19b7a470809e42034838ae64a5a0523667497
10191019
refs/heads/shahmishal-patch-1: e58ec0f7488258d42bef51bc3e6d7b3dc74d7b2a
10201020
refs/heads/typelist-existential: 4046359efd541fb5c72d69a92eefc0a784df8f5e
10211021
refs/tags/swift-4.2-DEVELOPMENT-SNAPSHOT-2018-08-20-a: 4319ba09e4fb8650ee86061075c74a016b6baab9

branches/rxwei-patch-1/lib/Sema/BuilderTransform.cpp

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -476,47 +476,25 @@ static bool hasReturnStmt(Stmt *stmt) {
476476
return finder.hasReturnStmt;
477477
}
478478

479-
bool TypeChecker::typeCheckFunctionBuilderFuncBody(FuncDecl *FD,
480-
Type builderType) {
479+
BraceStmt *
480+
TypeChecker::applyFunctionBuilderBodyTransform(FuncDecl *FD,
481+
BraceStmt *body,
482+
Type builderType) {
481483
// Try to build a single result expression.
482484
BuilderClosureVisitor visitor(Context, nullptr,
483485
/*wantExpr=*/true, builderType);
484-
Expr *returnExpr = visitor.visit(FD->getBody());
486+
Expr *returnExpr = visitor.visit(body);
485487
if (!returnExpr)
486-
return true;
488+
return nullptr;
487489

488490
// Make sure we have a usable result type for the body.
489491
Type returnType = AnyFunctionRef(FD).getBodyResultType();
490492
if (!returnType || returnType->hasError())
491-
return true;
492-
493-
TypeCheckExprOptions options = {};
494-
if (auto opaque = returnType->getAs<OpaqueTypeArchetypeType>()) {
495-
if (opaque->getDecl()->isOpaqueReturnTypeOfFunction(FD))
496-
options |= TypeCheckExprFlags::ConvertTypeIsOpaqueReturnType;
497-
}
498-
499-
// If we are performing code-completion inside the functions body, supress
500-
// diagnostics to workaround typechecking performance problems.
501-
if (Context.SourceMgr.rangeContainsCodeCompletionLoc(
502-
FD->getBody()->getSourceRange()))
503-
options |= TypeCheckExprFlags::SuppressDiagnostics;
504-
505-
// Type-check the single result expression.
506-
Type returnExprType = typeCheckExpression(returnExpr, FD,
507-
TypeLoc::withoutLoc(returnType),
508-
CTP_ReturnStmt, options);
509-
if (!returnExprType)
510-
return true;
511-
assert(returnExprType->isEqual(returnType));
493+
return nullptr;
512494

513495
auto returnStmt = new (Context) ReturnStmt(SourceLoc(), returnExpr);
514-
auto origBody = FD->getBody();
515-
auto fakeBody = BraceStmt::create(Context, origBody->getLBraceLoc(),
516-
{ returnStmt },
517-
origBody->getRBraceLoc());
518-
FD->setBody(fakeBody);
519-
return false;
496+
return BraceStmt::create(Context, body->getLBraceLoc(), { returnStmt },
497+
body->getRBraceLoc());
520498
}
521499

522500
ConstraintSystem::TypeMatchResult ConstraintSystem::applyFunctionBuilder(

branches/rxwei-patch-1/lib/Sema/TypeCheckStmt.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,14 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
524524
if (func->hasSingleExpressionBody()) {
525525
ctp = CTP_ReturnSingleExpr;
526526
}
527+
528+
// If we are performing code-completion inside a function builder body,
529+
// suppress diagnostics to workaround typechecking performance problems.
530+
if (func->getFunctionBuilderType() &&
531+
TC.Context.SourceMgr.rangeContainsCodeCompletionLoc(
532+
func->getBody()->getSourceRange())) {
533+
options |= TypeCheckExprFlags::SuppressDiagnostics;
534+
}
527535
}
528536

529537
auto exprTy = TC.typeCheckExpression(E, DC, TypeLoc::withoutLoc(ResultTy),
@@ -2166,9 +2174,9 @@ bool TypeChecker::typeCheckAbstractFunctionBodyUntil(AbstractFunctionDecl *AFD,
21662174

21672175
if (auto *func = dyn_cast<FuncDecl>(AFD)) {
21682176
if (Type builderType = getFunctionBuilderType(func)) {
2169-
// FIXME: this should be a transform on the body, not a separate type
2170-
// checking operation.
2171-
return typeCheckFunctionBuilderFuncBody(func, builderType);
2177+
body = applyFunctionBuilderBodyTransform(func, body, builderType);
2178+
if (!body)
2179+
return true;
21722180
} else if (func->hasSingleExpressionBody()) {
21732181
auto resultTypeLoc = func->getBodyResultTypeLoc();
21742182
auto expr = func->getSingleExpressionBody();

branches/rxwei-patch-1/lib/Sema/TypeChecker.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,9 @@ class TypeChecker final : public LazyResolver {
981981
SourceLoc EndTypeCheckLoc);
982982
bool typeCheckAbstractFunctionBody(AbstractFunctionDecl *AFD);
983983

984-
bool typeCheckFunctionBuilderFuncBody(FuncDecl *FD, Type builderType);
984+
BraceStmt *applyFunctionBuilderBodyTransform(FuncDecl *FD,
985+
BraceStmt *body,
986+
Type builderType);
985987
bool typeCheckClosureBody(ClosureExpr *closure);
986988

987989
bool typeCheckTapBody(TapExpr *expr, DeclContext *DC);

0 commit comments

Comments
 (0)