Commit Graph

78 Commits

Author SHA1 Message Date
Nadav Rotem
22b722d1c3 Document and explain which parts of the cache are locked.
Swift SVN r24098
2014-12-23 03:01:12 +00:00
Nadav Rotem
9dbd84932c Document some parts of the conformance search process. NFC.
Swift SVN r24093
2014-12-23 00:32:16 +00:00
Nadav Rotem
e2bd14ddfe Fix an 80-col violation.
Swift SVN r24092
2014-12-23 00:32:15 +00:00
Nadav Rotem
c9308b75b7 Remove the locks from the fast path of swift_conformsToProtocol
Swift SVN r24091
2014-12-23 00:32:15 +00:00
Nadav Rotem
fbd3264662 Whitespace.
Swift SVN r24090
2014-12-23 00:32:15 +00:00
Nadav Rotem
a4a835f712 Refactor the code that searches the conformance cache into a new method. NFC.
Swift SVN r24089
2014-12-23 00:32:14 +00:00
Nadav Rotem
65589c8c7a Whitespace
Swift SVN r24088
2014-12-23 00:32:14 +00:00
Nadav Rotem
0d6888dfa6 Refactor the code that installs the dylib inspection callbacks. NFC.
Swift SVN r24087
2014-12-23 00:32:11 +00:00
David Farler
3c4428dd78 Emit unique metadata for functions with inout
References to functions that take inout parameters crash the compiler
because InOutType isn't a "real" type in itself and has no special type
metadata to emit. It merely further qualifies the function's input
types.

For example, we would like to have a unique entry in the cache for:

var f: (T, T) -> ()

and

var f2: (inout T, T) -> ()

For each argument type metadata pointer in the function's input, take
advantage of pointer alignment and mark the lowest bit if it is inout.
Since the metadata cache uses pointers to create the key, this creates a
unique entry while still being able to extract the actual pointer.

This fixes <rdar://problem/17655125>, and a couple of other similar
crashes.

Swift SVN r23557
2014-11-22 22:01:23 +00:00
Graham Batty
17b1721f8f Implement ELF protocol conformance loading.
This works by loading the protocols from a specially named symbol,
which is generated by the linker through the help of a linker script
that merges all of the protocol conformance blocks into one section
with its size at the start of it and points a global symbol at
the section.

We do all this because unlike MachO, section information does not
survive to be loaded into memory with ELF binaries. Instead,
the mappings that survive are 'segments', which contain one or
more sections. Information about how these relate to their original
sections is difficult, if not impossible, to obtain at runtime.

Swift SVN r23518
2014-11-21 17:09:48 +00:00
Graham Batty
c61e40bbb8 Revert "Implement ELF protocol conformance loading."
This reverts commit r23475 at dgribenko's request.

Swift SVN r23487
2014-11-20 21:31:46 +00:00
Graham Batty
738a1b4ba0 Implement ELF protocol conformance loading.
This works by loading the protocols from a specially named symbol,
which is generated by the linker through the help of a linker script
that merges all of the protocol conformance blocks into one section
with its size at the start of it and points a global symbol at
the section.

We do all this because unlike MachO, section information does not
survive to be loaded into memory with ELF binaries. Instead,
the mappings that survive are 'segments', which contain one or
more sections. Information about how these relate to their original
sections is difficult, if not impossible, to obtain at runtime.

Swift SVN r23475
2014-11-20 17:40:05 +00:00
Maxwell Swadling
5f75d2dca8 Removed _stdlib_dynamicCastToExistential1 hack
It is no longer required.

Swift SVN r23379
2014-11-17 20:56:41 +00:00
Joe Groff
4c0e64f1da Handle class-constrained generic class-to-objc-existential casts.
Fixes rdar://problem/18638625.

Swift SVN r23324
2014-11-14 19:51:20 +00:00
Joe Groff
e5acb5be5c Don't die on a failed dynamicCastUnknownClass cast.
This still fails incorrectly in some cases, but we shouldn't crash the program. Part of rdar://problem/18638625

Swift SVN r23322
2014-11-14 18:16:51 +00:00
Michael Gottesman
9a691a55b2 [playgrounds] Implement _swift_isClass(x: Any) -> Bool.
This is acting as a temporary work around until the more general
getTypeKind() is finalized from an API perspective.

The reason that removing this now instead of waiting makes sense is:

1. The previous way playgrounds was performing this check was using the runtime
c++ implementation of swift_isClassOrObjCExistential via @asmname. We
want to move away from the @asmname approach in general since it is
brittle since it leads to loose cupling of dependencies.

2. The @asmname version in playgrounds caused the deserializer to assert since
the c++ version of swift_isClassOrObjCExistential() does not match the signature
of the swift declaration of swift_isClassOrObjCExistential().

This allows us to avoid the aforementioned issues and make forward
progress on re-enabling the playground logger with optimization.

rdar://18841292

Swift SVN r23307
2014-11-13 19:35:59 +00:00
Joe Groff
412b1332f9 Runtime: Fix crash in cast to existential metatype.
Handle a null conformances pointer in _conformsToProtocol, and when we want to overwrite a metatype, pass a correct conformances pointer for the existential metatype value.

Swift SVN r23304
2014-11-13 17:36:07 +00:00
Dmitri Hrybenko
0d42339173 Runtime: fix the build for !SWIFT_OBJC_INTEROP
Swift SVN r23265
2014-11-12 08:02:28 +00:00
Joe Groff
08fe138808 Runtime: Generate a human-understandable name for Any.Type.
Expose this in the stdlib as _typeName(Any.Type) -> String, pending API review.

Swift SVN r23254
2014-11-11 23:38:24 +00:00
Joe Groff
7ce4ea860c IRGen/Runtime: Handle non-class-metatype to ObjC existential casts.
These always fail, and it doesn't make sense to inline this check into the cast site, so provide additional runtime functions for metatype-to-objc-existential casts.

Swift SVN r23237
2014-11-11 18:51:09 +00:00
Joe Groff
cfa876b440 Use 'as? Protocol' casts in tests instead of a hacked-up entry point.
This exposes an issue with CF types. Looking up their dynamic types gives us an ObjC class, which doesn't necessarily have the same protocol conformances (and for non-bridged types is just NSObject).

Swift SVN r23153
2014-11-07 02:28:18 +00:00
Joe Groff
3c06c3e02d Runtime: Insert missing early exit.
Swift SVN r23152
2014-11-07 02:27:59 +00:00
Joe Groff
16d9998b85 Runtime: Look up witness tables when casting to protocol types that need them.
Swift SVN r23150
2014-11-07 01:17:52 +00:00
Joe Groff
32d148c807 Runtime: Improve type safety when working with witness tables.
Declare an opaque WitnessTable type instead of throwing void* around everywhere.

Swift SVN r23149
2014-11-07 01:17:51 +00:00
Greg Parker
e70ca2762d Runtime: Improve diagnostics for failed casts to ObjC class and protocol types.
Swift SVN r23146
2014-11-07 00:53:05 +00:00
Joe Groff
f0c4b46bf6 Runtime: Remove unused helper.
Swift SVN r23139
2014-11-06 22:32:13 +00:00
Joe Groff
e2cd398caf Runtime: Remove dead casting entry points.
Swift SVN r23138
2014-11-06 22:19:29 +00:00
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