Commit Graph

3150 Commits

Author SHA1 Message Date
Joe Groff
86157d533e Runtime: Reenable metatype casting code when ObjC interop is disabled.
Fixes rdar://problem/20583365, and incidentally gets test/Interpreter/layout_reabstraction.swift to work without ObjC interop as well.

Swift SVN r27557
2015-04-22 03:49:12 +00:00
Joe Groff
4c4069d9e9 Runtime: Use 'nullptr' instead of 'nil'.
'nil' is only defined if the ObjC runtime is imported.

Swift SVN r27545
2015-04-22 00:45:07 +00:00
Joe Groff
79ee6f21c4 Runtime: Recognize class and @objc existential metatypes as class instances in swift_isClassOrObjCExistential.
Fixes rdar://problem/20131232.

Swift SVN r27534
2015-04-21 18:24:10 +00:00
Devin Coughlin
c9bc783eed [Runtime] Remove an unneeded dispatch_once() in Availability.mm
Following Dmitri's advice, remove an unneeded dispatch_once() and use an
initializer of a function-local static variable instead. NFC.

Swift SVN r27516
2015-04-21 03:41:10 +00:00
Dave Abrahams
7cd1429f59 [stdlib] Add _getSuperclass(AnyClass)
We'll need this to handle class mirrors properly

Swift SVN r27500
2015-04-20 21:58:24 +00:00
Joe Groff
fcf535d682 Runtime: Implement ObjC-free metatype dynamic casts.
Swift SVN r27414
2015-04-17 05:30:35 +00:00
John McCall
a67452c72c SILGen for throwing foreign errors out of @objc thunks.
Also, create a new file specifically for the foreign-error
code.

Swift SVN r27347
2015-04-16 05:16:54 +00:00
Joe Groff
1b2fcd1852 IRGen/Runtime: AnyObject never has a witness table, even if it isn't @objc.
@objc protocols aren't supported with an ObjC runtime, but we still want values of AnyObject type to be word-sized. Handle this by turning the binary "needsWitnessTable" condition into a "dispatch strategy" enum, so we can recognize the condition "has no methods, so neither swift nor objc dispatch" as distinct from either swift or ObjC protocol representations. Assign this dispatch strategy when we lower AnyObject. Should be NFC for the ObjC-enabled build.

(It would also be beneficial for the ObjC-runtime-enabled version of Swift if AnyObject weren't an @objc protocol; that would mean we could give it a canonical protocol descriptor in the standard library, among other things. There are fairly deep assumptions in Sema that AnyObject is @objc, though, and it's not worth disturbing those assumptions right now.)

Reapplying with updates to the runtime unit tests.

Swift SVN r27341
2015-04-16 00:24:51 +00:00
Joe Groff
af6e1933f0 Revert "IRGen/Runtime: AnyObject never has a witness table, even if it isn't @objc."
This reverts commit r27338. Runtime unit tests need to be updated.

Swift SVN r27340
2015-04-16 00:13:52 +00:00
Joe Groff
2b93411ba7 IRGen/Runtime: AnyObject never has a witness table, even if it isn't @objc.
@objc protocols aren't supported with an ObjC runtime, but we still want values of AnyObject type to be word-sized. Handle this by turning the binary "needsWitnessTable" condition into a "dispatch strategy" enum, so we can recognize the condition "has no methods, so neither swift nor objc dispatch" as distinct from either swift or ObjC protocol representations. Assign this dispatch strategy when we lower AnyObject. Should be NFC for the ObjC-enabled build.

(It would also be beneficial for the ObjC-runtime-enabled version of Swift if AnyObject weren't an @objc protocol; that would mean we could give it a canonical protocol descriptor in the standard library, among other things. There are fairly deep assumptions in Sema that AnyObject is @objc, though, and it's not worth disturbing those assumptions right now.)

Swift SVN r27338
2015-04-15 23:53:25 +00:00
Joe Groff
225a0ebd70 Runtime: Non-ObjC-interoperable version of ErrorObject implementation.
This gets the runtime building again with ObjC interop disabled, though the standard library still has issues.

Swift SVN r27326
2015-04-15 20:27:24 +00:00
John McCall
156a4c7ed0 SILGen for calls under foreign error conventions. WIP.
Swift SVN r27270
2015-04-14 02:35:54 +00:00
Joe Groff
c0a2994564 AST: Start printing function types with @convention instead of old attributes.
And update tests to match.

Swift SVN r27262
2015-04-13 22:51:34 +00:00
Dmitri Hrybenko
29b15adff1 stdlib: make println() output atomic within one call
rdar://17016326

Swift SVN r27248
2015-04-13 05:51:47 +00:00
Greg Parker
69757f2b60 Fix 32-bit build after r27225.
On 32-bit, swift_allocBox() returns something that implicitly 
converts to BoxPair; it doesn't return a BoxPair directly.


Swift SVN r27226
2015-04-11 01:20:18 +00:00
Joe Groff
9869aed7bf Runtime: Allow value type ErrorTypes to dynamically coerce to NSError.
If we see an ErrorType-conforming value type while casting to NSError, do the coercion in the runtime, so that e.g. 'error as Any as! NSError' works as well as 'error as NSError'.

Unfortunately, we can't do this for ErrorType-conforming classes without shattering SIL's brittle view of the world due to rdar://problem/20507075. Casts between class types are fairly deeply assumed not to change the identity of the reference.

Swift SVN r27225
2015-04-11 00:18:33 +00:00
Joe Groff
768420d33b IRGen/Runtime: Give ErrorType its own retain/release entry points.
Some future-proofing to let us change ErrorType's reference counting in the future, or to use various tagged pointer optimizations in its representation.

Swift SVN r27213
2015-04-10 18:54:16 +00:00
Joe Groff
7612df1918 Runtime: Rename 'becomeNSError' to 'bridgeErrorTypeToNSError'.
We may want to use optimized ErrorType representations that don't naturally "become" NSErrors, such as tagged-pointer representations of small error enums, or a tagged function pointer to a deferred error type constructor. Rename the runtime function to something a bit more descriptive of its real purpose, not its implementation.

Swift SVN r27209
2015-04-10 17:37:40 +00:00
Devin Coughlin
857a60dea1 Runtime: Cache OS version for availability in a thread-safe manner.
On OS X 10.9 and iOS 7 the runtime support for #availability was reading the system plist
on every query. Now, use dispatch_once to cache the results of the expensive
plist lookup ourselves.

rdar://problem/18471069

Swift SVN r27199
2015-04-10 02:24:32 +00:00
Dmitri Hrybenko
ff2dd6320a stdlib: fix coding style
When colon specifies is-a relationship between types, we put spaces on
both sides of the colon.

Swift SVN r27016
2015-04-05 05:54:55 +00:00
Joe Groff
fe3d75eec8 Update for feedback from Dmitri.
Simplify the observation evaluation in the ErrorType race test by using evaluateObservationsAllEqual, and run the test for real. Apparently round-trip NSString and NSDictionary bridging doesn't produce a stable object, so use valueForKey as a hack to sidestep bridging so we can verify that the identities of the bridged domain and code aren't racy.

Swift SVN r27003
2015-04-05 03:07:42 +00:00
Joe Groff
41f73d43ae Runtime: Try to make lazy ErrorType-to-NSError bridging thread-safe.
Atomically initialize and load the NSError bridging fields within an ErrorType box so that we do the right thing when two threads concurrently coerce the box to NSError.

Swift SVN r26996
2015-04-05 00:17:34 +00:00
Joe Groff
b2cb75ad30 Runtime: Add a 'swift_becomeNSError' entry point to coerce an ErrorType box to an NSError instance.
If the NSError part of the box hasn't been initialized yet, fill it in with the domain and code of the contained value. This will allow us to efficiently turn ErrorType values into NSErrors, either for bridging or for coercion purposes.

Swift SVN r26958
2015-04-03 22:16:52 +00:00
Joe Pamer
980bd819a2 Propagate 'throws' information into function type metadata.
Swift SVN r26956
2015-04-03 21:45:33 +00:00
Chris Lattner
79ed57f9f2 standardize naming of tuples and tuple patterns on "elements".
Previously some parts of the compiler referred to them as "fields",
and most referred to them as "elements".  Use the more generic 'elements'
nomenclature because that's what we refer to other things in the compiler
(e.g. the elements of a bracestmt).

At the same time, make the API better by providing "getElement" consistently
and using it, instead of getElements()[i].

NFC.



Swift SVN r26894
2015-04-02 20:23:49 +00:00
Joe Groff
72643fd774 Runtime: Implement dynamic cast bridging from NSError to bridged error enums.
This allows ErrorTypes referencing Cocoa NSErrors to be pattern-matched against our bridged enums, at least dynamically. (The compiler still doesn't understand these bridging conversions yet.)

Swift SVN r26839
2015-04-02 00:19:30 +00:00
Greg Parker
5e8f6116e4 Fix +[SwiftObject description] and +[SwiftObject debugDescription].
rdar://20380089


Swift SVN r26810
2015-04-01 11:04:46 +00:00
Greg Parker
1d7a09d8b4 Implement +[SwiftObject instancesRespondToSelector:].
rdar://20307260


Swift SVN r26808
2015-04-01 09:48:42 +00:00
Greg Parker
3b4ba55cd9 Always return a valid zone from [SwiftObject zone].
Swift SVN r26807
2015-04-01 09:13:10 +00:00
Joe Groff
233f8cfc4f Runtime: Fix accidental fallthrough in swift_getErrorValue from NSError case to normal case.
Swift SVN r26713
2015-03-30 04:52:56 +00:00
Joe Groff
5f676656a0 Runtime: Fill in the hooks to be able to use an NSError as an ErrorType.
Swift SVN r26702
2015-03-29 15:44:35 +00:00
Joe Groff
89e0fbf7ff Runtime: Support casting into and out of ErrorType boxes.
Swift SVN r26619
2015-03-27 02:09:49 +00:00
Joe Groff
7514921a86 Runtime: Remove obsolete _stdlib_conformsToProtocol function.
'x is P' works now, and this function isn't used anywhere except by a test that exercises it. Removing this also lets us remove a swath of otherwise unused helper static functions in the runtime.

Swift SVN r26618
2015-03-27 02:08:58 +00:00
Erik Eckstein
663f08557a stdlib: Use a dedicated pointer spare bit to distinguish between native and ObjC object in BrigeStorage.
This simplifies the code for is-native checking. Now it can be done by a single and-mask operation.



Swift SVN r26591
2015-03-26 14:35:10 +00:00
Joe Groff
b7f84a68d7 Runtime: Allocate Swift errors as an NSError subclass.
After some more discussion with John, we decided that subclassing is the only realistic option, at least until we eventually are able to integrate with the OS. Switch things around to allocate Swift error boxes as an ObjC subclass that contains the error value instead of trying to game it as a CFError.

Swift SVN r26562
2015-03-25 23:02:57 +00:00
Joe Groff
ff5f87f56b Runtime: Add ExistentialTypeMetadata helpers for taking values.
Add a 'mayTakeValue' function, which returns true if we're allowed to take the value from an existential container (assuming we own the existential container value). This is true for class and opaque existential containers, but not for boxed existentials, where multiple owners may share references to the boxed value. Also add a 'deinitExistentialContainer' function to do any cleanup that must happen after the value has been consumed out of an existential container. Fix up an off-by-one indirection level in the SwiftError implementations of the existing existential container methods.

Swift SVN r26561
2015-03-25 23:02:56 +00:00
Joe Groff
33ce2bc61d Spot fixes, NFC
Swift SVN r26560
2015-03-25 23:02:56 +00:00
Joe Groff
ee69e2ea0d Runtime: Return after false assertion.
Swift SVN r26559
2015-03-25 23:02:55 +00:00
Ben Langmuir
784a05faf2 [cmake] Replace a bunch of OSX checks with Darwin checks
These should all apply to any Darwin platform, and the current behaviour
was breaking cross-compilation.

Introduces a SWIFT_DARWIN_VARIANTS pattern, to be used as follows:
    if(SWIFT_HOST_VARIANT MATCHES "${SWIFT_DARWIN_VARIANTS}")

Also fix one place where I checked the CMAKE_SYSTEM_NAME instead of the
host variant that I recently introduced.  I haven't attempted to find
the rest of the places we're doing this though.

Swift SVN r26554
2015-03-25 21:15:30 +00:00
Ben Langmuir
9b6ac6e089 Add swift_runtime_objc_sources on all Darwin platforms
They're not OSX-only.

Swift SVN r26540
2015-03-25 16:05:59 +00:00
Joe Groff
668928cc83 Runtime: Handle ErrorType's layout in ExistentialTypeMetadata accessors.
Teach ExistentialTypeMetadata how to project out the value pointer, type metadata, and protocol witness table from ErrorType containers. NFC yet; the dynamic casting and reflection machinery needs further work to correctly handle ErrorType boxes.

Swift SVN r26509
2015-03-25 00:56:16 +00:00
Joe Groff
8571b4f6a9 Runtime: Check for SpecialProtocol::AnyObject instead of strcmp'ing the mangled protocol name.
Swift SVN r26500
2015-03-24 21:48:08 +00:00
Joe Groff
feb5371e27 Runtime: Use ObjC pointer value witness for ErrorType.
Swift SVN r26497
2015-03-24 19:42:08 +00:00
Joe Groff
ef8cc448d0 Runtime: Instantiate existential metadata with special protocol set.
If an existential type for a special protocol (not a composition) is instantiated, carry the special protocol identifier from that protocol to the existential, allowing us to easily recognize existentials with unique runtime characteristics.

Swift SVN r26436
2015-03-23 17:06:22 +00:00
Joe Groff
9ec27cbd62 Runtime: Stub out runtime operations for ErrorType boxes.
Swift SVN r26335
2015-03-19 23:50:06 +00:00
Dmitri Hrybenko
85764fd6aa runtime: fix two bugs in swift_conformsToProtocol on Linux
First, on x86-64 Linux does not reserve lower 2 Gb of the address space,
and a space saving trick in the runtime did not work properly, confusing
pointers and failure generation numbers together.

Second, we ignored protocol conformances inside the executable (only
considered shared libraries).

Swift SVN r25972
2015-03-11 05:54:11 +00:00
Dmitri Hrybenko
e2c43ab2c0 Revert "wip"
This reverts commit r25880, which was done by accident.

Swift SVN r25885
2015-03-09 16:28:40 +00:00
Dmitri Hrybenko
89d1d924bd CMake: unbreak the build on Linux after stdlib reorganization
Runtime should use LINK_LIBRARIES to link to ICU, since it is a static
archive, and we need this link dependency to be propagated to the
libswiftSwiftCore library.  I have no idea why it linked correctly
worked before.

Swift SVN r25881
2015-03-09 10:09:36 +00:00
Dmitri Hrybenko
fbdbcf88aa wip
Swift SVN r25880
2015-03-09 10:09:33 +00:00
Dmitri Hrybenko
350248dae5 Reorganize the directory structure under 'stdlib'
The standard library has grown significantly, and we need a new
directory structure that clearly reflects the role of the APIs, and
allows future growth.

See stdlib/{public,internal,private}/README.txt for more information.

Swift SVN r25876
2015-03-09 05:26:05 +00:00