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

Allow implicit self in escaping closures when self usage is unlikely to cause cycle #23934

Merged
merged 37 commits into from
Dec 20, 2019

Conversation

Jumhyn
Copy link
Member

@Jumhyn Jumhyn commented Apr 10, 2019

Update the lookup logic for closures to allow resolution of implicit self to resolve to any direct captures of self (e.g. { [self] in ... }) in closures. Also introduce new diagnostic logic to suggest such a capture as a fix-it for implicit self in an escaping closure.

This is the implementation for an incoming Swift Evolution proposal.

Resolves SR-10218.

@beccadax beccadax added the swift evolution pending discussion Flag → feature: A feature that has a Swift evolution proposal currently in review label Jul 17, 2019
@Jumhyn Jumhyn force-pushed the implicit-self-capture branch from 6778567 to 3446add Compare July 21, 2019 19:28
Copy link
Contributor

@gregomni gregomni left a comment

Choose a reason for hiding this comment

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

This is awesome, just a few suggestions.

@Jumhyn
Copy link
Member Author

Jumhyn commented Aug 2, 2019

Hi @gregomni, thanks for the comments! I’ll have a chance to make changes re: your feedback this weekend.

@Jumhyn Jumhyn force-pushed the implicit-self-capture branch from c0efff6 to df5f6a1 Compare August 4, 2019 17:04
Copy link
Contributor

@beccadax beccadax left a comment

Choose a reason for hiding this comment

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

This looks pretty good! I have some minor suggestions, but they're mostly stylistic, plus a couple of edge cases.

@beccadax
Copy link
Contributor

If you fix the merge conflict and @ me, I'll kick off tests.

@Jumhyn
Copy link
Member Author

Jumhyn commented Aug 18, 2019

@brentdax Implementation updated and conflicts resolved. Made some new changes in lib/Parse/Lexer.cpp to better handle the bracket cases, so might want to give some thought there as to whether it will affect anything that I didn't consider. I think the change should be safe, and tests all run locally for me, but it's a member function with a lot of clients so there may be an edge case that I'm not thinking of.

Copy link
Contributor

@beccadax beccadax left a comment

Choose a reason for hiding this comment

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

Very minor suggestions, but I'm happy with this overall!

@Jumhyn
Copy link
Member Author

Jumhyn commented Oct 16, 2019

@brentdax Thanks for the comments! Sorry it took me a bit to get back to you; I had to update the implementation to integrate with the new AST scope lookup system. I have a working implementation now, so once I polish that up I’ll push it up and add the tests you’ve called out!

@theblixguy
Copy link
Collaborator

theblixguy commented Dec 17, 2019

To be honest I just created it because that's what Ted/Doug were trying to do. You can use it in Xcode to check if everything works and behaves as expected I guess.

That's weird - I don't get such an error (I am using Xcode 11.3 on macOS 10.15.1). The toolchain needs to be placed in /Library/Developer/Toolchains. Is that where you’ve placed the xctoolchain file?

@Jumhyn
Copy link
Member Author

Jumhyn commented Dec 17, 2019

Ah, gotcha. @tkremenek @DougGregor this is passing CI now and is ready to merge on my end!

@beccadax
Copy link
Contributor

It looks like you haven't run full tests recently, so just to be conservative, I'll do a test-and-merge.

@swift-ci please test and merge

@Jumhyn
Copy link
Member Author

Jumhyn commented Dec 18, 2019

@brentdax Should the test-and-merge job be reflected in the check statuses below? I'm not seeing anything change (still just the smoke test and build toolchain jobs).

@theblixguy
Copy link
Collaborator

theblixguy commented Dec 18, 2019

It will update soon, it's running: https://ci.swift.org/view/Pull%20Request/job/swift-PR-merge/2194/

@theblixguy
Copy link
Collaborator

Infrastructure problems... let’s try again:

@swift-ci please test

@swift-ci

This comment has been minimized.

@swift-ci

This comment has been minimized.

@theblixguy
Copy link
Collaborator

@swift-ci please test Linux

@theblixguy
Copy link
Collaborator

@swift-ci please test macOS

@Jumhyn
Copy link
Member Author

Jumhyn commented Dec 19, 2019

@brentdax Looks like the tests @theblixguy kicked off succeeded finally, but this still needs one last nudge to actually merge it :)

@theblixguy
Copy link
Collaborator

Let's run source compatibility tests as well, just to be extra sure. If that passes too, we can merge this:

@swift-ci please test source compatibility

@Jumhyn
Copy link
Member Author

Jumhyn commented Dec 19, 2019

Thank you @theblixguy! For future reference, are these all steps that I could have run myself (i.e., was I bothering you two needlessly)?

@theblixguy
Copy link
Collaborator

theblixguy commented Dec 19, 2019

You need commit access to run tests on CI, but I am happy to run them for you if needed! For testing locally, there's a doc: https://github.com/apple/swift/blob/master/docs/Testing.md (instructions for running source compat suite locally is here: https://github.com/apple/swift-source-compat-suite).

@theblixguy
Copy link
Collaborator

@swift-ci please test source compatibility debug

@theblixguy
Copy link
Collaborator

@swift-ci please test source compatibility release

@theblixguy
Copy link
Collaborator

Okay, all tests are passing so let's :shipit:. Thank you very much for your contribution @Jumhyn! Could you please mark the JIRA ticket as resolved? Also, I think it needs to be added to the changelog.

@brentdax can this be cherry-picked to 5.2 branch or is it too late?

@theblixguy theblixguy merged commit 71697c3 into swiftlang:master Dec 20, 2019
compnerd added a commit that referenced this pull request Dec 20, 2019
@phlegmaticprogrammer
Copy link

Oh it would be great if this could end up in 5.2. I have a DSL that would be much much nicer to use with this.

@theblixguy
Copy link
Collaborator

@Jumhyn Do you mind adding this to the changelog and also update the proposal as "Implemented" on Swift evolution repo?

@Jumhyn
Copy link
Member Author

Jumhyn commented Jan 17, 2020

@theblixguy Sure thing. Do you know what heading it should be put under in the changelog since it missed 5.2?

@theblixguy
Copy link
Collaborator

It should be under “Swift Next”. Also, I’m sorry for suggesting to update the proposal, since we don’t know which version of Swift this will end up in, its best to keep the current status as-is.

@Jumhyn
Copy link
Member Author

Jumhyn commented Jan 17, 2020

Great, done. Once this makes it into a Swift release I'll update the swift-evolution PR with the version number so that it can be merged in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
swift evolution approved Flag → feature: A feature that was approved through the Swift evolution process
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants