Commit Graph

121 Commits

Author SHA1 Message Date
Dmitri Hrybenko
bc50b2f58d stdlib: stop using CFSetCreateCopy() in set bridging
Use -[NSSet copyWithZone:] instead.

CFSetCreateCopy() is buggy in OSes that ship today: it copies the set
unconditionally, even if it is immutable, resulting in O(n) bridging.

Swift SVN r27733
2015-04-26 00:08:13 +00:00
Dmitri Hrybenko
ba6920e69d stdlib: stop using CFDictionaryCreateCopy() in dictionary bridging
Use -[NSDictionary copyWithZone:] instead.

CFDictionaryCreateCopy() is buggy in OSes that ship today: it copies the
dictionary unconditionally, even if it is immutable, resulting in O(n)
bridging.

Swift SVN r27732
2015-04-26 00:08:12 +00:00
Dmitri Hrybenko
309bc89e83 stdlib: update overlay code for Foundation nullability audit
Swift SVN r27731
2015-04-26 00:08:11 +00:00
David Farler
9e28dc777a Update standard library doc comments to Markdown
rdar://problem/20180478

Swift SVN r27726
2015-04-26 00:07:11 +00:00
Doug Gregor
793b3326af Implement the new rules for argument label defaults.
The rule changes are as follows:
  * All functions (introduced with the 'func' keyword) have argument
  labels for arguments beyond the first, by default. Methods are no
  longer special in this regard.
  * The presence of a default argument no longer implies an argument
  label.

The actual changes to the parser and printer are fairly simple; the
rest of the noise is updating the standard library, overlays, tests,
etc.

With the standard library, this change is intended to be API neutral:
I've added/removed #'s and _'s as appropriate to keep the user
interface the same. If we want to separately consider using argument
labels for more free functions now that the defaults in the language
have shifted, we can tackle that separately.

Fixes rdar://problem/17218256.

Swift SVN r27704
2015-04-24 19:03:30 +00:00
Nadav Rotem
32211041d2 Rename @semantics -> @_semantics.
Swift SVN r27533
2015-04-21 17:10:06 +00:00
John McCall
63f3232b96 Handle throwing initializers in allocating constructors.
Swift SVN r27391
2015-04-17 00:02:46 +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
John McCall
156a4c7ed0 SILGen for calls under foreign error conventions. WIP.
Swift SVN r27270
2015-04-14 02:35:54 +00:00
Dave Abrahams
ac3f047496 [stdlib] Renaming fallout from Mirror API review
toString(x)      => String(x)
toDebugString(x) => String(reflecting: x)
Printable        => CustomStringConvertible
DebugPrintable   => CustomDebugStringConvertible

Also updated comments to clarify these protocols

Swift SVN r27090
2015-04-07 20:32:26 +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
fd27530199 Foundation overlay: Groundwork for pattern-matching Swift error enums to Cocoa NSError domains.
Provide an _ObjectiveCBridgeableErrorType protocol, which requires a failable initializer that attempts to map an NSError to a value of the error type. To start things off, gyb up an _NSCocoaError enum (underscored because we need to bikeshed a naming scheme) that corresponds to the standard NSCocoaErrorDomain codes.

Swift SVN r26820
2015-04-01 19:57:33 +00:00
Dmitri Hrybenko
4edc305438 stdlib: change CVarArgType._encode() method into a '_cVarArgEncoding'
property per API review proposal that passed review

For a given type, obtaining its C vararg encoding is O(1) for any
instance.

Swift SVN r26794
2015-04-01 02:55:24 +00:00
Dmitri Hrybenko
cf912bcaae stdlib: underscore the only requirement of CVarArgType
Defining conformances to CVarArgType outside of the standard library is
not supported.

Swift SVN r26793
2015-04-01 02:16:15 +00:00
Joe Groff
c5dbf067ee Foundation overlay: Conform NSError and CFError to ErrorType.
Swift SVN r26684
2015-03-28 21:24:58 +00:00
Jordan Rose
d6bc8971c7 If imported calls return nil for __nonnull NSString *, pretend it was "".
The string version of r26479. There's a lot of backstory and justification
there, so just read that commit message again. The one addition for String
is that global NSString constants are loaded as String as well, so that
also has to go through the bridging code even though there's no function
call involved.

Finishes rdar://problem/19734621.

Swift SVN r26510
2015-03-25 01:16:45 +00:00
Jordan Rose
8247c2d357 If imported calls return nil for 'NSArray * __nonnull', pretend it was [].
...and similar for NSDictionary and NSSet.

For APIs that don't have a reason to distinguish "empty" and "absent" cases,
we encourage standardizing on "empty" and marking the result as non-optional
(or in Objective-C, __nonnull). However, there are system APIs whose
implementations currently do return nil rather than an empty collection
instance. In these cases, we recommend /changing/ the API to return the
appropriate "empty" value instead.

However, this can cause problems for backwards-deployment: while the API is
truly non-optional on system vN, a program may encounter a nil return value
if run on system vN-1. Objective-C can generally deal with this (especially
if the only thing you do is ask for the count or try to iterate over the
collection) but Swift can't. Therefore, we've decided to "play nice" and
accept nil return values for the collection types (NSArray, NSDictionary,
and NSSet) and implicitly treat them as "empty" values if they are the
result of an imported function or method.

Note that the current implementation has a hole regarding subscript getters,
since we still make an AST-level thunk for these in the Clang importer.
We can probably get rid of those these days, but I didn't want to touch
them at this point. It seems unlikely that there will be a subscript that
(a) is for a collection type, and (b) mistakenly returned nil in the past
rather than an empty collection.

There's another hole where an ObjC client calls one of these mistakenly-nil-
returning methods and then immediately hands the result off by calling a
Swift method. However, we have to draw the line somewhere.

(We're actually going to do this for strings as well; coming soon.)

rdar://problem/19734621

Swift SVN r26479
2015-03-24 03:36:45 +00:00
Dmitri Hrybenko
ab408d4dc3 Update the compiler and SDK overlay for nullability and generics in Foundation
We have an SPI between the Swift compiler and Foundation based on the
SWIFT_SDK_OVERLAY_FOUNDATION_EPOCH preprocessor macro that allows us to
request the new API.  rdar://20270080 tracks removing it.

Swift SVN r26475
2015-03-24 02:18:06 +00:00
Arnold Schwaighofer
e4ece365b9 Annotate bridgeTo/FromObjectiveC in Foundation.swift
This will allow us to recognize identity compositions.

 (bridge_from (bridge_to x)) -> x
 (bridge_to (bridge_from x)) -> x

rdar://19178324

Swift SVN r26240
2015-03-17 23:27:19 +00:00
Chris Lattner
20f8f09ea8 Land: <rdar://problem/19382905> improve 'if let' to support refutable patterns and untie it from optionals
This changes 'if let' conditions to take general refutable patterns, instead of
taking a irrefutable pattern and implicitly matching against an optional.

Where before you might have written:
  if let x = foo() {

you now need to write:
  if let x? = foo() {
    
The upshot of this is that you can write anything in an 'if let' that you can
write in a 'case let' in a switch statement, which is pretty general.

To aid with migration, this special cases certain really common patterns like
the above (and any other irrefutable cases, like "if let (a,b) = foo()", and
tells you where to insert the ?.  It also special cases type annotations like
"if let x : AnyObject = " since they are no longer allowed.

For transitional purposes, I have intentionally downgraded the most common
diagnostic into a warning instead of an error.  This means that you'll get:

t.swift:26:10: warning: condition requires a refutable pattern match; did you mean to match an optional?
if let a = f() {
       ^
        ?

I think this is important to stage in, because this is a pretty significant
source breaking change and not everyone internally may want to deal with it
at the same time.  I filed 20166013 to remember to upgrade this to an error.

In addition to being a nice user feature, this is a nice cleanup of the guts
of the compiler, since it eliminates the "isConditional()" bit from
PatternBindingDecl, along with the special case logic in the compiler to handle
it (which variously added and removed Optional around these things).




Swift SVN r26150
2015-03-15 07:06:22 +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