Skip to content

[libSyntax, tests] Preparations for verification of syntax tree on SILGen tests #16174

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

Merged
merged 6 commits into from
Apr 27, 2018

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Apr 26, 2018

These are a couple of minor fixes that will allow libSyntax to parse all the SILGen tests, in particular:

  • Add a -verify-syntax-tree frontend flag that will parse the syntax tree and error if any unknown nodes exist within it
  • libSyntax fixes
    • Allow key paths on specialised generics (e.g. Array<Int>.[])
    • Allow computed properties with non-standard accessors (e.g. unsafeMutableAddress)
    • Fix the parsing of delayed function bodies (I think this would never surface to the user but came up with the SILGen tests so I fixed it)
  • SILGen test updates
    • Update operator declaration to Swift 4 syntax (without {})
    • Update generic where clauses to Swift 4 syntax (trailing after the function signature instead of in the generics list)
    • Remove a superflous ) in one test

In an upcoming PR I will flip the switch to always verify the syntax tree generated when parsing the SILGen tests. That way we should have a smoke test making sure that no new syntax gets introduced without libSyntax being able to parse it.

@ahoppen ahoppen requested review from rintaro and nkcsgexi April 26, 2018 15:04
@ahoppen
Copy link
Member Author

ahoppen commented Apr 26, 2018

@swift-ci Please smoke test

@ahoppen ahoppen force-pushed the libsyntax-silgen-preparation branch from 27d023b to eb42a57 Compare April 26, 2018 16:10
@ahoppen
Copy link
Member Author

ahoppen commented Apr 26, 2018

@swift-ci Please smoke test

@nkcsgexi
Copy link
Contributor

@eeckstein could you take a look at the update of sil gen tests? @ahoppen makes all silgen tests also libSyntax tests by ensuring we have no problem parsing those valid syntax.

@nkcsgexi nkcsgexi requested a review from eeckstein April 26, 2018 17:12
Copy link
Contributor

@eeckstein eeckstein left a comment

Choose a reason for hiding this comment

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

lgtm.
@jckarter: any comments from your side?

@@ -476,7 +476,12 @@
Child('Modifier', kind='DeclModifier', is_optional=True),
Child('AccessorKind', kind='Token',
Copy link
Member

Choose a reason for hiding this comment

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

(Not in this PR) This should be ContextualKeywordToken (when we implement libSyntax-based syntax-coloring)

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll do that in a follow-up PR.

SyntaxParsingContext BlockItemListContext(SyntaxContext,
SyntaxKind::CodeBlockItemList);
SyntaxParsingContext BodyContext(SyntaxContext, SyntaxKind::CodeBlock);
BodyContext.setDiscard();
Copy link
Member

Choose a reason for hiding this comment

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

Please don't use setDiscard() here. Parsing this invalid code:

precedencegroup class {
    garbage...
}

loses roundtripness.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. I thought it was only used in delayed function body parsing. Changed it to a TokenList.

SyntaxKind::IdentifierExpr);
// Consume 'type'
keywordLoc = consumeToken();
}
Copy link
Member

Choose a reason for hiding this comment

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

Nice catch!

@@ -6,6 +6,6 @@ enum E<T>: Int {
}

// CHECK-LABEL: sil hidden @$S22enum_generic_raw_value1FO
enum F<T: ExpressibleByIntegerLiteral where T: Equatable>: T {
enum F<T: ExpressibleByIntegerLiteral>: T where T: Equatable {
Copy link
Member

Choose a reason for hiding this comment

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

(Not in this PR) We should consider accepting optional GenericWhereClause inside GenericParameterClause. As long as we offer fix-it, it should be treated as well-formed syntax.
(I'm not against fixing SILGen tests in this PR.)

Copy link
Member Author

Choose a reason for hiding this comment

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

I spoke with Argyrios about this and we decided not to support libSyntax parsing of Swift 3. It is being deprecated anyway and we will probably not be able to provide the coverage we will for Swift 4.

prefix operator ~~~
infix operator <*>
infix operator <**>
infix operator <===>
Copy link
Member

Choose a reason for hiding this comment

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

(But I don't want to accept {} for operator decls...) 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

What do you mean?

Copy link
Member

@rintaro rintaro Apr 27, 2018

Choose a reason for hiding this comment

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

I wanted to accept where clause in generic parameter clause, but I did not want to accept deprecated operator decl syntax.

This will parse the source file into a libSyntax tree and verify that no
unknown nodes exist within it
@ahoppen ahoppen force-pushed the libsyntax-silgen-preparation branch from eb42a57 to 569a710 Compare April 27, 2018 15:09
@ahoppen ahoppen force-pushed the libsyntax-silgen-preparation branch from 569a710 to dc3e43b Compare April 27, 2018 15:10
@ahoppen
Copy link
Member Author

ahoppen commented Apr 27, 2018

@swift-ci Please smoke test

@jckarter
Copy link
Contributor

@eeckstein SILGen test changes look fine to me.

@ahoppen ahoppen merged commit 95a3a43 into swiftlang:master Apr 27, 2018
@ahoppen ahoppen deleted the libsyntax-silgen-preparation branch April 27, 2018 16:33
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.

5 participants