Skip to content

Commit 0c8c8a5

Browse files
authored
Merge pull request #63334 from tshortli/print-back-deploy-attrs-coallesced
ModuleInterface: Coallesce `@_backDeploy` attributes when printed
2 parents 124b098 + 11a55ec commit 0c8c8a5

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
@@ -543,6 +543,25 @@ static void printShortFormAvailable(ArrayRef<const DeclAttribute *> Attrs,
543543
Printer.printNewline();
544544
}
545545

546+
static void printShortFormBackDeployed(ArrayRef<const DeclAttribute *> Attrs,
547+
ASTPrinter &Printer,
548+
const PrintOptions &Options) {
549+
assert(!Attrs.empty());
550+
Printer << "@_backDeploy(before: ";
551+
bool isFirst = true;
552+
553+
for (auto *DA : Attrs) {
554+
if (!isFirst)
555+
Printer << ", ";
556+
auto *attr = cast<BackDeployAttr>(DA);
557+
Printer << platformString(attr->Platform) << " "
558+
<< attr->Version.getAsString();
559+
isFirst = false;
560+
}
561+
Printer << ")";
562+
Printer.printNewline();
563+
}
564+
546565
/// The kind of a parameter in a `wrt:` differentiation parameters clause:
547566
/// either a differentiability parameter or a linearity parameter. Used for
548567
/// printing `@differentiable`, `@derivative`, and `@transpose` attributes.
@@ -754,6 +773,7 @@ void DeclAttributes::print(ASTPrinter &Printer, const PrintOptions &Options,
754773
AttributeVector shortAvailableAttributes;
755774
const DeclAttribute *swiftVersionAvailableAttribute = nullptr;
756775
const DeclAttribute *packageDescriptionVersionAvailableAttribute = nullptr;
776+
AttributeVector backDeployAttributes;
757777
AttributeVector longAttributes;
758778
AttributeVector attributes;
759779
AttributeVector modifiers;
@@ -791,6 +811,7 @@ void DeclAttributes::print(ASTPrinter &Printer, const PrintOptions &Options,
791811
}
792812

793813
AttributeVector &which = DA->isDeclModifier() ? modifiers :
814+
isa<BackDeployAttr>(DA) ? backDeployAttributes :
794815
isShortAvailable(DA) ? shortAvailableAttributes :
795816
DA->isLongAttribute() ? longAttributes :
796817
attributes;
@@ -803,6 +824,8 @@ void DeclAttributes::print(ASTPrinter &Printer, const PrintOptions &Options,
803824
printShortFormAvailable(packageDescriptionVersionAvailableAttribute, Printer, Options);
804825
if (!shortAvailableAttributes.empty())
805826
printShortFormAvailable(shortAvailableAttributes, Printer, Options);
827+
if (!backDeployAttributes.empty())
828+
printShortFormBackDeployed(backDeployAttributes, Printer, Options);
806829

807830
for (auto DA : longAttributes)
808831
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)