Skip to content
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

Add support for availability-style features #9815

Draft
wants to merge 1 commit into
base: next
Choose a base branch
from

Conversation

ahatanaka
Copy link

rdar://137999979

@ahatanaka ahatanaka force-pushed the feature-availability branch from 9c6c6b4 to 6b1eb91 Compare January 9, 2025 22:21
@ahatanaka ahatanaka marked this pull request as draft January 9, 2025 22:22
@ahatanaka ahatanaka force-pushed the feature-availability branch 2 times, most recently from db3f142 to e959883 Compare January 15, 2025 23:18
@ahatanaka
Copy link
Author

@swift-ci please smoke test

@ahatanaka ahatanaka force-pushed the feature-availability branch from e959883 to ffd2237 Compare February 7, 2025 10:56
@@ -630,6 +630,10 @@ void StmtPrinter::VisitObjCAvailabilityCheckExpr(
OS << "@available(...)";
}

void StmtPrinter::VisitObjCFeatureCheckExpr(ObjCFeatureCheckExpr *Node) {
OS << "@feature(...)";
Copy link

Choose a reason for hiding this comment

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

I think the body was elided on @available(...) because the AST doesn't retain full fidelity of the availability check and instead it drops the other platforms. Do we have that same problem with @feature()? If not, I think this should print the actual feature too, so you can write a test that checks it round-trips through serialization.

Copy link
Author

Choose a reason for hiding this comment

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

I've changed this to use @available instead of introducing a new keyword but haven't made any changes to StmtPrinter yet.

@@ -3999,6 +4008,23 @@ std::optional<AvailabilitySpec> Parser::ParseAvailabilitySpec() {
Actions.CodeCompletion().CodeCompleteAvailabilityPlatformName();
return std::nullopt;
}

if (Tok.is(tok::identifier) && GetLookAheadToken(1).is(tok::equal)) {
Copy link

Choose a reason for hiding this comment

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

Can you make it tok::colon instead? I think it's too late to change the feat: one, and it would be nice if they matched.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, domain:feature1 would be okay too.

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