Commit Graph

1543 Commits

Author SHA1 Message Date
Joe Groff
3a8f81433f IRGen: Add a nominal type descriptor to class metadata.
Swift SVN r9503
2013-10-18 22:51:27 +00:00
Joe Groff
a0cd122a76 Tweak NominalTypeDescriptor layout a bit.
No reason to try to shove the kind-dependent bits after the tail-emplaced generic parameter description. Let's plan to put the field names in here too so we can give a reasonable lowest common denominator display for aggregates even without debug info.

Swift SVN r9490
2013-10-18 21:04:52 +00:00
Joe Groff
0d50abcb04 Runtime: Sketch out a layout for NominalTypeDescriptor.
In the short term LLDB needs to be able to find and parse generic parameter vectors and field offset vectors from metadata records without necessarily having the debug info necessary to do so. Start off the descriptor by including these offsets and lengths.

Swift SVN r9458
2013-10-17 18:49:02 +00:00
Joe Groff
280fc60ce9 IRGen, runtime: Poke generic size and alignment into class metadata.
This should get us actually allocating and deallocating generic root class instances.

Swift SVN r9251
2013-10-12 03:34:27 +00:00
Joe Groff
43dd2f76d3 runtime: Add swift_initClassMetadata function.
Similar to swift_initStructMetadata, takes a vector of field type metadata and calculates the offsets of all of the fields.

Swift SVN r9237
2013-10-11 23:56:53 +00:00
Joe Groff
ef58b853f7 runtime: Add a swift_initStructMetadata entry point.
Does what it says on the tin: lays out the fields, storing their offsets into the metadata, and initializes the size, flags, and stride of the value witness table.

Swift SVN r9120
2013-10-10 00:55:51 +00:00
Joe Groff
e109124186 Replace 'union' keyword with 'enum'.
This only touches the compiler and tests. Doc updates to follow.

Swift SVN r8478
2013-09-20 01:33:14 +00:00
Greg Parker
1a07770bbc Remove x86-specific code that was unused on x86.
Swift SVN r8446
2013-09-19 10:58:32 +00:00
Joe Groff
000d8e4953 Runtime: Add functions for dynamic single-payload dispatch.
Add functions to dynamically query the extra inhabitants of a single-payload union's payload metadata, then identify or store bit patterns used to represent empty cases, whether they happen to use extra inhabitants or added tag bits.

Swift SVN r8320
2013-09-17 01:29:35 +00:00
Greg Parker
e37d06efff arm64 does not have fast entry points.
Swift SVN r8176
2013-09-13 01:24:02 +00:00
Greg Parker
9c0f1fafd1 Update slow versions of FastEntryPoints.
Swift SVN r7938
2013-09-05 02:45:34 +00:00
Joe Groff
33d2122ce9 IRGen/Runtime: Change generic metadata template to use a fill function.
Instead of hardcoding a walk of a list of fill ops, have generic metadata templates carry a pointer to a fill function for swift_getGenericMetadata to invoke to perform the fill operations. For types with dynamic layout, we will need to be able to perform more complex fill operations than a simple transfer of arguments into generic metadata slots.

Swift SVN r7893
2013-09-04 02:13:34 +00:00
Joe Groff
19fb7d6b64 runtime: Allocate refcounted storage for swift_NSStringToString.
Instead of letting swift_NSStringToString leak malloced memory, use swift_allocPOD to allocate storage for the converted String, and stash the heap object into the created string.

Swift SVN r7872
2013-09-03 22:27:40 +00:00
Joe Groff
691ce0e943 runtime: Add swift_allocPOD entry point.
swift_allocPOD allocates a heap object capable of holding POD data of some given size and alignment. This will allow 'alloc_box' and 'alloc_array' to lower specially without instantiating do-nothing heap metadata for POD types, as described in <rdar://problem/13129334>. Update the dynamic swift_allocBox entry point to use swift_allocPOD for POD types. This can also be used by other runtime functions that need to allocate reference-counted scratch memory, such as swift_NSStringToString, as noted in <rdar://problem/14646715>.

Swift SVN r7860
2013-09-03 20:49:02 +00:00
John McCall
14cb7001b3 Implement basic support for [weak].
Swift SVN r7041
2013-08-08 04:04:51 +00:00
John McCall
b77c430848 Add SIL-gen and some missing runtime support for [unowned].
Swift SVN r6881
2013-08-03 08:46:54 +00:00
Doug Gregor
0842fb5cf8 Rename "base class" to "superclass" and "derived class" to "subclass".
Standardize on the more-common "superclass" and "subclass" terminology
throughout the compiler, rather than the odd mix of base/derived and
super/sub. 

Also, have ClassDecl only store the Type of the superclass. Location
information will be part of the inheritance clause for parsed classes.




Swift SVN r6687
2013-07-29 15:48:34 +00:00
John McCall
7b86817b3c Basic value structure for [weak] and [unowned] references.
Add a bunch of new entrypoints and give them terrible
implementations.

Swift SVN r6322
2013-07-17 09:20:20 +00:00
Dave Zarzycki
e767497062 Basic runtime support for weak references
Swift SVN r5875
2013-06-28 20:01:30 +00:00
Joe Groff
89c343d7b9 runtime: Add dynamicCastIndirect* runtime functions.
Add swift_dynamicCastIndirect and swift_dynamicCastIndirectUnconditional runtime functions, which take an opaque value pointer and source and target type metadata and do a checked cast on the opaque value, calling down to dynamicCast for class casts or doing static equivalence checks for non-class casts.

Swift SVN r5681
2013-06-19 16:45:03 +00:00
Joe Groff
9a8ff4322f runtime: Stub out metadata for Bool.
This is a workaround for <rdar://problem/13986638>, since the compiler doesn't yet generate metadata for oneof types (and the final layout of oneof metadata is TBD).

Swift SVN r5360
2013-05-28 15:50:49 +00:00
John McCall
757c0ae304 Track whether a type is POD and whether it uses inline or allocated
storage in a flags word in the value witness table.  Pack the
alignment into only 16 bits of this word.  Optimize tuple value
witnesses based on whether they're POD and inline.

Swift SVN r5138
2013-05-10 06:16:33 +00:00
John McCall
d8cdb0160f Switch IR-generation to generally traffic in alignment
masks rather than raw alignments.

Swift SVN r5136
2013-05-10 06:16:28 +00:00
Chris Lattner
ca0091a445 add a few "optimized" runtime entrypoints for swift_getTupleTypeMetadata
that handle the 2/3 element cases specially.  These are not actually
optimized at the moment (they just call into swift_getTupleTypeMetadata)
but this could be done at some point.

This is a win for a couple reasons: this reduces the amount of code generated
inline and it allows swift_getTupleTypeMetadata2/3 to be marked readnone,
enabling CSE.  As a driveby, optimize metadata refs of zero element tuples
to directly use _TMdT_, eliminating a branch from swift_getTupleTypeMetadata.



Swift SVN r5070
2013-05-06 23:19:31 +00:00
Joe Groff
2be26b31a5 Make the deallocating destructor actually deallocate.
Emit the deallocObject runtime call inside the deallocating destructor for a heap object, instead of inside swift_release. This will allow for heap objects with known size to directly call fast deallocator entry points and potentially custom deallocators in the future.

Swift SVN r5027
2013-05-02 20:37:12 +00:00
Joe Groff
1594d6cbd6 runtime: Work around GNU 'typeof' extension.
Swift SVN r5021
2013-05-01 23:23:45 +00:00
Joe Groff
08b6f87524 Add 'typeof' to value witness tables.
To be able to get the dynamic type of a generic value, the 'typeof' operation needs to be part of the value witness for the type. Add 'typeof' to the value witness table layout, and in the runtime, provide standard typeof witnesses for static, Swift class, and ObjC class values.

Swift SVN r5013
2013-05-01 18:49:25 +00:00
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
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
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
13bbc9ac76 [objc] Fix closure->block conversion to handle closures with context.
Previously, we were relying on objc_retain to retain the closure, but
closure contexts aren't actually id-compatible. Now we use a C++ RAII
object for Swift to manage the closure context retain count.

In the process, Joe and I discovered that the closure context was being
passed to the conversion shim at +0; that has now been fixed to be +1.

Swift SVN r3948
2013-02-05 19:52:57 +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
Doug Gregor
26b5a375b8 Fix include paths for CMake build, and move the new ObCBridge.h into swift/Runtime.
Swift SVN r3429
2012-12-10 17:59:31 +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
4a591b8493 Move the last runtime header into include/swift/Runtime.
Swift SVN r3399
2012-12-07 16:01:01 +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