Commit Graph

9332 Commits

Author SHA1 Message Date
Joe Groff
0bedc1aa17 Move ctor archetype forwarding from TypeChecker to SILGen.
Creating forwarding substitutions is straightforward enough that we don't need to fudge them in the AST, so remove the forwarding substitutions from ConstructorDecl and construct them instead on the fly in SILGen. We're going to need to be able to forward archetypes in other places in SILGen, such as when emitting closures or curried thunks in generic contexts. No functionality change.

Swift SVN r5418
2013-05-31 04:09:56 +00:00
Joe Groff
56e8397621 SILGen: Avoid unneeded copy in address-only writeback.
We can just use the materialized temporary buffer for the property as the value for writeback if it's address-only.

Swift SVN r5416
2013-05-31 00:54:01 +00:00
Joe Groff
b98772fea4 SILGen: Don't reevaluate subscript parameters on writeback.
In an LValue GetterSetterComponent, stash the RValue from evaluating the subscript the first time it's accessed, and copy and reuse the value on subsequent accesses to the lvalue.

Swift SVN r5411
2013-05-30 19:46:16 +00:00
Joe Groff
60c9ef64f6 SILGen: Introduce writeback scopes for calls.
When emitting a call chain, wrap the natural uncurry level of the root call and subsequent chained calls in their own writeback scopes. Suppress writeback if a non-settable property is used as the 'this' argument of a method and during codegen of LoadExprs.

This uncovered a bug in SILGen where a subscript LValue reevaluates the subscript expression on every access, which breaks the stdlib implementation of printf(). I've applied a temporary workaround to keep it working; I'll fix it next.

Swift SVN r5410
2013-05-30 18:03:15 +00:00
Joe Groff
f817094c60 SILGen: Introduce writeback scopes.
Define a new WritebackScope RAII object to mark the beginning and end of the lifetime of a set of writebacks. Add a writeback stack to SILGenFunction to keep track of active writebacks. Replace the ad-hoc writeback tracking in emitAssignToLValue with a WritebackScope.

No functionality change just yet; this just sets the stage for handling writebacks in function arguments.

Swift SVN r5402
2013-05-30 05:07:21 +00:00
Joe Groff
6743d9bc41 SILGen: Route all lvalue expr emission through SILGenLValue.
Kill some redundant code for emitting *MemberRefExprs, and set us up for tying LValue objects to Writeback scopes.

Swift SVN r5396
2013-05-30 00:12:10 +00:00
Joe Groff
12c5999b44 Strip out -no-nsstring-is-string flag and associated LangOptions bit.
Swift SVN r5383
2013-05-29 19:42:12 +00:00
Joe Groff
66d4e683da Disable ObjC property thunks for function-type properties.
We can't autorelease a Swift function value to conform to the ObjC convention, we don't urgently need to expose function properties to ObjC, and the ultimate right thing to do is to convert between a Swift function value and an ObjC block value, so for now, we can just drop the property thunks.

Swift SVN r5373
2013-05-29 16:27:11 +00:00
Joe Groff
dedb986fa5 SILGen: Map String to NSString in ObjC method thunks.
If a method or property on an [objc] class takes String arguments or returns a String result in the Swift world, insert conversions to/from NSString into the ObjC thunk for the method.

Moving the code around in emitObjCThunk here induces a bit of extra retain/release traffic. But the SIL optimizer will take care of that real soon, right?

Swift SVN r5359
2013-05-28 02:14:38 +00:00
Chris Lattner
07ea8a41b6 print function calls with the type of the callee at the end. Putting the
type of the callee at the end is unusual but makes it easier to read the
call.  We now get something like this, which makes it obvious what is the
callee value and what are the arguments:

 %6 = apply %4(%5) : $[thin] ((), Int64.metatype) -> Int64 

We may end up needing types for arguments as well, but lets try to get 
away without them.



Swift SVN r5358
2013-05-27 00:50:41 +00:00
Joe Groff
8693c5efaa SIL: Emit String-to-NSString conversions.
If -nsstring-is-string is enabled, lower Strings in cc(c) and cc(objc) function types to NSString, and when calling them, insert calls to StringToNSString/NSStringToString to perform the bridging conversion.

This isn't quite ready for prime-time yet, because we still need to emit the inverse bridging for ObjC method thunks, and I haven't tested the IRGen end of things yet.

Swift SVN r5355
2013-05-26 20:29:09 +00:00
Chris Lattner
e052f3ca41 change the sil printer to print the type of the destination
operand, producing something like:

	%2 = store %0 to %1 : $*Int64

Enhance the sil parser to be able to parse this.  We can now
round trip everything required to handle this function:

func foo(a : Int) -> Int {
  return a
}




Swift SVN r5354
2013-05-26 14:43:17 +00:00
Chris Lattner
c08a0e87a7 remove dead code.
Swift SVN r5349
2013-05-26 05:56:56 +00:00
Chris Lattner
a34f4efa13 parse integer_literal. Parse and print tuple instructions with named
elements in a way that we can not lose information.


Swift SVN r5348
2013-05-26 01:09:46 +00:00
Chris Lattner
7383d09a36 add a new SILType::getAsString() method, to be used in diagnostics when
printing SILTypes.  Bias the values in ValueToIDMap in SILPrinter so that
uses of invalid operands will print as %-1.



Swift SVN r5342
2013-05-25 18:40:47 +00:00
Chris Lattner
3db9fff98f implement SILValue::replaceAllUsesWith, fix a linked list manipulation
bug in removeFromCurrent.  Clearly I would fail an interview manipulating
linked lists :-)


Swift SVN r5341
2013-05-25 18:39:37 +00:00
Chris Lattner
22a14d7214 simplify the ctor for SILBuilder
Swift SVN r5333
2013-05-25 15:21:52 +00:00
Joe Groff
0dc5c66cd2 SIL: Move SILFunctionTypeInfo into a side table.
Generate and cache SILFunctionTypeInfo from Swift types on the fly, and simplify the SILType representation down to a CanType and isAddress bit.

Swift SVN r5298
2013-05-24 16:33:52 +00:00
Joe Groff
e3269a3b95 Pick one name for 'getAbstractCC'.
getCC, getFunctionCC, getConvention...consolidate them all under one name.

Swift SVN r5297
2013-05-24 03:08:40 +00:00
Joe Groff
5e2779b51e SIL: Uncurry function types within the Swift type system.
Remove uncurry level as a property of SILType/SILFunctionTypeInfo. During SIL type lowering, map a (Type, UncurryLevel) pair to a Swift CanType with the uncurried arguments as a Swift tuple. For example, T -> (U, V) -> W at uncurry level 1 becomes ((U, V), T) -> W--in reverse order to match the low-level calling convention. Update SILGen and IRGen all over the place for this representation change.

SILFunctionTypeInfo is still used in the SILType representation, but it's no longer load-bearing. Everything remaining in it can be derived from a Swift type.

This is an ABI break. Be sure to rebuild clean!

Swift SVN r5296
2013-05-24 01:51:07 +00:00
Chris Lattner
0ad6fac283 Remove the basic block name field from SILBasicBlock. The name is currently
ignored and is going to be a private detail of the SILParser.


Swift SVN r5276
2013-05-22 22:24:39 +00:00
Chris Lattner
55fe34063f optimize this to use std::next
Swift SVN r5271
2013-05-22 19:59:11 +00:00
Chris Lattner
a1f43692e8 switch a bunch of instructions (e.g. load) to print types for their operand.
These are the instructions that don't require testsuite updates :-)


Swift SVN r5270
2013-05-22 18:07:48 +00:00
Chris Lattner
02f02fca0f [overpedantic] Get plurality right in the # users comment, printing:
%0 = tuple ()                                   // user: %1
  %1 = return %0 : $()

instead of "users".



Swift SVN r5268
2013-05-22 17:58:44 +00:00
Chris Lattner
aacbf8f560 print the type of the operand to return and autorelease_return,
print the element types of struct.

The empty function now prints as:

sil @_T1t5emptyFT_T_ : $[thin] () -> () {
bb0:
  %0 = tuple ()
  %1 = tuple ()                                   // users: %2
  %2 = return %1 : $()
}



Swift SVN r5267
2013-05-22 17:49:03 +00:00
Chris Lattner
1bdf645d4b code cleanup:
- use interleave a bit more
 - Inline printAsOperand() away.
 - Introduce a "getIDAndType" method that prints both ID and type in the standard form.


Swift SVN r5266
2013-05-22 17:44:48 +00:00
Chris Lattner
de0ab0474e change tuple instructions to print as "tuple (%0 : $Int, %1 : $Float)"
so they can be parsed.  Drop the comman in struct instructions so they
print as "struct $foostruct (%0, %1, %2)"



Swift SVN r5265
2013-05-22 17:33:12 +00:00
Chris Lattner
d2de474371 Add a public raw_stream inserter for SILType. Change SILType printing
to always prefix a printed SILType with a $.  Update SILPrinter to use
this instead of manually adding $ everywhere.

The only behavioral change of this is that BB arguments now have a $ on
their type.


Swift SVN r5263
2013-05-22 17:14:05 +00:00
Chris Lattner
0c294501d6 add a "container" version of interleave, use it in SILPrinter a bit more.
No behavior change.


Swift SVN r5262
2013-05-22 16:52:51 +00:00
Joe Groff
12c7d01708 SIL: Write a function for uncurrying function types within the Swift type system.
Add a TypeConverter::uncurryFunctionType method for making an uncurried AnyFunctionType given a nested AnyFunctionType and an uncurry level. Without actually wiring it into anything yet, spot-check that it does the right thing by hacking SILPrinter to print the uncurried types of SILFunctions in a comment before the sil decl.

Swift SVN r5260
2013-05-22 03:14:13 +00:00
Chris Lattner
ed2c094728 change the SIL printer to print return statements without parens around their operand.
Swift SVN r5258
2013-05-22 00:35:34 +00:00
Joe Groff
8993ed707e Split 'C' and 'ObjCMethod' calling conventions.
This cleans up some wishy-washy control flow that relied on the uncurryLevel of a type to distinguish ObjC methods from freestanding C functions. While we're here, clean up all the places we use ad-hoc comparison logic on the AbstractCC enum to use switches that properly cover the enum.

Swift SVN r5251
2013-05-21 15:19:37 +00:00
Chris Lattner
53338b0fdb use early return to reduce indentation.
Swift SVN r5231
2013-05-20 19:35:54 +00:00
Joe Groff
a4ce448280 Move cc attribute from SILType to AnyFunctionType.
We decided we're going to want to surface fine-grained representational control of functions to the user, so move AbstractCC and the calling convention attributes into the Swift type system. Like the [thin] attribute, we don't set this in the type-checker or importer at all yet, and let SILGen set the attribute where it wants it for now.

Swift SVN r5222
2013-05-20 17:55:51 +00:00
Chris Lattner
af3f2d2a66 cache the (recursive) computation of SILType::isAddressOnly in SILModule
to avoid expensive cases in extreme situations.


Swift SVN r5220
2013-05-19 04:23:29 +00:00
Chris Lattner
c1a7c7e3b9 flip the sense of the isLoadable predicate to check for isAddressOnly at
Joe's request.


Swift SVN r5219
2013-05-18 03:22:37 +00:00
Chris Lattner
1f971f88dd Remove the IsLoadable flag from SILType, and the isInvalid() state for SILType.
This frees up an extra bit in SILType, which we can expose to LLVM through
PointerLikeTypeTraits.  Use this bit in a PointerUnion, which allows simplifying
ValueBase, which happened to be the last use of the isInvalid() state.



Swift SVN r5218
2013-05-18 00:21:46 +00:00
Chris Lattner
650fafb11a Switch "loadable" from being a bit in SILType to being a predicate
function.  For now I'm not caching the result at all, and the
old bit still stays around until other dependencies can get
untangled.


Swift SVN r5217
2013-05-18 00:00:25 +00:00
Joe Groff
0b17473b03 Remove SILCompoundTypeInfo now that we don't need it.
We lose some verification for StructInst, but it was broken for generic types anyway.

Swift SVN r5216
2013-05-17 23:57:53 +00:00
Joe Groff
409655e037 SIL: Split tuple/struct field accessor insns.
Split ExtractInst and ElementAddrInst into separate Tuple and Struct versions, and have the Struct versions reference struct member VarDecls directly instead of integer indices.

Swift SVN r5215
2013-05-17 23:34:11 +00:00
Chris Lattner
9a9acb11ba SILType::isLoadable is going to soon require a SILModule argument.
Add it, and propagate this through other APIs that call it (like
isAddressOnly and isTrivial).  No functionality change.



Swift SVN r5213
2013-05-17 23:13:38 +00:00
Doug Gregor
4d60bb7173 Implement trailing closure syntax.
Trailing closure syntax allows one to write a closure following any
other postfix expression, which passes the closure to that postfix
expression as an arguments. For example:

        sort(fruits) { |lhs, rhs|
          print("Comparing \(lhs) to \(rhs)\n")
          return lhs > rhs
        }

As a temporary limitation to work around the ambiguity with

  if foo { ... } { ... }

we require trailing closures to have an explicit parameter list, e.g.,

  if foo { || ... } { ... }



Swift SVN r5210
2013-05-17 19:16:18 +00:00
Doug Gregor
10ecccceea Make Type's bool conversion explicit.
I just tripped over this.


Swift SVN r5209
2013-05-17 19:12:59 +00:00
Joe Groff
19b9ad913e SILGen: Use 'isObjC' bit on SILConstant.
When we intend an ObjC dispatch, indicate so in the SILConstant. This lets us distinguish Swift from ObjC dispatch for Swift classes with ObjC superclasses.

Swift SVN r5207
2013-05-17 18:12:29 +00:00
Chris Lattner
fd398e32e3 add a public way to get a primitive SILType. SILFunctionTypeInfo and
SILCompoundTypeInfo already have public construction functions that
unique in the SILModule.


Swift SVN r5201
2013-05-17 05:31:27 +00:00
Chris Lattner
86d9c43c34 Simplify the control flow in makeTypeLoweringInfo by handling
lvalue types up front, eliminating the isAddress bool and stuff
using it.


Swift SVN r5200
2013-05-17 05:29:05 +00:00
Chris Lattner
e40f09aa25 remove a dead method, and move const to the "right" place per prevalent coding standard.
Swift SVN r5199
2013-05-17 05:08:56 +00:00
Chris Lattner
e4ccec4cfc rename SILBAse.h -> SILAllocated.h and SILBase.cpp -> SILModule.cpp to
reflect their contents.


Swift SVN r5198
2013-05-17 04:25:49 +00:00
Chris Lattner
fa9adc72ed merge SILBase into SILModule, the only class that derives from it.
Swift SVN r5197
2013-05-17 04:22:00 +00:00
Chris Lattner
f018610708 some obsessive formatting changes, 80 column fixes, etc.
no functionality change.


Swift SVN r5196
2013-05-17 04:05:15 +00:00