Commit Graph

784 Commits

Author SHA1 Message Date
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
David Farler
2a0f027317 Review changes for _compiler_version
A couple of small tweaks to _compiler_version based on review comments:
- Fix &&/|| rejection to work with _compiler_version on either side of the
expression. Also add some test cases around this.
- Use clang/LLVM facilities for isdigit and atoi.
- Assert if parsing an invalid version string and there is no diagnostic
engine.
- Clean up some crumbs in the CMake configs.

rdar://problem/22730282

Swift SVN r32212
2015-09-24 22:47:01 +00:00
Xi Ge
c73a4e1509 [CodeComplete] Teach type context analyzer to analyzer for each statement. rdar://22831848
When completing at the sequence position of for each statment (for i in <HRER> {}),
values of sequence type should have higher priority than the rest.

Swift SVN r32202
2015-09-24 17:47:20 +00:00
David Farler
9d373d0fc7 Add _compiler_version build configuration
This configuration clause will suppress lex diagnostics and skip parsing
altogether if the code under the clause isn't active - the compiler must
have a repository version greater than or equal to the version given to
_compiler_version.

This option is only meant to be used sparingly and not to track the
Swift *language* version.

Example, if using a compiler versioned 700.0.28:

  #if _compiler_version("700.0.23")
    print("This code will compile for versions 700.0.23 and later.")
  #else
    This + code + will + not + be + parsed
  #endif

Included are new diagnostics for checking that the version is formatted
correctly and isn't empty.

New tests:
- Compiler version comparison unit tests
- Build configuration diagnostics
- Skipping parsing of code under inactive clauses

rdar://problem/22730282

Swift SVN r32195
2015-09-24 02:14:47 +00:00
Xi Ge
dfc48c8aee [CodeComplete] Add type relation descriptor when completing return statement. rdar://22788321
Swift SVN r32125
2015-09-21 21:18:26 +00:00
Xi Ge
9335511c0d [Parser] Better recovery from parsing errors in RepeatStmt so that indentation works. rdar://22713926
Swift SVN r32053
2015-09-18 00:39:49 +00:00
Xi Ge
e726cf0ee6 [Parser] Return statement should not expect expression when the following token is one of #if, #elseif, #endif and #else. rdar://21729212
Swift SVN r31897
2015-09-11 18:11:13 +00:00
Xi Ge
ef3b45871b [CodeComplete] Complete arguments of call expressions.
When users invoke code completion at an argument position, we suggest argument names,
if required however not specified, or a list of argument values. These values are annotated
with their type relation to the expected argument types, so that
Xcode can prioritize those values that apply over those that do not.
This also fixes: rdar://21727063

Swift SVN r31505
2015-08-26 22:01:25 +00:00
Dmitri Hrybenko
3f7d64c532 Diagnose invalid arguments for '#if _runtime()'
rdar://problem/20117677

Swift SVN r31336
2015-08-19 16:55:39 +00:00
Joe Groff
0b1283b1c9 Have 'defer' statements cons up func decls instead of closure literals.
The defer body func is only ever fully applied, so SILGen can avoid allocating a closure for it if it's declared as a 'func', making it slightly more efficient at -Onone.

Swift SVN r30638
2015-07-25 21:28:06 +00:00
Doug Gregor
f00e5bc6ab Allow a variadic parameter anywhere in the parameter list.
Requiring a variadic parameter to come at the end of the parameter
list is an old restriction that makes no sense nowadays, and which we
had all thought we had already lifted. It made variadic parameters
unusable with trailing closures or defaulted arguments, and made our
new print() design unimplementable.

Remove this restriction, replacing it with a less onerous and slightly
less silly restriction that we not have more than one variadic
parameter in a given parameter clause. Fixes rdar://problem/20127197.

Swift SVN r30542
2015-07-23 18:45:29 +00:00
Jordan Rose
4cdac3fc4c Don't add variables declared in 'guard let' to a SourceFile's Decls.
These variables really are local variables -- they have have a
TopLevelCodeDecl as their DeclContext rather than the SourceFile.
Treating them as global variables caused crashes in serialization.

We need an overhaul of top-level variables in script files anyway
(see rdar://problem/20992489&21628526), but this fixes the immediate
issue.

rdar://problem/21928533

Swift SVN r30519
2015-07-23 00:55:36 +00:00
Xi Ge
c783def2f5 [CodeCompletion] Add code completion for platform names inside #available() condition.
The code for generating the code completion string reuses that of the @available attribute.
rdar://21467109

Swift SVN r30346
2015-07-18 00:10:37 +00:00
Slava Pestov
4e26069c8f Parse: Fix EndLoc of #if without #endif in parseDeclIfConfig(), and clean up duplication
Fixes <rdar://problem/19671208>.

Swift SVN r30314
2015-07-17 08:31:21 +00:00
Chris Lattner
ae4aa79866 fix <rdar://problem/18776073> Swift's break operator in switch should be indicated in errors
Swift SVN r30116
2015-07-11 18:30:51 +00:00
Ben Langmuir
b17da688b2 [CodeCompletion] Avoid crash completing switch case at top-level
We always expect to get a pattern, but in top-level completion we forgot
to build the fallback AnyPattern to go in the error result.

rdar://21661308

Swift SVN r30078
2015-07-10 18:58:09 +00:00
Chris Lattner
b075f810ba Reimplement error recovery in C-style for statement, where we'd turn a ClosureExpr
into the body of the for statement.  Instead of ripping the body of the closureexpr
out and putting it into the C Style for, wrap up the closureExpr into a call.  This
avoids breaking AST invariants because the ClosureExpr will be the DeclContext for
anything inside of it.

This fixes <rdar://problem/21679557> compiler crashes on "for{{"
... which was Practical Swift's shortest crasher.



Swift SVN r29916
2015-07-06 06:19:30 +00:00
Chris Lattner
da4ea30b23 Make the parser handle #if directives better when skipping due to error recovery. Previously,
we would blow past a #endif directive, which leads to bad things later.

this will be tested in a forthcoming testcase.


Swift SVN r29915
2015-07-06 05:28:55 +00:00
Chris Lattner
c03c042ad4 fix <rdar://problem/21392677> for/case/in patterns aren't parsed properly
We weren't keeping track of the fact that we were parsing within a matching
pattern context, so we'd fail some patterns.


Swift SVN r29457
2015-06-17 21:33:32 +00:00
Chris Lattner
8e14bbaaa1 fix <rdar://problem/21110580> guard let in top level code doesn't work
We were just not injecting the vardecls into the SourceFile, so unqual name 
lookup couldn't find them later.


Swift SVN r29456
2015-06-17 20:00:05 +00:00
Jordan Rose
de81a3e15f Prefer using known-identifiers to using getIdentifier.
I didn't add anything to the table, just made use of what was already there.
We have plenty of additional calls to getIdentifier that could probably benefit
from this kind of easy access as well.

This commit also removes FOUNDATION_MODULE_NAME and OBJC_MODULE_NAME from
Strings.h. Neither of these is likely to change in the future, and both
already have KnownIdentifiers equivalents in use.

No intended functionality change.

Swift SVN r29292
2015-06-04 04:01:08 +00:00
Ben Langmuir
4c83738657 Address review feedback on r29070
* Make CHECK-NOT lines more robust
* Remove redundant assertion

Swift SVN r29079
2015-05-27 21:25:10 +00:00
Ben Langmuir
8ccaa86806 [CodeCompletion] Complete variables bound by catch
Make sure we build the CatchStmt and DoCatchStmt AST nodes when
code-completing inside the body of a catch so that we can complete the
bindings from the catch.

It's often a good idea to early-exit once we see a code completion
token, but not when we skip building an AST node that provides variable
bindings.  In code completion, we don't have Scope-based lookup, and
rely on having reachable AST nodes for patterns so that we can dig the
out the bindings we need.

Also extend the pattern checking to handle "IsPattern", since we
apparently weren't handling "let x as Foo", and that affects all complex
catch patterns because of an implicit "as ErrorType" or explicit
"as NSError".

rdar://problem/21116164

Swift SVN r29070
2015-05-27 19:01:16 +00:00
Jordan Rose
0c77785020 [Parser] Explicitly reject "try" before a statement with a specific diagnostic.
And for "try return", "try throw", and "try let", get even more specific,
with a fix-it to suggest moving the "try" onto the expression.

rdar://problem/21043120

Swift SVN r28862
2015-05-21 00:12:36 +00:00
Chris Lattner
258f91f60b revert: r28801 - improve the source location information for { and } in a ClosureExpr.
Instead, provide the location of the { in a closure expr to the argument formation as 
part of the datastructure already used to manage implicit closure arguments in the parser.


Swift SVN r28818
2015-05-20 03:19:56 +00:00