Skip to content

ModuleInterface: Coallesce @_backDeploy attributes when printed #63334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions lib/AST/Attr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,25 @@ static void printShortFormAvailable(ArrayRef<const DeclAttribute *> Attrs,
Printer.printNewline();
}

static void printShortFormBackDeployed(ArrayRef<const DeclAttribute *> Attrs,
ASTPrinter &Printer,
const PrintOptions &Options) {
assert(!Attrs.empty());
Printer << "@_backDeploy(before: ";
bool isFirst = true;

for (auto *DA : Attrs) {
if (!isFirst)
Printer << ", ";
auto *attr = cast<BackDeployAttr>(DA);
Printer << platformString(attr->Platform) << " "
<< attr->Version.getAsString();
isFirst = false;
}
Printer << ")";
Printer.printNewline();
}

/// The kind of a parameter in a `wrt:` differentiation parameters clause:
/// either a differentiability parameter or a linearity parameter. Used for
/// printing `@differentiable`, `@derivative`, and `@transpose` attributes.
Expand Down Expand Up @@ -754,6 +773,7 @@ void DeclAttributes::print(ASTPrinter &Printer, const PrintOptions &Options,
AttributeVector shortAvailableAttributes;
const DeclAttribute *swiftVersionAvailableAttribute = nullptr;
const DeclAttribute *packageDescriptionVersionAvailableAttribute = nullptr;
AttributeVector backDeployAttributes;
AttributeVector longAttributes;
AttributeVector attributes;
AttributeVector modifiers;
Expand Down Expand Up @@ -791,6 +811,7 @@ void DeclAttributes::print(ASTPrinter &Printer, const PrintOptions &Options,
}

AttributeVector &which = DA->isDeclModifier() ? modifiers :
isa<BackDeployAttr>(DA) ? backDeployAttributes :
isShortAvailable(DA) ? shortAvailableAttributes :
DA->isLongAttribute() ? longAttributes :
attributes;
Expand All @@ -803,6 +824,8 @@ void DeclAttributes::print(ASTPrinter &Printer, const PrintOptions &Options,
printShortFormAvailable(packageDescriptionVersionAvailableAttribute, Printer, Options);
if (!shortAvailableAttributes.empty())
printShortFormAvailable(shortAvailableAttributes, Printer, Options);
if (!backDeployAttributes.empty())
printShortFormBackDeployed(backDeployAttributes, Printer, Options);

for (auto DA : longAttributes)
DA->print(Printer, Options, D);
Expand Down
14 changes: 10 additions & 4 deletions test/ModuleInterface/back-deploy-attr.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ public struct TopLevelStruct {
@_backDeploy(before: macOS 12.0)
public func backDeployedFunc_SinglePlatform() -> Int { return 42 }

// CHECK: @_backDeploy(before: macOS 12.0)
// CHECK: @_backDeploy(before: iOS 15.0)
// CHECK: @_backDeploy(before: macOS 12.0, iOS 15.0)
// CHECK: public func backDeployedFunc_MultiPlatform() -> Swift.Int { return 43 }
@_backDeploy(before: macOS 12.0, iOS 15.0)
public func backDeployedFunc_MultiPlatform() -> Int { return 43 }

// CHECK: @_backDeploy(before: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0)
// CHECK: public func backDeployedFunc_MultiPlatformSeparate() -> Swift.Int { return 43 }
@_backDeploy(before: macOS 12.0)
@_backDeploy(before: iOS 15.0)
@_backDeploy(before: watchOS 8.0)
@_backDeploy(before: tvOS 15.0)
public func backDeployedFunc_MultiPlatformSeparate() -> Int { return 43 }

// CHECK: @_backDeploy(before: macOS 12.0)
// CHECK: public var backDeployedComputedProperty: Swift.Int {
// CHECK: get { 44 }
Expand Down Expand Up @@ -55,8 +62,7 @@ public func backDeployTopLevelFunc1() -> Int { return 47 }
@_backDeploy(before: _macOS12_1)
public func backDeployTopLevelFunc2() -> Int { return 48 }

// CHECK: @_backDeploy(before: macOS 12.1)
// CHECK: @_backDeploy(before: iOS 15.1)
// CHECK: @_backDeploy(before: macOS 12.1, iOS 15.1)
// CHECK: public func backDeployTopLevelFunc3() -> Swift.Int { return 49 }
@_backDeploy(before: _myProject 1.0)
public func backDeployTopLevelFunc3() -> Int { return 49 }