Commit Graph

856 Commits

Author SHA1 Message Date
Morten Bek Ditlevsen
a5a68ca25d Fix negation of 0 length Decimal (#15986)
A Decimal value with _length 0 and _isNegative set to 1 is interpreted as a NaN. The 'negate()' function however, flipped the _isNegative flag without regard for the _length 0 case. This meant that -0 would become NaN. The fix checks for the _length 0 special case. In NSDecimalSubtract() the same check was performed. Since this now happens in negate(), it is removed from the NSDecimalSubtract() function.
2018-04-18 10:18:34 -07:00
Philippe Hausler
57d0ea8013 [Foundation] Guard Data access to NSData._isCompact under availability guards 2018-04-12 09:53:34 -07:00
Devin Coughlin
302d82731a [Foundation] Address exclusivity violation in Data
Address an exclusivity violation in Data's Iterator.next() by changing two private
'let' stored properties to be 'var'.

Making the properties 'var' changes code generation of next() so that the stored
properties are read independently of the other contents of the struct. This
prevents an exclusivity violation when reading '_endIdx' and '_data' while
simultaneously mutating '_buffer' with the call to withUnsafeMutablePointer().

The 'let' pattern is an idiom we would eventually like to support (see SR-7396),
but for now we need to remove the exclusivity violation.
2018-04-09 16:18:17 -07:00
Sho Ikeda
9efd347100 [gardening][Overlay] Use isEmpty in Data.swift 2018-04-05 17:50:20 +09:00
Sho Ikeda
68e76535bc [gardening][Calendar] No need to discard the retrun value of insert(_:) which is discardable 2018-04-04 19:29:42 +09:00
Xi Ge
d93e0dfa01 Merge pull request #15636 from Fidetro/master
Fixed JSONEncoder code style issues
2018-04-01 08:39:04 -07:00
swift-ci
6c42bcccbd Merge pull request #15507 from devincoughlin/foundation-datecomponents-exclusivity-warnings 2018-03-31 10:47:38 -07:00
swift-ci
ee57586822 Merge pull request #15652 from brennanMKE/semicolon 2018-03-31 08:19:28 -07:00
brennanMKE
fb2f55f558 [stdlib] remove trailing semicolon in stdlib source 2018-03-30 22:44:05 -07:00
Slava Pestov
e1f50b2d36 SE-0193: Rename @_inlineable to @inlinable, @_versioned to @usableFromInline 2018-03-30 21:55:30 -07:00
fidetro
2bf6b88585 Fixed code style issues 2018-03-31 05:00:46 +08:00
Devin Coughlin
524f273d99 [Foundation] Fix exclusivity warnings in DateComponents
DateComponents has a number of exclusivity warnings that all result from the same idiom
for applying mutation in computed properties:

    public var era: Int? {
        get { return _handle.map { _getter($0.era) } }
        set { _applyMutation { $0.era = _setter(newValue) } }
    }

Here _applyMutation() is a mutating method, so it requires exclusive access to 'self'
for the duration of the call. However, calling the _setter() method in the block
requires access to read 'self', which conflicts with the already in-progress modifying
access begun by _applyMutation().

A fix is to change _setter() to be a static function, so it doesn't require access to
'self'.
2018-03-25 19:47:50 -07:00
Karoy Lorentey
18e7470ae7 [Foundation] NSArray, NSDictionary: Add custom AnyHashable representations
Now that Array and Dictionary conform to Hashable, we need to make sure that their bridged counterparts provide the same hash values when converted to AnyHashable.
2018-03-23 19:08:39 +00:00
Sho Ikeda
c133e09015 Merge pull request #15326 from ikesyo/use-isempty-over-count
[gardening][Data] Prefer `!isEmpty` over `count > 0`
2018-03-21 09:54:39 +09:00
Jordan Rose
f7bb041e0f Remove 'public' from a few NSError-bridging-related symbols (#14731)
We're still using most of this, but not all of it has to be public.

rdar://problem/35230025
2018-03-20 13:02:21 -07:00
Itai Ferber
feae8bd0b0 Merge pull request #15335 from ikesyo/use-isempty-over-count-2
[gardening][(JSON|Plist)Encoder] Prefer `!isEmpty` over `count > 0`
2018-03-20 08:02:38 -07:00
Sho Ikeda
e0eadc26bb [gardening][Foundation] Prefer macOS over OSX for @available 2018-03-20 21:35:58 +09:00
Sho Ikeda
a63df4daa1 [gardening][(JSON|Plist)Encoder] Prefer !isEmpty over count > 0 2018-03-19 13:42:31 +09:00
Sho Ikeda
ba3a62b725 [gardening][Data] Prefer !isEmpty over count > 0 2018-03-18 00:58:57 +09:00
Jordan Rose
520d6b9b91 Make NS_TYPED_ENUMS ObjectiveCBridgeable when they wrap an object (#15270)
This allows them to be used in generic arguments for NSArray et al.
We already do this for the ones that wrap bridged values (like
NSString/String), but failed to do it for objects that /weren't/
bridged to Swift values (class instances and protocol compositions),
or for Error-which-is-special.

In addition to this being a sensible thing to do, /not/ doing this led
to IRGen getting very confused (i.e. crashing) when we imported a
Objective-C protocol that actually used an NS_TYPED_ENUM in this way.

(We actually shouldn't be using Swift's IRGen logic to emit protocol
descriptors for imported protocols at all, because it's possible we
weren't able to import all the requirements. But that's a separate
issue.)

https://bugs.swift.org/browse/SR-6844
2018-03-15 16:17:38 -07:00
Sho Ikeda
f956609312 [gardening][Overlay] Prefer macOS over OSX for #available 2018-03-14 14:06:31 +09:00
Jordan Rose
e202e90294 Clean up _BridgedNSError and _BridgedStoredNSError (#14682)
Despite their similar names and uses, these protocols no longer share
much functionality - the former is used to take @objc enums defined in
Swift that conform to Error and expose them as NSErrors, and the
latter handles NS_ERROR_ENUM C enums, which get imported into Swift as
a wrapper around NSError. We can actually simplify them quite a bit.

- Eliminate base protocol __BridgedNSError, which no longer provides
  any implementation for _BridgedStoredNSError.

- Eliminate default implementations that match what the compiler would
  synthesize.

- Adopt recursive constraints and where-clauses on associated types
  (and update the Clang importer to handle this).

- Collapse signed and unsigned default implementations when reasonable.

- Fold _BridgedStoredNSError's _nsErrorDomain into the existing public
  requirement CustomNSError.errorDomain.

rdar://problem/35230080
2018-03-07 13:14:36 -08:00
Joe Groff
f213671327 Runtime: Handle getDescription correctly in +0 mode.
This can eventually be made more efficient by avoiding copies in all the
callees, but this is the minimal fix. Remove an unnecessary bit of
reverse-dependency on the Foundation overlay while we're here.

rdar://34222540
2018-03-05 11:48:40 -08:00
Philippe Hausler
26d4ea18b2 [Foundation] searching in slices should index relative to the slice (#14851) 2018-02-27 14:00:32 -08:00
Connor Wakamo
a2aacd73dd [stdlib] Deprecated PlaygroundQuickLook and CustomPlaygroundQuickLookable.
Deprecated the `PlaygroundQuickLook` enum and `CustomPlaygroundQuickLookable`
protocol. These are being targeted for removal in Swift 5, so we want to
unconditionally deprecate them now to encourage use of
`CustomPlaygroundDisplayConvertible` instead.

This commit includes deprecated the various `CustomPlaygroundQuickLookable`
conformances across the standard library and overlay libraries.
2018-02-21 13:38:31 -08:00
Jordan Rose
54a359731d [SDK] Remove Foundation's last use of _silgen_name (#14484)
No intended functionality change.
2018-02-08 11:42:40 -08:00
Greg Parker
4501e08cee Merge pull request #14373 from troughton/twowordpair-removal
[runtime] Remove TwoWordPair and use the Swift calling convention instead.
2018-02-02 16:27:25 -08:00
troughton
cf28ff448c Remove TwoWordPair and use SwiftCC instead. 2018-02-03 09:43:00 +13:00
Arthur Ariel Sabintsev
fe89d4d333 Fixed comment on Calendar's compare method 2018-02-02 11:20:53 -05:00
Ben Cohen
9ee856f386 [stdlib][WIP] Eliminate (Closed)CountableRange using conditional conformance (#13342)
* Make Range conditionally a Collection

* Convert ClosedRange to conditionally a collection

* De-gyb Range/ClosedRange, refactoring some methods.

* Remove use of Countable{Closed}Range from stdlib

* Remove Countable use from Foundation

* Fix test errors and warnings resulting from Range/CountableRange collapse

* fix prespecialize test for new mangling

* Update CoreAudio use of CountableRange

* Update SwiftSyntax use of CountableRange

* Restore ClosedRange.Index: Hashable conformance

* Move fixed typechecker slowness test for array-of-ranges from slow to fast, yay

* Apply Doug's patch to loosen test to just check for error
2018-02-01 20:59:28 -08:00
Karoy Lorentey
77992d37f0 Merge pull request #14033 from lorentey/rdar/35995647
[Foundation] Coalesce duplicate String keys in bridged NSDictionary and NSSet
2018-01-31 11:57:31 +00:00
Joe Groff
a7a3b17597 Replace nominal type descriptors with a hierarchy of context descriptors.
This new format more efficiently represents existing information, while
more accurately encoding important information about nested generic
contexts with same-type and layout constraints that need to be evaluated
at runtime. It's also designed with an eye to forward- and
backward-compatible expansion for ABI stability with future Swift
versions.
2018-01-29 16:19:25 -08:00
Michael Gottesman
ce0c40e40b [+0-all] Update more runtime files for +0 normal arguments.
This is NFC when --enable-guaranteed-normal-arguments isn't passed into
build-script.

rdar://34222540
2018-01-29 12:13:45 -08:00
Philippe Hausler
c734324a67 [Foundation] Address a potential leak when writing a data to a URL and the file system representation fails (#14176) 2018-01-26 13:25:55 -08:00
Mishal Shah
fdbf76e9f5 Update master to build with Xcode 9.3 beta 1 2018-01-25 16:03:11 -08:00
Michael Gottesman
18bcc1e143 [+0-args] Change SWIFT_CC(Swift) functions to use SWIFT_NS_RELEASES_ARGUMENT instead of NS_RELEASES_ARGUMENT.
rdar://34222540
2018-01-23 16:01:27 -08:00
Greg Parker
7b9224794e [runtime] Reinstate TwoWordPair hack for swiftcall returns. (#14079)
clang is miscompiling some swiftcall functions on armv7s.
Stop using swiftcall in some places until it is fixed.

Reverts c5bf2ec (#13299).

rdar://35973477
2018-01-23 01:04:01 -08:00
Karoy Lorentey
f2a96496a0 [StringGuts] Support for 32-bit platforms
Add 32-bit support to the new StringGuts.
2018-01-21 12:36:09 -08:00
Karoy Lorentey
3982875da0 Use Dictionary’s subscript setter rather than updateValue
It doesn’t matter which value we keep, and since we don’t currently check for duplicate values, there is no reason to retrieve the old value.
2018-01-20 00:58:44 +00:00
Karoy Lorentey
9e4dcd8bae [Foundation] Coalesce duplicate keys in String-keyed NSDictionary and NSSet instances
NSString has a stricter concept of equality than Swift’s String, so it is possible to construct NSDictionary/NSSet instances that contain duplicate keys according to Swift’s definition of string equality. This change improves how we handle these cases by coalescing the duplicate keys (keeping a single value).

rdar://problem/35995647
2018-01-19 22:35:59 +00:00
Ben Cohen
ca6c6b1d36 [stdlib] Cleanup DefaultIndices, delete dead code (#13952)
* Remove a bunch of Default(Bidirectional|RandomAccess)Indices usage from stdlib and test

* Remove some DefaultRandomAccessIndices and IndexDistance usage from Foundation

* Remove no-longer-used internal type in Existentials.swift

* Get rid of indicesForTraversal
2018-01-15 13:48:08 -08:00
Itai Ferber
1e110b8f63 Restore decoder state after throwing on decode
Resolve SR-6408 by restoring the JSON/PlistDecoder stack if an error
is thrown after a container was pushed during encode.
2018-01-11 12:20:01 -08:00
Itai Ferber
57e356b1c4 Restore encoder state after throwing on encode
Resolve SR-6078 by restoring the JSON/PlistEncoder stack if an error
is thrown after a container was pushed during encode.
2018-01-11 12:20:01 -08:00
Gregory Todd Williams
09ed106f25 [stdlib] Don't try to construct invalid UnicodeScalars in CharacterSet
Inserting and removing a single Unicode.Scalar in a CharacterSet must not
attempt to create a Range<Unicode.Scalar> because the upperBound value might
not always be a valid UnicodeScalar.

This fixes a regression to the fix for SR-2988.
2018-01-02 10:07:28 -08:00
Maxim Moiseev
128092a7d6 Rename filterMap to compactMap 2017-12-18 09:22:41 -08:00
Max Moiseev
8ec6c45d2d Use filterMap to avoid deprecation warnings 2017-12-18 09:16:37 -08:00
Thomas Roughton
c5bf2ec553 [runtime] Remove TwoWordPair and use the Swift calling convention instead. (#13299) 2017-12-07 19:27:24 -08:00
swift-ci
f767040b4a Merge pull request #13316 from ikesyo/nsrange-init 2017-12-07 19:19:37 -08:00
Sho Ikeda
4438834529 Merge pull request #13266 from ikesyo/sync-measurement-overlay
[overlay] Synchronize Measurement.swift with swift-corelibs-foundation
2017-12-08 08:53:40 +09:00
Sho Ikeda
dacd46c95e [overlay][gardening] Use NSRange.init over NSMakeRange 2017-12-07 22:03:14 +09:00