Commit Graph

1710 Commits

Author SHA1 Message Date
Graydon Hoare
66f2027f62 s/Version/PlatformVersion/ to availability specs, add LanguageVersion. 2016-10-12 11:20:42 -07:00
Graydon Hoare
42c1a6ce42 Rename UnconditionalAvailabilityKind and UnavailableInCurrentSwift.
UnconditionalAvailabilityKind => PlatformAgnosticAvailabilityKind
    ::UnavailableInCurrentSwift =>   ::SwiftVersionSpecific

Plus a couple related method renamings. Prep work for SR-2709.
2016-10-12 11:20:41 -07:00
Xi Ge
e5d77911a2 [SourceKit] Indent property getters disregarding of empty bodies. rdar://28049927 (#5246)
[SourceKit] Indentation: when the indented line starts with open brace and the
line before starts with a leading declaration keywords, we never add
indentation level on the brace. rdar://28049927
2016-10-11 19:23:29 -07:00
Rintaro Ishizaki
21513b8916 [Parse] Remove unecessary parameters from parseDeclAttributeList
`InParam` was not used at all.

`StopAtTypeAttributes`
As far as I understand, this option *was* merely for improving diagnostic QoI
for declarations like:
  func foo(@typeattr Arg) {}
to fix-it to:
  func foo(_: @typeattr Arg) {}

But, this causes the very loudy diagnostics for misplaced type attributes.
For example, on:
func foo(@convention(block) x: () -> CInt) {}

test.swift:1:10: error: expected parameter name followed by ':'
test.swift:1:10: error: expected ',' separator
test.swift:1:10: error: expected ')' in parameter
test.swift:1:9: note: to match this opening '('
test.swift:1:10: error: consecutive statements on a line must be separated by ';'
test.swift:1:11: error: attribute can only be applied to types, not declarations
test.swift:1:21: error: expected declaration
test.swift:1:44: error: statement cannot begin with a closure expression
test.swift:1:44: note: explicitly discard the result of the closure by assigning to '_'
test.swift:1:44: error: braced block of statements is an unused closure
test.swift:1:6: error: expected '{' in body of function declaration
test.swift:1:44: error: expression resolves to an unused function

Now, we emit more accurate diagnostic:
test.swift:1:11: error: attribute can only be applied to types, not declarations
func foo(@convention(block) x: () -> CInt) {}
          ^

Note that This causes small regression in diagnostics for bare type parameter
like `func foo(@convention(c) () -> CInt) {}`:

Before:
test.swift:1:10: error: unnamed parameters must be written with the empty name '_'
func foo(@convention(block) () -> CInt) {}
         ^
         _:

Now:
test.swift:1:11: error: attribute can only be applied to types, not declarations
func foo(@convention(block) () -> CInt) {}
          ^
test.swift:1:29: error: unnamed parameters must be written with the empty name '_'
func foo(@convention(block) () -> CInt) {}
                            ^
                            _:
2016-10-11 02:26:13 +09:00
Rintaro Ishizaki
183d4763f1 [QoI][Parse] Improve recovering from unknown attribute
By consuming parens.
As for type attributes, handle `@unknownAttribute(Arg) -> Ret` case.

Improves diagnostic QoI. For example, on:
func foo(x: @unknown(x) Int) {}

Before:
test.swift:1:14: error: unknown attribute 'unknown'
test.swift:1:25: error: expected ',' separator
test.swift:1:25: error: unnamed parameters must be written with the empty name '_'
test.swift:1:22: error: use of undeclared type 'x'

Now, we just emit the first one:
test.swift:1:14: error: unknown attribute 'unknown'
func foo(x: @unknown(x) Int) {}
             ^
2016-10-11 02:26:13 +09: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
Rintaro Ishizaki
e52e043d57 [Parse] Don't use tok::unknown as a dummy token (#5171)
Use tok::NUM_TOKENS instead. tok::unknown can easily appear in source code.

For instance `skipUntil(tok::eof)` did not work as expected, because that was
`skipUntil(tok::eof, tok::unknown)` hence does stop at error tokens such as
`0xG` (invalid hex number literal).

Revert 2abc92bbb5, since that was
accidental side-effect of 45118037cc.
Forward references are not allowed actually.
2016-10-07 14:37:11 +09:00
Rintaro Ishizaki
d07d0da9ae [Parse] Don't propagate static spelling to AST while parsing top level decls
`FuncDecl` of `static func foo() {}` in top level was accidentally
`isStatic()`. That causes assertion failure in `ASTPrinter`.
2016-10-04 02:55:36 +09:00
Slava Pestov
639bc460e8 Parser: Fix a case where we emit multiple in-flight diagnostics 2016-10-02 21:17:43 -04:00
Jacob Bandes-Storch
682ab47c2d [QoI] diagnose operator fixity attrs together; improve messages
Previously, `infix` was not recognized as conflicting with `prefix` and `postfix`. We now offer to remove all but the first fixity attribute.
2016-09-20 20:54:07 -07:00
Doug Gregor
7cb130254d [Scope map/parser/AST] Miscellaneous cleanups to avoid producing invalid source ranges.
The scope map relies fairly deeply on having reasonable source ranges
for AST nodes. Fix the construction and query of source ranges in a
few places throughout the parser and AST to provide stronger
invariants.
2016-09-08 14:27:02 -07:00
Jacob Bandes-Storch
d6590cd781 [QoI] improve diagnostics for operator declarations; unify parsing code 2016-09-04 22:17:29 -07:00
Doug Gregor
4eac3ea2e7 Always create initializer contexts for pattern binding entries in non-local scopes.
We were optimizing away unused pattern binding initializer contexts in
both the parser and in semantic analysis, which led to a
somewhat-unpredictable set of DeclContexts in the AST. Normalize
everything by always creating these contexts.
2016-09-02 10:39:19 -07:00
Doug Gregor
5e25d25c96 [AST] Separate the DeclContexts for different pattern binding entries in a pattern binding decl. 2016-09-02 10:39:19 -07:00
Xi Ge
c29286171f [Parser] Preserve empty getter functions for indentation (#4586)
* [Parser] Preserve empty getter functions to make sure indentation inside its body still works. rdar://28049927

* Using the consistent identifier even though they are identical.
2016-09-01 14:56:23 -07:00
Jordan Rose
e44e0d96e8 [Diag] Make fixItReplace slightly smart
Merge pull request #4499 from rintaro/fixitreplace-smart
2016-08-30 17:57:38 -07:00
Rintaro Ishizaki
b827298892 [CodeCompletion] Modifier related improvements in CompletionOverrideLookup
* If "required" or "convenience" is specified, emit only initializers
* If "final" or "open" is specified, don't emit initializers or typealias
* If "typealias" is specified, emit only associated type implementation
* Emit "override" or "required" modifier for initializers
* Emit access modifier for initializers
* Emit designated initializers even if "override" is specified
* Don't emit inheritance clause for associated type implentation
2016-08-27 03:48:51 +09:00
Rintaro Ishizaki
ba982bc01c [Diag] Make fixItReplace slightly smart
When replace something with a punctuator, we often prefer adding spaces around it.
For instance,

   func foo(): bar {}
   // fix it
   func foo() -> bar {}

In this case we want to add a space before '->', but not after that.

With this change, we can simply `fixItReplace(ColonLoc, " -> ")`.
`fixItReplace()` automatically adjust the spaces around it.
2016-08-25 13:51:55 +09:00
Ben Langmuir
223060f2af Merge pull request #4227 from rintaro/parsedecl-poundif
[SR-702][Parse] Disallow attributes before '#if'
2016-08-24 15:45:46 -07:00
Doug Gregor
68c3f3b1b3 Remove EnableSwift3Private staging option. 2016-08-19 21:53:32 -07:00
Doug Gregor
eb3ba78d94 Remove the swift3_migration attribute.
This attribute was a (my) bad idea that we ended up not using. Kill it.
2016-08-19 14:04:06 -07:00
Rintaro Ishizaki
ed8f901e5b [Parse] Improve fix-it for @autoclosure(escaping)
func f(x: @autoclosure(escaping) () -> Int) {}

used to be fixed as:

  func f(x: @@autoclosure @escaping  () -> Int) {}

Duplicated '@'
Unnecessary space after @escaping
2016-08-19 16:58:51 +09:00
Rintaro Ishizaki
131520e4e5 [Parse] Add TODO: we could emit better diagnostic for #if right after attributes 2016-08-16 17:55:32 +09:00
Rintaro Ishizaki
7af64b3ee3 [Parse] Disallow attributes before #sourceLocation and #line 2016-08-16 17:55:31 +09:00
Rintaro Ishizaki
0bfa734c6a [Parse][SR-702] Disallow attributes before #if 2016-08-16 17:55:31 +09:00
Jordan Rose
3d005f3ad9 [Parse] Add fix-its for empty Swift 2 operator decl braces. (#4309)
And improve the error message for non-empty braces; if we're going to
ignore the contents, we should at least point you in the right
direction for Swift 3.

rdar://problem/27576922
2016-08-15 14:43:09 -07:00
Michael Ilseman
045bc16b6d Merge pull request #4031 from milseman/noescape_by_default
noescape by default: deprecate @noescape and @autoclosure(escaping)
2016-08-05 13:25:00 -07:00
John McCall
7ad3e838ba Fix the source ranges of ill-formed precedence groups.
rdar://problem/27662943
2016-08-05 12:15:57 -07:00
Michael Ilseman
8c3b582793 [noescape by default] Incorporate Slav's feedback 2016-08-05 11:16:48 -07:00
Michael Ilseman
caa9d67469 [noescape by default] Emit deprecation warning/fixit for @noescape
@noescape is now the default behavior, so deprecate it and offer a
fixit.
2016-08-04 16:28:43 -07:00
Michael Ilseman
9e9a1b96c9 [noescape by default] Add @autoclosure @escaping syntax
Adds the preferred syntax for escaping autoclosures, which is
@autoclosure @escaping. Deprecates @autoclosure(escaping), and
provides fixits.
2016-08-04 15:27:34 -07:00
John McCall
afdda3d107 Implement SE-0117.
One minor revision: this lifts the proposed restriction against
overriding a non-open method with an open one.  On reflection,
that was inconsistent with the existing rule permitting non-public
methods to be overridden with public ones.  The restriction on
subclassing a non-open class with an open class remains, and is
in fact consistent with the existing access rule.
2016-08-02 07:46:38 -07:00
Jordan Rose
043c2e0c71 [Parse] Parse SE-0117's contextual 'open' keyword. (#3875)
This will allow us to start writing 'open' in downstream projects
while John finishes the implementation. (This patch is extracted from
his full WIP.)
2016-07-29 20:15:18 -07:00
John McCall
c8c41b385c Implement SE-0077: precedence group declarations.
What I've implemented here deviates from the current proposal text
in the following ways:

- I had to introduce a FunctionArrowPrecedence to capture the parsing
  of -> in expression contexts.

- I found it convenient to continue to model the assignment property
  explicitly.

- The comparison and casting operators have historically been
  non-associative; I have chosen to preserve that, since I don't
  think this proposal intended to change it.

- This uses the precedence group names and higherThan/lowerThan
  as agreed in discussion.
2016-07-26 14:04:57 -07:00
Slava Pestov
9a32575cbf Merge pull request #3738 from slavapestov/remove-protocol-typealias-flag
Remove -enable-protocol-typealiases staging flag
2016-07-26 11:41:49 -07:00
David Farler
7bfaeb57f1 [SE-0081] Warn on deprecated where clause inside angle brackets
and provide a fix-it to move it to the new location as referenced
in SE-0081.

Fix up a few stray places in the standard library that is still using
the old syntax.

Update any ./test files that aren't expecting the new warning/fix-it
in -verify mode.

While investigating what I thought was a new crash due to this new
diagnostic, I discovered two sources of quite a few compiler crashers
related to unterminated generic parameter lists, where the right
angle bracket source location was getting unconditionally set to
the current token, even though it wasn't actually a '>'.
2016-07-26 01:41:10 -07:00
Slava Pestov
1ae8e37058 Remove -enable-protocol-typealiases staging flag
It looks like migration fixits are done, and this doesn't
expose any new bugs that were not possible before, because
you could already define typealiases inside protocol
extensions.

To prevent some compiler_crasher regressions, add a simple
circularity-breaking hack. I'll need to do a sweep to clean
these up some day soon.
2016-07-25 23:18:49 -07:00
Jordan Rose
94a47a261a Put new private/fileprivate behavior behind a LangOptions flag.
If things don't seem to be working out, we can turn it back off,
leaving 'private' and 'fileprivate' interchangeable for compatibility.
2016-07-25 13:13:35 -07:00
Jordan Rose
508e825ff2 Split 'fileprivate' and 'private', but give them the same behavior.
'fileprivate' is considered a broader level of access than 'private',
but for now both of them are still available to the entire file. This
is intended as a migration aid.

One interesting fallout of the "access scope" model described in
758cf64 is that something declared 'private' at file scope is actually
treated as 'fileprivate' for diagnostic purposes. This is something
we can fix later, once the full model is in place. (It's not really
/wrong/ in that they have identical behavior, but diagnostics still
shouldn't refer to a type explicitly declared 'private' as
'fileprivate'.)

As a note, ValueDecl::getEffectiveAccess will always return 'FilePrivate'
rather than 'Private'; for purposes of optimization and code generation,
we should never try to distinguish these two cases.

This should have essentially no effect on code that's /not/ using
'fileprivate' other than altered diagnostics.

Progress on SE-0025 ('fileprivate' and 'private')
2016-07-25 13:13:35 -07:00
Joe
67dccb283e [SE-0095] Code feedback changes; Any is parsed as a keyword
- Any is made into a keyword which is always resolved into a TypeExpr,
allowing the removal of the type system code to find TheAnyType before
an unconstrained lookup.
- Types called `Any` can be declared, they are looked up as any other
identifier is
- Renaming/redefining behaviour of source loc methods on
ProtocolCompositionTypeRepr. Added a createEmptyComposition static
method too.
- Code highlighting treats Any as a type
- simplifyTypeExpr also does not rely on source to get operator name.
- Any is now handled properly in canParseType() which was causing
generic param lists containing ‘Any’ to fail
- The import objc id as Any work has been relying on getting a decl for
the Any type. I fix up the clang importer to use Context.TheAnyType
(instead of getAnyDecl()->getDeclaredType()). When importing the id
typedef, we create a typealias to Any and declare it unavaliable.
2016-07-19 12:01:37 -07:00
Joe
7b9e5de7b7 [SE-0095] simplifyTypeExpr for composition expressions
Also adds:
- Any is caught before doing an unconstrained lookup, and the
protocol<> type is emitted
- composition expressions can be handled by
`PreCheckExpression::simplifyTypeExpr` to so you can do lookups like (P
& Q).self
- Fixits corrected & new tests added
- Typeref lowering cases should have been optional
- This fixes a failing test case.
2016-07-19 12:01:37 -07:00
Joe
a6dad0091b [SE-0095] Initial parsing implementation for '&' composition syntax
This commit defines the ‘Any’ keyword, implements parsing for composing
types with an infix ‘&’, and provides a fixit to convert ‘protocol<>’

- Updated tests & stdlib for new composition syntax
- Provide errors when compositions used in inheritance.
Any is treated as a contextual keyword. The name ‘Any’
is used emit the empty composition type. We have to
stop user declaring top level types spelled ‘Any’ too.
2016-07-19 12:01:02 -07:00
Doug Gregor
80f0852504 [SE-0091] Allow 'static' operators to be declared within types and extensions thereof.
Allow 'static' (or, in classes, final 'class') operators to be
declared within types and extensions thereof. Within protocols,
require operators to be marked 'static'. Use a warning with a Fix-It
to stage this in, so we don't break the world's code.

Protocol conformance checking already seems to work, so add some tests
for that. Update a pile of tests and the standard library to include
the required 'static' keywords.

There is an amusing name-mangling change here. Global operators were
getting marked as 'static' (for silly reasons), so their mangled names
had the 'Z' modifier for static methods, even though this doesn't make
sense. Now, operators within types and extensions need to be 'static'
as written.
2016-07-18 23:18:57 -07:00
Robert Widmann
a77539aa38 Merge pull request #3425 from tanadeau/sr-1952-add-escaping-parsing
[WIP][Parser][SR-1952] Added @escaping attribute parsing
2016-07-15 15:30:14 -07:00
Robert Widmann
f97e5dcb0e [SE-0115][1/2] Rename *LiteralConvertible protocols to ExpressibleBy*Literal. This
change includes both the necessary protocol updates and the deprecation
warnings
suitable for migration.  A future patch will remove the renamings and
make this
a hard error.
2016-07-12 15:25:24 -07:00
Trent Nadeau
6ef59c09e5 Added @escaping attribute parsing 2016-07-08 21:14:39 -04:00
Jordan Rose
aee92ff612 SE-0025: Parsing and basic completion for 'fileprivate'. (#3391)
Right now 'fileprivate' is parsed as an alias for 'private' (or
perhaps vice versa, since the semantics of 'private' haven't changed
yet). This allows us to migrate code to 'fileprivate' without waiting
for the full implementation.
2016-07-07 15:20:41 -07:00
Jordan Rose
396c9f23b4 [Parse] Stop ignoring private decls for incremental purposes. (#3352)
We'd really like to say that private decls can't affect other files,
but we don't have enough information at parse-time:

- Private members of non-private classes still show up in vtables,
  which affects subclasses and callers in other files.

- Private stored properties of non-private structs change the
  layout of the struct.

- Private types may be used in private stored properties, affecting
  the layout of the containing struct.

- Private decls of /any kind/ can be used as the initial value of a
  stored property without an explicit type.

    private class Evil {
      class func defaultAlignment() -> Alignment { return .evil }
    }
    public struct Character {
      // Inferred type here!
      private var alignment = Evil.defaultAlignment()
    }

To be safe and correct, go back to only ignoring method bodies.

https://bugs.swift.org/browse/SR-1030
2016-07-06 12:32:06 -07:00
Slava Pestov
5a902935e8 Sema: Explicitly set interface type on all AbstractFunctionDecls
Previously getInterfaceType() would punt to getType() if no
interface type was set. This patch changes getInterfaceType()
to assert if no interface type is set, and updates various
places to set the interface type explicitly.

This brings us a step closer to removing PolymorphicFunctionType.
2016-07-05 00:24:28 -07:00
Chris Lattner
1b2da8c084 Remove the #setline directive, which was formerly known as #line and is now
known as #sourceLocation.  #setline was an intermediate but never endorsed state.

Upgrade the migration diagnostics for SE-0066 and SE-0049 to be errors instead of warnings.
2016-07-02 16:34:19 -07:00