Commit Graph

30 Commits

Author SHA1 Message Date
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
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
John McCall
36c605f7dc Remove ScalarToTupleExpr in favor of a flag on TupleShuffleExpr.
Also, implement in-place initialization through tuple shuffles.

Swift SVN r28227
2015-05-06 23:44:26 +00:00
Chris Lattner
d1351e221f completely remove the 'Kind' field/enum of Initialization. NFC.
Swift SVN r27464
2015-04-19 04:50:20 +00:00
Chris Lattner
fa6f078d0a Continue tidying up Initialization, NFC:
- Privatize "kind" in the base Initialization class.
 - Simplify canForwardInBranch() to just isSingleBuffer().
   There is only one client of it (which avoids emitting the
   formation of an optional temporary) and the only cases we're
   dropping is for "_" patterns and single element tuple patterns,
   which are not worth optimizing for.
 - Change getSubInitializationsForTuple() into a virtual method
   since it has wildly different behavior based on the subclass and
   requires otherwise private implementation details of those subclasses
   to implement it.
 - Simplify subclasses based on these changes.



Swift SVN r27463
2015-04-19 04:47:02 +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
Chris Lattner
3118f09856 Add SILGen support for Conditional PBD's and add the first example
refutable pattern (expr patterns) to show that this works, this enables
weird things like:

	let 1...40 = foo() else { ... }

:-)



Swift SVN r27050
2015-04-07 00:56:36 +00:00
Chris Lattner
0c35b2e8d4 refactor a bunch of stuff around Initialization to simplify the code and
make it easier to extend, NFC.

 3 files changed, 196 insertions(+), 238 deletions(-)



Swift SVN r27029
2015-04-06 06:00:30 +00:00
Joe Groff
07a47a02d0 SILGen: Remove InOutInitialization and its related "AddressBinding" initialization kind.
We don't need these now that we don't set up argument bindings via initializations.

Swift SVN r24413
2015-01-14 05:51:01 +00:00
John McCall
372d6513bb Don't propagate let-binding Initializations down into
conditional-executed initializers.

Swift SVN r16033
2014-04-08 01:12:56 +00:00
Chris Lattner
1344319677 Rename the internal compiler lexicon from val -> let.
Swift SVN r14408
2014-02-26 21:21:18 +00:00
Chris Lattner
28903887e7 Rename the internal compiler lexicon from let -> val.
Swift SVN r13992
2014-02-17 16:48:21 +00:00
Chris Lattner
827acad533 Various inout improvements:
- purge @inout from comments in the compiler except for places talking about
   the SIL argument convention.
 - change diagnostics to not refer to @inout
 - Change the astprinter to print InoutType without the @, so it doesn't show
   up in diagnostics or in closure argument types in code completion.
 - Implement type parsing support for the new inout syntax (before we just 
   handled patterns).
 - Switch the last couple of uses in the stdlib (in types) to inout.
 - Various testcase updates (more to come).



Swift SVN r13564
2014-02-06 06:22:27 +00:00
Chris Lattner
e57f8e436d simplify tuple processing code. We only want to do tuple element operations
in memory of the available type is address only, so simplify a check and
remove the predicate (which happens to be out of date anyway).


Swift SVN r12814
2014-01-22 23:36:49 +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
Chris Lattner
ed7a3fd4ae tweak comment.
Swift SVN r11928
2014-01-06 17:12:52 +00:00
Chris Lattner
5faf530cf2 implement restructuring assignment of let decls, repurposing the existing
implosion logic.  This resolves rdar://15716277


Swift SVN r11679
2013-12-27 22:30:28 +00:00
Chris Lattner
1788421e5d Change SILGen to lower and bind non-address-only 'let' variables
as values, without a box at all.  This generalizes some of the
previous hacks I had for silgen'ing 'self' as a value instead of
a box, and capturing them with CaptureKind::Constant.




Swift SVN r11360
2013-12-16 20:36:16 +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
John McCall
298577676e Introduce the monadic ? operator.
A ? operator is interpreted as this if it's left-bound,
so ternary operators now have to be spaced on the left.

Swift SVN r8832
2013-10-02 01:27:45 +00:00
John McCall
a1867380d0 Distinguish the "cleanup handle" and "scope" use-cases
of CleanupsDepth.

Only with different typedefs for now, but the communicative
effect is significant.

Swift SVN r8831
2013-10-02 01:27:41 +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
Joe Groff
3d4c1251f1 Rename 'byref' attribute to 'inout'.
Swift SVN r8661
2013-09-25 20:56:52 +00:00
Joe Groff
d69eb660a6 SILGen: Emit shadow copies of byref arguments.
Create a local box for byref arguments that can be closed over. The box receives the value of the byref at function entry, and the value in the box at function exit is written back to the byref. This will allow us to eliminate the no-capture restriction on byrefs, allowing them to be used in auto closures and other HOFs, and doing the right thing in the 99% case where closures are effectively nocapture without requiring user annotation. <rdar://problem/14732389>

There are a couple of loose ends:

- The type-checker can lose its restriction on byref captures. I'll do that next.
- Debug info needs to learn how to represent local byref boxes. Adrian is better qualified to decide how to do that.
- Byref shadow copies completely defeat the copy-on-write optimization for String, making append sequences ridiculously slow. Memory promotion needs to learn to eliminate shadow copies completely when it promotes away byref boxes in order to solve this regression.

Swift SVN r8630
2013-09-25 17:19:00 +00:00
Chris Lattner
9b53417e5f remove Initialization::defaultInitialize, which is dead now.
Swift SVN r7957
2013-09-05 20:41:57 +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
2ea48d3d52 [SIL] Assign SIL location info for tuple initialization code.
Swift SVN r7915
2013-09-04 21:57:50 +00:00
Chris Lattner
803f5dc551 Rearrange the careful dance that is Initialization finalization.
We had a weird (and problematic for me) situation before where
tuple initializations would not recursively finalize their tuple
elements when they were finalized.  Making them do so runs afoul
of the poorly named Initialization::getSubInitializations(x,y,z)
method, which had nothing to do with the
Initialization::getSubInitializations() method.  Rename the former
to "getSubInitializationsForTuple" to make it more clear what is
going on, and make it handle the finalization of the SingleElement
initialization when it explodes it.

No functionality change, this unblocks some cases definite init was
tripping over.



Swift SVN r7600
2013-08-26 23:01:48 +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
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