Skip to content

Commit 6d1876c

Browse files
committed
ModuleInterface: Coallesce @_backDeploy attributes when printed.
This should improve the readability of declarations with `@_backDeploy` attributes for multiple platforms. Resolves rdar://104712811
1 parent 3040221 commit 6d1876c

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

lib/AST/Attr.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,25 @@ static void printShortFormAvailable(ArrayRef<const DeclAttribute *> Attrs,
541541
Printer.printNewline();
542542
}
543543

544+
static void printShortFormBackDeployed(ArrayRef<const DeclAttribute *> Attrs,
545+
ASTPrinter &Printer,
546+
const PrintOptions &Options) {
547+
assert(!Attrs.empty());
548+
Printer << "@_backDeploy(before: ";
549+
bool isFirst = true;
550+
551+
for (auto *DA : Attrs) {
552+
if (!isFirst)
553+
Printer << ", ";
554+
auto *attr = cast<BackDeployAttr>(DA);
555+
Printer << platformString(attr->Platform) << " "
556+
<< attr->Version.getAsString();
557+
isFirst = false;
558+
}
559+
Printer << ")";
560+
Printer.printNewline();
561+
}
562+
544563
/// The kind of a parameter in a `wrt:` differentiation parameters clause:
545564
/// either a differentiability parameter or a linearity parameter. Used for
546565
/// printing `@differentiable`, `@derivative`, and `@transpose` attributes.
@@ -752,6 +771,7 @@ void DeclAttributes::print(ASTPrinter &Printer, const PrintOptions &Options,
752771
AttributeVector shortAvailableAttributes;
753772
const DeclAttribute *swiftVersionAvailableAttribute = nullptr;
754773
const DeclAttribute *packageDescriptionVersionAvailableAttribute = nullptr;
774+
AttributeVector backDeployAttributes;
755775
AttributeVector longAttributes;
756776
AttributeVector attributes;
757777
AttributeVector modifiers;
@@ -789,6 +809,7 @@ void DeclAttributes::print(ASTPrinter &Printer, const PrintOptions &Options,
789809
}
790810

791811
AttributeVector &which = DA->isDeclModifier() ? modifiers :
812+
isa<BackDeployAttr>(DA) ? backDeployAttributes :
792813
isShortAvailable(DA) ? shortAvailableAttributes :
793814
DA->isLongAttribute() ? longAttributes :
794815
attributes;
@@ -801,6 +822,8 @@ void DeclAttributes::print(ASTPrinter &Printer, const PrintOptions &Options,
801822
printShortFormAvailable(packageDescriptionVersionAvailableAttribute, Printer, Options);
802823
if (!shortAvailableAttributes.empty())
803824
printShortFormAvailable(shortAvailableAttributes, Printer, Options);
825+
if (!backDeployAttributes.empty())
826+
printShortFormBackDeployed(backDeployAttributes, Printer, Options);
804827

805828
for (auto DA : longAttributes)
806829
DA->print(Printer, Options, D);

test/ModuleInterface/back-deploy-attr.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,19 @@ public struct TopLevelStruct {
1111
@_backDeploy(before: macOS 12.0)
1212
public func backDeployedFunc_SinglePlatform() -> Int { return 42 }
1313

14-
// CHECK: @_backDeploy(before: macOS 12.0)
15-
// CHECK: @_backDeploy(before: iOS 15.0)
14+
// CHECK: @_backDeploy(before: macOS 12.0, iOS 15.0)
1615
// CHECK: public func backDeployedFunc_MultiPlatform() -> Swift.Int { return 43 }
1716
@_backDeploy(before: macOS 12.0, iOS 15.0)
1817
public func backDeployedFunc_MultiPlatform() -> Int { return 43 }
1918

19+
// CHECK: @_backDeploy(before: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0)
20+
// CHECK: public func backDeployedFunc_MultiPlatformSeparate() -> Swift.Int { return 43 }
21+
@_backDeploy(before: macOS 12.0)
22+
@_backDeploy(before: iOS 15.0)
23+
@_backDeploy(before: watchOS 8.0)
24+
@_backDeploy(before: tvOS 15.0)
25+
public func backDeployedFunc_MultiPlatformSeparate() -> Int { return 43 }
26+
2027
// CHECK: @_backDeploy(before: macOS 12.0)
2128
// CHECK: public var backDeployedComputedProperty: Swift.Int {
2229
// CHECK: get { 44 }
@@ -55,8 +62,7 @@ public func backDeployTopLevelFunc1() -> Int { return 47 }
5562
@_backDeploy(before: _macOS12_1)
5663
public func backDeployTopLevelFunc2() -> Int { return 48 }
5764

58-
// CHECK: @_backDeploy(before: macOS 12.1)
59-
// CHECK: @_backDeploy(before: iOS 15.1)
65+
// CHECK: @_backDeploy(before: macOS 12.1, iOS 15.1)
6066
// CHECK: public func backDeployTopLevelFunc3() -> Swift.Int { return 49 }
6167
@_backDeploy(before: _myProject 1.0)
6268
public func backDeployTopLevelFunc3() -> Int { return 49 }

0 commit comments

Comments
 (0)