Skip to content

Commit 54c1267

Browse files
committed
[Function builders] Short-circuit function builder inference earlier.
Eliminates both circular references and unwanted dependencies.
1 parent c5a9575 commit 54c1267

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

lib/Sema/TypeCheckRequestFunctions.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,18 @@ AttachedFunctionBuilderRequest::evaluate(Evaluator &evaluator,
186186
/// Attempt to infer the function builder type for a declaration.
187187
static Type inferFunctionBuilderType(ValueDecl *decl) {
188188
auto dc = decl->getDeclContext();
189-
if (!dc->isTypeContext())
189+
if (!dc->isTypeContext() || isa<ProtocolDecl>(dc))
190190
return Type();
191191

192192
auto funcDecl = dyn_cast<FuncDecl>(decl);
193-
if (!funcDecl)
193+
if (!funcDecl || !funcDecl->hasBody() ||
194+
!decl->getDeclContext()->getParentSourceFile())
195+
return Type();
196+
197+
// Check whether there are any return statements in the function's body.
198+
// If there are, the function builder transform will be disabled,
199+
// so don't infer a function builder.
200+
if (!TypeChecker::findReturnStatements(funcDecl).empty())
194201
return Type();
195202

196203
// Only getters can have function builders. When we find one, look at
@@ -248,12 +255,6 @@ static Type inferFunctionBuilderType(ValueDecl *decl) {
248255
if (matches.size() == 0)
249256
return Type();
250257

251-
// Check whether there are any return statements in the function's body.
252-
// If there are, the function builder transform will be disabled,
253-
// so don't infer a function builder.
254-
if (!TypeChecker::findReturnStatements(funcDecl).empty())
255-
return Type();
256-
257258
// Determine whether there is more than one actual function builder type.
258259
Type functionBuilderType = matches[0].functionBuilderType;
259260
for (const auto &match : matches) {

0 commit comments

Comments
 (0)