Skip to content

Commit 44cacfb

Browse files
authored
Merge pull request #26015 from nkcsgexi/print-function-build-attr
IDE: always print custom attributes associated with function builder
2 parents 4fd0671 + 0e438f6 commit 44cacfb

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/AST/Attr.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,17 @@ void DeclAttributes::print(ASTPrinter &Printer, const PrintOptions &Options,
349349
AttributeVector attributes;
350350
AttributeVector modifiers;
351351

352+
CustomAttr *FuncBuilderAttr = nullptr;
353+
if (auto *VD = dyn_cast_or_null<ValueDecl>(D)) {
354+
FuncBuilderAttr = VD->getAttachedFunctionBuilder();
355+
}
352356
for (auto DA : llvm::reverse(FlattenedAttrs)) {
357+
// Always print function builder attribute.
358+
bool isFunctionBuilderAttr = DA == FuncBuilderAttr;
353359
if (!Options.PrintImplicitAttrs && DA->isImplicit())
354360
continue;
355361
if (!Options.PrintUserInaccessibleAttrs &&
362+
!isFunctionBuilderAttr &&
356363
DeclAttribute::isUserInaccessible(DA->getKind()))
357364
continue;
358365
if (Options.excludeAttrKind(DA->getKind()))

test/IDE/print_swift_module.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ public func returnsAlias() -> Alias<Int> {
2525
return (0, 0)
2626
}
2727

28+
@_functionBuilder
29+
struct BridgeBuilder {}
30+
31+
public struct City {
32+
public init(@BridgeBuilder builder: () -> ()) {}
33+
}
34+
2835
// CHECK1: /// Alias comment
2936
// CHECK1-NEXT: typealias Alias<T> = (T, T)
3037

@@ -35,6 +42,8 @@ public func returnsAlias() -> Alias<Int> {
3542
// CHECK1-NEXT: public func foo2()
3643
// CHECK1-NEXT: }
3744

45+
// CHECK1: public init(@print_swift_module.BridgeBuilder builder: () -> ())
46+
3847
// CHECK1: public protocol P1 {
3948
// CHECK1-NEXT: /// foo1 comment from P1
4049
// CHECK1-NEXT: func foo1()

0 commit comments

Comments
 (0)