Commit Graph

812 Commits

Author SHA1 Message Date
Xiaodi Wu
cd32f345ec Fix Decimal 2016-08-26 03:54:28 -05:00
Doug Gregor
57f1090a11 Revert "[Set/Dictionary] Eliminate "bridging" collection entrypoints."
This reverts commit dc0ae675bc. The
change here (presumably the change to Foundation) caused a regression
in several of the bridging-related benchmarks, e.g.,
ObjectiveCBridgeFromNSSetAnyObjectToString, DictionaryBridge,
ObjectiveCBridgeFromNSDictionaryAnyObjectToString.
2016-08-24 13:20:03 -07:00
Doug Gregor
dc0ae675bc [Set/Dictionary] Eliminate "bridging" collection entrypoints.
Remove the functions
_(set|dictionary)Bridge(From|To)ObjectiveC(Conditional) from the
standard library. These entrypoints are no longer used by the compiler
(thanks to generalized collection up/downcasting), so stop using them
in Foundation and in tests.
2016-08-22 15:14:09 -07:00
Greg Parker
f50b1e73dc Revert "Make all CF types Equatable and Hashable." 2016-08-20 04:33:55 -07:00
Jordan Rose
361ab62454 Make all CF types Equatable and Hashable. (#4394)
Like NSObject, CFType has primitive operations CFEqual and CFHash,
so Swift should allow those types to show up in Hashable positions
(like dictionaries). The most general way to do this was to
introduce a new protocol, _CFObject, and then have the importer
automatically make all CF types conform to it.

This did require one additional change: the == implementation that
calls through to CFEqual is in a new CoreFoundation overlay, but the
conformance is in the underlying Clang module. Therefore, operator
lookup for conformances has been changed to look in the overlay for
an imported declaration (if there is one).

https://bugs.swift.org/browse/SR-2388
2016-08-19 13:21:24 -07:00
Jordan Rose
ba3de9ee3b NSNumber already preserves whether a value was originally boolean. (#4366)
Use that instead of rolling it up in _SwiftTypePreservingNSNumber so that we
get the right behavior when we go to write plists.

https://bugs.swift.org/browse/SR-2381
2016-08-18 15:45:30 -07:00
Doug Gregor
27515b623e Revert "NSNumber bridging: use BOOL rather than _Bool when bridging Bools." 2016-08-18 10:36:43 -07:00
Doug Gregor
d68e59371a NSNumber bridging: use BOOL rather than _Bool when bridging Bools.
The Objective-C type encoding of Boolean values in NSNumber is that of
BOOL, which is either signed char or _Bool depending on the
platform. _SwiftTypePreservingNSNumber was using _Bool, which led to
inconsistencies when bridging vs. creating an NSNumber directly. Use
BOOL consistently.

Fixes rdar://problem/27894308.
2016-08-17 16:49:30 -07:00
Ted Kremenek
e706666857 Merge pull request #4168 from phausler/CharacterSet
[Foundation] Ensure _SwiftNSCharacterSet overrides all abstract metho…
2016-08-17 06:18:35 -07:00
Doug Gregor
394094f732 [Foundation overlay] Drop redundant 'Error' in the CocoaError code names.
Note: we leave all of the old names in as deprecated (with a rename),
so that we don't actually break any existing source code. Fixes
rdar://problem/27778189.
2016-08-16 21:10:21 -07:00
Joe Groff
e8346935ea Foundation overlay: Fix optionality mismatch in NSMutableDictionary subscript.
`setObject:forKey:` takes a nonnull object, causing us to accidentally pass in a boxed Optional-in-an-Any from the Swift subscript's optional newValue. Fixes rdar://problem/27875914.
2016-08-16 18:05:09 -07:00
Jordan Rose
af1a8154a3 Guard against racy access to NSError.setUserInfoValueProvider. (#4280)
This API is documented in its headers to only allow being called once
for a particular domain, so we have to make sure our check for an
existing provider is synchronized with the setting.

rdar://problem/27541751
2016-08-15 13:34:30 -07:00
Dave Abrahams
e6dec58cc5 Merge pull request #4041 from xwu/memory-layout-of-value
[stdlib] Implement SE-0136 (Restore MemoryLayout.*(ofValue:))
2016-08-12 11:09:17 -07:00
Philippe Hausler
017f664158 [Foundation] Ensure _SwiftNSCharacterSet overrides all abstract methods on NSCharacterSet via @objc
The override methods were not marked with @objc which incorrectly funneled to the abstract base class methods. In the method isSuperset(of:) it would incorrectly hit a requirement of a subclass implementation. This exposed a flaw with NSCharacterSet in which that method cannot recieve subclasses to the other CharacterSet being passed. This is being tracked via rdar://problem/27768939 which will need to be accounted for by CoreFoundation. Until such a time that can be addressed the workaround by using CFCharacterSetIsSupersetOfSet must be used with a copy passed as the other set.

This resolves:
https://bugs.swift.org/browse/SR-2307
2016-08-09 14:08:46 -07:00
Philippe Hausler
25e93ad51d Additional conformance changes for Measurement and unit tests to verify comparison and equality
After speaking with the current owner of Measurement, the most sensible path is to at runtime verifty the conformance of Units to a specific dimension since we cannot directly check at compile time. If at a future point in time a more specific comparitor can be added that can restrict the comparison to measurements in a specific dimension without causing equatable failures we may want to revisit this. However as it stands this preserves the most reasonable implementation of comparison of disperate measurement unit types while preserving the expected logic of conversions within that dimension.
2016-08-09 14:04:24 -07:00
Philippe Hausler
2a9c11c564 [Foundation] Simplify the comparison routines for Measurement
The default implementation for comparable automatically adds >, >= etc by having == and < defined. Also the dynamic check for comparison of measurements that are convertible should traverse through the same runtime equality check instead of a static dispatch call out.

This resolves:
<rdar://problem/27556581> Measurement type defines two '==' functions
2016-08-09 14:04:24 -07:00
Slava Pestov
48bfec49fb Foundation overlay: Remove deprecated @noescape attribute 2016-08-08 11:51:15 -07:00
Xiaodi Wu
f9435b9ce8 [stdlib] Restore MemoryLayout.*(ofValue:) 2016-08-08 10:46:37 -05:00
Dave Abrahams
848f0a6304 Warning suppression 2016-08-07 17:56:11 -07:00
Dmitri Gribenko
609ba7321e stdlib: add SPI for bridging for Foundation 2016-08-07 14:20:36 -07:00
Dmitri Gribenko
88de90a92d stdlib: fix incorrect distance measurement between UTF-16 indices
String.UTF16View.Index.distance(to:) was returning a negated result.

Fixes SR-1988.
2016-08-07 13:40:34 -06:00
Michael Ilseman
045bc16b6d Merge pull request #4031 from milseman/noescape_by_default
noescape by default: deprecate @noescape and @autoclosure(escaping)
2016-08-05 13:25:00 -07:00
Ted Kremenek
2bea707e75 Merge pull request #3977 from phausler/Notification_userInfo
[Foundation] Scale back struct Notification's userInfo to be in-line …
2016-08-05 11:12:18 -07:00
Joe Groff
8ef5f40eae Merge pull request #3974 from jckarter/cvararg-post-0072
Make bridged String and collection types conform to CVarArg.
2016-08-05 09:44:25 -07:00
Ted Kremenek
375b5f6152 Merge pull request #3980 from phausler/Data_fixit_hints
[Foundation] add hints for replacement APIs for Data of some common u…
2016-08-05 07:32:29 -07:00
Michael Ilseman
b7c9eddd11 [noescape by default] drop @noescape from stdlib 2016-08-04 16:09:01 -07:00
swift-ci
47fe3bd82c Merge pull request #3945 from jckarter/foundation-overlay-post-0072 2016-08-04 09:50:05 -07:00
Joe Groff
62afa03eb9 Improve Foundation overlay to handle bridging subscripts and dictionary literals.
SE-0072 took implicit bridging conversions away, which regressed the ability to express NSDictionaries as dictionary literals and index them using literal keys. Address this by changing the signature of init(dictionaryLiteral:) to use Hashable and Any, and by replacing the subscript from Objective-C with one using _Hashable that does the bridging on the user's behalf. This largely restores the QoI of working with NS collections.
2016-08-04 08:42:36 -07:00
Joe Groff
7535acc86b Make bridged String and collection types conform to CVarArg.
This allows String, Array, Dictionary, and Set to be passed as variadic arguments to Cocoa APIs like NSLog, NSPredicate, stringWithFormat:, etc. rdar://problem/27651717
2016-08-04 07:14:55 -07:00
Dmitri Gribenko
b6b9fe2943 Merge pull request #3952 from eeckstein/nsdictionary
stdlib/Foundation: optimize the NSDictionary copy-constructor
2016-08-03 23:38:45 -07:00
Michael Gottesman
a0fca3a8f0 Merge pull request #3965 from gottesmm/support_per_host_cmake_and_tsan_of_runtime_via_buildscript
Support per host cmake and tsan of runtime via buildscript
2016-08-03 21:48:24 -07:00
Michael Gottesman
06a70d3942 [cmake] Add cmake support for only applying tsan to the swift stdlib/runtime. 2016-08-03 17:53:57 -07:00
Erik Eckstein
ae22fe7f6b stdlib/Foundation: optimize the NSDictionary and NSSet copy-constructors
rdar://problem/27678985
2016-08-03 17:20:46 -07:00
Philippe Hausler
956c310975 [Foundation] add hints for replacement APIs for Data of some common usage from NSData
This provides a hint to the proper API to use for struct Data when developers are migrating from NSData.
Purely a fixit addition (no actual functional code)

<rdar://problem/26206061> Missing fixit for Data.getBytes
2016-08-03 16:36:06 -07:00
Philippe Hausler
f96159b582 [Foundation] Scale back struct Notification's userInfo to be in-line with NSNotification
This simplifies the bridging story for Notifications to their objc counterparts since the id -> Any and AnyHashable changes have now been applied (which makes the previous boxing strategy no longer needed). Previous consumers of Notification that were using String keys should still work, however any explicit dictionary types should migrate from Swift 2.2 -> Swift 3 from userInfo as [NSObject:AnyObject] to [AnyHashable:Any]. The condition of distributed notifications (in non sandboxed apps) requiring plist types still applies and will fail at runtime if incorrect types are passed into the objective-c layer, and in the case of sandboxed apps userInfo still is forbidden (this change is a non functional change in the respect to those behaviors).

Resolves the following issues:
<rdar://problem/27426757>
<rdar://problem/27561621>
<rdar://problem/27259984>
2016-08-03 16:27:06 -07:00
Doug Gregor
75e85dc5bd [NSError bridging] Extract embedded NSError from an Error consistently.
When emitting an existential erasure to Error from an archetype, use
the _getEmbeddedNSError() witness. If it produces an NSError, erase
that; otherwise, go through the normal erasure path.

Of course, make NSError and CFError implement _getEmbeddedNSError() so
this kicks in for the obvious cases as well as the more obscure ones.

Fixes the rest of SR-1562 / rdar://problem/26370984.
2016-08-03 14:01:02 -07:00
Doug Gregor
d2195318d2 [NSError bridging] Use embedded NSError when erasing types to Error existentials.
Imported Cocoa error types are represented by structs wrapping an
NSError. The conversion from these structs to Error would end up
boxing the structs in _SwiftNativeNSError, losing identity and leading
to a wrapping loop.

Instead, extract the embedded NSError if there is one. In the Swift
runtime, do this as part of the dynamic cast to NSError, using a (new,
defaulted) requirement in the Error type so we can avoid an extra
runtime lookup of the protocol. In SILGEn, do this by looking for the
_BridgedStoredNSError protocol conformance when erasing to an Error
type. Fixes SR-1562 / rdar://problem/26370984.
2016-08-03 09:20:04 -07:00
Mishal Shah
d28ff854b9 Update master to build with Xcode 8 beta 4, OS X 10.12, iOS 10, tvOS 10, and watchOS 3 SDKs. 2016-08-02 11:47:10 -07:00
Jordan Rose
f42158b12e Revert "[Sema] ban multi-arguments to tuple coercion" (#3922)
It breaks cases where there really is a single unlabeled argument of tuple type, like this:

  let pairs = [(1, "A"), (2, "B")]
  print(pairs.map { $0.0 })
2016-08-01 19:22:19 -07:00
Dave Abrahams
43652bebf7 [stdlib] Remove incorrect format specifier checks
String.init(format:locale:arguments:) contained a check to make sure
that the format string didn't try to format more arguments than were
actually passed.  However, the check didn't guarantee safety (since the
format specifiers didn't have to match the *type* of the passed
argument) and contained bugs such as
https://bugs.swift.org/browse/SR-1378.  Since the check was not a
guarantor of safety and was wrong, it is hereby removed.

If checks are to be reintroduced, they should both be correct and
guarantee complete safety.  Doing this check correctly is a nontrivial
job (the code in Clang to parse such specifiers is well over 500 lines),
and should be taken on as a distinct project.
2016-08-01 15:43:50 -07:00
Daniel Duan
c9b73dacc2 [Sema] ban multi-arguments to tuple coercion
Implements part of SE-0110. Single argument in closures will not be accepted if
there exists explicit type with a number of arguments that's not 1.

```swift
let f: (Int, Int) -> Void = { x in } // this is now an error
```

Note there's a second part of SE-0110 which could be considered additive,
which says one must add an extra pair of parens to specify a single arugment
type that is a tuple:

```swift
let g ((Int, Int)) -> Void = { y in } // y should have type (Int, Int)
```

This patch does not implement that part.
2016-07-31 16:22:57 -07:00
Dmitri Gribenko
382d215ad3 stdlib: SE-0101: remove the last few uses of old APIs (sizeof, alignof, strideof) 2016-07-30 00:38:18 -07:00
Robert Widmann
b79fa44da5 Merge pull request #3878 from CodaFi/decltype
[SE-0096] Implement type(of:)
2016-07-29 18:05:01 -07:00
Dave Abrahams
f06a9a1154 Merge 'origin/master' into new-integer-protocols 2016-07-29 17:52:49 -07:00
Doug Gregor
b9363fe6bd [SE-0111] Enable SE-0111 by default. 2016-07-29 17:28:24 -07:00
Robert Widmann
4f465224ea Polish off uses of dynamicType in tests 2016-07-29 16:59:14 -07:00
Robert Widmann
14dc86cf15 Polish off uses of dynamicType in codebase 2016-07-29 16:58:40 -07:00
Dmitri Gribenko
99dffd7682 Merge pull request #3854 from rintaro/SE-0101-memorylayout
[SE-0101] Implement: Reconfiguring sizeof and related functions into a unified MemoryLayout struct - Part 1
2016-07-29 15:56:27 -07:00
Michael Ilseman
ccda8f33d1 [noescape by default] Proliferate @escaping
Adds an explicit @escaping throughout the standard library, validation
test suite, and tests. This will be necessary as soon as noescape is
the default for closure parameters.
2016-07-29 13:48:07 -07:00
Jordan Rose
b5003f4c48 Private members may not satisfy protocol requirements, ever. (#3842)
* Private members may not satisfy protocol requirements, ever.

...because by construction they can be invoked from outside of the
type.

Finishing up SE-0025 ('private' and 'fileprivate').

* Update docs and mark SE-0025 ('private' and 'fileprivate') as done!

There's still improvements we can make (see 508e825f), but the feature
is in place and should be working correctly.
2016-07-29 11:24:05 -07:00