-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Implement SE-0068: Expanding Swift Self
to class members and value types
#3866
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
Conversation
…d value types ‘Self’ type is now resolved to the type of the local type context.
@tkremenek Here is a PR which implements most of SE-0068 for Swift 3 |
@swift-ci smoke test |
@joewillsher thanks! Will have a couple people review this change. |
What happens if you use Self inside a non-Self-returning class method? Does it still work? |
I’m running tests on that updated version now — I can submit separately when it is ready. |
|
||
|
||
/// Retrieve the nearest enclosing nominal type context. | ||
NominalTypeDecl *getEnclosingNominalContext() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: I don't think it's correct to say a nominal is "enclosing" when you're in an extension.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getInnermostTypeContext()->getDeclaredTypeInContext()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a refactor of a global static function, but I will remove it and replace it with that, thanks
@jrose-apple I have made a bunch of these changes as well as finish of the rest of the SE proposal implementation, but there are still a few issues. |
Adding I’m going to have to look at changing the I will close this PR now and will open a new one when that work is complete. |
@slavapestov and @rjmccall have some short- and long-term ideas for improving how Self types get lowered in SIL. The current representation is pretty bogus. You might want to coordinate with them. |
Thanks Joe. Slava and John I would really appreciate some pointers here, this proposal requires some significant changes to this area and I’m not sure how to approach it. I’d be happy to work on implementing any ideas you have, thanks. |
I think the proposal as written is reasonable, but the compiler implementation needs a lot of work to live up to it. |
@joewillsher I think a good start is to put 'Self' behind a staging flag for now. Another thing to try is to give 'self' the dynamic 'Self' type in all class methods, not just those returning 'Self', again, guarding this with a staging flag. Presently, this will result in some optimizer regressions, but it might allow you to make more progress with the language change. |
What's in this pull request?
Implementation start on SE-0068. This does not yet implement allowing
Self
to refer to the dynamic type in non final classes outside of function signatures, just expandingSelf
to value types.Resolved bug number: (SR-1340)
Before merging this pull request to apple/swift repository:
Triggering Swift CI
The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:
Smoke Testing
A smoke test on macOS does the following:
device standard libraries are not built.
version of these tests are not run.
A smoke test on Linux does the following:
tests are not run.
Validation Testing
Lint Testing
Note: Only members of the Apple organization can trigger swift-ci.