Commit Graph

296 Commits

Author SHA1 Message Date
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
Dave Abrahams
5063c33cbb Rename "Stream" protocol back to "Generator"
The name Stream didn't seem to be working out as intended; we kept
gravitating back to calling it Generator, which is precedented in other
languages.  Also, Stream seems to beg for qualification as Input or
Output.  I think we'd like to reserve Stream for things that are more
bulk-character-API-ish.

Swift SVN r13893
2014-02-14 01:48:52 +00:00
Doug Gregor
04475c6a85 Use @unchecked optionals for member references into AnyObject/AnyClass.
This eliminates the need for a number of !'s when dealing with
Objective-C APIs. Now with actual executable behavior!


Swift SVN r13483
2014-02-05 07:58:18 +00:00
Joe Groff
9fe1ab427a Implement 'if let' and 'while let' statements.
Allow IfStmts and WhileStmts to have as their condition either an expression, as usual, or a pattern binding introduced by 'var' or 'let', which will conditionally bind to the value inside an optional. Unlike normal pattern bindings, these bindings require an in-line initializer, which will be required to be Optional type. Parse variable bindings in this position, and type-check them by requiring an Optional on the right-hand side and unwrapping it to form the pattern type. Extend SILGen's lowering of if and while statements to handle conditionally binding variables.

Swift SVN r13146
2014-01-30 10:37:39 +00:00
Chris Lattner
690e8a38af switch places the ignore the result of an rvalue to allow it to be +0. No
impact on stdlib or testsuite.


Swift SVN r12879
2014-01-23 22:06:21 +00:00
Chris Lattner
7cd0f1739a A big part of handling address-only types is making sure that various
emission routines use the SGFContext passed in.  To help with this and
to help the handshake, add a new "isInContext()" representation to 
ManagedValue.  This makes the code producing and consuming these more
explicit.  NFC.


Swift SVN r12783
2014-01-22 21:31:44 +00:00
Chris Lattner
63784ca41c remove the ManagedValue::Unmanaged marker, lets just use ManagedValue::forUnmanaged()
instead, which is shorter.  It is better to have one way to do things than two.


Swift SVN r12710
2014-01-22 06:26:34 +00:00
Jordan Rose
11008f0ed1 Split diagnostics out into separate files.
Thanks to the way we've set up our diagnostics engine, there's not actually
a reason for /everything/ to get rebuilt when /one/ diagnostic changes.
I've split them up into five categories for now: Parse, Sema, SIL, IRGen,
and Frontend, plus a set of "Common" diagnostics that are used in multiple
areas of the compiler. We can massage this later.

No functionality change, but should speed up compile times!

Swift SVN r12438
2014-01-17 00:15:12 +00:00
John McCall
1ccf23487e Remove unnecessary ASTContext& argument from getOptionalObjectType().
Swift SVN r12344
2014-01-15 21:00:58 +00:00
Chris Lattner
7db7d4a813 Three changes:
- constify the Initialization::getAddressOrNull/hasAddress functions.
 - Teach the initialization logic that 'let' initializations can be
   split into tuple subelements by address (i.e. i
   getSubInitializationsForTuple works on them) when the let decl has
   a backing memory allocation.
 - Teach LetValueInitialization to produce a backing memory object
   for address-only tuple arguments, since they are passed as multiple
   SILArguments and need some place in memory to reassemble them.

The collection fixes a bad miscompilation where the RValue logic emitted
a temporary (through getSingleValue) which we then accidentally lifetime
extended for the duration of the argument.  This led to bad things when
the temporary got destroyed too early.

Thanks to MichaelG for helping narrow down this problem, it initially looked
like a sil optimizer bug.


Swift SVN r12234
2014-01-13 17:24:40 +00:00
Dave Abrahams
ff076dc3f2 [stdlib] "Generator" => "Stream"
This is step 1 of implementing the new Container/Sequence/Stream
protocols.  See test/Prototypes/Container.swift for the complete picture
of where this is headed.

Swift SVN r11924
2014-01-06 16:40:32 +00:00
Chris Lattner
dc71faa766 Add a local cleanup to fix a problem in foreach expansion when the 'next()' call
would produce temporary stack allocations.  Before the dealloc_stack would get 
generated at the end of the foreach sequence, a violation the stack nesting verifier
caught.


Swift SVN r11673
2013-12-27 20:21:37 +00:00
Joe Groff
3e30cbcfef SILGen/IRGen: Don't emit top_level_code for libraries.
If there's no script-mode file in a module, don't produce a top_level_code SILFunction for it, and don't consider emitting an LLVM global_ctor for it. We should never emit static constructors from user code anymore.

Swift SVN r11644
2013-12-26 00:18:29 +00:00
John McCall
20e58dcf93 Change the type of function values in SIL to SILFunctionType.
Perform major abstraction remappings in SILGen.  Introduce
thunking functions as necessary to map between abstraction
patterns.

Swift SVN r10562
2013-11-19 22:55:09 +00:00
Joe Groff
19457c12ea Give Builtin.Word an abstract size.
Instead of hardcoding Builtin.Word to be an alias for Builtin.Int64, make it its own type of abstract pointer width.

- Change BuiltinIntegerType's width representation to accommodate abstract widths.

- In the AST and in SIL, store values of the types as the greatest supported size for the abstract width (64 bits for a pointer).

- Add some type safety to the ([sz]ext|trunc)(OrBitCast)? builtins that they're used appropriately given the upper and lower bounds of the abstract sizes they're working with.

- Now that Builtin.Word is a distinct type, give it its own mangling.

- In IRGen, lower pointer-sized BuiltinIntegerType appropriately for the target, and truncate lowered SIL values if necessary.

Fixes <rdar://problem/15367913>.

Swift SVN r10467
2013-11-14 19:56:26 +00:00
Anna Zaks
54524e622a Replace ExprStmtOrDecl with ASTNode and make it a struct.
Previously, the Parser and BranchStmt typedef-ed ExprStmtOrDecl as a pointer union. Using typedef made the objects compatible, but did not allow us to extend the type with helper methods, such as getSourceRange(), which is something you can get on all of the AST objects. This patch introduces ASTNode that subclasses from PointerUnion and is used by both parser and BranchStmt.

Swift SVN r9971
2013-11-05 21:46:59 +00:00
Anna Zaks
16774496fd [SILGen] Emit warnings when SILGen fails to emit unreachable code.
Previously, we just did not emit SIL for unreachable code from these examples.

Swift SVN r9949
2013-11-05 01:17:14 +00:00
Joe Groff
0bda31c02b Switch over to Generator as the 'for' loop protocol.
Rewrite ForEachStmt SILGen to use the Optional intrinsics with the Generator.next method to iterate through sequences, and kill off the Enumerator path in Sema. Cut over 'EnumeratorType.Element' requirements to instead require 'GeneratorType.Element' in the stdlib.

There are a couple of bugs remaining that need follow-up work. There appears to be a bug in nested enum layout (e.g. T??) that's causing test/Interpreter/enum to break; I'll investigate and fix. There's also a lingering type-checker bug with inferred associated types that causes them to fail requirement checks <rdar://problem/15172101>, which I think Doug needs to look into.

Swift SVN r9017
2013-10-08 01:46:51 +00:00
John McCall
916b566fa6 Push and invalidate uninitialized-local cleanups.
No effect currently; just resolves a FIXME.

Swift SVN r8830
2013-10-02 01:27:39 +00:00
John McCall
6f32a8464f Add a convenient method to create a new basic block.
Swift SVN r8326
2013-09-17 07:22:23 +00:00
Anna Zaks
fba35a3421 [SIL] Move condbranch location from if/while/.. stmt to the condition
We should be able to get the parent when necessary after we add the parent map.

Swift SVN r8057
2013-09-09 22:34:07 +00:00
Anna Zaks
c06bd83358 [SIL] Remove the last few uses of SILLocation constructor.
This also removes the constructor itself, which forces future users of
SILLocation to construct a valid location.

Swift SVN r8056
2013-09-09 22:34:05 +00:00
Anna Zaks
1ba2554fb2 [SIL] Ensure that all loop branches have valid locations.
Also, change the location of "looping back to head" branch to point to the closing brace of the body, which is a more natural source location than the beginning of the enclosing loop statement.

Swift SVN r7989
2013-09-06 17:46:15 +00:00
John McCall
a26584584e Move some basic l-values and address operations into SILGenLValue.cpp.
Swift SVN r7940
2013-09-05 06:44:46 +00:00
John McCall
6aae6402ba Refactor in support of semantic vs. storage type differences.
Swift SVN r7939
2013-09-05 06:44:44 +00:00
Anna Zaks
115a15830b [SIL] Replace empty locations with valid locations in tuple exploding/encoding and pattern gen code.
Tuple exploding happens during RValue construction, so changed the constructor and addElement() method to take the location parameter. The imploding happens on RValue::forwardAsSingleValue and RValue::getAsSingleValue(). Make sure the right SIL locations are passed to all of these

Also, added some missing locations in pattern matching code.

Swift SVN r7916
2013-09-04 21:57:52 +00:00
Anna Zaks
8f3c9002d0 [SIL] Add cleanup locations to SIL instructions.
I've decided to keep only the location of the scope AST node that corresponds to the cleanup. (Currently, there is no user that needs the originator expression, which caused the cleanup. So keeping things simple.)

Added the cleanup location to the Scope and JumpDest classes, which gets assigned on construction of those. The Scope's and JumpDest locations are used when we emit the cleanup instructions.

We now give better location info for 2 existing tests for definitive initialization.

(+ Rather sparse testing of all this.)

Swift SVN r7764
2013-08-29 23:14:22 +00:00
Dmitri Hrybenko
d98408425e Remove unused OwningPtr.h includes
Swift is C++11 and uses std::unique_ptr.


Swift SVN r7731
2013-08-29 20:09:49 +00:00
Anna Zaks
b67f3c3552 [SIL] Use the ReturnLocation/ImplicitReturnLocation instead of generic SILLocations.
We mark the branch instructions leading into single epilog code with ReturnLocation/ImplicitReturnLocation. If SIL Gen simplifies the code and merges the code representing the return into the epilog block, the terminator of the epilog block (the ReturnInst) will have the return location info on it. Otherwise, the ReturnInst has the RegularLocation, which represents the enclosing FunctionExpr or Constructor/Destructor Decls.
(I've discussed dropping the optimization from SILGen, and keeping the epilog code canonical, with Adrian; but he said that there might not be any wins in doing so, so keeping it for now.)

Added AutoGeneratedLocation to represent segments of code generated by SILGen. This will be used for thunks and other auto-generated segments.

Swift SVN r7634
2013-08-27 22:16:24 +00:00
Adrian Prantl
a1c6b653ad Move DebugScopeStack from SILBuilder to SILGenFunction, using the swift new
InsertedInstrs facility.
No functionality change intended.

Swift SVN r7520
2013-08-23 20:11:44 +00:00
John McCall
581cac8d83 Don't carry a type on an Initialization; just pass it down
where needed.

Removes a few more non-Sema uses of getTypeOfReference.

Swift SVN r7412
2013-08-21 18:44:59 +00:00
Dmitri Hrybenko
ce54da3123 Use NullablePtr in ForStmt
ForStmt::Cond is already a NullablePtr<>.  This patch changes
ForStmt::Initializer and ForStmt::Increment to be NullablePtr.  Otherwise it
looks like Cond can be null, while Initializer and Increment can not.


Swift SVN r7265
2013-08-15 17:51:32 +00:00
Stephen Lin
8d90466523 Reorganize SIL source tree: move lib/SIL/SILGen -> lib/SILGen, move lib/SIL/Passes -> lib/SILPasses, add lib/SILPasses/Utils
Swift SVN r7246
2013-08-14 23:47:29 +00:00