Commit Graph

132 Commits

Author SHA1 Message Date
Dmitri Gribenko
0f36bec31f Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-18 16:41:35 -08:00
John McCall
e249fd680e Destructure result types in SIL function types.
Similarly to how we've always handled parameter types, we
now recursively expand tuples in result types and separately
determine a result convention for each result.

The most important code-generation change here is that
indirect results are now returned separately from each
other and from any direct results.  It is generally far
better, when receiving an indirect result, to receive it
as an independent result; the caller is much more likely
to be able to directly receive the result in the address
they want to initialize, rather than having to receive it
in temporary memory and then copy parts of it into the
target.

The most important conceptual change here that clients and
producers of SIL must be aware of is the new distinction
between a SILFunctionType's *parameters* and its *argument
list*.  The former is just the formal parameters, derived
purely from the parameter types of the original function;
indirect results are no longer in this list.  The latter
includes the indirect result arguments; as always, all
the indirect results strictly precede the parameters.
Apply instructions and entry block arguments follow the
argument list, not the parameter list.

A relatively minor change is that there can now be multiple
direct results, each with its own result convention.
This is a minor change because I've chosen to leave
return instructions as taking a single operand and
apply instructions as producing a single result; when
the type describes multiple results, they are implicitly
bound up in a tuple.  It might make sense to split these
up and allow e.g. return instructions to take a list
of operands; however, it's not clear what to do on the
caller side, and this would be a major change that can
be separated out from this already over-large patch.

Unsurprisingly, the most invasive changes here are in
SILGen; this requires substantial reworking of both call
emission and reabstraction.  It also proved important
to switch several SILGen operations over to work with
RValue instead of ManagedValue, since otherwise they
would be forced to spuriously "implode" buffers.
2016-02-18 01:26:28 -08:00
Max Moiseev
3a3984877a Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-15 15:43:34 -08:00
Vedant Kumar
be87f04807 [Coverage] Fix the counter increment for repeat-while bodies
We need to increment the counter for repeat-while bodies immediately
after the loop body is entered. This allows us to handle "break" and
"return" statements in the repeat-while body correctly.

This also fixes an off-by-one error where we only updated the
repeat-while body counter when the loop condition evaluates to true.
2016-02-10 16:32:07 -08:00
Max Moiseev
61c837209b Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-04 16:13:39 -08:00
Erik Eckstein
506ab9809f SIL: remove getTyp() from SILValue 2016-01-25 15:00:49 -08:00
Max Moiseev
9a018bd77d Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-01-20 14:38:22 -08:00
Michael Gottesman
e25cd8860c Remove all uses of ilist_node::getNextNode() and ilist_node::getPrevNode() in favor of just using iterators.
This change is needed for the next update to ToT LLVM. It can be put
into place now without breaking anything so I am committing it now.

The churn upstream on ilist_node is neccessary to remove undefined
behavior. Rather than updating the different ilist_node patches for the
hacky change required to not use iterators, just use iterators and keep
everything as ilist_nodes. Upstream they want to eventually do this, so
it makes sense for us to just do it now.

Please do not introduce new invocations of
ilist_node::get{Next,Prev}Node() into the tree.
2016-01-19 14:44:58 -06:00
Max Moiseev
f51e708a8f Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-01-04 12:25:25 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
practicalswift
fa0b339a21 Fix typos. 2015-12-26 17:51:59 +01:00
Dmitri Gribenko
31598d41bf Rename GeneratorType to IteratorProtocol 2015-12-07 17:08:32 -08:00
Adrian Prantl
95d3851e1c Debug Info: Ensure that patterns bound in a while stmt end up in their own
debug scope.

Similar to rdar://problem/22677613

Swift SVN r31998
2015-09-16 17:51:17 +00:00
Adrian Prantl
7eccc60731 Debug Info: Ensure that patterns bound in a for stmt end up in their own
debug scope.

Similar to rdar://problem/22677613

Swift SVN r31997
2015-09-16 17:30:17 +00:00
Adrian Prantl
d1ec8a225b Debug Info: Ensure that patterns bound in a foreach stmt end up in their
own debug scope.

rdar://problem/22677613

Swift SVN r31996
2015-09-16 17:30:14 +00:00
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