Commit Graph

442 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
5b767efe72 Fix three unintended API changes from the argument label defaults change.
Swift SVN r27705
2015-04-24 20:31:41 +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
Dmitri Hrybenko
971598e430 Revert "stdlib: fix a warning"
This reverts commit r27570.  The SDK on buildbots is too old.

Swift SVN r27572
2015-04-22 07:17:56 +00:00
Dmitri Hrybenko
76b330519d stdlib: fix a warning
Swift SVN r27570
2015-04-22 07:06:40 +00:00
Chris Lattner
3ec09eec8e force adopt let/else and the Swift 1.2 if/let extensions in the stdlib a bit, for dogfooding
and cleanup.

I changes cases that had a non-trivial "then" body but a trivial else.  Most of the cases in
the stdlib have a trivial "then" clause, so I didn't change them.




Swift SVN r27567
2015-04-22 06:24:06 +00:00
Nadav Rotem
32211041d2 Rename @semantics -> @_semantics.
Swift SVN r27533
2015-04-21 17:10:06 +00:00
Chris Willmore
d4db635e3d Add object literal syntax and _{Color,Image}LiteralConvertible protocols
Add syntax "[#Color(...)#]" for object literals, to be used by
Playgrounds for inline color wells etc. The arguments are forwarded to
the relevant constructor (although we will probably change this soon,
since (colorLiteralRed:... blue:... green:... alpha) is kind of
verbose). Add _ColorLiteralConvertible and _ImageLiteralConvertible
protocols, and link them to the new expressions in the type checker.
CSApply replaces the object literal expressions with a call to the
appropriate protocol witness.

Swift SVN r27479
2015-04-20 12:55:56 +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
Dmitri Hrybenko
1e5dba8085 SceneKit overlay: add a generic overlay for -[SCNSceneSource entryWithIdentifier:withClass:]
This change depends on a coordinated SceneKit change which makes the
original method unavailable to avoid ambiguity.  The API also requires a
data file, so no tests yet.

rdar://20384835

Swift SVN r27319
2015-04-15 16:18:49 +00:00
Chris Willmore
98d17e318d Add support for AppleTV simulator tests.
You can run tests with e.g. 'ninja check-swift-appletvsimulator-x86_64'.

Swift SVN r27297
2015-04-14 23:53:03 +00:00
Devin Coughlin
d08b98b1ca Sema: Turn on availability checking by default
Enable checking for uses of potentially unavailable APIs. There is
a frontend option to disable it: -disable-availability-checking.

This commit updates the SDK overlays with @availability() annotations for the
declarations where the overlay refers to potentially unavailable APIs. It also changes
several tests that refer to potentially unavailable APIs to use either #available()
or @availability annotations.

Swift SVN r27272
2015-04-14 06:44:01 +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
42b9d14632 Foundation overlay: remove empty file
Swift SVN r27111
2015-04-08 00:28:44 +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
ed99e14f54 SDK overlay: create an overlay for SceneKit
rdar://20384803
rdar://20384835

Swift SVN r27069
2015-04-07 06:41:55 +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
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
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
David Farler
b60cf1efd4 Build iOS overlays for TVOS
SDK overlays built for iOS were guarded as iOS only. These are also
available in the tvOS SDK.

rdar://problem/20278575

Swift SVN r26499
2015-03-24 21:43:55 +00:00
Dmitri Hrybenko
1258662db9 CoreAudio overlay: add APIs that were blocked by rdar://16974298
(extensions on generic types in a different module)

Swift SVN r26486
2015-03-24 07:50:51 +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
Dmitri Hrybenko
6278badc4f Foundation overlay: use the current locale in String(localizedStringWithFormat:)
No test since a proper test requires method swizzling and that would
take a while to write.  Tested manually.

rdar://20171815

Swift SVN r26343
2015-03-20 01:17:44 +00:00
David Farler
544ef4002d Merge tvOS and watchOS Support
- Add frontend and standard library build support for tvOS.
- Add frontend support for watchOS.

watchOS standard library builds are still disabled during SDK bring-up.

To build for TVOS, specify --tvos to build-script.
To build for watchOS, specify --watchos to build-script (not yet supported).

This patch does not include turning on full tests for TVOS or watchOS, and
will be included in a follow-up patch.

Swift SVN r26278
2015-03-18 21:35:07 +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
Enrico Granata
b9f0a6d22b This is the equivalent of r24737 for iOS
"Only remove the view from the set of views that are being Mirror-drawn when you're actually done reflecting on it  The previous code would always remove the view on exit, even if it had not previously added it (default: case of the switch)  In simple cases, this didn't really matter, but if you caused the logger to be reinvoked on self in a loop, then you would end up removing the view before you were done looping over it, and eventually run out of stack space"

In this case, it fixes rdar://20193122



Swift SVN r26235
2015-03-17 21:15:48 +00:00
Dmitri Hrybenko
e6f53a38cc stdlib: remove swift_createDate
It was added for testing and it is actually never used now.

Swift SVN r26195
2015-03-16 22:25:27 +00:00
Chris Lattner
7b13a367a7 clean up some uses of typed patterns in nested contexts. The only reason anyone was using
them was because of the obsolete AnyObject warning.


Swift SVN r26159
2015-03-15 18:26:24 +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
Doug Gregor
c69294562e Clean up explicit protocol conformances in the standard library.
Eliminates redundant conformances and resolves ambiguous implied
conformances. NFC.

Swift SVN r26066
2015-03-12 21:11:12 +00:00
Dmitri Hrybenko
cf9635828a Update the overlay for iOS SDK changes: CIFilter.init() is now failable
Swift SVN r25893
2015-03-09 21:00:15 +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