Skip to content

[Swiftify] Emit @availability when expansions contain Span #81320

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 6 commits into from
May 8, 2025

Conversation

hnrklssn
Copy link
Contributor

@hnrklssn hnrklssn commented May 6, 2025

This prevents errors when compiling for older targets using a newer compiler.

rdar://150740330

This prevents errors when compiling for older targets using a newer
compiler.

rdar://150740330
@hnrklssn
Copy link
Contributor Author

hnrklssn commented May 6, 2025

@swift-ci please smoke test


// Check that ClangImporter correctly infers and expands @_SwiftifyImport macros for functions with __counted_by __noescape parameters.

import CountedByNoEscapeClang

// CHECK: @lifetime(p: copy p)
// CHECK: @available(macOS 10.14.4, *)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DougGregor We only need availability for the target OS right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm I figured out a convenient way to get all platform availabilities regardless of target. This makes testing much easier

@hnrklssn
Copy link
Contributor Author

hnrklssn commented May 6, 2025

@swift-ci please smoke test

@hnrklssn
Copy link
Contributor Author

hnrklssn commented May 7, 2025

@swift-ci please smoke test

// CHECK: @_alwaysEmitIntoClient public func complexExpr(_ len: Int{{.*}}, _ offset: Int{{.*}}, _ p: RawSpan)
// CHECK: @available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *)
// CHECK-NEXT: @_alwaysEmitIntoClient public func complexExpr(_ len: Int{{.*}}, _ offset: Int{{.*}}, _ p: RawSpan)
// CHECK-NEXT: @available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we generalize the check lines so this test can work on platforms that don't have availability defined (e.g., Linux)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we include inactive availability attributes we should always have the same output regardless of platform

ValueDecl *D = getDecl(Name);
out << "\"" << Name << "\":" << "\"";
llvm::SaveAndRestore<bool> hasAvailbilitySeparatorRestore(firstParam, true);
for (auto attr : D->getSemanticAvailableAttrs(/*includingInactive=*/true)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need the inactive availability attributes, do we?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, I forgot to test whether that made a difference

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this out now, and while we don't necessarily need to include inactive attributes, I think it kind of makes sense to include them. If we don't, we'll get @available(macOS 10.14.4, *) when compiling for macOS, other stuff for other Darwin platforms, and nothing for Linux and Windows. If we include inactive attributes we'll always get @available(visionOS 1.1, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *). This makes the output more consistent, making it significantly easier to test, and less confusing for someone reading the macro expansion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, that makes sense.

@hnrklssn
Copy link
Contributor Author

hnrklssn commented May 7, 2025

@swift-ci please smoke test

@hnrklssn
Copy link
Contributor Author

hnrklssn commented May 7, 2025

@swift-ci please smoke test

@hnrklssn
Copy link
Contributor Author

hnrklssn commented May 8, 2025

@swift-ci please smoke test windows

@hnrklssn hnrklssn merged commit 59d7d31 into swiftlang:main May 8, 2025
3 checks passed
hnrklssn added a commit to hnrklssn/swift that referenced this pull request May 8, 2025
…#81320)

This prevents errors when compiling for older targets using a newer
compiler.

rdar://150740330
(cherry picked from commit 59d7d31)
devincoughlin added a commit that referenced this pull request May 13, 2025
Catfish-Man pushed a commit that referenced this pull request May 15, 2025
This prevents errors when compiling for older targets using a newer
compiler.

rdar://150740330
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants