Commit Graph

797 Commits

Author SHA1 Message Date
Joe Groff
c9d6a351f5 IRGen: SIL ClosureInsts (almost).
Implement lowering of SIL ClosureInsts by packing the partial arguments into a heap allocation and emitting a thunk to unpack them and apply the closure function, similar to curried entry points. The test doesn't work quite yet because nested FuncDecls don't get visited anymore. I need to replace my hacked SIL path with a proper walk of the SIL module to generate functions and the AST to generate types.

Swift SVN r3817
2013-01-20 19:50:10 +00:00
Joe Groff
a17a812ad6 IRGen: Add 'retain' and 'release' to TypeInfos.
These let SILGen retain and release arbitrary Explosions without having to work around cleanups. Also remove 'transfer' because I'm dumb and didn't realize 'reexplode' already does the same thing.

Swift SVN r3816
2013-01-20 19:50:07 +00:00
John McCall
3713b6a549 Add a framework for distinguishing between deallocating
and non-deallocating destructors and allocating/non-allocating
constructors.

Non-deallocating destructors might not play well with ObjC
classes;  we might have to limit them to pure-swift hierarchies.

No functionality change except that I decided to not force
destructors to have internal linkage unconditionally.

Swift SVN r3814
2013-01-20 19:40:12 +00:00
Joe Groff
312e4872e9 IRGen: SIL class accessors.
Implement IRGen for RefElementAddr so that class accessors work. Add a loadUnmanaged method to TypeInfo classes so that we can populate Explosions without accruing unwanted cleanups.

Swift SVN r3779
2013-01-16 22:12:21 +00:00
Joe Groff
9b2727005f IRGen: Add a 'transfer' method to TypeInfo.
Transfers values from one Explosion to another similar to 'copy' by transferring ownership instead of copying the values/cleanups.

Swift SVN r3768
2013-01-16 01:20:13 +00:00
Joe Groff
8320df8b9d IRGen: SIL branching and variable allocation.
Implement SIL-to-IR lowering for allocation, deallocation, load, store, and branching instructions so that local variables and branching control flow can be used. Add a Fibonacci loop test to exercise the new instructions.

Swift SVN r3767
2013-01-15 22:32:49 +00:00
Joe Groff
9259c0d912 IRGen: Get "hello world" to compile through SIL.
Add a path through IRGenModule to optionally codegen FuncDecls using their corresponding SIL Functions when constructed with a SILModule. Jury-rig an IRGenSILFunction subclass of IRGenFunction that does the bare minimum necessary to compile "hello world" from SIL. There are some impedance mismatches between irgen and SIL that need to be smoothed out, particularly the AST-dependent way irgen currently handles function calls. Nonetheless, `swift -sil-i hello.swift` works!

Swift SVN r3759
2013-01-14 02:57:11 +00:00
John McCall
d4f80a3993 Introduce a ClassLayoutBuilder and use it to build layouts.
The test changes are that we're setting a class body on
some types that we weren't before.  For some of these,
this is okay;  for others, it's more questionable, but
ultimately not *harmful*.

Swift SVN r3746
2013-01-11 08:09:06 +00:00
Chris Lattner
b58a87c7c4 do an inttoptr/ptrtoint dance to enable atomics on Builtin.RawPointer,
implementing: rdar://12939803 - ER: support atomic cmpxchg/xchg with pointers


Swift SVN r3702
2013-01-07 19:14:01 +00:00
John McCall
b15b306314 Emit ObjC metadata and swift-as-ObjC thunks for methods.
Swift SVN r3697
2013-01-05 23:46:24 +00:00
Dave Zarzycki
5ffbcc907b Make Float/Double be typealiases to Float32/Float64
Swift SVN r3660
2013-01-03 19:44:51 +00:00
Chris Lattner
47dbc4051c update for mainline LLVM header file moves.
Swift SVN r3634
2013-01-02 14:38:42 +00:00
Chris Lattner
db63db1c6b expose the llvm atomicrmw instruction through the builtin module to swift code,
wrapping up rdar://12939282.


Swift SVN r3619
2012-12-30 09:53:41 +00:00
Chris Lattner
53baaafffb implement support for generating the fence instruction through
Builtin.fence_*, part of rdar://12939282


Swift SVN r3618
2012-12-30 09:36:08 +00:00
Chris Lattner
fd2a4490fa expose the llvm cmpxchg instruction featureset through to the swift Builtin module,
first part of rdar://12939282.


Swift SVN r3617
2012-12-30 09:21:26 +00:00
Joe Groff
7351a1a5b0 IRGen: Update for llvm changes.
llvm::Attribute::AttrVal was renamed to llvm::Attribute::AttrKind.

Swift SVN r3597
2012-12-23 18:23:38 +00:00
John McCall
e5434f80d9 Respond to a change in LLVM trunk.
Swift SVN r3568
2012-12-21 00:16:38 +00:00
John McCall
521f0742b4 Account for types that explode to sizes != 1 when computing the
consumed arguments of a method.

Swift SVN r3464
2012-12-13 00:24:42 +00:00
Doug Gregor
b4ca0f1fef Rename llvm::AttrListPtr -> llvm::AttributeSet to sync with LLVM mainline.
Swift SVN r3430
2012-12-10 23:21:19 +00:00
John McCall
4b246bce50 Implement the ObjC ownership conventions, using ARC-in-clang's
method annotations when possible.

Swift SVN r3427
2012-12-10 08:18:11 +00:00
John McCall
c6374093f6 Add support for messaging Objective-C classes.
Notably, there is still no support for +1 return values,
so we'll leak when doing alloc/init and so on;  but this gets
the fundamentals in place.  A lot of the extra stuff in here
is dealing with mapping between metatypes and class objects.

Swift SVN r3425
2012-12-10 08:18:03 +00:00
Jordan Rose
427be94945 Add the [iboutlet] and [ibaction] attributes.
Currently only used for parsing. The immediate intent of these attributes is
to have them behave like [objc] for the purpose of emitting method
implementations; however, they are semantically distinct and should only be
used to expose outlets and actions to Interface Builder.

Swift SVN r3416
2012-12-08 00:16:03 +00:00
Doug Gregor
d774de0c11 Any method marked [objc] should be called via objc_msgSend*.
Objective-C methods imported from Clang can be part of extensions,
which weren't covered by the existing logic. Note that we currently
ban [objc] methods in extensions written in Swift, a restriction we
may want to revisit.


Swift SVN r3284
2012-11-28 19:16:38 +00:00
Chris Lattner
f5e4474c76 fix build with mainline llvm.
Swift SVN r3246
2012-11-26 20:44:27 +00:00
John McCall
7c277001a4 Implement basic objc_msgSend capabilities.
Swift SVN r3104
2012-11-03 00:26:56 +00:00
Joe Groff
6449655e21 Implement selector-style function definition syntax.
rdar://12315571
Allow a function to be defined with this syntax:

  func doThing(a:Thing) withItem(b:Item) -> Result { ... }

This allows the keyword names in the function type (in this case
`(_:Thing, withItem:Item) -> Result`) to differ from the names bound in the
function body (in this case `(a:Thing, b:Item) -> Result`, which allows
for Cocoa-style `verbingNoun` keyword idioms to be used without requiring
those keywords to also be used as awkward variable names. In addition
to modifying the parser, this patch extends the FuncExpr type by replacing
the former `getParamPatterns` accessor with separate `getArgParamPatterns`
and `getBodyParamPatterns`, which retrieve the argument name patterns and
body parameter binding patterns respectively.



Swift SVN r3098
2012-11-01 21:53:15 +00:00
John McCall
310268c4fd Fix several bugs in the emission of metatype references.
In particular, fix a bug where DREs that refer to types were
always given trivial reps because we were trying to emit the
metatype's metatype.  This in turn exposes a number of bugs,
including a typechecker bug (where GetMetatypeExpr bases
weren't converted to r-values) and a bug where MREs that
refer to types were always assumed to produce trivial reps.

Swift SVN r3095
2012-10-31 08:09:28 +00:00
John McCall
85490080c2 Make protocol thunks expect a metatype pointer (for This) as
their last argument.  Pass it down correctly.

Swift SVN r3042
2012-10-23 07:59:35 +00:00
John McCall
3e0957af8f When emitting a polymorphic signature like <T,U> A<T,U>& -> (),
pass A<T,U>.metatype instead of breaking apart the type.
This is a WIP commit, because it breaks existentials quite
badly.

Swift SVN r3041
2012-10-23 07:59:30 +00:00
Chris Lattner
e475986dbc adapt to mainline llvm API changes.
Swift SVN r3006
2012-10-16 17:54:16 +00:00
John McCall
2353465f3f Add an API for reemitting as a substituted type and change
protocol witnesses over to the new API.  There's some badness
that we're papering over here involving generic types, but
this is a necessary first step.

Swift SVN r3003
2012-10-14 07:36:22 +00:00
Dave Zarzycki
89bf1a0fc9 Fix unused variable warnings with asserts disabled
Swift SVN r2996
2012-10-12 21:52:09 +00:00
John McCall
17944ddefe Rename emitRValueUnderSubstitutions to make clear the
direction of substitution.

Swift SVN r2974
2012-10-11 04:29:24 +00:00
Chris Lattner
4135441203 update to build with mainline API changes.
Swift SVN r2968
2012-10-10 22:22:06 +00:00
John McCall
ae978371ac Make calls to non-static methods on classes use virtual
dispatch.  Currently there is no possibility of override.

This was really not as difficult as I managed to make it
the first time through.

Swift SVN r2960
2012-10-10 01:31:47 +00:00
Eli Friedman
dd299a35af Fix for LLVM TargetData -> DataLayout rename.
Swift SVN r2959
2012-10-09 23:18:24 +00:00
John McCall
6e9a2aab8b Fix a conceptual bug in class metadata: the parent pointer
of a class is part of the class members section and is not
global to the entire class metadata.  This is crucial for
correct operation of functions expecting a base-class
metadata object.

That gives us the correct foundation to implement an
optimization under which generic arguments that can be
inferred from the 'this' pointer need not actually be
separately passed.  This has the important result of
making all class member functions with the same signature
up to abstraction actually have the same physical
signature.

Swift SVN r2936
2012-10-04 23:44:31 +00:00
John McCall
1f5b775bc7 Use metatype pointers as generic type arguments. Movements
towards optimizing generic calls to derive things from the
'this' pointer, which is actually crucial for virtual
dispatch (to get all methods to agree about how the
implicit arguments are passed).  Fix a number of assorted
bugs in metadata emission.  Lots of assorted enhancements.

This was proving surprisingly difficult to actually tease
apart into smaller patches.

Swift SVN r2927
2012-10-03 08:57:40 +00:00
John McCall
179e260ea3 Add an abstraction to encapsulate a Decl + explosion level +
uncurrying level, which is something I find myself passing around
quite a bit.  Make sure that it can propagate getter/setter
references in the same way.

Swift SVN r2902
2012-09-28 05:21:24 +00:00
John McCall
3467e63516 Emit pointers to final overriders of member functions into
the metadata objects for classes.  This is currently only
done for methods defined in the main class body, and it's
(naturally) totally fragile, and it's screwed up in a
couple known ways w.r.t. generic classes:  there's no
thunking when the overrider differs by abstraction from
the overridden method, and methods on classes currently
expect to get all the type arguments passed directly
and thus will disagree in signature from members of
non-generic classes.  Also, of course, we're not using
any of this in the call infrastructure.  But it's progress.

Swift SVN r2901
2012-09-27 06:17:46 +00:00
John McCall
ee012c0903 Make IR-gen use canonical types as the basic type currency.
This is kindof a pain in a few places where the type system
doesn't propagate canonicality.  Also, member initializations
are always direct-initializations and so are allowed to use
explicit constructors, which is a hole in our canonicality
tracking.  But overall I like the idea of always working
with canonical types.

Swift SVN r2893
2012-09-21 07:53:08 +00:00
John McCall
8499117b59 The value witnesses for size/alignment/stride can just be size_t's.
This requires us to potentially copy the value witness tables for
generic struct types as part of computing layout, but that's not
the end of the world (although it will rely on a future patch
to split value witnesses out from protocol witness tables).

Oh, and add a value witness for stride, changing Builtin.strideof
to use that.

Swift SVN r2829
2012-09-06 08:23:14 +00:00
John McCall
e7b9ae47fa Defer to the value witness when moving an archetype. This
is really a deficiency in TypeInfo::initializeWithTake, which
is now virtual and not implemented in TypeInfo anymore.  This
fixes rdar://problem/12153619.

While I'm at it, fix an inefficiency in how we were handling
ignored results of generic calls, and add 4 new builtins:
  Builtin.strideof is like sizeof, but guarantees that it
  returns a multiple of the alignment (i.e., like C sizeof,
  it is the appropriate allocation size for members of an
  array).
  Builtin.destroy destroys something "in place";  previously
  this was being simulated by moving and ignoring the result.
  Builtin.allocRaw allocates raw, uninitialized memory, given
  a size and alignment.
  Builtin.deallocRaw deallocates a pointer allocated with
  Builtin.allocRaw;  it must be given the allocated size.

Swift SVN r2720
2012-08-23 05:21:31 +00:00
Eli Friedman
eb1689710f Delete isa, cast, and dyn_cast on Type. Hopefully, this will lead to fewer stupid mistakes.
Swift SVN r2691
2012-08-20 22:15:10 +00:00
John McCall
fbafe28ffb Progress towards making GetterSetterComponent more abstractable.
Swift SVN r2617
2012-08-13 09:03:24 +00:00
John McCall
88e03293cc Change the formal type of subscript declarations to always
pass the index as a separate argument.  This makes it much
easier to work with these things generically.

Swift SVN r2616
2012-08-13 09:02:37 +00:00
Eli Friedman
95cb2d6af2 Add builtins to convert between arbitrary retainable pointers,
Builtin.ObjectPointer, and Builtin.RawPointer.  I don't really like the way
these builtins are defined (specifically, the part where messing up
gives a mysterious IRGen error), but it's workable. <rdar://problem/11976323>.



Swift SVN r2585
2012-08-08 00:40:07 +00:00
John McCall
9106aa6254 Rewrite the function-call infrastructure. This gets us
a lot closer to successfully emitting the polymorphic-min-over-ranges
example;  the main blocker right now seems to be that the witness
for a static member function is not, in fact, a static member
function at al, but a freestanding function.  That's legitimate,
but it probably needs some shepherding through the witness
system.

Swift SVN r2532
2012-08-03 08:10:47 +00:00
Eli Friedman
0bfcfbfb8a Change the type of ConstructorDecls to be of the form metatype<T> -> () -> (). Change a bunch of stuff to compensate. Get rid of ConstructorRefExpr, which is no longer used.
Swift SVN r2526
2012-08-03 03:58:44 +00:00
Eli Friedman
84e858da4e Fix static member functions so a member of type T has type "metatype<T> -> () -> ()" instead of "() -> ()".
This is much more convenient for IRGen, and gives us a reasonable representation for a static
polymorphic function on a polymorphic type.

I had to hack up irgen::emitArrayInjectionCall a bit to make the rest of this patch work; John, please
revert those bits once emitCallee is fixed.



Swift SVN r2488
2012-07-28 06:47:25 +00:00