Commit Graph

455 Commits

Author SHA1 Message Date
Doug Gregor
692ff2f52a Enable imports of failable initializers by default.
Swift SVN r21699
2014-09-04 06:32:12 +00:00
Dmitri Hrybenko
60cf5d3d1b SwiftIntTypes.py: remove transitional '_new' suffix from a function name
Swift SVN r21579
2014-08-29 15:38:22 +00:00
Dmitri Hrybenko
cb9e5c2c86 stdlib: use simpler interface to iterate over integer types
Swift SVN r21573
2014-08-29 14:32:46 +00:00
Enrico Granata
b3f6219ebe Add a very rough mutual exclusion mechanism to prevent a UIView from trying to provide its QuickLook object recursively. The same logic used for NSView is also used here basically verbatim. This is because in playgrounds, you can get a view to log itself as part of its drawRect method due to the way we defined our instrumentation. This very simple mechanism only works because drawing can only happen on the main thread - otherwise, we'd need something smarter than an NSSet of UIView pointers. Fixes rdar://17895769
Swift SVN r21444
2014-08-25 21:11:18 +00:00
Dmitri Hrybenko
1a5e9b486c Restore building SpriteKit overlay that I accidentally disabled
Swift SVN r21438
2014-08-25 16:12:33 +00:00
Dmitri Hrybenko
ea48185358 stdlib: don't silently truncate Float80 literals
We used to first truncate them to Float64, and then construct a Float80.

Swift SVN r21433
2014-08-25 13:21:54 +00:00
Dave Abrahams
6c07fb4ad1 [stdlib] Revert UnsafePointer casting change
The syntax being reverted added busywork and noise to the common case
where you want to say "I have the right address, but the wrong type,"
without adding any real safety.

Also it eliminated the ability to write UnsafePointer<T>(otherPointer),
without adding ".self" to T.  Overall, it was not a win.

This reverts commits r21324 and r21342

Swift SVN r21424
2014-08-22 21:53:12 +00:00
Doug Gregor
d603db43f2 Make factory methods unavailable when there is already a corresponding initializer.
Depending on visitation order, we would occasionally leave the factory
method available if we had completely imported the initializer
first. Fixes <rdar://problem/17261609>.

Swift SVN r21361
2014-08-21 16:45:17 +00:00
Dave Abrahams
1fb0f889d7 [stdlib] Make UnsafePointer conversions explicit
Previously, it was possible to write Unsafe[Mutable]Pointer(x) and have
Swift deduce the pointee type based on context.  Since reinterpreting
memory is a fundamentally type-unsafe operation, it's better to be
explicit about conversions from Unsafe[Mutable]Pointer<T> to
Unsafe[Mutable]Pointer<U>.  This change is consistent with the move from
reinterpretCast(x) to unsafeBitCast(x, T.self).

Also, we've encoded the operations of explicitly adding or removing
mutability as properties, so that adding mutability can be separated
from wild reinterpretCast'ing, a much more severe form of unsafety.

Swift SVN r21324
2014-08-20 23:15:56 +00:00
Doug Gregor
ebf4c1e5ca Allow "return nil" in a failable initializer to initiate failure.
Basic semantic analysis only; AST to follow.

Swift SVN r21309
2014-08-20 17:22:34 +00:00
Dmitri Hrybenko
a64dceed58 stdlib: remove a stale FIXME, '!= nil' is now required to test Optionals for
the presence of a value


Swift SVN r21230
2014-08-15 10:19:54 +00:00
Dmitri Hrybenko
938e7c2676 stdlib: introduce UnicodeScalarLiteralConvertible protocol
This allows UnicodeScalars to be constructed from an integer, rather
then from a string.  Not only this avoids an unnecessary memory
allocation (!) when creating a UnicodeScalar, this also allows the
compiler to statically check that the string contains a single scalar
value (in the same way the compiler checks that Character contains only
a single extended grapheme cluster).

rdar://17966622

Swift SVN r21198
2014-08-14 16:04:39 +00:00
Greg Parker
5a71cacec3 Remove nib-lookup hacks from UIViewController. Fixes rdar://17327189.
Swift SVN r21183
2014-08-13 20:57:55 +00:00
Anna Zaks
c519ecfe4f API Notes File: The product of the 2d nullability audit of Foundation.
As well as the required test/stdlib modifications.

Swift SVN r21181
2014-08-13 19:39:59 +00:00
Doug Gregor
8df878c02a Give CGRect/CGSize/CGVector initializers that take Doubles.
Now that CGFloat is its own distinct type, it's useful to have Double
initializers to go along with the Int initializers we added a while
back <rdar://problem/17224725>.

Swift SVN r21156
2014-08-12 21:54:50 +00:00
Doug Gregor
916e9a7eb5 Fix computation of “favored” constraints for binary expressions <rdar://problem/17943223>.
The determination of “favored” constraints for binary expressions was comparing the second argument to the first parameter to decide if the constraint is favored. Coupled with implicit bridging conversions through NSNumber, this meant that “1.0/10” would become Int when Foundation was imported, and hilarity ensued.

Fix the heuristic for favored constraints, tidy up this code a bit, and add ==(NSString, NSString) to cope with the ambiguity this creates.

Swift SVN r21154
2014-08-12 21:16:59 +00:00
Chris Hanson
b644ff5888 XCTAssert(true, "Pass") crashes in Swift
Instead of trying to bridge NSDictionary to [String:String], XCTest needs to
just request the objects from the NSDictionary as String.

Also, move the unwrapping of the optional from the might-throw block such that
it only happens when the block hasn't thrown. Unwrapping the optional if the
block has thrown would crash, because the optional would still be unset.

Addresses <rdar://problem/17952584>.

Swift SVN r21119
2014-08-08 22:51:30 +00:00
Anna Zaks
95d7e655ee Proactively, ensure that the overlay works with NSDictionary::objectForKey: optional return type.
Swift SVN r21117
2014-08-08 22:22:25 +00:00
Dmitri Hrybenko
6f20c51e3e stdlib: fix crashes in CGPoint, CGSize, CGRect mirrors
rdar://17933906


Swift SVN r21091
2014-08-07 15:59:24 +00:00
Jordan Rose
73cce9702e [CMake] Remove the CMakeLists file from apinotes/.
Also, move the ObjectiveC overlay into its own directory, so that we can
use the directory name as an indicator of what overlays exist.

This is in preparation for DevPubs providing the contents of the apinotes/
directory. The downside here is that adding new apinotes files doesn't
automatically trigger a rebuild; I intend to mitigate that somewhat by at
least triggering one when the revision number of the DevPubs repo changes.

Swift SVN r21078
2014-08-06 23:07:24 +00:00
Dmitri Hrybenko
8c41e1892b stdlib/NSString APIs on String: change stringByRemovingPercentEncoding property
type to be an optional string; add tests


Swift SVN r21021
2014-08-04 18:02:14 +00:00
Dmitri Hrybenko
67de904c15 stdlib/NSString APIs on String: change stringByAppendingPathExtension() to
return an optional String.  This behavior is not documeted, though.


Swift SVN r21016
2014-08-04 16:41:37 +00:00
Dmitri Hrybenko
a75c7a427a stdlib/NSString APIs on String: add more tests and fix a crash in
_countFormatSpecifiers() that was triggered by non-BMP characters in the format
string


Swift SVN r21014
2014-08-04 15:37:58 +00:00
Dmitri Hrybenko
edc664c36f stdlib/NSString APIs on String: change return type of
stringByAddingPercentEncodingWithAllowedCharacters() and
stringByAddingPercentEscapesUsingEncoding() to String?, and add API notes for
NSString to the same effect


Swift SVN r21007
2014-08-04 14:13:46 +00:00
Chris Hanson
91069e1647 Get XCTAssertEqual working with [T] and [T:U]
XCTest's equality assertions need overrides in order to work with Array<T> and
Dictionary<T,U>.

Addresses <rdar://problem/17257148>.

Swift SVN r20993
2014-08-04 02:10:03 +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
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
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
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
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
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
Greg Parker
1167c1722d Fix XCTest build.
Swift SVN r20813
2014-07-31 05:37:24 +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
Dmitri Hrybenko
cbdefd719b Unbreak iOS builds: there is no NSRectEdge on iOS
Swift SVN r20755
2014-07-30 13:08:11 +00:00
Dmitri Hrybenko
fc05064131 Foundation overlay: introduce correctly-typed NS{Min,Max}{X,Y}Edge constants
that correspond to macros in the SDK

... and revert the previous attempt at fixing this, r20269.

rdar://16593744


Swift SVN r20752
2014-07-30 11:33:25 +00:00
Dmitri Hrybenko
ac0d9b8175 stdlib/CGFloat: GYB'ify initializers that convert between CGFloat and
integer types.  Never miss an integer type again.

rdar://17853313

Swift SVN r20751
2014-07-30 11:24:11 +00:00
Dave Abrahams
6e7f83fe98 Internalize old array casting entry-points
The core compiler now uses just two entry points for array casting

Swift SVN r20725
2014-07-29 23:56:51 +00:00
Joe Pamer
1fec0afbd0 Disallow value-to-optional conversions between argument and parameter types when resolving overloads for operators applied to nil literal operands.
This is a targeted fix to address rdar://problem/16848110 ("Disallow non-optionals to be compared to nil") and its associated dupes.

Swift SVN r20716
2014-07-29 23:24:36 +00:00
Dave Abrahams
ebcaab1e52 [stdlib/core] add Array init from _CocoaArrayType
Swift SVN r20698
2014-07-29 21:41:09 +00:00
Dave Abrahams
0320ef85ab [stdlib] Consolidate array casting entry points
Swift SVN r20689
2014-07-29 20:54:24 +00:00
Dave Abrahams
c91e0f98a0 [stdlib] bugfix: Copy bridged NSMutableArray's
When NSArrays are bridged into Array<T>, they weren't being .copy()'d.
As a result, changes to an NSMutableArray (cast to NSArray), could cause
"unrelated" Swift Arrays to mutate.  Found by inspection while
bottlenecking unsafeBitCast's in Array implementation, which also
happens in this commit.

Swift SVN r20678
2014-07-29 17:59:41 +00:00
Dmitri Hrybenko
3e32ff188f stdlib/String: change String.stringByAbbreviatingWithTildeInPath into a
property, to match recent Foundation headers


Swift SVN r20674
2014-07-29 16:08:39 +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
Joe Pamer
f55c751958 Add a fixit for optional-typed expressions used in conditional expression positions.
Swift SVN r20639
2014-07-28 19:20:42 +00:00
Joe Pamer
94dac129d4 Remove the BooleanType conformance from optional types (rdar://problem/17110911)
To limit user confusion when using conditional expressions of type Bool?, we've decided to remove the BooleanType (aka "LogicValue") conformance from optional types. (If users would like to use an expression of type Bool? as a conditional, they'll need to check against nil.)

Note: This change effectively regresses the "case is" pattern over types, since it currently demands a BooleanType conformance. I've filed rdar://problem/17791533 to track reinstating it if necessary.

Swift SVN r20637
2014-07-28 19:20:39 +00:00
Doug Gregor
bd75425b0e Remove the notion of non-inheritable conformances entirely <rdar://problem/16880016>.
Swift SVN r20627
2014-07-28 16:29:05 +00:00
Doug Gregor
3cb58e833a Restrict non-final class protocol conformance when Self is part of the requirement signature.
When a non-final class satisfies a method requirement that returns
Self, it must do so with a method that also returns (dynamic)
Self. This ensures conformance will be inheritable, closing off an
awful type-safety hole <rdar://problem/16880016>. Other
non-contravariant uses of Self in the signatures of requirements cause
the protocol to be unusable by non-final classes.

I had to leave a tiny little gaping hole for the ~> operator, whose
removal is covered by <rdar://problem/17828741>. We can possibly put
this on firm footing with clever handling of generic witnesses, but
it's not important right now.



Swift SVN r20626
2014-07-28 16:15:16 +00:00