Commit Graph

562 Commits

Author SHA1 Message Date
John McCall
4d617d8508 Add API for copying values of unknown size given only a metadata
pointer.  This is suitable for use in a value-witness table.

Swift SVN r4803
2013-04-18 07:58:19 +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
John McCall
045d7e4934 Fix the unittests suite.
Just assume that there's a snarky comment about the magic of cmake here.

Swift SVN r4533
2013-03-29 03:17:15 +00:00
Joe Groff
4397944ea5 Runtime: Fix swift_dynamicCast.
The "Kind" field for class metadata is an isa pointer and not a member of MetadataKind, and so the switch in swift_dynamicCast was falling out and casting to an uninitialized pointer. Guard Metadata behind some accessor methods that do the right thing and update dynamicCast.

Swift SVN r4525
2013-03-28 23:32:01 +00:00
Joe Groff
14d9ed8f1e runtime: Make Metadata not publicly copyable.
Hopefully help prevent further occurrences of <rdar://problem/13284728>.

Swift SVN r4199
2013-02-25 21:41:18 +00:00
Jordan Rose
b3dda15540 Use -isKindOfClass: when casting to an Objective-C type.
Cocoa allows objects to override -isKindOfClass: to lie about their class.
As bad as it is, Swift should respect that. <rdar://problem/13013432>

Note that this clashes with the SWIFT_DISABLE_SWIFT_BIT_ON_CLASS_DATA hack;
on 10.9 -isKindOfClass: will always be used. In the long run, we don't
really want to ask if the target /type/ is an Objective-C type, but rather
if the target /object/ is an Objective-C object.

Swift SVN r3911
2013-01-31 00:34:06 +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
Doug Gregor
f30b9f8bfc Move the Swift runtime headers into include/swift/Runtime.
The runtime headers will be needed by both the Swift runtime layer and
by the Swift-ObjC bridge layer.


Swift SVN r3398
2012-12-07 15:54:25 +00:00