Commit Graph

293 Commits

Author SHA1 Message Date
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
Joe Groff
d07f093521 SILGen: Manage a foreach loop's generator payload before taking loop variables from it.
Fixes a leak when parts of the payload are ignored, as in rdar://problem/19631811.

Swift SVN r24809
2015-01-29 00:17:55 +00:00
David Farler
182792cada Reinstate multi-pattern conditions in if/while
rdar://problem/19450969

Undo reverts r24381..24384 with one fix: pull cleanup blocks from the
back of the list. When breaking out of a while loop, an extra release
could over-release a reference.

Swift SVN r24553
2015-01-20 09:59:44 +00:00
Nadav Rotem
fbf9ff6a2d Revert "Implement SILGen for multi-pattern conditions in if/while, finishing the "
This reverts commit 24348 and 24355 that that broke the build.
See rdar://19445271.

Conflicts:
	test/SILGen/if_while_binding.swift

Swift SVN r24384
2015-01-13 00:24:49 +00:00
Nadav Rotem
bec9d8704a Revert "substantially rewrite StmtCondition emission (again). In the previous attempt, we"
This reverts commit 24360 that depends on 24348 that broke the build.

Swift SVN r24383
2015-01-13 00:24:48 +00:00
Nadav Rotem
11d1a22ec2 Revert "Remove the "to" argument from emitActiveCleanups as Joe requests."
This reverts commit 24378 that depends on 24348 that broke the build.

Swift SVN r24382
2015-01-13 00:24:48 +00:00
Nadav Rotem
39237eeb0f Revert "destroy_addr on a known-nil optional is always a noop, *never* emit it."
This reverts commit 24380 that depends on 24348 that broke the build.

Swift SVN r24381
2015-01-13 00:24:47 +00:00
Chris Lattner
06ff115af9 destroy_addr on a known-nil optional is always a noop, *never* emit it.
This cleans up codegen for if-let a LOT and should make it more efficient
even in release builds.


Swift SVN r24380
2015-01-13 00:05:39 +00:00
Chris Lattner
ba455964c3 Remove the "to" argument from emitActiveCleanups as Joe requests.
Dont' emit destroy_addr if the element type is a class ref or is classbound.




Swift SVN r24378
2015-01-12 23:44:02 +00:00
Chris Lattner
c2793c249e substantially rewrite StmtCondition emission (again). In the previous attempt, we
emitted just the optional buffers, and tested them when evaluated the condition, then
consumed them all (producing the contained value) when the entire condition is true.
This doesn't work with where conditions, because the where condition can use the bound
variables.

The new approach emits the variable bindings as the conditions is emitted, allowing the
bindings to be in scope for where clauses.  In addition to this redesign, the implementation
is also somewhat simpler by being a recursive implementation which is (to me at least)
easier to reason about.

multi-pattern where bindings with where clauses should now be fully operational.


Swift SVN r24360
2015-01-11 03:56:19 +00:00
Chris Lattner
b2e11e4da5 Implement SILGen for multi-pattern conditions in if/while, finishing the
known implementation work required for:
<rdar://problem/19382942> Improve 'if let' to avoid optional pyramid of doom

I want to write some more tests and improve error recovery QoI in the parser,
but I believe it fully works now.  Please kick the tires and let me know if
you observe any problems (other than 19432424 which was pre-existing).



Swift SVN r24348
2015-01-10 01:59:47 +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
8236e7f18b Simplify the implementation of SILGenFunction::VarLoc by eliminating the
"isConstant" distinction.  This was an irritating bit of redundant state
that was making the code more complicated.  Clients of VarLoc really only
care about "has address" and "has box", not whether the VarLoc came from
a let or var (and if they did, they can ask the VarDecl directly).  NFC,
just more "yak shaving" as Doug likes to say.


Swift SVN r23869
2014-12-11 22:11:23 +00:00
Michael Gottesman
1afc987739 Refactor the SILArgument API on SILBasicBlock so we can insert bb arguments anywhere in the argument list. Also clean up the API names so that they all match.
Swift SVN r23543
2014-11-22 00:24:40 +00:00
Greg Parker
eef633d732 Replace assert(0) with llvm_unreachable() or llvm::report_fatal_error().
Swift SVN r23340
2014-11-15 00:24:32 +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
Joe Groff
a6a68d49cc SILGen: Avoid using a stdlib function to get optional values.
When we've already established that the optional has a value, using unchecked_take_enum_data_addr to directly extract the enum payload is sufficient and avoids a redundant call and check at -Onone. Keep using the _getOptionalValue stdlib function for checked optional wrapping operations such as "x!", so that the stdlib can remain in control of trap handling policy.

The test/SIL/Serialization failures on the bot seem to be happening sporadically independent of this patch, and I can't reproduce failures in any configuration I've tried.

Swift SVN r22537
2014-10-06 15:46:21 +00:00
Joe Groff
069ad18620 Revert "SILGen: Avoid using a stdlib function to get optional values."
This reverts commit r22533. The optimizing bots seem to have problems with it.

Swift SVN r22534
2014-10-06 04:40:58 +00:00
Joe Groff
28805f0d2a SILGen: Avoid using a stdlib function to get optional values.
When we've already established that the optional has a value, using unchecked_take_enum_data_addr to directly extract the enum payload is sufficient and avoids a redundant call and check at -Onone. Keep using the _getOptionalValue stdlib function for checked optional wrapping operations such as "x!", so that the stdlib can remain in control of trap handling policy.

Swift SVN r22533
2014-10-06 04:31:52 +00:00
Jordan Rose
042569a3be Optional: Replace uses of Nothing with None.
llvm::Optional (like Swift.Optional!) uses None as its placeholder value,
not Nothing.

Swift SVN r22476
2014-10-02 18:51:42 +00:00
Dmitri Hrybenko
d396134832 Portability: use std::make_tuple instead of relying on a libc++
extension (an implicit constructor in std::tuple)

Swift SVN r22339
2014-09-28 18:44:34 +00:00
Anna Zaks
782fac1d6a [SIL Unreachability] Do not report false positives in single statement closures
(I suspect SILLocation annotation code in other places is not aware of isImplicit() AST flag...)

Swift SVN r22110
2014-09-19 01:40:03 +00:00
Joe Groff
88da4626b8 SILGen: Clean up 'self' before entering the failure block of a failing initializer.
A couple reasons for this:

- How 'self' gets cleaned up is dependent on where the failure occurs. If we propagate failure from a class initializer, the failed 'super.init' or 'self.init' has already cleaned up the object, so we only need to deallocate the box. In cases where we fail explicit, we release 'self', which works out because we're only supporting failure with a fully-initialized object for now.
- This lets us set the location info for the cleanup to the AST node that instigated failure, giving better QoI for DI failures (such as failing with a partially-initialized object).

Swift SVN r21505
2014-08-28 01:13:49 +00:00
Joe Groff
d63be086e0 SILGen: Forward failure from a delegated value constructor.
Swift SVN r21427
2014-08-23 00:14:56 +00:00
Joe Groff
c23434a569 SILGen: Wrap the result of a failable value constructor in an optional.
Swift SVN r21370
2014-08-21 18:35:33 +00:00