Skip to content

[Function builders] Remove buildDo. #33564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion include/swift/AST/KnownIdentifiers.def
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ IDENTIFIER(atIndexedSubscript)
IDENTIFIER_(bridgeToObjectiveC)
IDENTIFIER(buildArray)
IDENTIFIER(buildBlock)
IDENTIFIER(buildDo)
IDENTIFIER(buildEither)
IDENTIFIER(buildExpression)
IDENTIFIER(buildFinalResult)
Expand Down
14 changes: 2 additions & 12 deletions lib/Sema/BuilderTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,6 @@ class BuilderClosureVisitor
}

VarDecl *visitBraceStmt(BraceStmt *braceStmt) {
return visitBraceStmt(braceStmt, ctx.Id_buildBlock);
}

VarDecl *visitBraceStmt(BraceStmt *braceStmt, Identifier builderFunction) {
SmallVector<Expr *, 4> expressions;
auto addChild = [&](VarDecl *childVar) {
if (!childVar)
Expand Down Expand Up @@ -380,7 +376,7 @@ class BuilderClosureVisitor

// Call Builder.buildBlock(... args ...)
auto call = buildCallIfWanted(braceStmt->getStartLoc(),
builderFunction, expressions,
ctx.Id_buildBlock, expressions,
/*argLabels=*/{ });
if (!call)
return nullptr;
Expand All @@ -395,13 +391,7 @@ class BuilderClosureVisitor
}

VarDecl *visitDoStmt(DoStmt *doStmt) {
if (!builderSupports(ctx.Id_buildDo)) {
if (!unhandledNode)
unhandledNode = doStmt;
return nullptr;
}

auto childVar = visitBraceStmt(doStmt->getBody(), ctx.Id_buildDo);
auto childVar = visitBraceStmt(doStmt->getBody());
if (!childVar)
return nullptr;

Expand Down
18 changes: 1 addition & 17 deletions test/Constraints/function_builder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,6 @@ struct TupleBuilder {
return (t1, t2, t3, t4, t5)
}

static func buildDo<T1>(_ t1: T1) -> Do<(T1)> {
.init(value: t1)
}

static func buildDo<T1, T2>(_ t1: T1, _ t2: T2) -> Do<(T1, T2)> {
.init(value: (t1, t2))
}

static func buildDo<T1, T2, T3>(_ t1: T1, _ t2: T2, _ t3: T3)
-> Do<(T1, T2, T3)> {
.init(value: (t1, t2, t3))
}

static func buildIf<T>(_ value: T?) -> T? { return value }

static func buildEither<T,U>(first value: T) -> Either<T,U> {
Expand All @@ -65,7 +52,7 @@ func tuplify<T>(_ cond: Bool, @TupleBuilder body: (Bool) -> T) {
print(body(cond))
}

// CHECK: (17, 3.14159, "Hello, DSL", main.Do<(Swift.Array<Swift.String>, Swift.Int)>(value: (["nested", "do"], 6)), Optional((2.71828, ["if", "stmt"])))
// CHECK: (17, 3.14159, "Hello, DSL", (["nested", "do"], 6), Optional((2.71828, ["if", "stmt"])))
let name = "dsl"
tuplify(true) {
17
Expand Down Expand Up @@ -664,7 +651,6 @@ struct TupleBuilderWithOpt {
return (t1, t2, t3, t4, t5)
}

static func buildDo<T>(_ value: T) -> T { return value }
static func buildOptional<T>(_ value: T?) -> T? { return value }

static func buildEither<T,U>(first value: T) -> Either<T,U> {
Expand Down Expand Up @@ -718,7 +704,6 @@ protocol FunctionBuilderProtocol {

static func buildExpression(_ expression: Expression) -> Component
static func buildBlock(_ components: Component...) -> Component
static func buildDo(_ components: Component...) -> Component
static func buildOptional(_ optional: Component?) -> Component
static func buildArray(_ components: [Component]) -> Component
static func buildLimitedAvailability(_ component: Component) -> Component
Expand All @@ -729,7 +714,6 @@ protocol FunctionBuilderProtocol {
extension FunctionBuilderProtocol {
static func buildExpression(_ expression: Expression) -> Component { .expression(expression) }
static func buildBlock(_ components: Component...) -> Component { .block(components) }
static func buildDo(_ components: Component...) -> Component { .block(components) }
static func buildOptional(_ optional: Component?) -> Component { .optional(optional) }
static func buildArray(_ components: [Component]) -> Component { .block(components) }
static func buildLimitedAvailability(_ component: Component) -> Component { component }
Expand Down