808 Commits

Author SHA1 Message Date
practicalswift
abfecfde17 [gardening] if ([space]…[space]) → if (…), for(…) → for (…), while(…) → while (…), [[space]x, y[space]] → [x, y] 2016-04-04 16:22:11 +02:00
Ben Langmuir
ff895d2f5e [CodeCompletion] Fix completion in string literal interpolation at top-level
Mostly this was just returning the ParserStatus bits that we got from
parseExprList from parseExprStringLiteral. The rest was just cleaning up
places that didn't handle EOF very well, which is important here because
the code completion token is buried in the string literal, so the
primary lexer will walk past it.

rdar://problem/17101944
2016-03-14 23:13:15 -07:00
Chris Lattner
4992474168 Add support for #sourceLocation in its ratified forms. Switch gyb to produce
the new form.  This keeps accepting #setline for now, but we should rip it out
at some point.
2016-03-11 22:21:42 -08:00
Ben Langmuir
19d13c3aee Reapply "[CodeCompletion] Don't show the loop index before it is visible"
With the tests updated to account for not having the correct behaviour
for brace-stmt items from after the code-completion point.  That part
turns out to be harder to fix.

This reverts commit a5325e6281.
2016-03-09 14:02:51 -08:00
Daniel Duan
9b00e35290 [Parser] refactor nested 'init' diagnostics. NFC
Add better comment. Replace a dyn_cast with cast per Jordan's observation.
2016-03-09 10:38:50 -08:00
Ben Langmuir
a5325e6281 Revert "[CodeCompletion] Don't show the loop index before it is visible"
This reverts commit ce77c868d1.
2016-03-07 22:29:00 -08:00
Ben Langmuir
ce77c868d1 [CodeCompletion] Don't show the loop index before it is visible
for i in <here>            // should *not* show 'i'
for i in ...  where <here> // should show 'i'
for i in ... { <here>      // should show 'i'

Part of rdar://problem/24873625
2016-03-07 22:04:49 -08:00
Daniel Duan
ea0a2d3b8d [Parser][Qol] improve diagnostic with missing "self." in init
This improvement was reported in
[SR-852](https://bugs.swift.org/browse/SR-852).

before:

```
$ cat t.swift
class A {
    init(x: Int) {}

    convenience init() { init(x: 1) }
}

$ swiftc -c t.swift
t.swift:6:13: error: initializers may only be declared within a type
    init(x: 1)
        ^
t.swift:6:17: error: expected parameter type following ':'
    init(x: 1)
            ^
t.swift:6:17: error: expected ',' separator
    init(x: 1)
            ^
           ,
t.swift:6:17: error: expected parameter type following ':'
    init(x: 1)
            ^
t.swift:6:17: error: expected ',' separator
    init(x: 1)
            ^
                                                                                                                                                       ,
```

after:

```
t.swift:6:9: error: missing 'self.' at initializer invocation
    init(x: 1)
    ^
    self.
```
2016-03-03 00:11:21 -08:00
Daniel Duan
ba9809c390 [Parser][SE-0034] deprecate line directive in favor of #setline 2016-03-01 16:33:19 -08:00
Adrian Prantl
310b0433a9 Reapply "Serialize debug scope and location info in the SIL assembler language.""
This ireapplies commit 255c52de9f.

Original commit message:

Serialize debug scope and location info in the SIL assembler language.
At the moment it is only possible to test the effects that SIL
optimization passes have on debug information by observing the
effects of a full .swift -> LLVM IR compilation. This change enable us
to write targeted testcases for single SIL optimization passes.

The new syntax is as follows:

 sil-scope-ref ::= 'scope' [0-9]+
 sil-scope ::= 'sil_scope' [0-9]+ '{'
                 sil-loc
                 'parent' scope-parent
                 ('inlined_at' sil-scope-ref )?
               '}'
 scope-parent ::= sil-function-name ':' sil-type
 scope-parent ::= sil-scope-ref
 sil-loc ::= 'loc' string-literal ':' [0-9]+ ':' [0-9]+

Each instruction may have a debug location and a SIL scope reference
at the end.  Debug locations consist of a filename, a line number, and
a column number.  If the debug location is omitted, it defaults to the
location in the SIL source file.  SIL scopes describe the position
inside the lexical scope structure that the Swift expression a SIL
instruction was generated from had originally. SIL scopes also hold
inlining information.

<rdar://problem/22706994>
2016-02-26 13:28:57 -08:00
Adrian Prantl
255c52de9f Revert "Serialize debug scope and location info in the SIL assembler language."
Temporarily reverting while updating the validation test suite.

This reverts commit c9927f66f0.
2016-02-26 11:51:57 -08:00
Adrian Prantl
c9927f66f0 Serialize debug scope and location info in the SIL assembler language.
At the moment it is only possible to test the effects that SIL
optimization passes have on debug information by observing the
effects of a full .swift -> LLVM IR compilation. This change enable us
to write targeted testcases for single SIL optimization passes.

The new syntax is as follows:

 sil-scope-ref ::= 'scope' [0-9]+
 sil-scope ::= 'sil_scope' [0-9]+ '{'
                 sil-loc
                 'parent' scope-parent
                 ('inlined_at' sil-scope-ref )?
               '}'
 scope-parent ::= sil-function-name ':' sil-type
 scope-parent ::= sil-scope-ref
 sil-loc ::= 'loc' string-literal ':' [0-9]+ ':' [0-9]+

Each instruction may have a debug location and a SIL scope reference
at the end.  Debug locations consist of a filename, a line number, and
a column number.  If the debug location is omitted, it defaults to the
location in the SIL source file.  SIL scopes describe the position
inside the lexical scope structure that the Swift expression a SIL
instruction was generated from had originally. SIL scopes also hold
inlining information.

<rdar://problem/22706994>
2016-02-26 10:46:29 -08:00
gregomni
63f810d2fd Variables in 'case' labels with multiple patterns.
Parser now accepts multiple patterns in switch cases that contain variables.
Every pattern must contain the same variable names, but can be in arbitrary
positions. New error for variable that doesn't exist in all patterns.

Sema now checks cases with multiple patterns that each occurence of a variable
name is bound to the same type. New error for unexpected types.

SILGen now shares basic blocks for switch cases that contain multiple
patterns. That BB takes incoming arguments from each applicable pattern match
emission with the specific var decls for the pattern that matched.

Added tests for all three of these, and some simple IDE completion
sanity tests.
2016-02-24 15:46:36 -08:00
Jordan Rose
6272941c5c Rename "build configurations" to "conditional compilation blocks".
...because "build configuration" is already the name of an Xcode feature.

- '#if' et al are "conditional compilation directives".
- The condition is a "conditional compilation expression", or just
  "condition" if it's obvious.
- The predicates are "platform conditions" (including 'swift(>=...)')
- The options set with -D are "custom conditional compilation flags".
  (Thanks, Kevin!)

I left "IfConfigDecl" as is, as well as SourceKit's various "BuildConfig"
settings because some of them are part of the SourceKit request format.
We can change these in follow-up commits, or not.

rdar://problem/19812930
2016-02-12 11:09:26 -08:00
Slava Pestov
bbbe307980 SIL: Introduce SILDefaultWitnessTable and start plumbing
This will be used to help IRGen record protocol requirements
with resilient default implementations in protocol metadata.

To enable testing before all the Sema support is in place, this
patch adds SIL parser, printer and verifier support for default
witness tables.

For now, SILGen emits empty default witness tables for protocol
declarations in resilient modules, and IRGen ignores them when
emitting protocol metadata.
2016-02-05 20:57:11 -08:00
Chris Lattner
8dedfb31e3 Add support for #file/#line, etc according to SE-0028. __FILE__ and friends
are still accepted without deprecation warning as of this patch.
2016-02-04 14:22:22 -08:00
Ben Langmuir
7eaed61b6f [CodeCompletion] Fix completion after unspaced binary operator
We were miscalculating 'isRightBound' when the RHS was a code-completion
token leading to missing completions in unspaced binary expressions
  1+<here>
  1...<here>

rdar://problem/24278699
2016-02-03 18:46:15 -08:00
Chris Lattner
f6bb09aefb Fix comment typo, NFC. 2016-02-02 22:27:11 -08:00
Chris Lattner
0d57fe5b34 Fix <rdar://problem/24467411> QoI: Using "&& #available" should fixit to comma
This tweet: https://twitter.com/radexp/status/694561060230184960 pointed out
the sad truth that most people don't know that stmt-condition can contain
(including a fixit) when they try to use && instead of commas between clauses.

Before:

t.swift:4:16: error: #available may only be used as condition of an 'if', 'guard' or 'while' statement
  if x == y && #available(iOS 9, *) { }
               ^
t.swift:5:27: error: expected '{' after 'if' condition
  if #available(iOS 9, *) && x == y {}
                          ^
t.swift:5:37: error: braced block of statements is an unused closure
  if #available(iOS 9, *) && x == y {}
                                    ^
t.swift:5:37: error: expression resolves to an unused function
  if #available(iOS 9, *) && x == y {}
                                    ^~

After:

t.swift:4:13: error: expected ',' joining parts of a multi-clause condition
  if x == y && #available(iOS 9, *) { }
            ^~
            ,
t.swift:5:27: error: expected ',' joining parts of a multi-clause condition
  if #available(iOS 9, *) && x == y {}
                          ^~
                          ,
2016-02-02 22:20:20 -08:00
David Farler
3f635d04c7 Reinstante var bindings in refutable patterns, except function parameters.
This reverts commits: b96e06da44,
                      8f2fbdc93a,
                      93b6962478,
                      64024118f4,
                      a759ca9141,
                      3434f9642b,
                      9f33429891,
                      47c043e8a6.

This commit leaves 'var' on function parameters as a warning to be
merged into Swift 2.2. For Swift 3, this will be an error, to be
converted in a follow-up.
2016-01-29 15:27:08 -08:00
Doug Gregor
8336419844 Include completion source location information compound DeclNames.
When one spells a compound declaration name in the source (e.g.,
insertSubview(_:aboveSubview:), keep track of the locations of the
base name, parentheses, and argument labels.
2016-01-25 14:13:13 -08:00
David Farler
c32fb8e7b9 SE-0020: Swift Language Version Build Configuration
Introduce a new "swift" build configuration that guards declarations
and statements with a language version - if the current language version
of the compiler is at least that version, the block will parse as normal.
For inactive blocks, the code will not be parsed an no diagnostics will
be emitted there.

Example:

    #if swift(>=2.2)
      print("Active")
    #else
      this code will not parse or emit diagnostics
    #endif

https://github.com/apple/swift-evolution/blob/master/proposals/0020-if-swift-version.md
rdar://problem/19823607
2016-01-21 16:31:19 -08:00
Doug Gregor
ecfde0e71c Start parsing names with argument labels.
Basic implementatation of SE-0021, naming functions with argument
labels. Handle parsing of compound function names in various
unqualified-identifier productions, updating the AST representation of
various expressions from Identifiers to DeclNames. The result doesn't
capture all of the source locations we want; more on that later.

As part of this, remove the parsing code for the "selector-style"
method names, since we now have a replacement. The feature was never
publicized and doesn't make sense in Swift, so zap it outright.
2016-01-20 17:09:01 -08:00
Chris Lattner
d69a1a00d7 Fix <rdar://problem/21080671> QoI: try/catch (instead of do/catch) creates silly diagnostics
People will keep typing try/catch either due to muscle memory from other languages or
when they are first learning swift.  We now produce a nice error message + fixit of:

t.swift:14:3: error: the 'do' keyword is used to specify a 'catch' region
  try {
  ^~~
  do

instead of spewing out:

t.swift:15:4: error: consecutive statements on a line must be separated by ';'
  } catch { }
   ^
   ;
t.swift:15:5: error: expected expression
  } catch { }
    ^
t.swift:15:11: error: braced block of statements is an unused closure
  } catch { }
          ^
t.swift:14:7: error: expression resolves to an unused function
  try {
  ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
t.swift:15:11: error: expression resolves to an unused function
  } catch { }
          ^~~
t.swift:14:3: warning: no calls to throwing functions occur within 'try' expression
  try {
  ^
2016-01-17 15:14:35 -08:00
gregomni
854a76304e Fix diagnosis location for missing while after repeat body
Also cleaned up unnecessary body.isNonNull() check here. The code just
above already constructs a synthetic empty brace stmt for the body if
it didn’t have a real one.
2016-01-15 15:50:39 -08:00
Chris Lattner
8d81349fe1 fix rdar://24029542 "Postfix '.' is reserved" error message" isn't helpful
This adds some heuristics so we can emit a fixit to remove extraneous
whitespace after a . and diagnose the case where a member just hasn't
been written yet better.  This also improves handling of tok::unknown
throughout the parser a bit.

This is a re-commit of ff4ea54 with an update for a SourceKit test.
2016-01-11 15:11:20 -08:00
Erik Eckstein
acc243a002 Revert "fix rdar://24029542 "Postfix '.' is reserved" error message" isn't helpful"
It's probably the cause for the fail of SourceKit/SyntaxMapData/syntaxmap-edit-del.swift

This reverts commit ff4ea54614.
2016-01-11 10:43:39 -08:00
Chris Lattner
ff4ea54614 fix rdar://24029542 "Postfix '.' is reserved" error message" isn't helpful
This adds some heuristics so we can emit a fixit to remove extraneous
whitespace after a . and diagnose the case where a member just hasn't
been written yet better.  This also improves handling of tok::unknown
throughout the parser a bit.
2016-01-10 15:28:03 -08:00
Chris Lattner
a30ae2bf55 Merge pull request #836 from zachpanz88/new-year
Update copyright date
2015-12-31 19:36:14 -08:00
Chris Lattner
7daaa22d93 Completely reimplement/redesign the AST representation of parameters.
Parameters (to methods, initializers, accessors, subscripts, etc) have always been represented
as Pattern's (of a particular sort), stemming from an early design direction that was abandoned.
Being built on top of patterns leads to patterns being overly complicated (e.g. tuple patterns
have to have varargs and default parameters) and make working on parameter lists complicated
and error prone.  This might have been ok in 2015, but there is no way we can live like this in
2016.

Instead of using Patterns, carve out a new ParameterList and Parameter type to represent all the
parameter specific stuff.  This simplifies many things and allows a lot of simplifications.
Unfortunately, I wasn't able to do this very incrementally, so this is a huge patch.  The good
news is that it erases a ton of code, and the technical debt that went with it.  Ignoring test
suite changes, we have:
   77 files changed, 2359 insertions(+), 3221 deletions(-)

This patch also makes a bunch of wierd things dead, but I'll sweep those out in follow-on
patches.

Fixes <rdar://problem/22846558> No code completions in Foo( when Foo has error type
Fixes <rdar://problem/24026538> Slight regression in generated header, which I filed to go with 3a23d75.

Fixes an overloading bug involving default arguments and curried functions (see the diff to
Constraints/diagnostics.swift, which we now correctly accept).

Fixes cases where problems with parameters would get emitted multiple times, e.g. in the
test/Parse/subscripting.swift testcase.

The source range for ParamDecl now includes its type, which permutes some of the IDE / SourceModel tests
(for the better, I think).

Eliminates the bogus "type annotation missing in pattern" error message when a type isn't
specified for a parameter (see test/decl/func/functions.swift).

This now consistently parenthesizes argument lists in function types, which leads to many diffs in the
SILGen tests among others.

This does break the "sibling indentation" test in SourceKit/CodeFormat/indent-sibling.swift, and
I haven't been able to figure it out.  Given that this is experimental functionality anyway,
I'm just XFAILing the test for now.  i'll look at it separately from this mongo diff.
2015-12-31 19:24:46 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Slava Pestov
36ddea64ae Merge pull request #729 from ken0nek/fix-can-not
Convert [Cc]an not -> [Cc]annot
2015-12-22 16:06:20 -08:00
practicalswift
6e3b700b44 Fix typos. 2015-12-23 00:31:13 +01:00
ken0nek
fcd8fcee91 Convert [Cc]an not -> [Cc]annot 2015-12-23 00:55:48 +09:00
Xi Ge
b797871ed2 [CodeCompletion] Add type relation indicators to completion results at the conditions of repeat-while statements.
Boolean expressions should have higher priority at loop conditions.
2015-12-11 15:00:13 -08:00
Johan K. Jensen
fa76656c82 Remove instances of duplicated words 2015-12-03 20:00:29 +01:00
Chris Willmore
e7bdaeace2 Warn about indentation of returned expr in single expression closure.
If the returned expression has the same indentation as the "return"
keyword, warn. This warning already existed but wasn't happening
for single-expression closures. Move emission of the warning from Sema
to Parse.

<rdar://problem/16798323>
2015-11-06 17:17:45 -08:00
Xi Ge
9586337981 [Parser] Allow FuncDecl to record the locations of accessor keywords, e.g. set, get, etc. 2015-11-03 18:13:32 -08:00
David Farler
64024118f4 Make always-immutable pattern bindings a warning for now
These will become errors after the next release branch.

rdar://problem/23172698
2015-11-03 12:46:38 -08:00
Ben Langmuir
04138e2cd0 [CodeCompletion] Add a new StmtOrExpr code completion kind
We want to distinguish keywords that are only valid at
statement/declaration context from those valid in any expression.
2015-11-02 13:27:34 -08:00
Xi Ge
6c983366cc [CodeComplete] Show #available completion only in guard and if statements. rdar://23228191
Swift SVN r32893
2015-10-26 20:54:00 +00:00
David Farler
a759ca9141 Disallow 'var' bindings in case patterns
Make the following illegal:

switch thing {
  case .A(var x):
    modify(x0
}

And provide a replacement 'var' -> 'let' fix-it.

rdar://problem/23172698

Swift SVN r32883
2015-10-25 18:53:02 +00:00
David Farler
3434f9642b Disallow 'var' pattern bindings in if, while, and guard statements
Make the following patterns illegal:

  if var x = ... {
    ...
  }

  guard var x = ... else {
    ...
  }

  while var x = ... {
    ...
  }

And provide a replacement fixit 'var' -> 'let'.

rdar://problem/23172698

Swift SVN r32855
2015-10-24 01:46:30 +00:00
Xi Ge
3f79328949 Put no assumption on argument evaluation order, NFC.
Swift SVN r32849
2015-10-23 20:25:29 +00:00
Xi Ge
afe90ff3c2 [CodeComplete] Suggested by Ben, deliver #available completion after # token and add placeholder to represent platform names.
Swift SVN r32847
2015-10-23 19:49:57 +00:00
David Farler
47c043e8a6 Disallow 'var' specifier in for-in patterns
Don't allow a pattern like:

  for var x in sequence {
    ...
  }

and provide a removal fix-it for the 'var' keyword.

Additionally, for the following code:

  for let x in sequence {
    ...
  }

Provide a removal fix-it since the 'let' specifier is now
redundant.

rdar://problem/23172698

Swift SVN r32818
2015-10-22 00:46:25 +00:00
David Farler
e1a7a0f0ab Refactor CompilerVersion
This is a WIP to make CompilerVersion more general.

- Rename CompilerVersion to just "Version"
- Make version comparison general and put _compiler_version special logic
  with its second version component in a specialized parsing function
- Add a generic version parsing function

Swift SVN r32726
2015-10-16 17:43:28 +00:00
Xi Ge
f9e13626ce [CodeComplete] Delay the processing of code completion tokens to preserve AST. rdar://21491053
Swift SVN r32386
2015-10-01 23:14:56 +00:00
David Farler
a0811a3c09 Put diagnostic caret on arch/os argument, not the function name
If an unknown architecture or operating system argument is provided
to the arch/os build configuration functions, put the warning caret
on the actual argument instead of at the build config names.

rdar://problem/22052176

Swift SVN r32223
2015-09-25 06:05:42 +00:00
David Farler
69b6763797 Emit a warning when using unknown arch/os build configurations
'arch' and 'os' build configurations with valid identifiers as
arguments, but which are unknown to the compiler, will cause the
compiler to silently skip over that code as it has an inactive clause.
Emit a diagnostic, but not an error so as not to inadvertantly break
code that may be in a compiler without knowledge of a particular
operating system or architecture.

rdar://problem/22052176

Swift SVN r32219
2015-09-25 05:24:34 +00:00