Skip to content

Commit b6c0145

Browse files
committed
[SE-0289] Continue printing @_functionBuilder in .swiftinterfaces.
Maintain the ability for older Swift compilers to read .swiftinterfaces that make use of result builders by always emitting @_functionBuilder rather than the newer @resultBuilder.
1 parent 6d41524 commit b6c0145

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

lib/AST/Attr.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,10 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
771771
case DAK_Optimize:
772772
if (DeclAttribute::isDeclModifier(getKind())) {
773773
Printer.printKeyword(getAttrName(), Options);
774+
} else if (Options.IsForSwiftInterface && getKind() == DAK_ResultBuilder) {
775+
// Use @_functionBuilder in Swift interfaces to maintain backward
776+
// compatibility.
777+
Printer.printSimpleAttr("_functionBuilder", /*needAt=*/true);
774778
} else {
775779
Printer.printSimpleAttr(getAttrName(), /*needAt=*/true);
776780
}

test/ModuleInterface/Inputs/result_builders_client.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import FunctionBuilders
1+
import ResultBuilders
22

33
let name = "dsl"
44
tuplify(true) {

test/ModuleInterface/result_builders.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend -typecheck -module-name FunctionBuilders -emit-module-interface-path %t/FunctionBuilders.swiftinterface %s
3-
// RUN: %FileCheck %s < %t/FunctionBuilders.swiftinterface
2+
// RUN: %target-swift-frontend -typecheck -module-name ResultBuilders -emit-module-interface-path %t/ResultBuilders.swiftinterface %s
3+
// RUN: %FileCheck %s < %t/ResultBuilders.swiftinterface
44
// RUN: %target-swift-frontend -I %t -typecheck -verify %S/Inputs/result_builders_client.swift
5-
// RUN: %target-swift-frontend -compile-module-from-interface %t/FunctionBuilders.swiftinterface -o %t/FunctionBuilders.swiftmodule
5+
// RUN: %target-swift-frontend -compile-module-from-interface %t/ResultBuilders.swiftinterface -o %t/ResultBuilders.swiftmodule
6+
// RUN: %FileCheck %s < %t/ResultBuilders.swiftinterface
67

8+
// CHECK: @_functionBuilder public struct TupleBuilder
79
@resultBuilder
810
public struct TupleBuilder {
911
public static func buildBlock<T1, T2>(_ t1: T1, _ t2: T2) -> (T1, T2) {
@@ -38,7 +40,7 @@ public struct TupleBuilder {
3840
public static func buildIf<T>(_ value: T?) -> T? { return value }
3941
}
4042

41-
// CHECK-LABEL: public func tuplify<T>(_ cond: Swift.Bool, @FunctionBuilders.TupleBuilder body: (Swift.Bool) -> T)
43+
// CHECK-LABEL: public func tuplify<T>(_ cond: Swift.Bool, @ResultBuilders.TupleBuilder body: (Swift.Bool) -> T)
4244
public func tuplify<T>(_ cond: Bool, @TupleBuilder body: (Bool) -> T) {
4345
print(body(cond))
4446
}
@@ -52,13 +54,13 @@ public struct UsesBuilderProperty {
5254
"goodbye"
5355
}
5456

55-
// CHECK: public func myFunc(@FunctionBuilders.TupleBuilder fn: () -> ())
57+
// CHECK: public func myFunc(@ResultBuilders.TupleBuilder fn: () -> ())
5658
public func myFunc(@TupleBuilder fn: () -> ()) {}
5759
}
5860

5961
public protocol ProtocolWithBuilderProperty {
6062
associatedtype Assoc
61-
62-
// CHECK: @FunctionBuilders.TupleBuilder var myVar: Self.Assoc { get }
63+
64+
// CHECK: @ResultBuilders.TupleBuilder var myVar: Self.Assoc { get }
6365
@TupleBuilder var myVar: Assoc { get }
6466
}

0 commit comments

Comments
 (0)