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

[Sema] Diagnose internal(set) from @inlinable functions #21033

Merged

Conversation

harlanhaskins
Copy link
Contributor

@harlanhaskins harlanhaskins commented Dec 5, 2018

This patch mainly consolidates the functions used to check accessors vs.
other decls, and makes sure we check setter access as well as regular
decl access.

rdar://45217648
Resolves SR-8969

@harlanhaskins harlanhaskins force-pushed the trouble-at-the-roller-rink branch from 9ac1139 to 0a0bd7b Compare December 5, 2018 19:30
@harlanhaskins harlanhaskins requested review from jrose-apple and slavapestov and removed request for jrose-apple December 5, 2018 19:34
@harlanhaskins harlanhaskins force-pushed the trouble-at-the-roller-rink branch from 0a0bd7b to aa8b5e4 Compare December 5, 2018 19:35
@harlanhaskins
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Dec 5, 2018

Build failed
Swift Test OS X Platform
Git Sha - 0a0bd7b2b06f2c602207e99be57726e09cb11f88

@swift-ci
Copy link
Contributor

swift-ci commented Dec 5, 2018

Build failed
Swift Test Linux Platform
Git Sha - 0a0bd7b2b06f2c602207e99be57726e09cb11f88


NOTE(resilience_decl_declared_here,
none, "%0 %1 is not '@usableFromInline' or public", (DescriptiveDeclKind, DeclName))
none, DECL_OR_ACCESSOR "2 %1 is not '@usableFromInline' or public",
(DescriptiveDeclKind, DeclName, bool))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you make sure each of these diagnostics is tested?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There currently aren't any tests for the downgradeToWarning variant of this. Should I copy test/attr/attr_inlinable.swift and rewrite the expected-errors?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes please! cc @slavapestov just to make sure they're not hidden somewhere.

Copy link
Contributor Author

@harlanhaskins harlanhaskins Dec 5, 2018

Choose a reason for hiding this comment

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

I'll do this in a followup PR now Gonna roll this in because there are other changes I'm making.

Copy link
Contributor

Choose a reason for hiding this comment

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

Take a look at test/Compatibility/attr_inlinable*.swift

@jrose-apple
Copy link
Contributor

Note that if we can't take this on the Swift 5 branch it all gets trickier w/r/t source compat / when to use warnings vs. errors…

@harlanhaskins harlanhaskins force-pushed the trouble-at-the-roller-rink branch 2 times, most recently from 3c5eba9 to 42233e4 Compare December 6, 2018 01:36
@harlanhaskins
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Dec 6, 2018

Build failed
Swift Test Linux Platform
Git Sha - aa8b5e48be3f6dc4e80eff64d396a5b245596744

@swift-ci
Copy link
Contributor

swift-ci commented Dec 6, 2018

Build failed
Swift Test OS X Platform
Git Sha - aa8b5e48be3f6dc4e80eff64d396a5b245596744

Copy link
Contributor

@slavapestov slavapestov left a comment

Choose a reason for hiding this comment

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

Looks good except for one nit

public internal(set) var x: Int // expected-note {{setter for 'x' is not '@usableFromInline' or public}}

@inlinable public mutating func setsX() {
x = 10 // expected-error {{setter for 'x' is internal and cannot be referenced from an '@inlinable' function}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, wait, we can't make this an error in 4.2 mode.

Copy link
Contributor Author

@harlanhaskins harlanhaskins Dec 6, 2018

Choose a reason for hiding this comment

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

I've updated the PR for this, but should I update attr_inlinable.swift to Swift 5 and put the 4.2 compat stuff in Compatibility/attr_inlinable_swift42.swift? Or leave it where there's a Compatibility/attr_inlinable_swift5.swift?

Copy link
Contributor

Choose a reason for hiding this comment

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

@slavapestov Any preference? I think we've been leaning towards always putting the latest behavior in the "normal" file and older behavior in "Compatibility".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Went ahead and just did that

@harlanhaskins harlanhaskins force-pushed the trouble-at-the-roller-rink branch from 42233e4 to 0701f81 Compare December 6, 2018 22:55
Harlan Haskins added 3 commits December 7, 2018 12:42
Also add a compatibility test for Swift 4.2 behavior
Previously, members of protocols that were not protocol requirements,
like accessors and typealiases, did not inherit @usableFromInline from
the parent protocol. Change this so they do.
This patch mainly consolidates the functions used to check accessors vs.
other decls, and makes sure we check setter access as well as regular
decl access.

rdar://45217648
@harlanhaskins harlanhaskins force-pushed the trouble-at-the-roller-rink branch from 0701f81 to 1abeeb8 Compare December 7, 2018 20:46
@harlanhaskins
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Dec 7, 2018

Build failed
Swift Test Linux Platform
Git Sha - 42233e404e00552fdcb86232de1f8b045f3ec8e6

@swift-ci
Copy link
Contributor

swift-ci commented Dec 7, 2018

Build failed
Swift Test OS X Platform
Git Sha - 42233e404e00552fdcb86232de1f8b045f3ec8e6

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.

None yet

4 participants