Commit Graph

985 Commits

Author SHA1 Message Date
Argyrios Kyrtzidis
a935e7c13e [Lexer] Recognize editor placeholders as identifiers and provide a specific error when encountered.
Swift SVN r26212
2015-03-17 01:52:59 +00:00
Chris Lattner
27ef444db5 Remove the "isLet" parameter from the pattern parsing logic. It was (almost)
duplicated by the InVarOrLetPattern state in the Parser object.  Beef 
InVarOrLetPattern up so that we can remove it.

NFC except that we now reject pointless let patterns in foreach loops,
similar to how we reject var patterns inside of let patterns.



Swift SVN r26163
2015-03-15 21:06:37 +00:00
Chris Lattner
20f8f09ea8 Land: <rdar://problem/19382905> improve 'if let' to support refutable patterns and untie it from optionals
This changes 'if let' conditions to take general refutable patterns, instead of
taking a irrefutable pattern and implicitly matching against an optional.

Where before you might have written:
  if let x = foo() {

you now need to write:
  if let x? = foo() {
    
The upshot of this is that you can write anything in an 'if let' that you can
write in a 'case let' in a switch statement, which is pretty general.

To aid with migration, this special cases certain really common patterns like
the above (and any other irrefutable cases, like "if let (a,b) = foo()", and
tells you where to insert the ?.  It also special cases type annotations like
"if let x : AnyObject = " since they are no longer allowed.

For transitional purposes, I have intentionally downgraded the most common
diagnostic into a warning instead of an error.  This means that you'll get:

t.swift:26:10: warning: condition requires a refutable pattern match; did you mean to match an optional?
if let a = f() {
       ^
        ?

I think this is important to stage in, because this is a pretty significant
source breaking change and not everyone internally may want to deal with it
at the same time.  I filed 20166013 to remember to upgrade this to an error.

In addition to being a nice user feature, this is a nice cleanup of the guts
of the compiler, since it eliminates the "isConditional()" bit from
PatternBindingDecl, along with the special case logic in the compiler to handle
it (which variously added and removed Optional around these things).




Swift SVN r26150
2015-03-15 07:06:22 +00:00
John McCall
0802e85975 Implement the naked 'do' statement.
For now, we assume that 'while' after the braces starts
a do/while rather than being an independent statement.
We should disambiguate this, or better, remove do/while.

Tests later.

Swift SVN r26079
2015-03-13 01:58:42 +00:00
Chris Lattner
da1dfcd55c implement <rdar://problem/19150249> Allow labeled "break" from an "if" statement
This doesn't allow 'continue' out of an if statement for the same reason we don't
allow it on switch: we'd prefer people to write loops more explicitly.



Swift SVN r25565
2015-02-26 22:32:30 +00:00
Chris Lattner
99aa4352b2 remove upgrading support for the old @class_protocol attribute.
Swift SVN r25526
2015-02-25 02:04:06 +00:00
Chris Lattner
a9e69c0c36 Take a bozooka out to fix <rdar://problem/19932544> refine error for using @autoclosure and @noescape on the same decl
We didn't have a consistent way to utter attributes in diagnostics, sometimes saying the

'foo' attribute is not allowed
@foo attribute is not allowed
'foo' is not allowed
@foo is not allowed

etc.  Standardize on the last one, since it is clear (with the @ sign, with no quotes, with no
'attribute' word in the diagnostic) that we're talking about an attribute.  Move a bunch of
diagnostics inline with this.



Swift SVN r25524
2015-02-25 01:19:04 +00:00
Chris Lattner
02f5c325d4 fix <rdar://problem/19939746> Improve error recovery for malformed if statements
Swift SVN r25511
2015-02-24 20:39:06 +00:00
Chris Lattner
3357ee21f3 Revert r25417, r25408, and r25370. This adds back back the warning for
un-type-annotated AnyObject binding in "if let", and allows general 
patterns in if-let.

This also reverts some unrelated QoI improvements that went in with those
patches, but I'll add those back next.


Swift SVN r25507
2015-02-24 18:55:54 +00:00
Chris Lattner
dc46dd1a5a improve diagnostic and add fixit for if/let pattern error, as recommended by Dmitri.
Swift SVN r25417
2015-02-20 04:49:31 +00:00
Chris Lattner
fee103c42c Reapply two tweaks to if/let handling:
two logically independent but related patches conflated together: 
 - Improve error recovery for malformed if/let conditions, particularly 
   when the user uses "," instead of &&. Add testcases for error recovery 
   requested by Jordan.

- Add a syntactic requirement that the pattern of an if/let condition be 
  a simple identifier or _. We allow slightly broader patterns here now, 
  but they will change in the future when refutable patterns are allowed. 
  It is best to be narrow and then open it up later so we can do a great
  job of QoI then.

This includes the changes to the stdlib directory that I forgot to commit
with the patch the previous time.



Swift SVN r25408
2015-02-20 02:15:25 +00:00
Erik Eckstein
a44814b776 Revert 25371: "[25371] two logically independent but related patches conflated together:"
It broke the stdlib build.



Swift SVN r25372
2015-02-18 17:30:31 +00:00
Chris Lattner
6ad3a975db two logically independent but related patches conflated together:
- Improve error recovery for malformed if/let conditions, particularly
  when the user uses "," instead of &&.  Add testcases for error recovery
  requested by Jordan.

- Add a syntactic requirement that the pattern of an if/let condition be
  a simple identifier or _.  We allow slightly broader patterns here now,
  but they will change in the future when refutable patterns are allowed.
  It is best to be narrow and then open it up later so we can do a great 
  job of QoI then.



Swift SVN r25371
2015-02-18 06:16:06 +00:00
Chris Lattner
3e723974cc Implement support for a leading boolean condition in an if-let condition,
resolving <rdar://problem/19797158> Swift 1.2's "if" has 2 behaviours. They could be unified.



Swift SVN r25369
2015-02-18 04:54:27 +00:00
Chris Lattner
635d46d909 Fix <rdar://problem/19821633> only allow autoclosure on parameters, not on properties and globals
Disallow autoclosure on anything but paramdecls, and provide better QoI when you use them in enums.



Swift SVN r25262
2015-02-13 01:55:56 +00:00
Doug Gregor
954b4e4d83 Implement @autoclosure(escaping).
Addresses rdar://problem/19499207.

Swift SVN r25249
2015-02-12 21:09:47 +00:00
Justin Bogner
59bb06b0fb InstrProf: SIL-level coverage mapping and lowering to LLVM
The adds the sil_coveragemap construct to SIL and the needed IRGen to
turn these into LLVM's coverage maps.

Swift SVN r25210
2015-02-12 00:28:39 +00:00
Jordan Rose
fac5a83bbf Allow capturing super in explicit closures and nested functions.
The previous commit enabled this; now it's just about removing the
restriction in the parser and tightening up code completion.

Using 'super' in a closure where 'self' is captured weak or unowned still
doesn't work; the reference to 'self' within the closure is treated as
strong regardless of how it's declared. Fixing this requires a cascade of
effort, so instead I just cloned rdar://problem/19755221.

rdar://problem/14883824

Swift SVN r25065
2015-02-07 03:56:11 +00:00
Denis Vnukov
6d232296d4 Fix for rdar://problem/19540536, Fuzzing Swift: assertion in parser: Assertion failed: (Tok.getKind() == tok::kw_let || Tok.getKind() == tok::kw_var)
Added an error in c-style for statement parsing for cases when we don’t find ‘var’ or ‘let’ after we parsed declaration attributes.



Swift SVN r24761
2015-01-27 22:20:00 +00:00
John McCall
dc4431ebff Split addressors into unsafe, owning, and pinning variants.
Change all the existing addressors to the unsafe variant.

Update the addressor mangling to include the variant.

The addressor and mutable-addressor may be any of the
variants, independent of the choice for the other.

SILGen and code synthesis for the new variants is still
untested.

Swift SVN r24387
2015-01-13 03:09:16 +00:00
Chris Lattner
763bb6386f Implement parser, AST representation, type checker, etc support for generalized
if-let statements (also while and var, of course) that include multiple bindings
and where clauses.

SILGen support still remains, it currently just asserts on the new constructs.



Swift SVN r24239
2015-01-07 07:03:02 +00:00
Jordan Rose
9b009af3be Tweak accessor diagnostic text, add tests.
rdar://problem/18114964

Swift SVN r24128
2014-12-23 22:43:19 +00:00
Chris Lattner
407bad1445 remove @autoclosure as a type attribute. Recognize it in a parameter
list and produce a nice fixit, so that people using it have an obvious
upgrade path.


Swift SVN r24075
2014-12-22 20:14:56 +00:00
Manman Ren
16cc4dfa65 Revert r23713
Swift SVN r23739
2014-12-05 18:41:27 +00:00
Manman Ren
d0068877f5 [PGO] Add SILMetadata for branch weights.
SILMetadata is the base class with a single enum member (MDKind).
SILBranchNode is the derived class with additional members:
  unsigned NumOperands
  an array of uint32_t

A static member function SILBranchNode::get is implemented to get or create
SILBranchNode. All SILMetadata created are uniqued and saved in SILModule's
member variable:
  llvm::FoldingSet<SILMetadata> Metadatas

Usage of SILMetadta by SILInstruction is captured in SILModule's member variable:
  llvm::DenseMap<const SILInstruction *, SILMetadata *> MetadataStore
This is similar to LLVM's Metadata. Another option is to add a SILMetadata* to
SILInstruction. The disadvantage is the waste of space when we don't have PGO on.

This commit also enables parsing and printing of SILMetadata.

We add keyword sil_metadata to define SILMetadata:
  sil_metadata !0 = {"branch_weights", 3, 5}

For parsing, we add a map in SILModule
  llvm::DenseMap<unsigned, SILMetadata *> NumberedMetadata
that maps from ID to SILMetadata* to help matching usage of "!id" in SILFunction
with definition of "!id" in sil_metadata section.

For printing, we assign IDs to SILMetadata at SILModule scope, we then pass in
an optional argument of
  llvm::DenseMap<const SILMetadata *, unsigned> *MetadataMap
to SILFunction::print in order to get the ID of SILMetadata used in
SILInstruction.

Post-commit review will be appreciated.

rdar://18269754


Swift SVN r23713
2014-12-05 01:47:11 +00:00
Chris Lattner
9a2ae45bd3 Fix <rdar://problem/18819742> QOI: "[strong self]" in capture list generates unhelpful error message
We removed "strong" but never updated a diagnostic.  Update the diagnostic.


Swift SVN r23686
2014-12-04 18:57:51 +00:00
Chris Lattner
440e38f66f fix <rdar://problem/19135222> swift reserves 'new' keyword and doesn't use it
by removing the old fixit code for migrating code away from the obsolete 'new' syntax
for allocating arrays.



Swift SVN r23664
2014-12-03 23:16:45 +00:00
Denis Vnukov
3c4c4f1483 Fix for rdar://problem/18926814 (Fuzzing swift: Swift parser crash).
The issue is reproducible in erroneous code scenario when a string literal
has invalid stuff inside interpolation segment, like: “... \( abc } ) ...”.

In this case we used to do some magic for switching context inside the string 
and parse the interior of \(...) as regular expression list, but expected that 
the parsing finishes at closing “)” which does not necessarily true in case
the code has errors.

The assertion was replaced with an error diagnostics.



Swift SVN r23296
2014-11-13 00:22:23 +00:00
Chris Willmore
ac86dc2ab2 Raise an error on declaring a protocol initializer with default args.
rdar://problem/18637242

Swift SVN r22853
2014-10-20 22:40:48 +00:00
Chris Willmore
e871742deb Fix diagnostic category typo "parseing" -> "parsing".
Swift SVN r22852
2014-10-20 22:40:47 +00:00
Joe Groff
f4518aa1b1 Stop banning optional multidimensional array types.
[[T]]? is unambiguous now.

Swift SVN r22646
2014-10-09 23:24:48 +00:00
Joe Groff
9205bf64cf SIL: Remove enum_is_tag.
Swift SVN r22616
2014-10-09 05:03:43 +00:00
John McCall
88b8254057 Lift the restrictions on addressors so that you can
define properties and subscripts with the
get+mutableAddress combination of accessors.

Fix a couple of simple problems this exposes.

rdar://17270560

Swift SVN r22419
2014-10-01 02:05:23 +00:00
Joe Groff
a89949183d Give opened existential archetypes globally unique identifiers.
This lets us reliably print and parse opened archetypes across different compiler invocations. Using a source-related locator would be ideal, but that's complicated by the need to manufacture, print, and parse these things during SIL passes, so cop out and burn a UUID for now.

Swift SVN r22385
2014-09-30 14:07:31 +00:00
John McCall
fac2c13d95 Don't advertise 'address' and 'mutableAddress' in the
"I expected an accessor here" diagnostic.

Swift SVN r22250
2014-09-24 00:57:01 +00:00
John McCall
a7c65273d5 Parsing and Sema support for addressors.
Swift SVN r22229
2014-09-23 20:34:21 +00:00
Devin Coughlin
d9c10b1915 Extend parsing of #os(...) to allow queries for multiple platforms.
This patch extends the AST and parsing of #os(...) queries to permit queries for
multiple platforms, e.g., #os(OSX >= 10.10, iOS >= 8.0). It also improves
parsing error recovery.


Swift SVN r22154
2014-09-21 01:27:53 +00:00
Devin Coughlin
d33876ec5c Add option to enable experimental API availability checking
Swift SVN r21884
2014-09-11 18:46:56 +00:00
Devin Coughlin
0d7996f4ee Add parsing of availability query expressions (#os(...))
This patch adds a new 'pound_os' token, a new case for it in parseExprPostfix, and parsing of platform version constraints, e.g., OSX >= 10.10. 

It also adds enough type checking and SILGen to get the parsing tests to run without triggering "Unimplemented" assertions.


Swift SVN r21865
2014-09-11 02:59:05 +00:00
Joe Groff
ad78204c50 Parser: Explicitly ban closures at the beginning of statements.
This already can't happen in most circumstances because of trailing closures, but we didn't explicitly disallow it at the beginning of a BraceStmt or following a statement production. Fixes the parser part of rdar://problem/17850752 (though there's a type checker bug there too).

Swift SVN r21663
2014-09-03 00:37:55 +00:00
Dave Abrahams
1676c8d59e Improve clarity/consistency of deinit diagnostics
The old message, "deinitializer does not have a parameter clause," was
confusing because it would be issued for a deinit that clearly *had* a
parameter clause.  Also, one out of three messages called deinitializers
"'deinitializer' functions."  Since "deinitializer" does not appear in
the program text, it doesn't make sense to quote it, either.

Swift SVN r21468
2014-08-27 00:01:15 +00:00
Nadav Rotem
8dd52d63cd Add the @effects(readonly/readnone/readwrite) attribute.
Swift SVN r21070
2014-08-06 18:48:20 +00:00
Doug Gregor
9d5ba31daa Ban __conversion functions.
Swift SVN r21015
2014-08-04 15:54:15 +00:00
Jordan Rose
ddcc1b7698 Parse the @availability attribute in full.
Swift SVN r20843
2014-07-31 18:58:16 +00:00
Chris Lattner
a2beb62f85 fix <rdar://problem/16786168> Functions currently permit 'var inout' parameters
fix <rdar://problem/17867059> ` upgrade logic should be removed




Swift SVN r20817
2014-07-31 06:18:42 +00:00
Chris Lattner
fcb6b3df07 Fix <rdar://problem/17391625> Swift Compiler Crashes when Declaring a Variable and didSet in an Extension
This moves a crude parser check for stored properties in enums & extensions into Sema, and changes it
to be correct (rejecting the case that caused the crash in the radar) as well as more descriptive.



Swift SVN r20695
2014-07-29 21:19:56 +00:00
Chris Lattner
1436c35eb4 now that Beta 5 has branched, we can remove some migration stuff from
what will become beta 6.  This resolves:

<rdar://problem/17662823> Beta 6: remove "operator infix" -> "infix operator" rewrite
<rdar://problem/17670579> Remove @assignment fixit upgrade logic
<rdar://problem/17747208> remove auto_closure upgrade logic after Beta 5 branches



Swift SVN r20629
2014-07-28 16:38:31 +00:00
Chris Lattner
6d0934d33d Introduce a new 'renamed' modifier on unavailable attributes. This allows Xcode
to emit fixit's when we rename something, e.g.:

t.swift:6:9: error: 'float' has been renamed to Float
var y : float
        ^~~~~
        Float

Adopt this in the stdlib.



Swift SVN r20549
2014-07-25 18:00:37 +00:00
Manman Ren
cb8f19dbbe SILParser: add more diagnostics.
Swift SVN r20521
2014-07-24 21:52:58 +00:00
Jordan Rose
3a43d4c72b Revert "SILParser: add diagnostics."
This reverts r20426. It breaks IRGen/witness_method.sil and
SILPasses/performance_inliner.sil.

Swift SVN r20434
2014-07-23 22:29:01 +00:00