Commit Graph

1012 Commits

Author SHA1 Message Date
Chris Lattner
b170b700f8 move the rest of the state out of Parameter and into ParamDecl,
in prep for Parameter going away.  NFC.
2016-01-01 15:27:53 -08:00
Chris Lattner
5e8c9a3444 Revert "remove the Parameter::isTypeImplicit hack and replace it with something more"
This reverts commit 277a62a0d6.  It broke
the stdlib build, and my attempt to solve it a different way isn't working.
2016-01-01 15:02:00 -08:00
Chris Lattner
4479b46ef0 move the TypeLoc for a parameter out of Parameter and onto ParamDecl. NFC. 2016-01-01 14:13:13 -08:00
Chris Lattner
277a62a0d6 remove the Parameter::isTypeImplicit hack and replace it with something more
principled (NFC).
2016-01-01 13:47:55 -08:00
Chris Lattner
5ce3de8dd6 remove & dial back three old bits of syntax auto-upgrading support:
1. Array type parsing for postfix array types Int[].  We now handle this
   in the parser, but remove the AST representation of this old form.  We
   also stop making vague promises about the future by saying that "fixed
   size arrays aren't supported... yet".  Removal of this fixes a compiler
   crasher too.

2. Remove the special case support for migrating @autoclosure from types
   to parameters, which was Swift 1.0/1.1 syntax.  The world has moved or
   we don't care anymore.

3. Remove upgrade support for # arguments (nee "backtick" arguments), which
   was a Swift 1.x'ism abolished in an effort to simplify method naming
   rules.

NFC on valid code.
2015-12-31 22:29:39 -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
practicalswift
149b50d901 Fix typos in code (non-comment/documentation typos). 2015-12-28 11:42:15 +01:00
Chris Lattner
c5acfa1849 fix <rdar://problem/23952125> QoI: Subscript in protocol with missing {}, better diagnostic please
we used to say:
error: expected '{' for subscripting

we now say:

error: subscript in protocol must have explicit { get } or { get set } specifier

and produce a fixit to insert { get set }
2015-12-22 22:38:19 -08:00
ken0nek
fcd8fcee91 Convert [Cc]an not -> [Cc]annot 2015-12-23 00:55:48 +09:00
Argyrios Kyrtzidis
042efbfb26 [AST] Introduce internal attribute '_migration_id'.
It's intended use is to keep track of stdlib changes for migration purposes.
2015-12-16 21:28:38 -08:00
Chris Lattner
7b323a8460 fix <rdar://problem/19911096> QoI: terrible recovery when using '·' for an operator
This patch improves error recovery for malformed operator declarations,
previously we'd stop parsing the operator decl and try to parse the
body as an expression, hilarity (and a pile of horrible errors) would
ensue.
2015-12-16 15:30:19 -08:00
Jacob Bandes-Storch
1b142ed054 Add missing setIsParseError() during enum case parsing
An invalid `case` construct would incorrectly return a successful status, causing `parseDecl` to crash later when it assumed there were valid decls in the `Entries` vector.
2015-12-13 13:11:22 -08:00
Kanstantsin Linou
e0d240070f Fix typo in ParseDecl.cpp
<code>paramter</code> -> <code>parameter</code>
2015-12-09 16:28:40 +03:00
Xi Ge
d08d37f249 [CodeCompletion] Omit code completion token if it immediately follows imported module names.
Not doing so may lead to concatenating unrelated code completion results on SourceKit. rdar://22847412
2015-12-08 13:18:11 -08:00
Bartosz Przybylski
0e5c7ddfb8 Make c++ defer looks like a swift one 2015-12-04 11:03:39 +01:00
Johan K. Jensen
fa76656c82 Remove instances of duplicated words 2015-12-03 20:00:29 +01:00
Joe Groff
fbd2e4d872 Rename @asmname to @_silgen_name.
This reflects the fact that the attribute's only for compiler-internal use, and isn't really equivalent to C's asm attribute, since it doesn't change the calling convention to be C-compatible.
2015-11-17 14:13:48 -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
Xi Ge
0f881f5ad7 [CodeComplete] Add code completion for Clang sub-modules at import decls. rdar://23244877
e.g. completing at "import Foundation.<HERE>" should give the list of the submodules of Foundation.

Swift SVN r32852
2015-10-24 00:22:25 +00:00
Xi Ge
30c3205c76 [CodeComplete] Adjust the end location of a delayed-parsing var decl. rdar://22981278
Before this commit, for a var decl at top level, code completion engine assumes the code
completion token contained in this decl is the end point of the delayed parsing, i.e. the
second pass of code completion. This may lead to incomplete ASTs during the second pass, for
instance, when the code completion token lies at the second argument of a call expr that takes
three arguments. We fix the issue by allowing the first pass to pre-register the end location of
a top-level var decl since the first pass is a more error-tolerant and holistic parsing, and the second
pass to reuse this loc.

Swift SVN r32729
2015-10-16 20:38:52 +00:00
Doug Gregor
07bec981d8 Introduce FixedTypeRepr to handle those few cases where we need a Type in a TypeRepr.
This TypeRepr should be used sparingly, where we have some fixed type
that cannot otherwise be expressed in the language. It's better than
faking up an IdentTypeRepr.

Swift SVN r32372
2015-10-01 18:30:51 +00:00
Doug Gregor
997caa25d7 Downgrade "unknown platform" error to a warning.
It's rather unfriendly for a platform-portability feature to error
just because it doesn't know about a platform.

Swift SVN r32277
2015-09-28 18:10:02 +00:00
Chris Willmore
538f7847f5 Only ignore private decls at global level.
<rdar://problem/22856386> Changing a private stored property (in a
struct or class) or a private method (in a class) /should/ force other
files to recompile

Swift SVN r32239
2015-09-25 21:16:54 +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
c707382e91 [Parser] Mark parsed getter/setter of lazy vars invalid. rdar://22284278
Swift SVN r31453
2015-08-25 21:16:48 +00:00
Chris Willmore
0e326dbeeb Exclude private decls from interface token hash.
After parsing a private decl, reset the token hash state to what it was
before the decl was parsed. This way, adding a private decl or editing
its type or name will not trigger a rebuild of downstream files.

<rdar://problem/22239821> Modifying private APIs shouldn't cause dependents to recompile

Swift SVN r31358
2015-08-20 03:43:43 +00:00
Chris Lattner
4b96cba12b Fix <rdar://problem/22143680> QoI: terrible diagnostic when trying to form a generic protocol
Swift SVN r31108
2015-08-10 16:50:45 +00:00
Chris Willmore
7f12c9ffd5 [CodeCompletion] Add the initial support for code completing import declaration.
When a user invoke code completion after import keywords, the names of
visible top level clang modules were recommended for finishing the import decl.

(Undoing revert r30961 of r30957, which just required lockstep commit to
SourceKit -- cwillmore)

Swift SVN r30962
2015-08-03 21:08:32 +00:00
Chris Willmore
e4d1ac9c24 Revert "[CodeCompletion] Add the initial support for code completing import declaration."
This reverts r30957 because it broke the following tests on Jenkins:

    SourceKit :: CodeComplete/complete_open.swift
    SourceKit :: CodeComplete/complete_test.swift

<rdar://problem/22120345> swift-incremental-RA #8289 failed to build

Swift SVN r30961
2015-08-03 21:04:46 +00:00
Xi Ge
5e0014bcc4 [CodeCompletion] Add the initial support for code completing import declaration.
When a user invoke code completion after import keywords, the names of
visible top level clang modules were recommended for finishing the import decl.

Swift SVN r30957
2015-08-03 20:02:17 +00:00
Joe Groff
67b8b6f35c Sema: Base lvalue-ness of storage access on whether setter is mutating, not on kind of type.
More progress on rdar://problem/21578832. A property access off of a reference type may still require an lvalue base if it's a protocol extension implementation with a mutating setter. This gets us another step toward correct type-checking behavior, but the resulting AST still improperly loads the base reference, which leads to SILGen breakage.

Swift SVN r30837
2015-07-31 02:42:41 +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
fbb8d3f9a8 Add "interface hash" for improved incremental builds.
Compute the hash of all interface tokens when parsing; write the
interface hash to the swiftdeps file, or if the -dump-interface-hash
option is passed to the frontend. This hash will be used in incremental
mode to determine whether a file's interface has changed, and therefore
whether dependent files need to be rebuilt in response to the change.

Committed on ChrisW's behalf while he gets his setup unborked.

rdar://problem/15352929

Swift SVN r30477
2015-07-22 00:13:54 +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
Slava Pestov
c83cc8ccd6 Parser: Fix a couple of crashes when parsing invalid enum cases
Also make some diagnostic wording more consistent.

Fixes <rdar://problem/19582394>.

Swift SVN r30300
2015-07-17 04:31:03 +00:00
Jordan Rose
7b37043857 Fix some but not all of the errors that had been fixed by the reverted commit.
...and regress a few cases that were previously passing. On the whole I think it's
a win, though.

Swift SVN r30296
2015-07-17 01:57:28 +00:00
Slava Pestov
9fb2080a94 Parser: Fix AST verifier failure with missing braces on struct and enum decls
Looks like classes were alrady doing the right thing.

Once again my fat fingers lead me to fix a compiler_crasher.

Swift SVN r29947
2015-07-07 21:44:59 +00:00
Joe Groff
66ba6827bf Parse the 'indirect' attribute on enums and cases.
Swift SVN r29777
2015-06-28 21:52:59 +00:00
Slava Pestov
67a1f24d59 Sema: 'dynamic' attribute now diagnoses if Foundation is not imported
This prevents us from seeing a less useful error message from SILGen
further down the line.

Also fix a bug where @objc without importing Foundation was not diagnosed
after the first top-level form. Some tests were relying on this behavior,
so fix those tests, either by splitting off the objc parts of the test, or
just by passing the -disable-objc-attr-requires-foundation-module flag.

Fixes <rdar://problem/20660270>.

Swift SVN r29359
2015-06-10 01:18:27 +00:00
Slava Pestov
b7d448efa6 Revert "Sema: 'dynamic' attribute now diagnoses if Foundation is not imported"
This isn't quite ready.

This reverts commit d63e0f69966eef2fa95841f141d06fb25593cb4b.

Swift SVN r29352
2015-06-08 23:16:16 +00:00
Slava Pestov
637a0884f6 Sema: 'dynamic' attribute now diagnoses if Foundation is not imported
This prevents us from seeing a less useful error message from SILGen
further down the line.

Fixes <rdar://problem/20660270>.

Swift SVN r29351
2015-06-08 22:25:39 +00:00
Chris Willmore
52d441ba61 Have a bit per PatternBindingEntry saying whether the corresponding
initializer has been type-checked, rather than a bit for the entire
PatternBindingDecl.

<rdar://problem/21057425> Crash while compiling attached test-app.

Swift SVN r29049
2015-05-27 01:31:28 +00:00
Ben Langmuir
bb78a4dd54 QoI: handling of leading '.' in an enum case declaration
1. Recover the case name for code completion.
2. Provide a specialized diagnostic with a fixit to remove the '.'

Swift SVN r29031
2015-05-26 16:47:29 +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
Devin Coughlin
bf402b3079 Add fix-it to change @availability to @available.
When we parse '@availability', treat it as '@available' and emit a Fix-It to rename.

rdar://problem/20974602

Swift SVN r28771
2015-05-19 09:22:24 +00:00
Devin Coughlin
c9952640bb Support short-form @available attributes.
Allow availability attributes of the form:

  @available(iOS 8.0, OSX 10.10, *)
  func foo() { }

This form is intended for use by third-party developers when annotating their
own declarations and uses the same syntax as #available(). This annotation
says that on iOS foo() is available on version 8.0 and newer; on OSX it is
available on 10.10; and on any other un-mentioned platform it considered
available on the minimum deployment target and greater. Just like with

For now, we support this form during parsing by synthesizing multiple implicit
long-form @available attributes. So, for example, the above annotation will
synthesize two implicit attributes:

  @available(iOS, introduced=8.0)
  @available(OSX, introduced=10.10)
  func foo() { }

Synthesizing attributes in this way is not ideal -- it makes for a poor Fix-It
experience, among other things -- but it exposes the short-form syntax with
minimal invasiveness.

rdar://problem/20938565

Swift SVN r28647
2015-05-15 23:36:11 +00:00
Ted Kremenek
62feb5c949 Change @availability to @available.
This came out of today's language review meeting.
The intent is to match #available with the attribute
that describes availability.

This is a divergence from Objective-C.

Swift SVN r28484
2015-05-12 20:06:13 +00:00
Doug Gregor
340e4d8f8a Simplify parsing and representation of extension declarations.
Now that we don't have generic parameter lists at arbitrary positions
within the extended type of an extension declaration, simplify the
representation of the extended type down to a TypeLoc along with a
(compiler-synthesized) generic parameter list.

On the parsing side, just parse a type for the extended type, rather
than having a special grammar. We still reject anything that is not a
nominal type (of course), but it's simpler just to call it a type.

As a drive-by, fix the crasher when extending a type with module
qualification, rdar://problem/20900870.

Swift SVN r28469
2015-05-12 16:26:13 +00:00