Commit Graph

985 Commits

Author SHA1 Message Date
Ding Ye
3dca923371 Add a fix-it and rephrase some warning messages. 2018-08-31 08:40:19 +10:00
Ding Ye
b790eb5dcf [Parser] Improve diagnostics for special platforms in available attribute.
This patch adds warnings when a version number is used
on the non-specific '*' platform. In addition, it fixes
some misleading warning messages on 'swift' platform.

Resolves: SR-8598.
2018-08-31 08:40:19 +10:00
John Holdsworth
4209b72a66 Delimiter specific diagnostic 2018-08-27 10:15:50 +01:00
John McCall
b80618fc80 Replace materializeForSet with the modify coroutine.
Most of this patch is just removing special cases for materializeForSet
or other fairly mechanical replacements.  Unfortunately, the rest is
still a fairly big change, and not one that can be easily split apart
because of the quite reasonable reliance on metaprogramming throughout
the compiler.  And, of course, there are a bunch of test updates that
have to be sync'ed with the actual change to code-generation.

This is SR-7134.
2018-08-27 03:24:43 -04:00
Robert Widmann
e12fbc2aa2 Reject empty associated value lists
SE-0155 makes an empty associated value list in an enum element
declaration illegal.  Warn about this in legacy Swift mode, and reject
it otherwise.  This offers two fixes:
1) Remove the empty associated value list
2) Insert a 'Void' associated value
2018-08-24 10:50:23 -07:00
Joe Groff
44b55ae197 Runtime support for identity key paths.
Make sure the implementation can handle a key path with zero components by removing inappropriate assumptions that the number of components is always non-empty. Identity key paths also need some special behavior:

- Appending an identity key path should be an identity operation for the other operand
- Identity key paths have a `MemoryLayout.offset(of:)` zero
- Identity key paths interop with KVC as key paths to `@"self"`

To be able to exercise and test this behavior, add a `Builtin.identityKeyPath()` function and `WritableKeyPath._identity` accessor in lieu of finalized syntax.
2018-08-20 14:00:46 -07:00
Huon Wilson
75934be398 [Parse] Fixit for inserting 'if' for 'else ... {' all on one line.
Fixes rdar://problem/33023297.
2018-08-09 20:08:11 +10:00
Doug Gregor
9a9b4af4c7 [Parser] Remove custom diagnostic that relies on AST-level name lookup.
The parser was using an AST-level name lookup operation to provide a
slightly improved diagnostic (suggesting "self." if there was a member
of that name in the enclosing type context). This is a fairly unfortunate
layering violation: name lookup cannot produce correct results at this
point. Remove the custom diagnostic and the lookup; this can come back
when all lookup moves out of the parser.
2018-08-02 09:33:50 -07:00
Rintaro Ishizaki
66d121799d Merge pull request #17789 from rintaro/parse-ifconfig-drop3
[Parse] Drop Swift3 support for conditional compilation condition
2018-07-25 19:36:54 +09:00
Rintaro Ishizaki
5058ec9158 Merge pull request #17787 from rintaro/parse-miscdiag-drop3
[Parse] Drop Swift3 support for misc diagnostics
2018-07-25 19:36:24 +09:00
John McCall
7a4aeed570 Implement generalized accessors using yield-once coroutines.
For now, the accessors have been underscored as `_read` and `_modify`.
I'll prepare an evolution proposal for this feature which should allow
us to remove the underscores or, y'know, rename them to `purple` and
`lettuce`.

`_read` accessors do not make any effort yet to avoid copying the
value being yielded.  I'll work on it in follow-up patches.

Opaque accesses to properties and subscripts defined with `_modify`
accessors will use an inefficient `materializeForSet` pattern that
materializes the value to a temporary instead of accessing it in-place.
That will be fixed by migrating to `modify` over `materializeForSet`,
which is next up after the `read` optimizations.

SIL ownership verification doesn't pass yet for the test cases here
because of a general fault in SILGen where borrows can outlive their
borrowed value due to being cleaned up on the general cleanup stack
when the borrowed value is cleaned up on the formal-access stack.
Michael, Andy, and I discussed various ways to fix this, but it seems
clear to me that it's not in any way specific to coroutine accesses.

rdar://35399664
2018-07-23 18:59:58 -04:00
John McCall
06edd256c2 Generalize the recording of parsed accessors.
As part of this, lift the now-unnecessary restriction against
combining a non-mutable addressor with a setter.  I've also
tweaked some of the diagnostics.

This is in preparation for generalized accessors.
2018-07-20 17:54:57 -04:00
Rintaro Ishizaki
d9746f2067 [Parse] Drop Swift3 support for misc diagnostics
Several diagnostics were warnings in Swift3, but errors in Swift4+

Related: https://github.com/apple/swift/pull/10908
2018-07-07 23:28:36 +09:00
Rintaro Ishizaki
2946597362 [Parse] Drop Swift3 support for conditional compilation condition
In Swift3:
* `#if A is B` were warning
* `#if A(foo:)` were warning
* `#if A || B && C` has different meaning from Swift4+ and was diagnosed with
  migration support fix-it.
2018-07-07 23:27:31 +09:00
John McCall
34b0cbc11d Merge pull request #16237 from davezarzycki/metaprogram_ref_storage_types
[AST] NFC: Enable reference storage type meta-programming
2018-07-05 14:45:38 -04:00
David Zarzycki
8e1c9032b4 [Parse] NFC: Adopt reference storage type meta-programming macros 2018-06-30 06:44:33 -04:00
John McCall
9bee3cac5a Generalize storage implementations to support generalized accessors.
The storage kind has been replaced with three separate "impl kinds",
one for each of the basic access kinds (read, write, and read/write).
This makes it far easier to mix-and-match implementations of different
accessors, as well as subtleties like implementing both a setter
and an independent read/write operation.

AccessStrategy has become a bit more explicit about how exactly the
access should be implemented.  For example, the accessor-based kinds
now carry the exact accessor intended to be used.  Also, I've shifted
responsibilities slightly between AccessStrategy and AccessSemantics
so that AccessSemantics::Ordinary can be used except in the sorts of
semantic-bypasses that accessor synthesis wants.  This requires
knowing the correct DC of the access when computing the access strategy;
the upshot is that SILGenFunction now needs a DC.

Accessor synthesis has been reworked so that only the declarations are
built immediately; body synthesis can be safely delayed out of the main
decl-checking path.  This caused a large number of ramifications,
especially for lazy properties, and greatly inflated the size of this
patch.  That is... really regrettable.  The impetus for changing this
was necessity: I needed to rework accessor synthesis to end its reliance
on distinctions like Stored vs. StoredWithTrivialAccessors, and those
fixes were exposing serious re-entrancy problems, and fixing that... well.
Breaking the fixes apart at this point would be a serious endeavor.
2018-06-30 05:19:03 -04:00
John McCall
9022b5152f Rename accessor kinds from IsGetter -> IsGet, etc.
Introduce some metaprogramming of accessors and generally prepare
for storing less-structured accessor lists.

NFC except for a change to the serialization format.
2018-06-14 17:08:55 -04:00
Robert Widmann
dfe42d2e55 Revert "Reject bad string interpolations (#17074)"
This reverts commit fc23f3404d.
2018-06-13 15:06:33 -07:00
Brent Royal-Gordon
fc23f3404d Reject bad string interpolations (#17074)
* Reject bad string interpolations

String interpolations with multiple comma-separate expressions or argument labels were being incorrectly accepted.

* Tweak error name to match message

* Diagnose empty interpolations more clearly

* Don’t double-diagnose parse errors

Fixes a test at Parse/recovery.swift:799 which the previous commit broke.

* Fix incorrect test RUN: line

A previous version of this test used FileCheck instead of -verify, and the run line wasn’t properly corrected to use -verify.

* Update comment

* Add more argument label tests

Ensures that we don’t get different results from an initializer that doesn’t exist or doesn’t take a String.

* Resolve the SR-7958 crasher test

We now diagnose the error and remove the label before it has an opportunity to crash.
2018-06-12 18:46:52 -07:00
Pavel Yaskevich
6e9d5f533e Merge pull request #17078 from xedin/rdar-40945329
[Sema] Diagnose misplaced InOutExpr in `preCheckExpression`
2018-06-12 11:13:24 -07:00
enomoto
bfff091fa8 Fix error message for a subscript without accessors says "computed property" 2018-06-08 20:45:05 -07:00
Pavel Yaskevich
82025f8e2d [Parse] Don't try to diagnose extraneous & while parsing
Trying to diagnose extraneous use of `&` in parser is too early
and affects some valid cases like patterns in `case` statements,
where we still want to allow use of `&`.
2018-06-08 20:14:45 -07:00
Slava Pestov
7d49370d8e Remove duplicate diagnostic between Parse and Sema 2018-06-06 22:55:01 -07:00
fischertony
d88162f1d3 [Gardening][.def] Add MARK annotations for better nav 2018-05-21 22:50:06 +03:00
Wes Wickwire
3d1bfcb8d1 [SR-7501] corrected the error message to be lowercased (#16703) 2018-05-18 09:12:37 -07:00
Wesley Wickwire
d0c1fd6e72 added suggestion for inlinable misspelling 2018-05-14 23:53:10 -04:00
Slava Pestov
8bf90f21d4 AST: Remove unneeded isDefinition and needsCapture methods from ValueDecl 2018-05-13 22:42:47 -07:00
Kazutaka Homma
cfc91fd7b3 [SR-6996]Better diagnostic when declaring a class inheritance with parentheses (#15010)
add diagnosis for python style inheritance clause
2018-05-07 13:27:08 +09:00
Alex Hoppen
00604fb3dc [libSyntax] Add -verify-syntax-tree frontend flag
This will parse the source file into a libSyntax tree and verify that no
unknown nodes exist within it
2018-04-27 07:51:08 -07:00
Ahmad Alhashemi
1603ec2bee [Parser] Detect nonbreaking space U+00A0 and fixit 2018-04-22 15:54:07 -04:00
Rintaro Ishizaki
e60d75e873 [Parse] Remove unused diagnostics. 2018-04-13 11:58:33 +09:00
Rintaro Ishizaki
07fd8b8a4b [Parse] Handle edge case of '@unknown' for switch case
* Previously, hit assertion if '@unknown' has argument clause
* Diagnose multiple '@unknown' for single 'case'
2018-04-12 01:27:40 +09:00
David Zarzycki
42890e97ef Merge pull request #15597 from davezarzycki/more_TVO_CanBindToInOut_removal
[Sema] NFC: More TVO_CanBindToInOut removal
2018-03-31 16:39:07 -04:00
Slava Pestov
f7697291df Parse: Backward compatibility for old spellings @_inlineable and @_versioned
Just parse these as @inlinable and @versioned, then emit a warning
(Swift 4.2 and below) or error (Swift 5).
2018-03-30 21:55:31 -07:00
David Zarzycki
67710606e6 [Parse] Move tok::amp_prefix closer to parameter list logic
The amp_prefix token is currently tolerated in any unary expression
context and then diagnosed later by Sema. This patch changes parsing to
only accept tok::amp_prefix in its allowed position: parameter lists.

This also fixes two "compiler crasher" tests.
2018-03-30 17:56:36 -04:00
Robert Widmann
03580d2fe5 Add a parameter list to EnumElementDecl
This models, but does not plumb through, default arguments.
2018-03-28 00:05:56 -04:00
Rintaro Ishizaki
c73065e698 Merge pull request #15257 from rintaro/parse-eliminate-square_lit
[Parse] Eliminate {l,r}_square_lit tokens.
2018-03-15 17:39:55 +09:00
Rintaro Ishizaki
0a26e287ba [Parse] Diagnose unknown pound expressions
Implemented diagnostics for `'#' identifier arguments?` at expression
position.
Also, added back diagnostics (and fix-it) for legacy object literals.
2018-03-15 15:36:51 +09:00
Joe Groff
a795b4fc0c SIL: Move responsibility for external keypath equals/hash to the caller.
A public subscript might have generic indexes that aren't unconditionally Hashable, or might use indexes that are retroactively made Hashable, so the property descriptor on the implementer's side can't always resiliently provide this information to the final instantiated KeyPath.
2018-03-14 14:05:49 -07:00
Huon Wilson
e307e54098 [AST] Explicitly track things marked __owned. 2018-03-08 12:36:24 +11:00
swift-ci
68be7927eb Merge pull request #14830 from graydon/typo-fix-plaform-platform 2018-02-26 11:58:21 -08:00
Graydon Hoare
111674acdb [typo] s/plaform/platform/ everywhere. 2018-02-26 09:29:29 -08:00
Joe Groff
d365c153d4 SIL: Introduce sil_property declarations for property descriptors.
This provides SILGen a place to generate the key path component information for an exported property so that it can be linked to from other modules.
2018-02-23 14:57:45 -08:00
Harlan
5e02d2a877 Implement #warning and #error (#14048)
* Implement #warning and #error

* Fix #warning/#error in switch statements

* Fix AST printing for #warning/#error

* Add to test case

* Add extra handling to ParseDeclPoundDiagnostic

* fix dumping

* Consume the right paren even in the failure case

* Diagnose extra tokens on the same line after a diagnostic directive
2018-02-03 18:07:05 -05:00
Xi Ge
71af76a87e libSyntax: optionally emit diagnostics for unknown expressions and declarations. (#13973)
With more syntax nodes being specialized, we'd like this
straight-forward way to pinpoint unknown entities. This diagnostics
is only issued in -emit-syntax frontend action and swift-syntax-test
invocation.
2018-01-16 16:14:57 -08:00
Vedant Kumar
6debe84674 [Coverage] Record PGO function name in SILCoverageMap
This simplifies the lowering of instrprof_increment by getting rid of a
call to llvm::getPGOFuncName().
2018-01-05 17:20:20 -08:00
Rintaro Ishizaki
e7be78b84d [Parse] Skip type specifiers in middle of composition types
Like `P & inout P2`.
Don't bother to construct wrapped TypeRepr for them.
2017-11-30 15:59:35 +09:00
Graydon Hoare
94988a253e [Parse] Add suggestion to targetEnvironment diagnostic. 2017-11-28 15:55:12 -08:00
Graydon Hoare
d31bad45b8 [Parse] Add fixit for targetEnvironment(simulator) 2017-11-28 13:51:01 -08:00