Commit Graph

122 Commits

Author SHA1 Message Date
John McCall
b186be429b Catch errors in top-level code.
Swift SVN r28133
2015-05-04 22:15:28 +00:00
John McCall
5c171fd448 Parsing, type-checking, SILGen, and IRGen for try!.
Swift SVN r28085
2015-05-02 08:03:15 +00:00
Nadav Rotem
9b2b75b859 IRGen: Insert a call to swift_willThrow to allow lldb to place a breakpoint.
rdar://20356658.

Swift SVN r27710
2015-04-24 22:09:15 +00:00
Joe Groff
00f7520888 IRGen/Runtime: Combine the separate per-convention function metadata caches into one.
We have enough flag bits on function types now to warrant stashing an extra word in the metadata key alongside the arguments and results, so add one, and pack the number of arguments, function convention, and 'throws' bit in there. This lets us merge the separate metadata caches for thick/thin/block/C functions into one, saving a bit of runtime memory, and simplifying a bunch of repetitive code in the runtime and IRGen.

This also fixes a subtle bug we had where the runtime getFunctionTypeMetadata function expected the result argument to be passed in the arguments array, but IRGen was passing it as a separate argument, which would have caused function type metadata to fail to be uniqued by result type.

Swift SVN r27651
2015-04-23 22:58:11 +00:00
Joe Groff
c4ec47ddea IRGen/Runtime: Metadata for @convention(c) function types.
For now, C&P a new metadata cache for C function pointers, like we do for blocks and thin types.

Swift SVN r27595
2015-04-22 18:06:23 +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
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
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
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 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
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
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
ee69e2ea0d Runtime: Return after false assertion.
Swift SVN r26559
2015-03-25 23:02:55 +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
9ec27cbd62 Runtime: Stub out runtime operations for ErrorType boxes.
Swift SVN r26335
2015-03-19 23:50:06 +00:00