Commit Graph

79 Commits

Author SHA1 Message Date
John McCall
38b34b7307 Pass #1 at localizing assumptions about fixed layout and
handling non-fixed layouts.

This uncovered a bug where we weren't rounding up the header
size to the element alignment when allocating an array of archetypes.

Writing up a detailed test case for *that* revealed that we were
never initializing the length field of heap arrays.  Fixing that
caused a bunch of tests to crash trying to release stuff.  So...
I've left this in a workaround state right now because I have to
catch a plane.

Swift SVN r4804
2013-04-18 07:58:21 +00:00
Joe Groff
9fbd9f19b8 Runtime: Clean up swift_allocBox a bit.
Per John's comments, make a GenericBox struct to represent the layout of a generic box allocation, move all the layout calculations into methods on GenericBox, and alter swift_deallocBox to take the type as an argument so that it's future-proofed for when we start special-casing certain types in allocBox.

Swift SVN r4613
2013-04-05 18:51:36 +00:00
Joe Groff
14355a8134 Runtime: Add swift_allocBox.
Add a runtime function that, given a generic type metadata pointer, allocates a heap object capable of containing a value of that type. This is a first-pass implementation that always does the worst case thing of stuffing the type metadata into the box with the value and using its value witness table to size, align, and destroy the box. Use swift_allocBox to implement ArchetypeTypeInfo::allocate correctly for heap object allocations. This means SIL's alloc_box $T now works for archetypes, and a simple generics test now (almost) compiles through SIL!

Swift SVN r4599
2013-04-05 01:34:28 +00:00
Joe Groff
fd0c5d6403 IRGen: Fix name of swift_getTupleTypeMetadata.
Fixes <rdar://problem/13284728>.

Swift SVN r4198
2013-02-25 21:41:16 +00:00
Joe Groff
4792c60d2d IRGen: Implement super method calls.
For Objective-C super calls, build an objc_super struct value containing the receiver and class/metaclass object and pass it to objc_msgSendSuper2. For Swift super calls, emit a direct call to the super implementation.

Swift SVN r4023
2013-02-13 02:41:20 +00:00
Jordan Rose
1066341cba Don't use _objc_empty_vtable in JIT mode.
In 10.9, the method cache now takes up two words, and the vtable is gone.
Code compiled statically will work fine, but runtime classes need to fill
the rest of the method cache with zero, instead of an address.

I tested this on 10.8 as well and it seems to do no harm.

Swift SVN r3910
2013-01-31 00:19:48 +00:00
Joe Groff
5be34d6337 IRGen: Fix type of initing ctor, destroying dtor
IRGen was generating the exact same signature for the initializing/allocating constructors and destroying/deallocating destructors. Make it do the right thing by typing the initializing constructor as Swift T -> (...) -> T and the destroying destructor as LLVM void(%swift.refcounted*). (This will later change to '%swift.refcounted*(%swift.refcounted*)' pending some irgen/runtime cleanup.)

Swift SVN r3837
2013-01-22 23:36:35 +00:00
John McCall
2d03621435 Fill in _objc_empty_cache and _objc_empty_vtable.
The ObjC ABI requires these class fields to be initialized by
resolving symbols from the runtime.  So this is a historical
requirement.  Note that there is a desire to optimize this
even for ObjC, because in a project with many classes, these
can actually end up representing a significant fraction of
the external non-lazy relocations in the linked image.  But
for now we follow the spec, as we must.
The ObjC ABI requires these to be taken from the runtime,
although there is an effort to make them not require external
relocations like this, since in large projects it can actually
add up to a large percentage of the non-lazy external relocs.
3,6d
2i

Swift SVN r3804
2013-01-19 10:06:47 +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
2e0070e229 Emit metaclass stub objects for swift classes.
Swift SVN r3740
2013-01-11 08:08:50 +00:00
Chris Lattner
47dbc4051c update for mainline LLVM header file moves.
Swift SVN r3634
2013-01-02 14:38:42 +00:00
Doug Gregor
662861fd66 Implement runtime checking for super-to-archetype casts, finishing <rdar://problem/12768631>.
Introduce a new swift_dynamicCast pair that take in a general metatype
pointer, rather than the more specific class-metatype pointer used for
class downcasts, and grab the class out of that general metatype
pointer, which may actually be an Objective-C wrapper. This is
slightly slower, but it works for the super-to-archetype cases like
T(an_NSObject), where T can have either kind of metadata.

NSTypedArray<T> is actually run-time type checked now, yay!


Swift SVN r3564
2012-12-20 18:47:39 +00:00
Doug Gregor
5a857292bb Rename swift_dynamicCast to swift_dynamicCastClass.
This variant of swift_dynamicCast requires us to have data that's
guaranteed to be class metadata, but it's not always natural to
generate class metadata. No functionality change yet.


Swift SVN r3562
2012-12-20 18:07:08 +00:00
Doug Gregor
b9667e701a Perform runtime checking of downcasts, aborting if they fail <rdar://problem/12768631>.
We add a new runtime entry point, swift_dynamicCastUnconditional(),
that aborts when the cast fails. We'll probably want to throw an
exception in the future, but this is fine for now.


Swift SVN r3554
2012-12-19 23:42:10 +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
John McCall
59d4677b35 Implement metatype references to ObjC classes.
The interesting thing here is that we need runtime support in
order to generate references to metatypes for classes, mostly
because normal ObjC classes don't have all the information we want
in a metatype (which for now just means the VWT pointer).
We'll need to be able to reverse this mapping when finding a
class pointer to hand off to, say, an Objective-C class method,
of course.

Swift SVN r3424
2012-12-10 08:17:57 +00:00
John McCall
65db19395d Make metatype layout compatible with struct objc_class.
The principal difficulty here is that we need accessing the
value witness table for a type to be an efficient operation,
but there (obviously) isn't a VWT field for ObjC classes.
Placing this field after the metatype would tend to bloat
metatypes by quite a bit.  Placing it before is best, but
it introduces an unfortunate difference between the address
point of a metatype and the address of the global symbol.
That, however, can be fixed with appropriate linker support.
Still, for now this is rather unfortunately over-subtle.

Swift SVN r3307
2012-11-30 02:47:01 +00:00
John McCall
3c053a7b98 In preparation for shifting the metadata layout, widen
the metadata kind field to a full word.

Swift SVN r3183
2012-11-14 08:45:29 +00:00
John McCall
5eb36187d6 Teach IR-gen how to emit metatypes for metatypes.
Swift SVN r3180
2012-11-14 08:45:17 +00:00
John McCall
7c277001a4 Implement basic objc_msgSend capabilities.
Swift SVN r3104
2012-11-03 00:26:56 +00:00
Doug Gregor
b10920d65d Cope with DataLayout::getIntPtrType() change on mainline.
Swift SVN r3073
2012-10-28 03:30:24 +00:00
John McCall
e298448e7d Compensate for a trunk LLVM change.
Swift SVN r2983
2012-10-11 20:14:08 +00:00
Eli Friedman
dd299a35af Fix for LLVM TargetData -> DataLayout rename.
Swift SVN r2959
2012-10-09 23:18:24 +00:00
John McCall
34da6d1650 Implement grabbing an external value witness table. I
described this mangling in a previous commit, and the runtime
is already using it for some standard tables.

Swift SVN r2870
2012-09-19 06:33:36 +00:00
John McCall
2c21ee7796 Add the compiler infrastructure for emitting references to tuple and
function metadata.

Swift SVN r2864
2012-09-18 07:23:51 +00:00
John McCall
5b10c5df32 Move emitClassMetadataRef to GenMeta.cpp and make it work for
an arbitrary metadata type.

Swift SVN r2862
2012-09-18 07:23:44 +00:00
John McCall
1529e0ddd4 Arrange for general mangling of type metadata.
Swift SVN r2853
2012-09-13 21:26:07 +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
John McCall
20bfc9c1ec Initial, untested support for uniquing generic class metadata,
which is necessary to embed the value witnesses there.

Swift SVN r2671
2012-08-17 06:47:33 +00:00
Chris Lattner
cd3f362faf revert r2364, which introduced the swift_allocClass entrypoint. The optimization that it was
trying to block has since been reverted, and I think there are other approachs that will work.


Swift SVN r2547
2012-08-03 23:27:15 +00:00
Eli Friedman
29b3994cca Add a new entry point for allocating classes. This API probably isn't really
right, but we need something in the meantime to make the optimizer understand
that there could be non-trivial destructors involved.



Swift SVN r2366
2012-07-17 23:25:02 +00:00
John McCall
e53aed65d7 Initial support for IR-genning generic function bodies.
Mangling is still a hack, pending a better type AST.  Fixed
a bug where arguments passed indirectly were not being destroyed
by the callee (when passed by value).  Changed some of the protocol
signatures to use the generic opaque pointer type, making the
types a bit more self-documenting in the IR.

Swift SVN r2274
2012-06-28 08:50:06 +00:00
John McCall
668f674bfa Split off a PolymorphicFunctionType from FunctionType. I am
*positive* that the behavior here is blatantly wrong in a lot
of places, but I'm going to leave it to Doug to clean up after me. :)

Swift SVN r2255
2012-06-27 00:22:15 +00:00
John McCall
b35ab5e4df Make the opaque type be a named IR type.
Swift SVN r2248
2012-06-25 20:45:06 +00:00
John McCall
770ce0fde7 Refactor to make it easier to keep common information in
the type converter.

Swift SVN r2241
2012-06-25 20:44:59 +00:00
John McCall
24a84132ca More CC-related changes.
Swift SVN r2150
2012-06-05 04:51:04 +00:00
Chris Lattner
16cf77644f switch the frontend to generate swift_retain_noresult calls instead of
swift_retain calls.  The pertinent difference is that the former can be
marked nocapture, allowing general LLVM optimizations more flexibility.

With this change, early-cse is able to zap 9 more instructions, and 3
more functions are able to be marked nocapture by functionattrs in the
stdlib.


Swift SVN r2043
2012-05-28 20:20:07 +00:00
Chris Lattner
4f4636db31 adjust to mainline API change, and implement rdar://11542870 - @swift_release should be marked nocapture
Swift SVN r2031
2012-05-28 01:52:47 +00:00
John McCall
40d1591f89 Some minor tweaks to make our use of the allocation entrypoints
match the actual entrypoints vended by the runtime:
1) there is no swift_slowRawAlloc
2) swift_deallocObject takes two arguments
Also, make all calls to swift_allocObject go through a common
function so that we can easily use optimized entrypoints if the
runtime provides them.

Swift SVN r1993
2012-05-25 17:34:59 +00:00
John McCall
4b562e6b62 Use the actual raw-allocation APIs, including the optimized
allocation entrypoints.

Swift SVN r1976
2012-05-24 19:16:09 +00:00
Dave Zarzycki
94e67cc4e9 Add fast/basic alloc/dealloc APIs
Swift SVN r1908
2012-05-21 17:08:54 +00:00
John McCall
38bac7c706 Add Builtin.ObjCPointer with accompanying IR-gen support and
wrap it in an 'id' type in the standard library.

Also fix a bug noticed by inspection where initWithTake for
function types wasn't entering a cleanup for the taken value.
This probably doesn't matter for existing possibilities, but
it's potentially important under exceptions.

Swift SVN r1902
2012-05-18 23:40:17 +00:00
John McCall
d461d72e85 Implement ErasureExpr in IR-gen, at least as far as generating
value witnesses goes.

There are three major remaining things to do to support protocols:
  - laying out the actual protocol members
  - emitting witnesse for the actual protocol members
  - detecting uses of the actual protocol members and funnelling
    them through the witnesses as appropriate
All this work was just to let us treat protocol types as
first-class values.

Swift SVN r1899
2012-05-18 10:02:01 +00:00
John McCall
85acda32bb Implement basic functionality for protocol types, with the
exception of assign.

Swift SVN r1895
2012-05-18 10:01:46 +00:00
John McCall
48cd78cfef Allow an opaque struct type to be specified as the struct
to perform struct-layout into.

Swift SVN r1823
2012-05-12 07:19:43 +00:00
John McCall
5ad3782b01 Rework the IR-generation of initialization and teach the
compiler to enter properly-scoped cleanups to destroy local
variables.

Swift SVN r1385
2012-04-11 03:00:08 +00:00
John McCall
f3e27d90ff Change IR-generation so that it emits metadata objects for the
heap allocations it makes, and switch swift_alloc over to pass
that pointer in as well as the alignment.  Also, compute
whether a type is POD during its generation and cache that in
the object, and introduce a method on TypeInfo to destroy an
object in memory.

Swift SVN r1356
2012-04-10 06:28:22 +00:00
Eli Friedman
29f3fca950 First iteration of CaptureAnalysis.
Swift SVN r1284
2012-03-29 00:24:03 +00:00
John McCall
aafaae22bc Properly include the heap header when laying out structures
for the heap.

Swift SVN r1275
2012-03-27 23:54:10 +00:00