Commit Graph

317 Commits

Author SHA1 Message Date
Justin Bogner
0604d88bda InstrProf: Emit the counter for falling out of a do-catch immediately after the body
We were emitting the counter for falling out of a do block at the end
of the entire construct's scope, but this can cause us to miss the
increment if the insertion point isn't valid there. Move the increment
to immediately after we emit the body.

rdar://problem/22346924

Swift SVN r31356
2015-08-20 00:22:51 +00:00
Jordan Rose
76cf1781df [SILGen] Emit all TopLevelCodeDecls in a single scope.
This gets the cleanups right, which is important for the 'locals' that
come from top-level guard statements as well as top-level defer statements.
The former could lead to accessing destroyed memory.

rdar://problem/22064894

Swift SVN r30811
2015-07-30 19:47:54 +00:00
Joe Groff
0b1283b1c9 Have 'defer' statements cons up func decls instead of closure literals.
The defer body func is only ever fully applied, so SILGen can avoid allocating a closure for it if it's declared as a 'func', making it slightly more efficient at -Onone.

Swift SVN r30638
2015-07-25 21:28:06 +00:00
Justin Bogner
80f4156bf4 InstrProf: Fix coverage mapping for GuardStmt
We were creating a coverage mapping for GuardStmt, but we were never
incrementing its counter, so the results were quite strange. This
moves the counter to the body of the guard (instead of the
non-existent "then" clause) and increments the counter in the obvious
place.

rdar://problem/21291670

Swift SVN r29965
2015-07-08 06:13:37 +00:00
Adrian Prantl
760baa4e42 Debug Info: Fix the line table entry generated for the jump out of
a do or do-catch block to point to end of the do body rather than the
location of the "do" keyword.

<rdar://problem/21194177> line table entries for "do" happen after the body of the do is executed

Swift SVN r29239
2015-06-02 18:07:37 +00:00
Chris Lattner
8cdf88cd8c fix <rdar://problem/21088517> throw in an initializer causes bogus error
a false positive (with no location information) when an init immediately throws.


Swift SVN r28965
2015-05-23 16:03:32 +00:00
Slava Pestov
e5f1fcfad6 SILGen: Don't crash on DoCatchStmt with non-throwing body in non-throwing context
Fixes <rdar://problem/20994248>.

Swift SVN r28748
2015-05-19 04:35:50 +00:00
Slava Pestov
14dd0a4221 SILGen: Refactor emitOrDeleteBlock() to take a JumpDest rather than a BB
This allows us to invalidate the JumpDest to ensure it won't point
to a deleted block. NFC

Swift SVN r28747
2015-05-19 04:35:49 +00:00
John McCall
26a9a4d1e5 SILGen for 'rethrows'. WIP; committed to get broader testing
of an assertion.

Swift SVN r28733
2015-05-19 00:54:32 +00:00
Mark Lacey
30c52d15f4 Fix typo.
Noticed browsing code.

Swift SVN r28715
2015-05-18 18:35:51 +00:00
Slava Pestov
3f1f5b8932 Fix a nit
Swift SVN r28694
2015-05-18 00:42:07 +00:00
Slava Pestov
42d7c7251c SILGen: better diagnostic for code after break and throw
Swift SVN r28689
2015-05-18 00:26:19 +00:00
Chris Lattner
e517ad9182 Fix unreachable code handling to properly diagnose things like:
throw x 
whatever()  

as being unreachable after the throw.



Swift SVN r28680
2015-05-17 15:13:35 +00:00
Dmitri Hrybenko
0a1f7c09df Revert "Fix unreachable code handling to properly diagnose things like:"
This reverts commit 28678.  It broke the IDE/complete_exception.swift
test.

Swift SVN r28679
2015-05-17 12:27:57 +00:00
Chris Lattner
5ead9764bd Fix unreachable code handling to properly diagnose things like:
throw x
  whatever()

as being unreachable after the throw.



Swift SVN r28678
2015-05-17 05:56:02 +00:00
Slava Pestov
60eb9780a1 SILGen: fix generation of switch containing try
When emitting try_apply, don't start a new scope between adding
a cleanup and forwarding the value. This would leave behind a
dead cleanup, which would fire an assertion in emitSharedCaseBlocks().

Fixes <rdar://problem/20923654>.

Swift SVN r28572
2015-05-14 17:22:47 +00:00
Slava Pestov
cbbde4739e SILGen: remove dead diagnostics for error handling
Looks like Sema is checking all of this stuff now. NFC

Swift SVN r28571
2015-05-14 17:22:44 +00:00
Chris Lattner
3814b7003f Implement support for arbitrary pattern matching in for-each statements,
which composes straight-forwardly on top of the existing stuff for if/let
and guard.



Swift SVN r28371
2015-05-09 21:34:35 +00:00
Chris Lattner
58b63193d5 Implement support for 'where' clauses on foreach loops, part of
<rdar://problem/14482451> Allow refutable patterns & 'where' in 'for-each' loops




Swift SVN r28338
2015-05-08 23:57:01 +00:00
Chris Lattner
f35677de14 Revise SILGen of foreach loops to only drop the optional generator result value in memory when it is address-only. This leads to better -O0 performance and easier to read silgen output. This is ongoing progress towards rdar://20642198.
This recommits r28318 with a fix that simplifies away a bunch of code and a bug.



Swift SVN r28328
2015-05-08 21:26:56 +00:00
Chris Lattner
5e7a45ff70 revert r28318, it is causing a problem on perftests. I'll investigate after lunch.
Swift SVN r28321
2015-05-08 18:02:24 +00:00
Chris Lattner
f379b1e15b Revise SILGen of foreach loops to only drop the optional generator result value
in memory when it is address-only.  This leads to better -O0 performance and 
easier to read silgen output.  This is ongoing progress towards rdar://20642198.


Swift SVN r28318
2015-05-08 17:46:20 +00:00
Chris Lattner
37f5452d15 require -> guard.
Swift SVN r28223
2015-05-06 22:53:38 +00:00
Adrian Prantl
301aae1492 Promote the "true"-Scope of a condition to an actual lexical scope.
<rdar://problem/20394204> Scoping of if/let declarations too broad

Swift SVN r28203
2015-05-06 16:40:11 +00:00
Chris Lattner
0011b3ae21 rename "unless" to "require" and give it an 'else' keyword.
Swift SVN r28059
2015-05-02 00:16:44 +00:00
Chris Lattner
e2a7ec2f68 implement SILGen support for 'unless'
Swift SVN r27995
2015-04-30 21:07:00 +00:00
Chris Lattner
c6aa041fb9 Add parser/ast/sema/sourcekit/etc support for 'unless' statement.
SILGen support still missing.



Swift SVN r27961
2015-04-30 05:55:11 +00:00
Justin Bogner
569273a507 InstrProf: Add support for the do-catch construct
Add a counter in each catch block and one for the fallthrough out of
the entire do-catch block, and implement the logic to handle these and
throw statements in the coverage mapping.

Swift SVN r27950
2015-04-30 00:11:53 +00:00
Nadav Rotem
3f675c5f06 Emit calls to swift_willThrow only in throw sites (not in re-throw sites).
rdar://20356658

Swift SVN r27891
2015-04-28 23:21:11 +00:00
Chris Lattner
82ef514f99 Reimplement the AST, Sema, and SILGen of defer to be closure based.
Now we bind the defer body into a ClosureExpr and emit it at the point of
the defer.  At any exit points out of the controlled region, we emit a call 
to the closure.

This should cover any problems where expressions cannot be emitted multiple times.
However, this is dramatically more complex than the obvious implementation, so I 
hope this patch can be reverted.



Swift SVN r27767
2015-04-26 17:58:06 +00:00
Chris Lattner
5fa05e93ca implement SILGen support for 'defer' statement. The only
missing piece now is Sema support for detecting invalid exits
out of defer bodies.  That said, SILGen will also detect it,
and produce an error if sema misses something, e.g.:

t.swift:11:23: error: defer statement is not allowed to be exited
  while false { defer { break } }
                      ^
t.swift:12:9: error: defer statement is not allowed to be exited
  defer { return }
        ^

we should still diagnose these in Sema for better QoI of course.

This wraps up: <rdar://problem/17302850> Add a defer keyword to swift



Swift SVN r27760
2015-04-26 15:50:34 +00:00
Chris Lattner
ee96164996 implement parsing, AST, and basic Sema support for 'defer'.
SILGen support and diagnosing jumps out of a defer aren't done
yet.



Swift SVN r27759
2015-04-26 15:16:37 +00:00
Chris Willmore
c7c7388cf2 Change do-while to repeat-while.
Change all uses of "do { ... } while <cond>" to use "repeat" instead.
Rename DoWhileStmt to RepeatWhileStmt. Add diagnostic suggesting change
of 'do' to 'repeat' if a condition is found afterwards.

<rdar://problem/20336424> rename do/while loops to repeat/while & introduce "repeat <count> {}" loops

Swift SVN r27650
2015-04-23 22:48:31 +00:00
Chris Lattner
06ad473cab Switch if/let SILGen to use the same codepath as let/else, instead of using the
ClauseMatrix stuff.



Swift SVN r27565
2015-04-22 05:49:57 +00:00
Chris Lattner
fd69300bdf rework lowering of 'self' in class init methods to use normal cleanups and variable
emission instead of hand coded magic.  Eliminating special cases allows simplifying
other parts of the compiler, and this probably helps the error handling initiative 
as well.

This uses the (horrible) new null_class instruction to properly model rebinding of
self.  The code that SILGen was producing before was wildly incorrect and we only
got lucky that it seemed to work in most cases before.

NFC except that SILGen tests see the new null_class instructions, and we get better
location info for 'return nil' for obscure reasons that don't really matter.



Swift SVN r27530
2015-04-21 16:43:46 +00:00
Chris Lattner
7beb6d52de Extend SILGen's emitEpilog() to work with epilog blocks that are
already set up, allowing clients to generate code before the top-level
cleanup stack is emitted.

Use this to switch value constructors onto emitEpilog() and, more importantly,
to start managing the self box as a normal local variable tracked with cleanups
instead of being tracked with ad-hoc code spread through SILGen.

Among other things, once classes are switched over to the same model, we can
remove SGF.FailSelfDecl and the code to support it.  NFC.



Swift SVN r27472
2015-04-20 00:30:30 +00:00
Chris Lattner
020fe7835d Various cleanups for the initialization logic:
- Use virtual dispatch to localize some predicates instead
   of having special cases for LetValue inits in global places.
 - Improve 'const'ness of methods.
 - Introduce a common "KnownAddressInitialization" class to centralize
   the notion of an initialization corresponding to a specific physical
   address that is known up front.  Consolidate dupes of this concept into
   uses of it.

NFC.



Swift SVN r27462
2015-04-19 04:12:02 +00:00
John McCall
6d2326f08a Test (and fix) some simple calls to foreign-error methods.
Swift SVN r27296
2015-04-14 23:52:53 +00:00
John McCall
156a4c7ed0 SILGen for calls under foreign error conventions. WIP.
Swift SVN r27270
2015-04-14 02:35:54 +00:00
John McCall
79cc258f65 Lower 'throws' to an error result.
Swift SVN r27108
2015-04-08 00:09:29 +00:00
John McCall
08d3460a19 Implement throw expressions. Untested.
Tests tomorrow for this and 'catch', I promise. :)

Swift SVN r26432
2015-03-23 08:10:15 +00:00
John McCall
ee4aa14703 Stop reordering blocks in SILBuilder::emitBlock.
This change permits SILGen to make smarter decisions about
block placement by keeping related blocks together instead
of always inserting to the end to the function.  The
flipside is that SILGen needs to be somewhat careful to
create blocks in the right order.  Counter-intuitively,
that order is the reverse of the order in which the blocks
should be laid out, since blocks created later will be
inserted before blocks created earlier.  Note, however,
that this produces the right results for recursive
emission.

To that end, adjust a couple of places in SILGen to
create blocks in properly nested order.

All of the block-order differences in the tests seem
to be desirable; several of them even had confused
comments wondering how on earth a block got injected
where it did.

Also, fix the implementation of SILBuilder::moveBlockTo,
and fix a latent bug in epilogue emission where epilogBB
was erased from its parent (deleting it) and then
queried multiple times (!).

Swift SVN r26428
2015-03-23 06:38:20 +00:00
John McCall
a0a16d78d2 Implement the do/catch statement. Tests to follow.
This patch also introduces some SILGen infrastructure for
dividing the function into "ordinary" and "postmatter"
sections, with error-handling-like stuff going into the
final section.  Currently, this is largely undermined by
SILBuilder, but I'm going to fix that in a follow-up.

Swift SVN r26422
2015-03-23 02:08:26 +00:00
John McCall
080b7dfabf Remove the default handle-all Decl and DeclAttribute
cases from ASTVisitor and privatize SILGen's statement
emitter.  NFC.

Swift SVN r26402
2015-03-22 03:22:45 +00:00
John McCall
4d7510db63 Test do{}, and fix the inevitable bug.
Swift SVN r26200
2015-03-17 00:25:48 +00:00
Chris Lattner
e2fe7704ad Reimplement emission of StmtCondition (e.g. if/let & while/let) to be
in terms of the pattern binding/emission facilities that are currently
used for switches.  They are more general (handling all patterns,
not hacked up just for optionals).

This leads to us producing better code for if/let bindings, because we 
don't alloc_stack a temporary and deal with memory for non-address-only
types (e.g. the common case of an optional pointer).  Instead, the code 
emits a select_enum{_addr} on the value.

While this changes the generated code in the compiler, there is no exposed
behavioral change to the developer.




Swift SVN r26142
2015-03-14 20:31:23 +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
Dmitri Hrybenko
a5138dd4df Replace a use of libc++ extension for tuple initialization with portable code
Swift SVN r25606
2015-02-27 19:25:47 +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
Justin Bogner
a49008298e InstrProf: Set up the basic infrastructure for profiling swift
This adds the -profile-generate flag, which enables LLVM's
instrumentation based profiling. It implements the instrumentation
for basic control flow, such as if statements, loops, and closures.

Swift SVN r25155
2015-02-11 01:06:18 +00:00