Commit Graph

805 Commits

Author SHA1 Message Date
Chris Lattner
7faecf021e minor cleanups along the way, NFC.
Swift SVN r24347
2015-01-10 01:58:25 +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
Chris Lattner
54a49cbd85 rearrange code to put simple case + early exit first, NFC.
Swift SVN r24231
2015-01-06 23:44:37 +00:00
Chris Lattner
9414378210 change maintenance of "ParentPattern" in VarDecl to be implicitly handled by PatternBindingDecl itself, instead of having all clients do it.
Swift SVN r23918
2014-12-13 07:35:34 +00:00
Chris Lattner
274310b888 Fix a few VarDecls that are initialized with a PatternBindingDecl but which aren't
getting their ParentPattern set up properly.


Swift SVN r23915
2014-12-13 07:09:30 +00:00
Chris Lattner
11a84793ec Add a new bit to VarDecl to track cases where a vardecl gets an
initializer but has no "parent" PatternBindingDecl or Pattern (i.e.
paramdecls).  This is currently set on decls in the pattern of 
foreach loops and case patterns, but I'll add it to other places I
find as well.

NFC since this bit is only set and not read, just more yak shaving.


Swift SVN r23910
2014-12-13 06:25:14 +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
Denis Vnukov
7b3daab9b3 Fix for rdar://problem/19016271, Fuzzing swift: Swift parser/validator crash.
When BraceStmt is generated to represent missing {...} block it should be marked as 
implicit and be associated with the owning statement.




Swift SVN r23531
2014-11-21 20:35:44 +00:00
Denis Vnukov
448822b1c4 Fixed an issue in IfConfigStmt parsing leading to source ranges verification assertions (rdar://problem/18251200).
The change also includes replacing BraceStmt* reference in IfConfigStmtClause structure with a simple list of clause elements.




Swift SVN r22868
2014-10-21 22:48:20 +00:00
Graham Batty
7676c8240d Add compile time config flag for detecting objc-interop.
Swift SVN r22605
2014-10-08 17:09:34 +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
Dmitri Hrybenko
caabe782e4 Parser: when recovering from an incomplete 'for' statement, don't set the
source location of synthesized AST nodes to point to EOF.  This causes the
source range to span more tokens than the parent node does.

rdar://17630645


Swift SVN r21282
2014-08-19 15:56:52 +00:00
Dmitri Hrybenko
8234c70f88 Code completion: fix delayed parsing of closures
The delayed parsing was in place, but the expressions were being thrown away by
"recovery" in the parser.

rdar://16274593


Swift SVN r20151
2014-07-18 11:43:38 +00:00
Chris Lattner
fe30b66a93 move "override" onto the new fangle decl modifier code, instead of being a virtual
attribute.  As part of this, introduce a new "NotSerialized" flag in Attr.def.
This eliminates a bunch of special case code in the parser and elsewhere for handling
this modifier.



Swift SVN r19997
2014-07-16 01:23:58 +00:00
Doug Gregor
2f3f6acf21 Make "true" and "false" Boolean literal constants for the BooleanLiteralConvertible protocol.
Introduce the new BooleanLiteralConvertible protocol for Boolean
literals. Take "true" and "false" as real keywords (which is most of the
reason for the testsuite churn). Make Bool BooleanLiteralConvertible
and the default Boolean literal type, and ObjCBool
BooleanLiteralConvertible. Fixes <rdar://problem/17405310> and the
recent regression that made ObjCBool not work with true/false.


Swift SVN r19728
2014-07-09 16:57:35 +00:00
Adrian Prantl
400f1774e9 Add support for a #line directive.
This patch extends the syntax with a new #line directive that is inspired
by the homonymous CPP directive. It can be specified in all locations a #if
is legal (Stmt, Decl).

Semantics
---------

#line 42 "file.swift"
This makes diagnostics and debug information behave as if the subsequent
lines came from file.swift+42.

#line // without arguments
This switches back to the main source file and the switches back to the
normal line numbering. Any previous #line directives will result in gaps
in the main file.

Rationale
---------

LLDB and the REPL need this for making expressions that are entered into
the expression evaluator or REPL debugable. For more info see
<rdar://problem/17441710> Need #line directive or something similar so we can enhance the debugging of expressions and REPL

Also, I believe the stdlib would benefit from this and it would allow us
to get rid of the line-directive wrapper script.

Swift SVN r19384
2014-06-30 23:50:11 +00:00
Doug Gregor
461cde049a Teach parseMatchingToken() to set a matched location even when it wasn't matched.
We were working around this in several different places, which was
error-prone (see <rdar://problem/17479771>). This way, we always have
usable left/right delimiter locations.

Swift SVN r19292
2014-06-27 15:17:05 +00:00
Dmitri Hrybenko
71427b241a Parser: don't refer to 'default:' as 'case' in diagnostics
rdar://16846052

Swift SVN r19090
2014-06-23 13:48:14 +00:00
Argyrios Kyrtzidis
24bbc2d0a5 [Parser] Fix infinite loop when there is a syntax error inside an uncovered statement in a switch.
rdar://17303380

Swift SVN r19031
2014-06-20 04:37:15 +00:00
Joe Pamer
a17cec6cb2 Some test and diagnostic cleanup:
- Mine conjunction constraints for constraint failure data. (rdar://problem/16833763)
- Rather than crash, add a diagnostic to signify a missing user constraint. (rdar://problem/16747055) I don't have a deterministic repro for this to include as a test, but users hit it from time to time, I'd like to address this issue holistically, and we're hoping that the new diagnostic will help us collect isolated repros.
- As promised, remove the temporary "compiler_submit_version" build configuration predicate in time for WWDC. (rdar://problem/16380797)

Swift SVN r17705
2014-05-08 18:46:08 +00:00
Chris Lattner
d500e40dc7 Fix <rdar://problem/16843747> Disallow a single semicolon to be used as the only statement within a switch case
go back to disallowing ; in switch statements, people should use break
for empty statements.  It is much more explicit and obvious what you mean.




Swift SVN r17662
2014-05-08 01:08:51 +00:00
Chris Lattner
c24991cff6 Fix <rdar://problem/16798323> Following a 'break' statment by another statement on a new line result in an error/fit-it
Introduce a small amount of whitespace sensitivity into break/continue parsing
so that we don't consider an identifier on the next line to be a label.



Swift SVN r17439
2014-05-05 14:53:57 +00:00
Chris Lattner
92af326a15 generalize consumeIdentifier to work with self and Self. Use it in a few
more places to simplify code.  NFC.


Swift SVN r17438
2014-05-05 14:48:56 +00:00
Argyrios Kyrtzidis
2442d063ef [IDE] Fix syntax annotation crash with #if blocks that are missing an #endif.
rdar://16785562

Swift SVN r17231
2014-05-02 06:12:05 +00:00
Doug Gregor
9cfb1b5ca4 Keep track of the locations of the element names in a TupleExpr.
As part of this, use tail allocation to reduce the memory footprint of
TupleExprs. Use factory methods to make it easier to construct.

I'll be using this information in a follow-on patch. SourceKit
probably wants it as well.


Swift SVN r17129
2014-05-01 00:16:36 +00:00
Chris Lattner
11a79fafb6 tighten up some logic, principly by using dyn_cast instead of dyn_cast_or_null,
NFC.


Swift SVN r16954
2014-04-27 23:42:16 +00:00
Chris Lattner
c2bdc22925 Implement <rdar://problem/16380439> Add support for "#if false" and "#if true"
This implements true and false as magic constants in build configurations.
I considered adding 0 and 1 as magic integers, but true/false fit better with 
our boolean centric model.


Swift SVN r16915
2014-04-27 05:08:27 +00:00
Chris Lattner
0c390777ba Implement <rdar://problem/16204675> Need #elseif
This restructures IfConfigDecl/Stmt to be a list of clauses controlled
by a condition.  This makes it straight-forward to drop in #elseif support.

While I'm in here, this patch moves checking for extraneous stuff at the
end of the #if line from the lexer to the parser.  This means that you can
now put a comment on the same line as a #if/#else/#elseif/#endif.



Swift SVN r16912
2014-04-27 04:51:36 +00:00
Chris Lattner
0a5b27baf4 Implement labeled break/continue support, implementing rdar://11562938.
Right now you can 'break' out of a labeled switch statement, but unlabeled 
break retains its previous semantics of breaking out of the nearest loop.


Swift SVN r16616
2014-04-21 14:38:16 +00:00
Chris Lattner
0e7489c9d5 implement AST support for labels on loops & switch statements. This also
improves location information to track the label location in the AST.  We
don't currently track the location of the colon, but that would be trivial
to drop in if it is interesting.


Swift SVN r16608
2014-04-21 04:56:55 +00:00
Chris Lattner
8a6a9101e2 parser support for labels on loops and switch statements. No AST representation
yet.


Swift SVN r16603
2014-04-21 04:31:15 +00:00
Chris Lattner
b204be71cd simplify Parser::isStartOfStmt: just use the current token instead of having
all of the clients pass in the current token.  NFC.


Swift SVN r16601
2014-04-21 04:01:03 +00:00
Dmitri Hrybenko
f90e0c153b Make 'override' a keyword
rdar://16462192

Swift SVN r16115
2014-04-09 14:19:50 +00:00
Dmitri Hrybenko
a8f85d72bc Allow semicolon can be used as a single no-op statement in otherwise empty cases in
switch statements.

rdar://16381532


Swift SVN r16112
2014-04-09 10:40:48 +00:00
Joe Pamer
7b771affd9 Add limited build configuration support for testing against compiler submit versions. (rdar://problem/16337966)
This is meant to be utilized for a narrow set of scenarios specific to dogfooding our pre-1.0 compiler, so please do not take any dependencies on this.  In fact, I'll be removing this in the next milestone.  (See rdar://problem/16380797.)

Also included - improve error recovery when parsing broken build configuration clauses.

Swift SVN r15694
2014-03-31 20:34:02 +00:00
Joe Pamer
a54848d470 Fix regression when parsing #if clauses without a configuration expression. (rdar://problem/16376781)
Swift SVN r15539
2014-03-27 00:08:50 +00:00
Argyrios Kyrtzidis
f1d14c0911 [Basic/LangOptions] Remove std::unordered_map/unordered_set from LangOptions and use SmallVector instead.
The config options are so few that a map is not worth it currently.

Swift SVN r15476
2014-03-26 00:26:17 +00:00
Argyrios Kyrtzidis
121bf14dd1 [AST] In IfConfigDecl/IfConfigStmt keep track of whether the IfBlock is active or not.
Swift SVN r15444
2014-03-25 03:55:29 +00:00
Argyrios Kyrtzidis
3064e04d47 [Parser] Add the IfConfigDecl/IfConfigStmt ahead of its active members, so we can see it before them, in source order.
Swift SVN r15443
2014-03-25 03:55:28 +00:00
Argyrios Kyrtzidis
8f810a3887 [AST] Add EndLoc to the IfConfigStmt.
Swift SVN r15441
2014-03-25 03:55:26 +00:00
Chris Lattner
1f275532a6 now that nothing uses the PatternBindingDecl::HasStorage bit, there is no
reason to compute it, store it, serialize it, etc.  Remove the associated
logic.



Swift SVN r15302
2014-03-20 22:49:43 +00:00
Dmitri Hrybenko
11fea869c1 Change 'switch' not to fall through between empty cases and always require at
least one statement per case

rdar://16301313


Swift SVN r15266
2014-03-20 11:44:59 +00:00
Dmitri Hrybenko
c5f0a44c60 Parser: don't use EOF as source location for an error expr, AST verifier
rightfully complains about improper source range nesting

<rdar://problem/16276969> Crash in swift::ide::isSourceInputComplete()


Swift SVN r15115
2014-03-16 21:49:47 +00:00
Joe Pamer
3a0363b405 When parsing build configuration blocks, pass the actual BraceItemListKind through, rather than signify whether something is "top level" or not. This allows proper codegen for overloaded operators at the module top-level.
Swift SVN r14611
2014-03-03 21:48:36 +00:00
Joe Pamer
535cb4667c Minor code cleanup for the build configuration implementation.
Swift SVN r14475
2014-02-27 21:19:03 +00:00
Dmitri Hrybenko
56395e1849 Fix a type checker crash on:
func braceStmt3() {
  {
    undefinedIdentifier {}
  }
}

caused by the parser trying to be helpful and unwrapping the closure's
BraceStmt.  Unfortunately, DeclContexts inside the BraceStmt are wrong with
this recovery approach.

Unfortunately, this causes us to produce some extra error messages that the
original recovery strategy tried to avoid.

One thing we could do alternatively without making QoI worse is trying to save
the parser position and trying to reparse with correct assumptions, but that
could slow down the parser, so I did not implement this.


Swift SVN r14456
2014-02-27 10:25:38 +00:00
Chris Lattner
c16db63ae7 switch "val" to "let" in in the ASTPrinter, unbreaking tests.
Produce a warning + fixit for uses of 'val'.


Swift SVN r14435
2014-02-27 00:32:17 +00:00
Chris Lattner
1344319677 Rename the internal compiler lexicon from val -> let.
Swift SVN r14408
2014-02-26 21:21:18 +00:00
Joe Pamer
a0c57f496d Improve error recover for parsing build configuration blocks. Specifically, improve diagnostics for when users try to use #if/#else/#endif blocks in ways that would break brace statement or member list parsing. (Like if they were trying to emulate the C preprocessor.)
Swift SVN r14369
2014-02-26 02:06:29 +00:00