Commit Graph

132 Commits

Author SHA1 Message Date
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
Doug Gregor
344ecfd3f9 Add a new 'fail' statement to the AST for failing from an initializer.
The spelling of the 'fail' statement is simply 'return nil', but
distinguishing it in the AST clarifies intent for SILGen.

Swift SVN r21310
2014-08-20 17:22:36 +00:00
Joe Groff
e8c79f3236 SILGen: Ignore the result of a "for" loop increment.
Fixes <rdar://problem/17236237>.

Swift SVN r20685
2014-07-29 19:42:09 +00:00
John McCall
ba597ece5d Add a convenience method for emitting a break
out of a particular statement exactly like a
break-statement would.

Swift SVN r19335
2014-06-30 11:55:27 +00:00
Joe Groff
31e761ca3e SILGen: Don't overrelease the for-each iteration value when break-ing.
We don't ever need to destroy_addr the iteration value buffer, because either the for loop exited normally because it's nil, or it exited by 'break' and it contains a stale 'Some' value that was consumed by the loop body. Fixes <rdar://problem/16687672>.

Swift SVN r16942
2014-04-27 21:39:03 +00:00
Chris Lattner
7e93a509a9 enhance the AST representation of break and continue statements to specify the
LabeledStmt that they target: have sema fill this in, and make silgen respect it.

NFC, because this was specifically written to behave the same as before (e.g. no
break out of switches).


Swift SVN r16610
2014-04-21 05:53:44 +00:00
Joe Groff
92f63e857a SILGen: Close conditional binding scope before exiting while loop.
Don't leak cleanups for conditional bindings. Serves me right for implementing this at 2am. Fixes <rdar://problem/16202294>.

Swift SVN r16559
2014-04-19 01:05:11 +00:00
Joe Groff
e6276a1c2f SILGen: Emit brace stmt exprs and for stmt initializers as ignored exprs.
Add an emitIgnoredExpr entrypoint to SILGenFunction that emits an expression, ignoring its result. This isn't an extensive implementation but just tackles the low-hanging fruit of allowing +0 rvalues and not crashing on sudden lvalues, fixing <rdar://problem/16650625>.

Swift SVN r16536
2014-04-18 17:55:41 +00:00
John McCall
8a6dd6e124 Give CanType a getAnyOptionalObjectType accessor.
Swift SVN r15079
2014-03-14 22:00:06 +00:00
Chris Lattner
8869767260 Implement the rest of rdar://16242700
Fix a phase ordering problem: SILGen of a noreturn function doesn't drop an unreachable after the function,
and doing so is problematic for various reasons (all expressions would have to handle their insertion point
vaporizing, and would have to emit unreachable code diagnostics).  Instead, run a simple pass that folds
noreturn calls and diagnoses unreachable code, and do it before DI.  This prevents DI from seeing false
paths, and rejecting what seems like invalid code.



Swift SVN r14711
2014-03-06 01:29:32 +00:00
Joe Pamer
988a5877f2 Some updates:
- Respond to Doug's code review feedback
   - Stop hacking around with scopes and use "emplace" to work around RAII in the inactive config case
   - Limit use of StringRef on the front-end, in favor of std::string
   - Use ArrayRef rather than SmallVector within IfConfigDecl
   - Reorder new property declarations on BraceStmt to prevent unnecessary alignment issues
- Update ParseBraceItems to better capture top-level declarations, rather than using token lookahead

Swift SVN r14306
2014-02-24 18:16:49 +00:00
Joe Pamer
f83f94d9d8 Support build and target configurations
These changes add support for build and target configurations in the compiler.
Build and target configurations, combined with the use of #if/#else/#endif allow
for conditional compilation within declaration and statement contexts.

Build configurations can be passed into the compiler via the new '-D' flag, or
set within the LangOptions class. Target configurations are implicit, and
currently only "os" and "arch" are supported.

Swift SVN r14305
2014-02-24 18:16:48 +00:00