mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Function builders] Infer function builder from a protocol requirement.
Allow a protocol requirement for a function or property to declare a function builder. A witness to such a protocol requirement will infer that function builder when all of the following are two: * The witness does not explicitly adopt a function builder * The witness is declared within the same context that conforms to the protocol requirement (e.g., same extension or primary type declaration) * The witness's body does not contain a "return" statement (since those disable the function builder transform).
This commit is contained in:
@@ -1401,10 +1401,6 @@ BraceStmt *swift::applyFunctionBuilderTransform(
|
||||
captured.first, captured.second)));
|
||||
}
|
||||
|
||||
/// Find the return statements in the given body, which block the application
|
||||
/// of a function builder.
|
||||
static std::vector<ReturnStmt *> findReturnStatements(AnyFunctionRef fn);
|
||||
|
||||
Optional<BraceStmt *> TypeChecker::applyFunctionBuilderBodyTransform(
|
||||
FuncDecl *func, Type builderType) {
|
||||
// Pre-check the body: pre-check any expressions in it and look
|
||||
@@ -1708,7 +1704,7 @@ PreCheckFunctionBuilderRequest::evaluate(Evaluator &eval,
|
||||
return PreCheckFunctionBuilderApplication(fn, false).run();
|
||||
}
|
||||
|
||||
std::vector<ReturnStmt *> findReturnStatements(AnyFunctionRef fn) {
|
||||
std::vector<ReturnStmt *> TypeChecker::findReturnStatements(AnyFunctionRef fn) {
|
||||
PreCheckFunctionBuilderApplication precheck(fn, true);
|
||||
(void)precheck.run();
|
||||
return precheck.getReturnStmts();
|
||||
|
||||
Reference in New Issue
Block a user