Skip to content

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

Closed
wants to merge 6 commits into from

Conversation

joewillsher
Copy link
Contributor

@joewillsher joewillsher commented Jul 1, 2016

What's in this pull request?

Implementation for SE-0095: Replace protocol<P1, P2> syntax with P1 & P2.

This PR implements:

  • Parsing of the new syntax (in parseTypeIdentifierOrTypeComposition)
  • A warning for the old syntax which will soon be changed to an error, plus a fixit to move to new syntax
  • Any becomes a keyword and is removed from the standard library
  • Changed the demangler & AST printer to use the new syntax
  • IRGen mangles compositions slightly differently
  • PreCheckExpression supports parsing compositions
  • Code completion for the Any keyword

Resolved bug number: (SR-1938)


Before merging this pull request to apple/swift repository:

  • Test pull request on Swift continuous integration.

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

Platform Comment
All supported platforms @swift-ci Please smoke test
All supported platforms @swift-ci Please smoke test and merge
OS X platform @swift-ci Please smoke test OS X platform
Linux platform @swift-ci Please smoke test Linux platform

Validation Testing

Platform Comment
All supported platforms @swift-ci Please test
All supported platforms @swift-ci Please test and merge
OS X platform @swift-ci Please test OS X platform
OS X platform @swift-ci Please benchmark
Linux platform @swift-ci Please test Linux platform

Lint Testing

Language Comment
Python @swift-ci Please Python lint

Note: Only members of the Apple organization can trigger swift-ci.

@CodaFi
Copy link
Contributor

CodaFi commented Jul 1, 2016

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)) {
Copy link
Contributor

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

Copy link
Contributor Author

@joewillsher joewillsher Jul 4, 2016

Choose a reason for hiding this comment

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

Thanks, fixed

@joewillsher
Copy link
Contributor Author

Added PR to swift-corelibs-foundation to accompany this one.

@jrose-apple jrose-apple changed the title Implement SE-0095 Implement SE-0095: Replace protocol<P1, P2> syntax with P1 & P2 Jul 5, 2016
@joewillsher
Copy link
Contributor Author

@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)
Copy link
Contributor

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.

@joewillsher
Copy link
Contributor Author

@jrose-apple Changes made, I’ve done everything apart from verifying that (P1 & P2).self will always be resolved into a OverloadedDeclRefExpr.

How does it look, and thanks for your help so far!

@joewillsher
Copy link
Contributor Author

@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;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: whitespace

@CodaFi
Copy link
Contributor

CodaFi commented Jul 16, 2016

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?

@CodaFi
Copy link
Contributor

CodaFi commented Jul 16, 2016

Second, I believe you've been git pulling without rebasing, so could you squash the commits that mention merging upstream and even fixup the old irrelevant/duplicate commits. Ideally this patch should introduce 3-5 commits at most to the repo.

@@ -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,
Copy link
Member

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.

@joewillsher
Copy link
Contributor Author

joewillsher commented Jul 18, 2016

@jckarter Looks like it came from the renaming of ErrorProtocol to Error, should I fix in this PR or do it separately?

@jckarter
Copy link
Contributor

Ah, I didn't realize this wasn't merged yet. Sorry.

@joewillsher
Copy link
Contributor Author

No problem — would you mind triggering the CI bot?

@DougGregor
Copy link
Member

@swift-ci please test and merge

@DougGregor
Copy link
Member

@swift-ci please test and merge

@joewillsher joewillsher force-pushed the master branch 2 times, most recently from 57c8fae to 2050200 Compare July 18, 2016 20:48
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.
@DougGregor
Copy link
Member

@swift-ci please smoke test and merge

@DougGregor
Copy link
Member

ARGH! Should have forced a merge before it conflicted again.

@joewillsher
Copy link
Contributor Author

I've fixed a few of the failing cases, I'll resolve conflicts and push when I can in a bit.

@DougGregor
Copy link
Member

Okay!

@DougGregor
Copy link
Member

FYI, I did a merge + fix-up and just pushed the result

@DougGregor
Copy link
Member

0eaa576

@joewillsher
Copy link
Contributor Author

Oh fantastic, thanks for that!

@DougGregor
Copy link
Member

@joewillsher, I'm going to close out this PR because all of the commits from it have been integrated in master. THANK YOU!

@DougGregor DougGregor closed this Jul 19, 2016
@joewillsher
Copy link
Contributor Author

@DougGregor One last thing: we should merge this corelibs-foundation PR too.

@DougGregor
Copy link
Member

Okay, done. Thanks!

@jrose-apple
Copy link
Contributor

…sorry for not handing this off explicitly before going on vacation! Thanks for all the work, Joe.

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.

8 participants