@@ -1925,49 +1925,7 @@ static Type getFunctionBuilderType(FuncDecl *FD) {
19251925}
19261926
19271927bool TypeChecker::typeCheckAbstractFunctionBody (AbstractFunctionDecl *AFD) {
1928- return evaluateOrDefault (Context.evaluator ,
1929- TypeCheckFunctionBodyRequest{AFD},
1930- true );
1931- }
1932-
1933- llvm::Expected<bool >
1934- TypeCheckFunctionBodyRequest::evaluate (Evaluator &evaluator,
1935- AbstractFunctionDecl *func) const {
1936- ASTContext &ctx = func->getASTContext ();
1937- if (!func->hasInterfaceType ()) {
1938- TypeChecker &tc = *static_cast <TypeChecker *>(ctx.getLazyResolver ());
1939- tc.validateDecl (func);
1940- }
1941-
1942- // HACK: don't type-check the same function body twice. This will eventually
1943- // be handled by the request-evaluator's caching mechanism.
1944- (void )func->getBody ();
1945- if (func->isBodyTypeChecked ())
1946- return false ;
1947-
1948- FrontendStatsTracer StatsTracer (ctx.Stats , " typecheck-fn" , func);
1949- PrettyStackTraceDecl StackEntry (" type-checking" , func);
1950-
1951- if (ctx.Stats )
1952- ctx.Stats ->getFrontendCounters ().NumFunctionsTypechecked ++;
1953-
1954- Optional<FunctionBodyTimer> timer;
1955- TypeChecker &tc = *static_cast <TypeChecker *>(ctx.getLazyResolver ());
1956- if (tc.DebugTimeFunctionBodies || tc.WarnLongFunctionBodies )
1957- timer.emplace (func, tc.DebugTimeFunctionBodies , tc.WarnLongFunctionBodies );
1958-
1959- tc.requestRequiredNominalTypeLayoutForParameters (func->getParameters ());
1960-
1961- bool error = tc.typeCheckAbstractFunctionBodyUntil (func, SourceLoc ());
1962- func->setBodyTypeCheckedIfPresent ();
1963-
1964- if (error)
1965- return true ;
1966-
1967- if (func->getBody ())
1968- performAbstractFuncDeclDiagnostics (tc, func);
1969-
1970- return false ;
1928+ return typeCheckAbstractFunctionBodyUntil (AFD, SourceLoc ());
19711929}
19721930
19731931static Expr* constructCallToSuperInit (ConstructorDecl *ctor,
@@ -2163,18 +2121,37 @@ static void checkClassConstructorBody(ClassDecl *classDecl,
21632121 }
21642122}
21652123
2166- bool TypeChecker::typeCheckAbstractFunctionBodyUntil (AbstractFunctionDecl *AFD,
2167- SourceLoc EndTypeCheckLoc) {
2168- validateDecl (AFD);
2169- checkDefaultArguments (AFD->getParameters (), AFD);
2124+ llvm::Expected<bool >
2125+ TypeCheckFunctionBodyUntilRequest::evaluate (Evaluator &evaluator,
2126+ AbstractFunctionDecl *AFD,
2127+ SourceLoc endTypeCheckLoc) const {
2128+ ASTContext &ctx = AFD->getASTContext ();
2129+
2130+ // Accounting for type checking of function bodies.
2131+ // FIXME: We could probably take this away, given that the request-evaluator
2132+ // does much of it for us.
2133+ FrontendStatsTracer StatsTracer (ctx.Stats , " typecheck-fn" , AFD);
2134+ PrettyStackTraceDecl StackEntry (" type-checking" , AFD);
2135+
2136+ if (ctx.Stats )
2137+ ctx.Stats ->getFrontendCounters ().NumFunctionsTypechecked ++;
2138+
2139+ Optional<FunctionBodyTimer> timer;
2140+ TypeChecker &tc = *static_cast <TypeChecker *>(ctx.getLazyResolver ());
2141+ if (tc.DebugTimeFunctionBodies || tc.WarnLongFunctionBodies )
2142+ timer.emplace (AFD, tc.DebugTimeFunctionBodies , tc.WarnLongFunctionBodies );
2143+
2144+ tc.validateDecl (AFD);
2145+ tc.requestRequiredNominalTypeLayoutForParameters (AFD->getParameters ());
2146+ tc.checkDefaultArguments (AFD->getParameters (), AFD);
21702147
21712148 BraceStmt *body = AFD->getBody ();
21722149 if (!body || AFD->isBodyTypeChecked ())
21732150 return false ;
21742151
21752152 if (auto *func = dyn_cast<FuncDecl>(AFD)) {
21762153 if (Type builderType = getFunctionBuilderType (func)) {
2177- body = applyFunctionBuilderBodyTransform (func, body, builderType);
2154+ body = tc. applyFunctionBuilderBodyTransform (func, body, builderType);
21782155 if (!body)
21792156 return true ;
21802157 } else if (func->hasSingleExpressionBody ()) {
@@ -2195,15 +2172,15 @@ bool TypeChecker::typeCheckAbstractFunctionBodyUntil(AbstractFunctionDecl *AFD,
21952172 // simplifies SILGen.
21962173 SmallVector<ASTNode, 8 > Elts (body->getElements ().begin (),
21972174 body->getElements ().end ());
2198- Elts.push_back (new (Context ) ReturnStmt (body->getRBraceLoc (),
2199- /* value*/ nullptr ,
2200- /* implicit*/ true ));
2201- body = BraceStmt::create (Context , body->getLBraceLoc (), Elts,
2175+ Elts.push_back (new (ctx ) ReturnStmt (body->getRBraceLoc (),
2176+ /* value*/ nullptr ,
2177+ /* implicit*/ true ));
2178+ body = BraceStmt::create (ctx , body->getLBraceLoc (), Elts,
22022179 body->getRBraceLoc (), body->isImplicit ());
22032180 }
22042181
2205- StmtChecker SC (* this , AFD);
2206- SC.EndTypeCheckLoc = EndTypeCheckLoc ;
2182+ StmtChecker SC (tc , AFD);
2183+ SC.EndTypeCheckLoc = endTypeCheckLoc ;
22072184 bool hadError = SC.typeCheckBody (body);
22082185
22092186 // If this was a function with a single expression body, let's see
@@ -2222,16 +2199,30 @@ bool TypeChecker::typeCheckAbstractFunctionBodyUntil(AbstractFunctionDecl *AFD,
22222199 }
22232200 }
22242201
2202+ // Class constructor checking.
22252203 if (auto *ctor = dyn_cast<ConstructorDecl>(AFD)) {
22262204 if (auto classDecl = ctor->getDeclContext ()->getSelfClassDecl ()) {
22272205 checkClassConstructorBody (classDecl, ctor, body);
22282206 }
22292207 }
22302208
2209+ // If nothing went wrong yet, perform extra checking.
2210+ if (!hadError && endTypeCheckLoc.isInvalid ())
2211+ performAbstractFuncDeclDiagnostics (tc, AFD, body);
2212+
2213+ // Wire up the function body now.
22312214 AFD->setBody (body, AbstractFunctionDecl::BodyKind::TypeChecked);
22322215 return hadError;
22332216}
22342217
2218+ bool TypeChecker::typeCheckAbstractFunctionBodyUntil (AbstractFunctionDecl *AFD,
2219+ SourceLoc EndTypeCheckLoc) {
2220+ return evaluateOrDefault (
2221+ Context.evaluator ,
2222+ TypeCheckFunctionBodyUntilRequest{AFD, EndTypeCheckLoc},
2223+ true );
2224+ }
2225+
22352226bool TypeChecker::typeCheckClosureBody (ClosureExpr *closure) {
22362227 checkParameterAttributes (closure->getParameters ());
22372228
0 commit comments