Commit Graph

51 Commits

Author SHA1 Message Date
Graham Batty
d15c24e25b Changes to runtime library to support non-objc targets
Swift SVN r23122
2014-11-05 23:17:07 +00:00
Joe Groff
6c3e43f653 Runtime: Fix race in conformsToProtocol failure case.
Another thread could pull enqueued records into the cache while we're waiting on the lock, leaving us with an empty queue but an updated cache. Recognize this by sticking a generation on the cache and retrying instead of failing if the generation increased while we waited. Fixes rdar://problem/18856858.

Swift SVN r23091
2014-11-04 01:22:33 +00:00
Joe Groff
90cb504b75 Runtime: Switch swift_conformsToProtocol over to the new implementation.
Swift SVN r23083
2014-11-03 06:12:18 +00:00
Joe Groff
e773d9a1aa IRGen: Unique the metadata for imported structs and enums at runtime.
Move the uniquing information for ForeignTypeMetadata behind the address point so we can share the layout between foreign classes and the existing layout for struct and enum metadata. Emit metadata records for imported structs and enums as foreign metadata candidates, and dynamically unique references to the metadata by calling swift_getForeignTypeMetadata.

Swift SVN r23081
2014-11-03 06:12:13 +00:00
Joe Groff
ef82526795 Runtime: Hack up support for conformance lookup on ObjC classes.
As a stopgap till IRGen properly emits indirected class references, support direct class reference protocol conformance records. This should get us to the point we can replace the dlsym hack with the new implementation.

Swift SVN r23073
2014-11-03 00:17:55 +00:00
Joe Groff
4d4698b73d IRGen: Handle CF types and (improperly) imported value types.
We should unique foreign struct/enum metadata the same way we do CF foreign class metadata, but for now, treat them as direct references like we do in IRGen.

Swift SVN r23072
2014-11-02 23:38:42 +00:00
Joe Groff
01554448fc Runtime: Walk up superclass chains to find class conformances.
Swift SVN r23065
2014-11-02 15:41:00 +00:00
Joe Groff
139bf0323d Runtime: Cache nondependent generic witnesses for lookup.
We can share a lookup cache entry under the generic metadata pattern when the witness table for a protocol conformance is shared among all instances of the type. (This happens to always be the case currently.)

Swift SVN r23062
2014-11-02 01:17:14 +00:00
Joe Groff
f205082b6d IRGen: Register JITed conformances with the runtime.
dyld won't help us with JIT code, so we need to inject a runtime call to add the conformances ourselves in JIT mode.

Swift SVN r23058
2014-11-01 22:20:10 +00:00
Joe Groff
2dc7678253 Runtime: Handle the easy cases for protocol lookup.
Set up the basic logic for first looking into a cache then pulling in conformances from enqueued images and trying again for exact-matchable types (pretty much just nongeneric native value types).

Swift SVN r23053
2014-11-01 02:46:52 +00:00
Ben Langmuir
67c058fa6c Fix no-asserts build after r23025
dump() is not available when NDEBUG is defined.

Swift SVN r23034
2014-10-31 16:38:41 +00:00
Joe Groff
81568bf895 Runtime: Beginnings of protocol conformance lookup.
Set up lazy registration of a dyld add image callback that looks up the "__DATA,__swift1_proto" section in the loaded image. As a first-pass sanity check, just walk the section and dump the records.

Swift SVN r23025
2014-10-31 02:57:57 +00:00
Greg Parker
59f3ef1ca1 Print the source and target type names when a dynamic cast fails.
rdar://18223450. Some types do not have friendly output yet (rdar://16392852).


Swift SVN r22938
2014-10-25 01:37:49 +00:00
Dmitri Hrybenko
aacb5ef3a7 Runtime: use std::max_align_t on Apple platforms and a replacement
otherwise

Clang changed the type that max_align_t is defined to from long double
to a struct.

Swift SVN r22546
2014-10-06 18:54:21 +00:00
Dmitri Hrybenko
29623177b0 Revert "Runtime: add a static assertion that swift_max_align_t is correct for"
This breaks the build on some OS X versions.

Swift SVN r22539
2014-10-06 18:01:00 +00:00
Dmitri Hrybenko
bca99fd265 Runtime: add a static assertion that swift_max_align_t is correct for
Darwin

Swift SVN r22538
2014-10-06 16:53:53 +00:00
Dmitri Hrybenko
97cfe4f993 Runtime: define our own max_align_t that matches the definition in
libc++ for Darwin and is correct for x86_64 Linux

Swift SVN r22493
2014-10-03 15:33:08 +00:00
Graham Batty
ed46e650f3 runtime: Simple wrappers to skip objc refcounts
Swift SVN r22410
2014-09-30 22:31:59 +00:00
Dmitri Hrybenko
165cecfe19 Include required headers
Swift SVN r22327
2014-09-28 02:21:13 +00:00
Joe Groff
93cb4dd83e Runtime: Remove dead HeapArrayMetadata kind.
Swift SVN r22294
2014-09-26 03:12:21 +00:00
Joe Groff
7a08716de3 Runtime: Factor out a helper function on Metadata to say when metadata refers to a class type.
Rename the existing misleadingly-named "isClassType" to "isClassObject", and document that it refers to (swift or ObjC) class objects, the latter of which aren't always type metadata.

Swift SVN r22153
2014-09-21 00:18:16 +00:00
Joe Groff
d2ffcf6afe Runtime: Foreign classes are classes.
Fixes bridging containers of CF types to ObjC. rdar://problem/18397496

Swift SVN r22143
2014-09-19 19:42:43 +00:00
Doug Gregor
e00aaadf48 Allow dynamic casting of foreign metatypes.
Another part of CF casting support, <rdar://problem/18088474>.


Swift SVN r21402
2014-08-22 04:47:11 +00:00
Doug Gregor
61ee5f7529 Allow dynamic casts between foreign classes and other classes.
These casts always succeed, because we don't have any way to check
them (yet). Part of <rdar://problem/18088474>.

Swift SVN r21386
2014-08-21 22:54:10 +00:00
John McCall
77ea35ab46 Introduce a flag to mark classes with Swift-native
refcounting and take advantage of it.

Also, set the Swift1 flag in classes we generate.

Also, initialize a global cache of the non-pointer-isa
mask and use that instead of object_getClass, at least
within the runtime.

Also, centralize the runtime on a _swift_getSuperclass
function and make that use a direct access while we
await word from Greg on the desired ABI requirements.

Swift SVN r21077
2014-08-06 21:51:45 +00:00
Doug Gregor
c25eac69c2 Dynamic casting: fix an overrelease in object-to-value casting via bridging.
When the dynamic cast caller asked to take on success but not destroy
on failure, we still performed the release on failure. Test case to
follow.


Swift SVN r20975
2014-08-03 19:51:27 +00:00
Doug Gregor
c66a1ef98f Dynamic casting: handle value-to-class-existential casts via bridging.
This allows one to cast a value type (say, [String]) to AnyObject or
NSCoding, for example. It's another piece of <rdar://problem/17637959>.


Swift SVN r20964
2014-08-03 05:15:47 +00:00
Doug Gregor
4c06dff759 Dynamic casting: Handle object-to-value casts that use bridging.
For example, this allows dynamic casts from NSArray to [Int], using
bridging. Part of <rdar://problem/17637959>.


Swift SVN r20963
2014-08-03 04:11:45 +00:00
Doug Gregor
a53f7f5dbf Formatting cleanup and comments; NFC
Swift SVN r20952
2014-08-02 16:36:18 +00:00
Doug Gregor
c593d49b08 Rework the _ObjectiveCBridgeable to use inout parameters rather than returns.
The _forceBridgeFromObjectiveC and _conditionallyBridgeFromObjectiveC
requirements of the _ObjectiveCBridgeable protocol previously returned
Self and Self?, respectively, where 'Self' is the value type that is
bridged. This use of returns is fairly hostile to the idea of calling
the witnesses for these requirements from the C++ part of the runtime,
leading to "interesting" tricks with OpaqueExistentialContainer that
made it hard to use these witnesses within the dynamic casting
infrastructure.

Replace the returns with inout Self? parameters, which are far easier
to deal with in the C++ part of the runtime. Despite the churn because
we're changing the _ObjectiveCBridgeable protocol, this is NFC.

Swift SVN r20934
2014-08-02 01:03:41 +00:00
Doug Gregor
fd3fa7228f Dynamic casting from Objective-C bridged value types to class types.
First part of <rdar://problem/17637959>.

Swift SVN r20906
2014-08-01 18:44:05 +00:00
Dmitri Hrybenko
c7a5b1daca stdlib/runtime: fix leaks in swift_bridgeNonVerbatimToObjectiveC
Swift SVN r20827
2014-07-31 15:49:17 +00:00
John McCall
934527a029 Eliminate all uses of the typeof value witness.
Swift SVN r20734
2014-07-30 04:40:58 +00:00
Dave Abrahams
9a13a7148b [stdlib] Consolidate bridging protocols
Squash _[Conditionally]BridgedToObjectiveC into one protocol.  This
change results in simpler bridging code with fewer dynamic protocol
conformance checks, and solves the nasty naming/semantics problem that
resulted from having _ConditionallyBridgedToObjectiveC refining
_BridgedToObjectiveC.

Also, rename things so they're more symmetrical and less confusing.

Swift SVN r20664
2014-07-29 01:30:27 +00:00
Dmitri Hrybenko
4c4f83fb52 stdlib: underscore-prefix requirements of _BridgedToObjectiveCType and
_ConditionallyBridgedToObjectiveCType protocols

rdar://17283639


Swift SVN r20079
2014-07-17 09:42:19 +00:00
Dmitri Hrybenko
d125ac1e24 stdlib/runtime: stdlib casts to existentials: correctly project the buffer as
required

rdar://17628745


Swift SVN r20024
2014-07-16 15:17:46 +00:00
Dave Abrahams
6d1095f44e Protocol names end in "Type," "ible," or "able"
Mechanically add "Type" to the end of any protocol names that don't end
in "Type," "ible," or "able."  Also, drop "Type" from the end of any
associated type names, except for those of the *LiteralConvertible
protocols.

There are obvious improvements to make in some of these names, which can
be handled with separate commits.

Fixes <rdar://problem/17165920> Protocols `Integer` etc should get
uglier names.

Swift SVN r19883
2014-07-12 17:29:57 +00:00
Doug Gregor
c7adb497ba Blocks "are" classes, from the runtime perspective.
This allows arrays of blocks to be bridged at runtime
<rdar://problem/17035548>.

Swift SVN r19765
2014-07-10 00:12:14 +00:00
Doug Gregor
0598b6db5e Casting runtime: Use the runtime's constant for reserved bits in an ObjC pointer.
Previously, we had a predicate that only worked properly for 64-bit
architectures; the 32-bit platforms don't have tagged pointers, and
have an annoying tendency to allocate objects with the high bit of the
address set. Fixes <rdar://problem/17544277>.

Swift SVN r19523
2014-07-03 17:55:38 +00:00
Doug Gregor
2618061168 Eliminate a pointless and wrong initialization from swift_bridgeNonVerbatimFromObjectiveCConditional.
Fixes part of <rdar://problem/17411843>.

Swift SVN r19485
2014-07-02 22:15:47 +00:00
John McCall
d0dc196e8b Fix a metatype casting bug in the new casting runtime.
Swift SVN r19078
2014-06-22 09:53:34 +00:00
Doug Gregor
e47b0c220f Address Dmitri's review comments
Swift SVN r19047
2014-06-20 13:57:00 +00:00
Doug Gregor
22dc55058e Make bridgeFromObjectiveC return non-optional.
Now that we use bridgeFromObjectiveCConditional to perform conditional
bridging, make bridgeFromObjectiveC handle forced bridging. For the
latter, deferred checking is acceptable.

Almost all of <rdar://problem/17319154>.


Swift SVN r19046
2014-06-20 13:15:41 +00:00
John McCall
47427ccc5a Ensure that we deallocate opaque existential containers
if we dynamic-cast out of them as a take.

Swift SVN r19043
2014-06-20 07:47:01 +00:00
Doug Gregor
2e3863b211 Introduce _ConditionallyBridgedToObjectiveC.bridgeFromObjectiveCConditional.
This entry point is used in conditional downcasts (as?) to attempt to
bridge from an Objective-C class down to a specific native type (e.g.,
array, dictionary), bridging all elements eagerly so that it can
produce nil if the bridging would fail.

This is the scaffolding for <rdar://problem/17319154>, and makes the
example there work, but there is much more cleanup and optimization to
do.



Swift SVN r18999
2014-06-19 14:48:00 +00:00
John McCall
9890d8bca0 Add swift_dynamicCast.
This is the most general dynamic cast operation, permitting
arbitary source and destination types and handling arbitrary
changes in representation.  A value of the destination type
is constructed in an address provided by the caller; flags
control the behavior w.r.t. the source value.

Not yet used; probably buggy in various particulars.

Swift SVN r18815
2014-06-12 00:13:13 +00:00
John McCall
0f0874bb4b Add variants of the checked-cast instructions that
put the result in a different place.

WIP: no IRGen support yet.

This will eventually be the required form when casting
to an address-only type; the existing instructions will
have only scalar outputs.

Swift SVN r18780
2014-06-10 07:43:22 +00:00
John McCall
5e1c15df93 Rationalize the class-instance dynamicCast runtime functions.
dynamicCastClass assumes that the destination type is a
Swift class type.

dynamicCastObjCClass assumes that the destination type is
an ObjC class type (represented as ObjC metadata, not type
metadata).

dynamicCastUnknownClass assumes only that the destination
type is some kind of class.

Swift SVN r18776
2014-06-10 02:11:24 +00:00
Joe Groff
cf20524271 Fix typo.
Swift SVN r18761
2014-06-09 22:19:12 +00:00
John McCall
1f5fa04724 Move the rest of the dynamic-cast code over to Casting.cpp.
Swift SVN r18759
2014-06-09 21:42:30 +00:00