Skip to content

[Parser] Improve diagnostics for special platforms in available attribute. #18895

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 3 commits into from
Sep 1, 2018

Conversation

dingobye
Copy link
Contributor

@dingobye dingobye commented Aug 22, 2018

This patch adds warnings when a version number is used on the non-specific * platform. For example, it warns unexpected version number in 'available' attribute for non-specific platform '*' in the following case:

@available(*, deprecated: 4.2)

In addition, it fixes some misleading warning messages on swift platform as mentioned by @airspeedswift , including the following cases:

@available(swift, unavailable)
 ^
- warning: unknown platform 'swift' for attribute 'available'
+ warning: 'unavailable' cannot be used in 'available' attribute for platform 'swift'


@available(swift, deprecated)
 ^
- warning: unknown platform 'swift' for attribute 'available'
+ warning: expected version number with 'deprecated' in 'available' attribute for platform 'swift'


@available(swift, message: "missing valid option")
 ^
- warning: unknown platform 'swift' for attribute 'available'
+ warning: expected 'introduced', 'deprecated', or 'obsoleted' in 'available' attribute for platform 'swift'

Resolves SR-8598.

@airspeedswift
Copy link
Member

@swift-ci please test

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

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

Thanks for picking this up!

@@ -1316,6 +1316,20 @@ ERROR(attr_availability_expected_equal,none,
ERROR(attr_availability_expected_version,none,
"expected version number in '%0' attribute", (StringRef))

WARNING(attr_availability_swift_platform_expected_option,none,
"expected '%0' option with a version number for swift platform, "
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: I suggest using this as "platform 'swift'" (like "platform '*'"). It seems a little clearer to me.

After seeing it in context, I also think it might just be better to simplify to something like "expected 'introduced', 'deprecated', or 'obsoleted' in '%0' attribute for platform 'swift'". It does mean we have to keep it up to date, but it's less circumlocution.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

"expected '%0' option with a version number for swift platform, "
"such as 'introduced', 'deprecated', or 'obsoleted'", (StringRef))
WARNING(attr_availability_swift_platform_deprecated,none,
"'deprecated' must have a version number for swift platform in '%0' "
Copy link
Contributor

Choose a reason for hiding this comment

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

This could also apply to obsoleted or introduced, right?

Copy link
Contributor Author

@dingobye dingobye Aug 23, 2018

Choose a reason for hiding this comment

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

In general, obsoleted and introduced must always have a version number alongside, while version for deprecated is optional. In this particular case (i.e., platform 'swift'), however, deprecated cannot be used alone and must followed by a version. So, the motivation of such warning here is for deprecated only.

"'deprecated' must have a version number for swift platform in '%0' "
"attribute", (StringRef))
WARNING(attr_availability_swift_platform_infeasible,none,
"argument '%0' is infeasible for swift platform in '%1' attribute",
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: To match the tone of other diagnostics, I would prefer something more like "cannot be used with" instead of "is infeasible for". (I'm also not sure we call them "arguments" in attributes, but in this case I think just leading with '%0' is fine.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -528,6 +547,14 @@ ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(
return nullptr;
}

// Warn if any version is specified for non-specific '*' platforms.
if (Platform == "*" && SomeVersion) {
diagnose(AttrLoc,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to add a fix-it for this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea! Fix-it added.

@jrose-apple jrose-apple requested a review from rintaro August 22, 2018 15:48
@dingobye
Copy link
Contributor Author

Thanks for the review, Jordan! I updated the code to address your comments.

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

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

Thanks, this looks great!

@jrose-apple
Copy link
Contributor

@swift-ci Please test

@jrose-apple jrose-apple self-assigned this Aug 23, 2018
@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 153b57924af970fed8c92646d6bbee11dae75297

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 153b57924af970fed8c92646d6bbee11dae75297

Copy link
Member

@rintaro rintaro left a comment

Choose a reason for hiding this comment

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

Looks great! thank you!

@dingobye
Copy link
Contributor Author

Oh, just noticed some warnings are raised from stdlib. Please let me fix those before merging this PR.

@dingobye
Copy link
Contributor Author

I updated the code to fix the warnings in stdlib.

In addition, I checked other projects and found corelibs-libdispatch affected. I created #391 there.

@jrose-apple
Copy link
Contributor

Whoops. Thank you for checking. cc @airspeedswift

Copy link
Member

@airspeedswift airspeedswift left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@airspeedswift
Copy link
Member

@swift-ci please test

@jrose-apple
Copy link
Contributor

Let's wait for the SCD changes before merging.

…bute.

This patch adds warnings when a version number is used
on the non-specific '*' platform. In addition, it fixes
some misleading warning messages on 'swift' platform.

Resolves: SR-8598.
@dingobye
Copy link
Contributor Author

Hi Jordan, thank you for taking care of the dependency PR #391 in swift-corelibs-libdispatch repo.

I just updated the code here to make sure it is conflict-free.

@jrose-apple
Copy link
Contributor

Let's do it!

@swift-ci Please test

@jrose-apple jrose-apple merged commit 78560c7 into swiftlang:master Sep 1, 2018
ktopley-apple pushed a commit to swiftlang/swift-corelibs-libdispatch that referenced this pull request Dec 6, 2018
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.

5 participants