Commit Graph

1224 Commits

Author SHA1 Message Date
Joe Groff
fc23781906 Sema: First pass at type-checking Swift key paths.
TODO:

- Select the KeyPath subclass corresponding to the write capability of the key path components
- Figure out an issue with unresolved solutions being chosen with contextually-typed keypaths
- Diagnostic QoI
2017-04-04 11:31:15 -07:00
Joe Groff
e3046d6f75 Parsing for native keypaths.
Use `#keyPath2` as a stand-in for the final syntax.
2017-04-04 11:31:15 -07:00
Joe Groff
a5ca6ccd61 Restructure KeyPathExpr to allow more kinds of components.
Expand the representation in anticipation of more kinds of components. NFC intended yet.
2017-04-04 11:31:15 -07:00
Joe Groff
eb5d006e40 Rename ObjCKeyPathExpr -> KeyPathExpr.
We can use the same general shape of expression for native key paths.
2017-04-04 11:31:15 -07:00
Huon Wilson
49277e4e05 [Parser] Don't warn about unescaping the _ in foo(_: 3).
foo(_: 3) is equivalent to foo(3), so calling a function that has _ as
an argument label (func foo(`_`: 3)) still requires the _ to be
escaped. Before this patch, the compiler would suggest removing the `s,
even though that changes behaviour.

Fixes rdar://problem/31077797.
2017-03-21 15:28:11 -07:00
David Farler
3645736ac0 Merge pull request #7393 from bitjammer/syntax-tree
Start the Syntax structured editing library
2017-02-17 15:26:00 -08:00
David Farler
7ee42994c8 Start the Syntax library and optional full token lexing
Add an option to the lexer to go back and get a list of "full"
tokens, which include their leading and trailing trivia, which
we can index into from SourceLocs in the current AST.

This starts the Syntax sublibrary, which will support structured
editing APIs. Some skeleton support and basic implementations are
in place for types and generics in the grammar. Yes, it's slightly
redundant with what we have right now. lib/AST conflates syntax
and semantics in the same place(s); this is a first step in changing
that to separate the two concepts for clarity and also to get closer
to incremental parsing and type-checking. The goal is to eventually
extract all of the syntactic information from lib/AST and change that
to be more of a semantic/symbolic model.

Stub out a Semantics manager. This ought to eventually be used as a hub
for encapsulating lazily computed semantic information for syntax nodes.
For the time being, it can serve as a temporary place for mapping from
Syntax nodes to semantically full lib/AST nodes.

This is still in a molten state - don't get too close, wear appropriate
proximity suits, etc.
2017-02-17 12:57:04 -08:00
Rintaro Ishizaki
1d499546eb [Parse] Don't construct DeclRefExpr in #if conditions (#7522)
This code should compile:

  func foo(FOO: Int, swift: String, Linux: Bool) {
  #if FOO && swift(>=3.0) && os(Linux)
    // do something
  #endif
  }
2017-02-17 12:41:42 +09:00
practicalswift
45c3111d19 Avoid potential dereference of a null pointer 2017-02-15 09:27:20 +01:00
Hugh Bellamy
f001b7562b Use relatively new LLVM_FALLLTHROUGH instead of our own SWIFT_FALLTHROUGH 2017-02-12 10:47:03 +07:00
Jacob Bandes-Storch
e1fd8aa6c7 [Parse] Fix crash in conditional compilation parsing (#7331) 2017-02-08 23:10:26 -08:00
Jacob Bandes-Storch
c98e515734 [QoI] Improvements to function call & closure diagnostics (#7224) 2017-02-07 17:36:11 -08:00
Jacob Bandes-Storch
d2831da80b [QoI] typo correction for anonymous closure params (#7255) 2017-02-07 11:12:34 -08:00
Jacob Bandes-Storch
3e7e923e6d [Parse] Reject trailing closures on literals (#7202)
`1 { }` was parsed as a call expression with a trailing closure. This made the diagnostics for `var x = 1 { get { ... } }` extremely bad. Resolves SR-3671.
2017-02-02 10:32:47 -08:00
Rintaro Ishizaki
abeaaeb42f [Parse] Fix potential crasher regarding EndLoc of erroneous 'type(of:)' expr 2017-02-02 17:13:14 +09:00
Rintaro Ishizaki
5a92f5ed4b [Parse] Dead code elimination
These conditional branches are unreachable.
2017-02-02 17:08:53 +09:00
Rintaro Ishizaki
590ac72316 [Parse] Parse subscript with '#' expressions
Fixes: https://bugs.swift.org/browse/SR-3439
2017-01-27 19:59:55 +09:00
Rintaro Ishizaki
c92dbe5319 [Parse] Remove declaration list specific logic from parseList() 2017-01-17 17:19:36 +09:00
Slava Pestov
48ef1ad00d Merge pull request #5721 from rintaro/parse-functy
[Parse] Minor code improvement in function-type parsing
2017-01-12 19:22:34 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Robert Widmann
96f2a04f55 Merge pull request #6490 from modocache/ast
[SR-2757][Sema] Mark VarDecl in capture lists
2017-01-05 21:36:16 -07:00
Joe Groff
796df2dc44 Merge pull request #6429 from jckarter/type-of-by-overload-resolution
`withoutActuallyEscaping`
2017-01-03 18:47:29 -08:00
Robert Widmann
e36b52c25d Resolve some compiler crashers
Crashers fixed are minor logic errors:

Patterns: Crash occurred when requesting the range of a created
Pattern.  Validity of the range should be checked before returning it
to keep the entire range valid or invalid but never both.

ParseExpr/ParsePattern: The same fixes as the ones provided in #6319

CSDiag: The generic visitor needn’t look through TypeVarTypes either.
2017-01-03 18:53:06 -07:00
Brian Gesiak
4108e1d9af [Sema] Mark VarDecl in capture lists
Fixes SR-2757.

Variables in capture lists are treated as 'let' constants, which can
result in misleading, incorrect diagnostics. Mark them as such in order
to produce better diagnostics, by adding an extra parameter to the
VarDecl initializer.

Alternatively, these variables could be marked as implicit, but that
results in other diagnostic problems: capture list variables that are
never used produce warnings, but these warnings aren't normally emitted for
implicit variables. Other assertions in the compiler also misfire when
these variables are treated as implicit.

Another alternative would be to walk up the AST and determine whether
the `VarDecl`, but there doesn't appear to be a way to do so.
2017-01-01 12:41:06 -05:00
Joe Groff
1889fde228 Resolve type(of:) by overload resolution rather than parse hackery.
`type(of:)` has behavior whose type isn't directly representable in Swift's type system, since it produces both concrete and existential metatypes. In Swift 3 we put in a parser hack to turn `type(of: <expr>)` into a DynamicTypeExpr, but this effectively made `type(of:)` a reserved name. It's a bit more principled to put `Swift.type(of:)` on the same level as other declarations, even with its special-case type system behavior, and we can do this by special-casing the type system we produce during overload resolution if `Swift.type(of:)` shows up in an overload set. This also lays groundwork for handling other declarations we want to ostensibly behave like normal declarations but with otherwise inexpressible types, viz. `withoutActuallyEscaping` from SE-0110.
2016-12-22 16:28:31 -08:00
practicalswift
b253b21014 [gardening] Make sure argument names in comments match the actual parameter names 2016-12-21 22:56:01 +01:00
practicalswift
38be6125e5 [gardening] C++ gardening: Terminate namespaces, fix argument names, ...
Changes:
* Terminate all namespaces with the correct closing comment.
* Make sure argument names in comments match the corresponding parameter name.
* Remove redundant get() calls on smart pointers.
* Prefer using "override" or "final" instead of "virtual". Remove "virtual" where appropriate.
2016-12-17 00:32:42 +01:00
Robert Widmann
443bc682f6 Actually improve recovery when parsing bogus expressions
The crashes fixed appeared at first to be related to IfConfigStmt
parsing, but are in reality symptoms of being too lax in what we accept
when parsing of sub-expressions fail.

Optional type annotation parsing used to propagate failures before it
was patched to ‘recover’ with an AnyPattern.  Instead, we’ll just hit
the error path for parsing in the main expressions because what is here
now isn’t a reasonable thing to return.

#selector parsing assumed that the current token it was at after
consuming up to a right-brace wasn’t bogus.  Instead, if we’ve got
here, we may as well just return a loc we know is valid: PreviousLoc.
2016-12-15 19:08:26 -05:00
Michael Gottesman
59c6a64f5a [gardening] 0 => nullptr. Fixed with clang-tidy. 2016-12-06 23:14:13 -08:00
Argyrios Kyrtzidis
fc678740db [code-completion] Avoid a tentantive parse when in code-completion mode and make sure CodeCompletionExpr has a token range.
The tentantive parse is used for diagnostic purposes but can cause code-completion to delay the same decl twice.
The range of CodeCompletionExpr was previously character range which invalidated invariants of the AST.

Fixes:
	validation-test/IDE/crashers_fixed/084-swift-parser-consumedecl.swift
	validation-test/IDE/crashers_fixed/104-swift-gettypeofcompletioncontextexpr.swift
2016-12-05 17:09:49 -08:00
Rintaro Ishizaki
e4c18ba9ba [Parse] Add fix-it for 'rethrows' in function type 2016-11-30 23:09:38 +09:00
Rintaro Ishizaki
755dadf14d [Parse] Parse attribute as a type expression
Fixes: https://bugs.swift.org/browse/SR-3208

When '@' or 'inout' found in expression context, try to parse it as a type.
So that we can resolve '[(inout Int) -> Void]' as a TypeExpr expression
for ArraySliceType.
2016-11-29 23:30:59 +09:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
David Farler
f450f0ccdf Revert "Preserve whitespace and comments during lexing as Trivia"
This reverts commit d6e2b58382.
2016-11-18 13:23:31 -08:00
David Farler
44f15558d6 Revert "Refactor: Rename Parser::consumeToken, consumeLoc. Add consumeToken API."
This reverts commit 39bfc123a3.
2016-11-18 13:23:31 -08:00
David Farler
39bfc123a3 Refactor: Rename Parser::consumeToken, consumeLoc. Add consumeToken API.
These APIs return SourceLocs, and eventually the Parser should consume
tokens, which now include source trivia such as whitespace and comments,
and package them into a purely syntactic tree.  Just a tiny step. NFC.
2016-11-15 16:11:57 -08:00
David Farler
d6e2b58382 Preserve whitespace and comments during lexing as Trivia
Store leading a trailing "trivia" around a token, such as whitespace,
comments, doc comments, and escaping backticks. These are syntactically
important for preserving formatting when printing ASTs but don't
semantically affect the program.

Tokens take all trailing trivia up to, but not including, the next
newline. This is important to maintain checks that statements without
semicolon separators start on a new line, among other things.

Trivia are now data attached to the ends of tokens, not tokens
themselves.

Create a new Syntax sublibrary for upcoming immutable, persistent,
thread-safe ASTs, which will contain only the syntactic information
about source structure, as well as for generating new source code, and
structural editing. Proactively move swift::Token into there.

Since this patch is getting a bit large, a token fuzzer which checks
for round-trip equivlence with the workflow:

fuzzer => token stream => file1
  => Lexer => token stream => file 2 => diff(file1, file2)

Will arrive in a subsequent commit.

This patch does not change the grammar.
2016-11-15 16:11:57 -08:00
Ben Langmuir
e43a1d35ab [codecompletion] Don't complete global names after var/let
We are expecting a new identifier, and completing global names is not
helpful.  If the editor chooses to automatically provide completions, it
may be actively harmful if we end up inserting a completion here.

rdar://problem/29118428
2016-11-09 13:53:45 -08:00
Rintaro Ishizaki
df0c350cce [Parse] Eliminate unneeded backtracking scope in parsing .dynamicType 2016-10-26 21:30:08 +09:00
Rintaro Ishizaki
c2279d22c8 [Parse] Allow whitespaces before period in superclass-expression (#5423)
Previously:
  error: expected '.' or '[' after 'super'
      super .init()
            ^

There's no reason to reject this while accepting 'self .init()'
2016-10-26 02:52:02 +09:00
Graydon Hoare
1af5c856fa Support #if swift(subminor-version), rdar://problem/28786959 / SR-2908. 2016-10-24 18:12:45 -07:00
Graydon Hoare
77cad91716 Parse and print @available(swift N) / @available(swift, ...) 2016-10-12 11:20:43 -07:00
Graydon Hoare
66f2027f62 s/Version/PlatformVersion/ to availability specs, add LanguageVersion. 2016-10-12 11:20:42 -07:00
Rintaro Ishizaki
f772c40e75 [Parse] Eliminate Parser::canParseAttributes()
`@foo=bar` style attributes are no longer supported anyway.
So as ',' separated attribute list.

In `canParseTypeTupleBody()`, `canParseType()` can more accurately consume
type attributes.

In `isStartOfGetSetAccessor`, we can trivially inline the functionality.
2016-10-11 02:26:13 +09:00
practicalswift
b19481f887 [gardening] Fix 67 recently introduced typos 2016-09-16 11:16:07 +02:00
Rintaro Ishizaki
d75c4c4cbb [gardening][Parse] Remove 2 unused flags in Parser (#4743)
* [Parse] Remove unused GreaterThanIsOperatorRAII. NFC

Last usage was removed in 68af974227.

* [Parse] Remove unused ArgumentIsParameter flag. NFC

Last usage was removed in 4e4173f2e6
2016-09-13 21:54:03 -07:00
Robert Widmann
8d23005cbe Improve fallthrough diagnostics 2016-07-30 13:00:53 -07:00
Robert Widmann
9c83e7223e Fixup diagnostics around type(of:) and dynamicType handling
Be laxer about the parsing for type(of:) so as not to get in the way of
other declarations that may use ‘type’ as their base name.
2016-07-30 03:24:05 -07:00
Robert Widmann
4e5665a8bd [SE-0096] Remove support for dynamicType member 2016-07-30 03:24:05 -07:00
Robert Widmann
80fb5c1c5a Remove usage of getMetatypeLoc() 2016-07-29 16:59:14 -07:00