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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/swift/AST/DiagnosticsParse.def
Original file line number Diff line number Diff line change
Expand Up @@ -1585,8 +1585,8 @@ ERROR(availability_query_repeated_platform, none,
//------------------------------------------------------------------------------
// syntax parsing diagnostics
//------------------------------------------------------------------------------
WARNING(unknown_syntax_entity, PointsToFirstBadToken,
"unknown %0 syntax exists in the source", (StringRef))
ERROR(unknown_syntax_entity, PointsToFirstBadToken,
"unknown %0 syntax exists in the source", (StringRef))

#ifndef DIAG_NO_UNDEF
# if defined(DIAG)
Expand Down
3 changes: 3 additions & 0 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ def verify_generic_signatures : Separate<["-"], "verify-generic-signatures">,
MetaVarName<"<module-name>">,
HelpText<"Verify the generic signatures in the given module">;

def verify_syntax_tree : Flag<["-"], "verify-syntax-tree">,
HelpText<"Verify that no unknown nodes exist in the libSyntax tree">;

def show_diagnostics_after_fatal : Flag<["-"], "show-diagnostics-after-fatal">,
HelpText<"Keep emitting subsequent diagnostics after a fatal error">;

Expand Down
5 changes: 5 additions & 0 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
Opts.NamedLazyMemberLoading &= !Args.hasArg(OPT_disable_named_lazy_member_loading);
Opts.DebugGenericSignatures |= Args.hasArg(OPT_debug_generic_signatures);

if (Args.hasArg(OPT_verify_syntax_tree)) {
Opts.BuildSyntaxTree = true;
Opts.VerifySyntaxTree = true;
}

Opts.DebuggerSupport |= Args.hasArg(OPT_debugger_support);
if (Opts.DebuggerSupport)
Opts.EnableDollarIdentifiers = true;
Expand Down
18 changes: 12 additions & 6 deletions lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3870,7 +3870,11 @@ static ParameterList *parseOptionalAccessorArgument(SourceLoc SpecifierLoc,
return ParameterList::create(P.Context, StartLoc, param, EndLoc);
}

static unsigned skipUntilMatchingRBrace(Parser &P) {
static unsigned skipUntilMatchingRBrace(Parser &P,
SyntaxParsingContext *&SyntaxContext) {
SyntaxParsingContext BlockItemListContext(SyntaxContext,
SyntaxKind::CodeBlockItemList);
SyntaxParsingContext BodyContext(SyntaxContext, SyntaxKind::TokenList);
unsigned OpenBraces = 1;
while (OpenBraces != 0 && P.Tok.isNot(tok::eof)) {
if (P.consumeIf(tok::l_brace)) {
Expand All @@ -3888,9 +3892,11 @@ static unsigned skipUntilMatchingRBrace(Parser &P) {
return OpenBraces;
}

static unsigned skipBracedBlock(Parser &P) {
static unsigned skipBracedBlock(Parser &P,
SyntaxParsingContext *&SyntaxContext) {
SyntaxParsingContext CodeBlockContext(SyntaxContext, SyntaxKind::CodeBlock);
P.consumeToken(tok::l_brace);
unsigned OpenBraces = skipUntilMatchingRBrace(P);
unsigned OpenBraces = skipUntilMatchingRBrace(P, SyntaxContext);
if (P.consumeIf(tok::r_brace))
OpenBraces--;
return OpenBraces;
Expand All @@ -3904,7 +3910,7 @@ void Parser::consumeGetSetBody(AbstractFunctionDecl *AFD,
BodyRange.Start = Tok.getLoc();

// Skip until the next '}' at the correct nesting level.
unsigned OpenBraces = skipUntilMatchingRBrace(*this);
unsigned OpenBraces = skipUntilMatchingRBrace(*this, SyntaxContext);

if (OpenBraces != 1) {
// FIXME: implement some error recovery?
Expand Down Expand Up @@ -5102,7 +5108,7 @@ void Parser::consumeAbstractFunctionBody(AbstractFunctionDecl *AFD,
BodyRange.Start = Tok.getLoc();

// Consume the '{', and find the matching '}'.
unsigned OpenBraces = skipBracedBlock(*this);
unsigned OpenBraces = skipBracedBlock(*this, SyntaxContext);
if (OpenBraces != 0 && Tok.isNot(tok::code_complete)) {
assert(Tok.is(tok::eof));
// We hit EOF, and not every brace has a pair. Recover by searching
Expand Down Expand Up @@ -6458,7 +6464,7 @@ Parser::parseDeclPrecedenceGroup(ParseDeclOptions flags,
(void) consumeIf(tok::r_brace);
} else if (Tok.isNot(tok::eof) && peekToken().is(tok::l_brace)) {
consumeToken();
skipBracedBlock(*this);
skipBracedBlock(*this, SyntaxContext);
}
return nullptr;
}
Expand Down
9 changes: 7 additions & 2 deletions lib/Parse/ParseExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3563,8 +3563,13 @@ ParserResult<Expr> Parser::parseExprTypeOf() {
// DynamicTypeExpr.
SyntaxParsingContext CallCtxt(SyntaxContext, SyntaxKind::FunctionCallExpr);

// Consume 'type'
SourceLoc keywordLoc = consumeToken();
SourceLoc keywordLoc;
{
SyntaxParsingContext IdentifierExprContext(SyntaxContext,
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!


// Parse the leading '('.
SourceLoc lParenLoc = consumeToken(tok::l_paren);
Expand Down
2 changes: 1 addition & 1 deletion test/SILGen/Inputs/AppKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ public func NSApplicationMain(
return argv.withMemoryRebound(to:UnsafePointer<Int8>.self, capacity: Int(argc)) {
argv in
return __NSApplicationMain(argc, argv)
})
}
}
2 changes: 1 addition & 1 deletion test/SILGen/enum_generic_raw_value.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.

case A = 1
}
36 changes: 18 additions & 18 deletions test/SILGen/generic_signatures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,36 @@ class C {}

func a<T>(x: T) {}
func b<T: P>(x: G<T>, y: T.Assoc) {}
func c<T where T: P>(x: T, y: T.Assoc) {}
func c<T>(x: T, y: T.Assoc) where T: P {}
func d<T: P, U: P & Q>(x: T, y: U) {}
func e<T, U where T: P, U: P, U: Q>(x: T, y: U) {}
func e<T, U>(x: T, y: U) where T: P, U: P, U: Q {}
// FIXME: Same-type constraints expose a typechecker bug.
// <rdar://problem/15730168>
func f<T: Q where T.Assoc1 == T.Assoc2>(x: T) {}
func g<T where T: Q, T.Assoc1 == T.Assoc2>(x: T) {}
func h<T: P, U where T.Assoc == U>(x: T) {}
func i<T: P where T.Assoc: Q, T.Assoc.Assoc1 == T.Assoc.Assoc2>(x: T) {}
func f<T: Q>(x: T) where T.Assoc1 == T.Assoc2 {}
func g<T>(x: T) where T: Q, T.Assoc1 == T.Assoc2 {}
func h<T: P, U>(x: T) where T.Assoc == U {}
func i<T: P>(x: T) where T.Assoc: Q, T.Assoc.Assoc1 == T.Assoc.Assoc2 {}
func j<T: C>(_: T) {}
func k<T where T: C>(_: T) {}
func l<T: C where T: P>(_: T) {}
func m<T: P where T.Assoc: C>(_: T) {}
func k<T>(_: T) where T: C {}
func l<T: C>(_: T) where T: P {}
func m<T: P>(_: T) where T.Assoc: C {}

struct Foo<V> {
func z() {}

func a<T>(x: T) {}
func b<T: P>(x: G<T>, y: T.Assoc) {}
func c<T where T: P>(x: T, y: T.Assoc) {}
func c<T>(x: T, y: T.Assoc) where T: P {}
func d<T: P, U: P & Q>(x: T, y: U) {}
func e<T, U where T: P, U: P, U: Q>(x: T, y: U) {}
func f<T: Q where T.Assoc1 == T.Assoc2>(x: T) {}
func g<T where T: Q, T.Assoc1 == T.Assoc2>(x: T) {}
func h<T: P, U where T.Assoc == U>(x: T) {}
func i<T: P where T.Assoc: Q, T.Assoc.Assoc1 == T.Assoc.Assoc2>(x: T) {}
func e<T, U>(x: T, y: U) where T: P, U: P, U: Q {}
func f<T: Q>(x: T) where T.Assoc1 == T.Assoc2 {}
func g<T>(x: T) where T: Q, T.Assoc1 == T.Assoc2 {}
func h<T: P, U>(x: T) where T.Assoc == U {}
func i<T: P>(x: T) where T.Assoc: Q, T.Assoc.Assoc1 == T.Assoc.Assoc2 {}
func j<T: C>(_: T) {}
func k<T where T: C>(_: T) {}
func l<T: C where T: P>(_: T) {}
func m<T: P where T.Assoc: C>(_: T) {}
func k<T>(_: T) where T: C {}
func l<T: C>(_: T) where T: P {}
func m<T: P>(_: T) where T.Assoc: C {}
}

// Test that we handle interface type lowering when accessing a dependent
Expand Down
Loading