Commit Graph

573 Commits

Author SHA1 Message Date
Rintaro Ishizaki
18582d3406 [CodeCompletion] Handle ExprPattern in context type analysis
This improves type inference for code completion in argument position of
EnumElementPattern.
2018-08-09 19:49:25 +09:00
Rintaro Ishizaki
5217b68f08 [Parse] Set ErrorType to invalid ParamDecl
TypeChecker assumes invalid decl has valid type.

https://bugs.swift.org/browse/SR-8475
rdar://problem/43057057
2018-08-09 15:55:33 +09:00
Rintaro Ishizaki
5058ec9158 Merge pull request #17787 from rintaro/parse-miscdiag-drop3
[Parse] Drop Swift3 support for misc diagnostics
2018-07-25 19:36:24 +09:00
Slava Pestov
df9f7f979a Parse: Remove uses of getParameterLists() from default argument parsing 2018-07-22 20:56:56 -07:00
Slava Pestov
bfc4121971 AST: Rework AbstractFunctionDecl construction away from multiple parameter lists
There are two general constructor forms here:

- One took the number of parameter lists, to be filled in later.
  Now, this takes a boolean indicating if there is an implicit
  'self'.

- The other one took the actual parameter lists and filled them
  in right away. This now takes a separate 'self' ParamDecl and
  ParameterList.

Instead of storing the number of parameter lists, an
AbstractFunctionDecl now only needs to store if there is a 'self'
or not.

I've updated most places that construct AbstractFunctionDecls to
properly use these new forms. In the ClangImporter, there is
more code that remains to be untangled, so we continue to build
multiple ParameterLists and unpack them into a ParamDecl and
ParameterList at the last minute.
2018-07-21 07:30:30 -07:00
Slava Pestov
8df02a96c9 Parse: Discard curried parameter lists
We still produce the same diagnostic as before, but don't add the
parameter lists to the function declaration at all. This allows us
to begin assuming that functions either have 1 or 2 parameter lists.
2018-07-19 12:28:26 -07:00
Rintaro Ishizaki
1e0dd7a209 [Parse/Sema] Diagnose invalid attributes for ParamDecl
Previously, invalid attributes were silently accepted and ignored.

https://bugs.swift.org/browse/SR-8202
2018-07-10 20:29:23 +09:00
Rintaro Ishizaki
d9746f2067 [Parse] Drop Swift3 support for misc diagnostics
Several diagnostics were warnings in Swift3, but errors in Swift4+

Related: https://github.com/apple/swift/pull/10908
2018-07-07 23:28:36 +09:00
Slava Pestov
7f9d364bac Parse: Fix crash in error recovery path with specifier before parameter name
We should let Sema set ParamDecl's specifier always, instead of setting
it in the parser in this odd corner case where we're recovering from
'inout' being written before the parameter name.
2018-06-06 22:55:01 -07:00
Robert Widmann
28a8fb1c0b [NFC] Drop mutability from parameter context changes
Refactoring in this area means we no longer mutate the array, just
call non-const members on the elements.
2018-05-24 12:15:14 -07:00
Rintaro Ishizaki
4a247efc0a [Parse] Parse label in tuple type as tok::identifier
Made an utility method 'consumeArgumentLabel', and use it for:
* Labels in tuple type
* Labels in tuple expression
* Argument and parameter names in parameter clause
2018-05-22 13:46:42 +09:00
Rintaro Ishizaki
e60d75e873 [Parse] Remove unused diagnostics. 2018-04-13 11:58:33 +09:00
Rintaro Ishizaki
203496f048 [Parse] Hoist diagnostics for named 'subscript'/'init'
Mainly for code readability.
2018-04-13 11:58:33 +09:00
Robert Widmann
03580d2fe5 Add a parameter list to EnumElementDecl
This models, but does not plumb through, default arguments.
2018-03-28 00:05:56 -04:00
Huon Wilson
e307e54098 [AST] Explicitly track things marked __owned. 2018-03-08 12:36:24 +11:00
Rintaro Ishizaki
2134f9f768 [Parse] Move SyntaxParsingContext to Parse (#14360)
This is only for the Parser.
Also, this resolves layering violation where libAST and libSyntax
depends on each other.
2018-02-03 10:43:52 +09:00
Rintaro Ishizaki
d01f5d1da3 [Syntax] Parse "statement condition" nodes 2017-12-23 12:20:34 +09:00
Rintaro Ishizaki
93a74fea44 [Syntax] Parse "is type pattern" syntax node 2017-12-20 19:59:22 +09:00
Rintaro Ishizaki
89d9993f59 [Syntax] Parse matching pattern syntax node
Added support for ExprPattern and UnresolvedPatternExpr.
2017-12-20 19:47:32 +09:00
Rintaro Ishizaki
bc768b6e0e [Syntax] Parse "value binding pattern" nodes 2017-12-20 18:22:08 +09:00
Rintaro Ishizaki
c379f5c232 [Syntax] Parse wildcard pattern node 2017-12-20 17:33:30 +09:00
Rintaro Ishizaki
a1340fd9a2 [Syntax] Parse tuple pattern node 2017-12-20 17:32:30 +09:00
Xi Ge
e0d167f1dd libSyntax: create syntax nodes for variable declarations.
Variable declarations are declarations led by either 'var' or 'let'. It
can contain multiple pattern bindings as children.

For patterns, this patch only creates syntax nodes for simple identifier
patterns, e.g. 'a = 3'. The rest of the pattern kinds are still left
unknown (UnknownPattern).
2017-12-19 12:25:51 -08:00
Rintaro Ishizaki
e616b2ad37 [Syntax] Use initializer clause syntax node for function parameter (#13430) 2017-12-14 08:12:10 -08:00
Xi Ge
9ddd60d4ef libSyntax: create syntax nodes for closure signature. (#13415)
This patch also refactors the structure of function signature node so
that closure signature can re-use parts of function signature. For
instance, we group arrow and return type to be "ReturnClause". And we
group parenthesized parameter list to be "ParamClause".

This structure of closure signature also calls for a good way to
represent either-or node in libSyntax APIs, since we've two ways to
specify parameters in closure: one is as regular function parameter and
the other is dot-separated simple names.
2017-12-13 16:48:24 -08:00
Xi Ge
7901583833 libSyntax: create parameter list for function signatures without parameters.
If we don't create the empty parameter list, a 0-parameter function declaration
will not be well-formed.
2017-12-08 15:59:59 -08:00
Xi Ge
ec5232a359 libSyntax: support function signature. 2017-12-07 14:38:44 -08:00
Xi Ge
1b24d23c1e libSyntax: support function parameter nodes. (#13324) 2017-12-07 14:09:17 -08:00
Xi Ge
0390d452a6 libSyntax: parse function argument syntax node. (#12803)
This commit teaches parser to parse two libSyntax nodes: FunctionCallArgument and
FunctionCallArgumentList. Along with the change, some libSyntax parsing infrastructure changes
as well: (1) parser doesn't directly insert token into the buffer for libSyntax node creation;
instead, when creating a simple libSyntax node like integer literal expression, parser should indicate the location of the last token in the node; (2) implicit libSyntax nodes like empty
statement list must contain a source location indicating where the implicit nodes should appear
(immediately before the token at the given location).
2017-11-07 15:59:00 -08:00
Slava Pestov
93c80da77c Parse: __shared and __owned should be contextual keywords
This was a source compatibility regression, someone actually had
an identifier named __shared.
2017-10-24 20:45:50 -07:00
Xi Ge
34e2aec662 Parser: use parser to generate a refined token stream to help syntax coloring. (#11809)
This patch allows Parser to generate a refined token stream to satisfy tooling's need. For syntax coloring, token stream from lexer is insufficient because (1) we have contextual keywords like get and set; (2) we may allow keywords to be used as argument labels and names; and (3) we need to split tokens like "==<". In this patch, these refinements are directly fulfilled through parsing without additional heuristics. The refined token vector is optionally saved in SourceFile instance.
2017-09-08 10:28:19 -07:00
Robert Widmann
b77f2c147c Parse Shared
Add parser support for __shared and __owned as type attributes.  Also, extend parser diagnostics and tests to account for the new type attributes.
2017-07-23 21:47:25 -07:00
Huon Wilson
74ea3c12d4 [Parse] Upgrade unlabeled_parameter_following_variadic_parameter to Swift 4 error.
Part of rdar://problem/28961650 .
2017-07-12 13:17:40 -07:00
Robert Widmann
82b13d11ac Merge pull request #10784 from CodaFi/my-sweet-noescape
[SR-5296] @autoclosure and @noescape are not decl attributes
2017-07-06 00:01:21 -07:00
Robert Widmann
ab580a3a0a Remove @autoclosure and @noescape as decl attributes
Using these in declaration position has been deprecated and
removed in Swift 3.  These attributes were not being parsed and
contained deadweight diagnostics that should have been moved
when these attributes became type attributes.
2017-07-05 21:27:04 -07:00
Robert Widmann
4da853e7cb Rename Specifier::None to Specifier::Owned 2017-07-05 14:02:26 -07:00
Robert Widmann
ac5594dabe Use a meaningful representation of parameter specifiers
In anticipation of future attributes, and perhaps the ability to
declare lvalues with specifiers other than 'let' and 'var', expand
the "isLet" bit into a more general "specifier" field.
2017-06-29 16:03:49 -07:00
Robert Widmann
43f29399f3 Remove an old diagnostic for 'var' in param position
Using the attribute in this position is a relic from the Swift 2
days, and fixing it required letting invalid code fall through to
Sema instead of being diagnosed in Parse proper.  Treat 'var'
in this position like 'let' by simply offering to remove it
instead of extracting it into a separate variable.
2017-06-29 13:35:59 -07:00
Pavel Yaskevich
ddaccf88bb [QoI] Properly diagnose closure parameter distructuring after SE-0110
Swift 3 supported limited argument destructuring when it comes to
declaring (trailing) closures. Such behavior has been changed by
SE-0110. This patch aims to provide better error message as well
as fix-it (if structure of the expected and actual arguments matches)
to make the migration easier and disambiguate some of the common
mistakes.

Resolves: SR-4738, SR-4745, rdar://problem/31892961.
2017-05-08 23:04:37 -07:00
Slava Pestov
162b2d252e AST: Include gardening to minimize dependencies on Expr.h
A lot of files transitively include Expr.h, because it was
included from SILInstruction.h, SILLocation.h and SILDeclRef.h.

However in reality most of these files don't do anything
with Exprs, especially not anything in IRGen or the SILOptimizer.

Now we're down to 171 files in the frontend which depend on
Expr.h, which is still a lot but much better than before.
2017-03-12 22:26:56 -07:00
Rintaro Ishizaki
49d134f1a9 [Parse] Stop lying about QuestionLoc of implicit OptionalTypeRepr (#7384)
In conditional statement let/var patterns.
Set invalid location instead.
2017-02-11 13:39:51 +09:00
Slava Pestov
d880053dd5 Merge pull request #7050 from rintaro/parse-diag-consecutiveids
[Parse] Improve diagnostics for consecutive identifiers
2017-01-31 21:19:19 -08:00
Doug Gregor
400684e20a Merge pull request #6823 from matthewcarroll/SR-2475-Warn-when-an-unlabeled-parameter-follows-a-variadic-parameter
[QoI] SR-2475: Warn when an unlabeled parameter follows a variadic parameter
2017-01-30 10:15:05 -08:00
Slava Pestov
d3966d2567 Parse: Fix recursive diagnostic corner-case with invalid UTF8 in source file 2017-01-28 18:35:25 -08:00
Rintaro Ishizaki
9b4f549943 [Parse] Improve diagnostics for consecutive identifiers 2017-01-26 15:37:19 +09:00
Jordan Rose
dec7f9fe7e Merge pull request #6863 from matthewcarroll/SR-3600-Better-recovery-for-naming-an-initializer-deinitializer-or-subscript
[DiagnosticsQoI] SR-3600: Better recovery for trying to name an initializer, deinitializer, or subscript
2017-01-23 16:30:50 -08:00
Matthew Carroll
f8f147ecf9 [DiagnosticsQoI] SR-3600: Better recovery for trying to name an initializer, deinitializer, or subscript
- Restrict this diagnostic to identifiers that are followed by a left paren.
2017-01-21 11:32:09 -05:00
Matthew Carroll
7882ddcf40 [DiagnosticsQoI] SR-3600: Better recovery for trying to name an initializer, deinitializer, or subscript
Add a diagnostic to remove the name of an initializer, deinitializer, or subscript. The identifier token is consumed and skipped to prevent the parser from emitting additional error messages.

Add tests to verify that the name is removed from initializers, deinitializers, and subscripts declared with a name.
2017-01-17 17:21:56 -05:00
Rintaro Ishizaki
c92dbe5319 [Parse] Remove declaration list specific logic from parseList() 2017-01-17 17:19:36 +09:00
Matthew Carroll
33083f0351 [QoI] SR-2475: Warn when an unlabeled parameter follows a variadic parameter
Add a diagnostic that warns when an unlabeled parameter follows a variadic parameter.
https://bugs.swift.org/browse/SR-2475
2017-01-15 16:34:29 -05:00