Skip to content

Commit f92d2ca

Browse files
authored
Merge pull request #30517 from nkcsgexi/58544718
ModuleInterface: print function-builder custom attribute only on parameters
2 parents ea3ef98 + b00698d commit f92d2ca

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/AST/Attr.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,19 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
770770
}
771771
break;
772772
}
773+
case DAK_Custom: {
774+
if (!Options.IsForSwiftInterface)
775+
break;
776+
// For Swift interface, we should only print function builder attribute
777+
// on parameter decls. Printing the attribute elsewhere isn't ABI relevant.
778+
if (auto *VD = dyn_cast<ValueDecl>(D)) {
779+
if (VD->getAttachedFunctionBuilder() == this) {
780+
if (!isa<ParamDecl>(D))
781+
return false;
782+
}
783+
}
784+
break;
785+
}
773786
default:
774787
break;
775788
}

test/ModuleInterface/function_builders.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,14 @@ public func tuplify<T>(_ cond: Bool, @TupleBuilder body: (Bool) -> T) {
3636
}
3737

3838
public struct UsesBuilderProperty {
39-
// CHECK: @FunctionBuilders.TupleBuilder public var myVar: (Swift.String, Swift.String) {
39+
// CHECK: public var myVar: (Swift.String, Swift.String) {
4040
// CHECK-NEXT: get
4141
// CHECK-NEXT: }
4242
@TupleBuilder public var myVar: (String, String) {
4343
"hello"
4444
"goodbye"
4545
}
46+
47+
// CHECK: public func myFunc(@FunctionBuilders.TupleBuilder fn: () -> ())
48+
public func myFunc(@TupleBuilder fn: () -> ()) {}
4649
}

0 commit comments

Comments
 (0)