-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Implement SE-0095: Replace protocol<P1, P2> syntax with P1 & P2 #3293
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
Looks like you have conflicts. Could you rebase onto master and fix them please? |
@@ -1744,8 +1744,7 @@ DeclName Parser::parseUnqualifiedDeclName(bool afterDot, | |||
// Consume the base name. | |||
Identifier baseName = Context.getIdentifier(Tok.getText()); | |||
SourceLoc baseNameLoc; | |||
if (Tok.is(tok::identifier) || Tok.is(tok::kw_Self) || | |||
Tok.is(tok::kw_self)) { | |||
if (Tok.isAny(tok::identifier, tok::kw_Self, tok::kw_Self)) { |
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.
I guess you want the S on the second kw_Self
lowercase
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.
Thanks, fixed
Added PR to swift-corelibs-foundation to accompany this one. |
@lattner Could you (or someone else) please review the code in this PR when you get a chance? I think it is ready to merge and I have some local work for another problem I’d like to submit (but can’t until this is merged), thanks. |
@@ -60,6 +60,7 @@ IDENTIFIER(RawValue) | |||
IDENTIFIER(Selector) | |||
IDENTIFIER(self) | |||
IDENTIFIER(Self) | |||
IDENTIFIER(Any) |
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: Please keep this list alphabetized.
@jrose-apple Changes made, I’ve done everything apart from verifying that How does it look, and thanks for your help so far! |
@jrose-apple And that is done too, we no longer look at the result of the OverloadedDeclRefExpr in simplifyTypeExpr. |
@@ -58,11 +59,14 @@ ParserResult<TypeRepr> Parser::parseTypeSimple(Diag<> MessageID, | |||
|
|||
switch (Tok.getKind()) { | |||
case tok::kw_Self: | |||
ty = parseTypeIdentifier(); | |||
break; |
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: whitespace
Jordan is away on vacation for the next few days. In the meantime I can pick up some of his end on code review. In general the first thing I've noticed this patch overruns our 80-column limit in a few places and introduces extraneous whitespace into the diff. Could you wrap things and tidy up please? |
Second, I believe you've been |
@@ -654,6 +654,11 @@ ERROR(expected_rangle_protocol,PointsToFirstBadToken, | |||
ERROR(disallowed_protocol_composition,PointsToFirstBadToken, | |||
"protocol composition is neither allowed nor needed here", ()) | |||
|
|||
WARNING(deprecated_protocol_composition,PointsToFirstBadToken, |
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.
PointsToFirstBadToken isn't needed here; just use 'none' for all of these.
Ah, I didn't realize this wasn't merged yet. Sorry. |
No problem — would you mind triggering the CI bot? |
@swift-ci please test and merge |
@swift-ci please test and merge |
57c8fae
to
2050200
Compare
This commit defines the ‘Any’ keyword, implements parsing for composing types with an infix ‘&’, and provides a fixit to convert ‘protocol<>’ - Updated tests & stdlib for new composition syntax - Provide errors when compositions used in inheritance. Any is treated as a contextual keyword. The name ‘Any’ is used emit the empty composition type. We have to stop user declaring top level types spelled ‘Any’ too.
Also adds: - Any is caught before doing an unconstrained lookup, and the protocol<> type is emitted - composition expressions can be handled by `PreCheckExpression::simplifyTypeExpr` to so you can do lookups like (P & Q).self - Fixits corrected & new tests added - Typeref lowering cases should have been optional - This fixes a failing test case.
…ition syntax - All parts of the compiler now use ‘P1 & P2’ syntax - The demangler and AST printer wrap the composition in parens if it is in a metatype lookup - IRGen mangles compositions differently - “protocol<>” is now “swift.Any” - “protocol<_TP1P,_TP1Q>” is now “_TP1P&_TP1Q” - Tests cases are updated and added to test the new syntax and mangling
Now that Any isn’t in the stdlib we need to add it to code completion separately.
- Any is made into a keyword which is always resolved into a TypeExpr, allowing the removal of the type system code to find TheAnyType before an unconstrained lookup. - Types called `Any` can be declared, they are looked up as any other identifier is - Renaming/redefining behaviour of source loc methods on ProtocolCompositionTypeRepr. Added a createEmptyComposition static method too. - Code highlighting treats Any as a type - simplifyTypeExpr also does not rely on source to get operator name. - Any is now handled properly in canParseType() which was causing generic param lists containing ‘Any’ to fail - The import objc id as Any work has been relying on getting a decl for the Any type. I fix up the clang importer to use Context.TheAnyType (instead of getAnyDecl()->getDeclaredType()). When importing the id typedef, we create a typealias to Any and declare it unavaliable.
@swift-ci please smoke test and merge |
ARGH! Should have forced a merge before it conflicted again. |
I've fixed a few of the failing cases, I'll resolve conflicts and push when I can in a bit. |
Okay! |
FYI, I did a merge + fix-up and just pushed the result |
Oh fantastic, thanks for that! |
@joewillsher, I'm going to close out this PR because all of the commits from it have been integrated in master. THANK YOU! |
@DougGregor One last thing: we should merge this corelibs-foundation PR too. |
Okay, done. Thanks! |
…sorry for not handing this off explicitly before going on vacation! Thanks for all the work, Joe. |
What's in this pull request?
Implementation for SE-0095: Replace
protocol<P1, P2>
syntax withP1 & P2
.This PR implements:
parseTypeIdentifierOrTypeComposition
)Any
becomes a keyword and is removed from the standard libraryPreCheckExpression
supports parsing compositionsAny
keywordResolved bug number: (SR-1938)
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
Validation Testing
Lint Testing
Note: Only members of the Apple organization can trigger swift-ci.