Commit Graph

4650 Commits

Author SHA1 Message Date
Dmitri Hrybenko
4c0075f5bd stdlib: fix mirrors for UTF8 and UTF16 String views so that they actually work
instead of causing a stack overflow

rdar://17897212


Swift SVN r20974
2014-08-03 19:44:17 +00:00
Dmitri Hrybenko
56473c34cd stdlib: change out-of-bounds subscripting traps on mirrors to be
_preconditionFailure()s.  Some of these checks are clearly redundant (for
example, the check of array subscript), but since we have no tests for
these traps (and reflection is not fast in general), I prefer to keep this
transformation as straightforward as possible.


Swift SVN r20971
2014-08-03 18:42:53 +00:00
Dmitri Hrybenko
5746e4e9ca stdlib: rename _fatalError to _sanityCheckFailure. Name similarity between
fatalError and _fatalError has caused some damage already, as some
memory-safety checks in Mirrors are _fatalErrors.


Swift SVN r20969
2014-08-03 15:20:37 +00:00
Doug Gregor
54c4dbb666 Fix weird formatting; NFC
Swift SVN r20968
2014-08-03 05:57:48 +00:00
Doug Gregor
e32acec6e3 VarArgs: use "is" checking on metatypes to check for floating-point arguments on x86-64.
Previously, we were checking whether a particular argument could be
dynamic-casted to a Float or Double (via as?). However, now that
dynamic casting considers bridging, this would try to pass an NSNumber
in a floating-point register, and hilarity ensues. Fixes the
regression I introduced with object-to-value bridging in r20963.


Swift SVN r20967
2014-08-03 05:56:19 +00:00
Joe Groff
dc926bc649 Runtime: Intercept -_tryRetain on the magic base classes of bridged containers.
Strings that get used to name SpriteKit nodes on Mavericks end up weakly referenced by NSMapTables using the legacy GC-compatible weak pointer personality, which for our bridged objects ended up falling into the default NSObject implementation of reference counting via the "_tryRetain" SPI, causing heap corruption. I tried really hard to isolate a test case and failed, but this fixes the Adventure crasher in <rdar://problem/17887502>.

Swift SVN r20966
2014-08-03 05:33:09 +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
Dmitri Hrybenko
6d4f8adbf5 stdlib/String: fix a race in _StringBuffer.grow()
rdar://17855614


Swift SVN r20960
2014-08-02 22:50:45 +00:00
Dmitri Hrybenko
76fc166cd5 stdlib: add missing file comment
Swift SVN r20953
2014-08-02 17:02:07 +00:00
Doug Gregor
a53f7f5dbf Formatting cleanup and comments; NFC
Swift SVN r20952
2014-08-02 16:36:18 +00:00
Dave Abrahams
a7e485d601 [stdlib] _StringCore.replaceRange precondition checks
Swift SVN r20949
2014-08-02 06:01:12 +00:00
Dave Abrahams
6edfddcc1f [stdlib] Remove obsolete _precondition check
Range now guarantees it won't be inverted.

Swift SVN r20948
2014-08-02 06:01:11 +00:00
Dave Abrahams
f270a5b6f3 [stdlib] _StringCore : RangeReplaceable
Swift SVN r20947
2014-08-02 05:44:40 +00:00
Dmitri Hrybenko
eff9c61a14 stdlib: attempt to fix Runtime.swift test on some systems; looks like a
compiler bug -- all I changed is inlined the _withUninitializedString
function into the caller

Swift SVN r20942
2014-08-02 02:16:24 +00:00
Dmitri Hrybenko
000df9699d stdlib: remove @semantics("readonly") from toString while this change is being
discussed and redesigned


Swift SVN r20939
2014-08-02 01:20:22 +00:00
Dave Abrahams
23ee8d34be [stdlib] Make Array RangeReplaceable test generic
...and uncover memory leaks in the process: <rdar://problem/17892507>

Swift SVN r20936
2014-08-02 01:08:57 +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
Chris Hanson
63a37b29a5 XCTest assertions will eventually EXC_BAD_ACCESS
The SPI that XCTest exposes to the overlay has Objective-C semantics,
while anything exposed to Swift code via @asmname needs Swift semantics.

Add a bridge to the overlay that handles this adaptation.

Addresses <rdar://problem/17408423>.

Swift SVN r20932
2014-08-02 00:17:28 +00:00
Chris Hanson
666e4ee2f3 Further work on handling exceptions in XCTest
Rather than use a header file and -import-objc-header, use @asmname and
@objc_block to tell the overlay about the Objective-C function used to
capture exceptions.

Further addresses <rdar://problem/16453199>.

Swift SVN r20929
2014-08-01 23:36:48 +00:00
Dave Abrahams
921045c7f8 [stdlib] Enable commented test part
As I was reducing a test case for a typechecker bug, I ended up
commenting out important test code in the regression suite.  This
restores it (and makes it work).

Swift SVN r20925
2014-08-01 23:01:02 +00:00
Dave Abrahams
1f8ec23ebe [stdlib] Correct/test _StringCore.reserveCapacity
The old one could never have worked.

Swift SVN r20916
2014-08-01 21:35:15 +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
Dave Abrahams
bcc7bd3560 [stdlib] Construct String from NSString, publicly!
Yes, we do need a straightforward way to do this.

Swift SVN r20897
2014-08-01 17:27:28 +00:00
Dmitri Hrybenko
142a32a944 stdlib/Assert: allow string interpolation in assertion messages
rdar://17248446


Swift SVN r20892
2014-08-01 13:44:38 +00:00
Dmitri Hrybenko
a79339ee8f stdlib/Assert: adopt new names for trapping functions:
assert() / assertionFailure() -- debug mode
precondition() / preconditionFailure() -- debug and release modes
fatalError() -- always traps


Swift SVN r20890
2014-08-01 10:22:23 +00:00
Chris Hanson
76631d14bd Catch exceptions thrown during assertions.
Since Swift itself has no exception support, use an Objective-C helper function
to evaluate a block and return an NSDictionary indicating whether an exception
was thrown out of that block (and if so, which exception).

Addresses <rdar://problem/16453199>.

Swift SVN r20880
2014-08-01 02:45:39 +00:00
Dave Abrahams
5f02ce8f03 [stdlib] Use Range<UnsafePointer> in _StringBuffer.grow()
Swift SVN r20876
2014-08-01 01:47:50 +00:00
Dave Abrahams
5465993f81 [stdlib] UnsafePointer : RandomAccessIndexType
It can be useful to form Ranges of these things, and there's no reason
it shouldn't be efficient to measure them, for example.

Swift SVN r20875
2014-08-01 01:46:09 +00:00
Nadav Rotem
6cc5fa218e Mark another function as @readonly.
Swift SVN r20860
2014-07-31 23:30:42 +00:00
Nadav Rotem
08e5bff61b Mark some more conversion functions as @readonly.
On -Ounchecked we are now able to zap this expression (from Richards):
  UnicodeScalar(UInt32(2)+"0".value)

However, on -O we still check for overflow and actually need to construct the string.



Swift SVN r20856
2014-07-31 22:15:36 +00:00
Nadav Rotem
52ecfc8a27 Mark some more string builders as @readonly.
This accelerates Richards by 4X because we don't need to construct debug strings such as:

debug("TCB \(tcb!.id) state \(tcb!.state.bits)")



Swift SVN r20853
2014-07-31 21:55:29 +00:00
Jordan Rose
a627411b43 [ClangImporter] Imported NS_OPTIONS structs should not conform to BooleanType.
In general, RawOptionSetType no longer inherits from BooleanType.

Swift SVN r20846
2014-07-31 19:23:08 +00:00
Dave Abrahams
8419d20f1c [stdlib] ImplicitlyUnwrappedOptional is not Boolean
Swift SVN r20839
2014-07-31 18:40:29 +00:00
Dave Abrahams
020c5893a7 [stdlib] AutoreleasingUnsafePointer is not Boolean
Swift SVN r20838
2014-07-31 18:32:02 +00:00
Dave Abrahams
104da6740b [stdlib] Make && and || generic
...instead of using Existentials, which don't specialize well.

Swift SVN r20837
2014-07-31 18:22:56 +00:00
Dmitri Hrybenko
c7a5b1daca stdlib/runtime: fix leaks in swift_bridgeNonVerbatimToObjectiveC
Swift SVN r20827
2014-07-31 15:49:17 +00:00
Dave Abrahams
ea21309150 [stdlib] _StringCore: ExtensibleCollectionType
Swift SVN r20825
2014-07-31 14:57:42 +00:00
Dave Abrahams
1614ed7386 [stdlib] Improve comments
Fill in what some default implementations would look like, if we had
that feature.  At least it will help implementors.

Swift SVN r20824
2014-07-31 14:57:41 +00:00
Dmitri Hrybenko
8150b9296b stdlib: fix leaks of Swift.String when passing them from runtime to
Swift (in mirrors and demangling)

Swift SVN r20823
2014-07-31 14:48:54 +00:00
Dmitri Hrybenko
0194e2675b stdlib/UnsafePointer: add more doc comments
Swift SVN r20822
2014-07-31 14:28:04 +00:00
Dmitri Hrybenko
30749d9f69 stdlib/Reflection: really fix a leak when reflecting a class (turned out to be
in swift_ObjCMirror_count)

rdar://17840810


Swift SVN r20821
2014-07-31 13:11:55 +00:00
Dmitri Hrybenko
9c8d30ea11 stdlib/Reflection: fix over-release that I introduced in r20671 trying to fix a
leak.  The release was valid only for some code paths.

Added some comments explaining ownership and parameter passing conventions.

Fixes rdar://17855302, restores half of the leak in rdar://17840810 (only for
objects that inherit from NSObject).


Swift SVN r20820
2014-07-31 11:49:43 +00:00
Greg Parker
1167c1722d Fix XCTest build.
Swift SVN r20813
2014-07-31 05:37:24 +00:00
Dave Abrahams
50aac71847 [stdlib] Arrays : RangeReplaceableCollectionType
Add the missing APIs and make the conformance complete

Swift SVN r20807
2014-07-31 02:54:27 +00:00
John McCall
97025f15b0 Remove compiled python file.
Swift SVN r20804
2014-07-31 02:06:00 +00:00
John McCall
c367362f22 Properly flag opaque existential types as not being
bitwise-takable.

Swift SVN r20803
2014-07-31 02:03:56 +00:00
John McCall
36a27a61a4 Replace the typeOf value witness with an
initializeBufferWithTakeOfBuffer value witness.

Attempt to use initializeBufferWithTakeOfBuffer in
some appropriate places.

There are some changes enabled by this which are
coming in a follow-up patch.

Swift SVN r20802
2014-07-31 02:03:53 +00:00
Chris Hanson
867429b0f4 Make XCTAssertEqualWithAccuracy work with CGFloat
Now that CGFloat is a peer of Float and Double, we need to add appropriate handling
to it for XCTAssertEqualWithAccuracy.

Addresses <rdar://problem/17762421>.

Swift SVN r20800
2014-07-31 01:36:32 +00:00
Dave Abrahams
bd2bd78b23 [stdlib] Add RangeReplaceableCollectionType
Swift SVN r20791
2014-07-31 00:38:24 +00:00