Commit Graph

415 Commits

Author SHA1 Message Date
Nate Cook
58933d88c5 [stdlib] Rename index(...) methods to firstIndex(...)
A la SE-204.
2018-04-21 18:07:25 -05:00
Karoy Lorentey
882462ff8a [stdlib] Array._hash(into:): Include the count as a discriminator value
This makes the hash encoding unambiguous when arrays are hashed in sequence.
2018-04-19 20:05:29 +01:00
Karoy Lorentey
ccdc218cbd [stdlib] _Hasher: append => combine 2018-04-18 14:18:44 +01:00
Slava Pestov
2e5aef9c8d stdlib: Remove redundant @usableFromInline attributes 2018-04-06 00:02:30 -07:00
Mark Lacey
32d006de4a stdlib: Collapse some multi-line closures to single-line closures.
The change in CheckMutableCollectionType.swift.gyb previously resulted
in a runtime failure, and before that a compiler crash.

It appears that whatever type checker bug(s) were causing the issue
have been resolved in the last few months, so I'm returning this
closure to a single-expression form and cleaning up a couple other
places where we had an unneeded temporary as well.

Resolves rdar://problem/33781464.
2018-04-03 22:26:33 -07:00
Slava Pestov
e1f50b2d36 SE-0193: Rename @_inlineable to @inlinable, @_versioned to @usableFromInline 2018-03-30 21:55:30 -07:00
Karoy Lorentey
e485c1506b Merge pull request #15382 from lorentey/conditional-hashable2
[SE-0143][stdlib] Conditionally conform stdlib types to Hashable
2018-03-28 21:45:02 +01:00
Michael Gottesman
a1089a2923 [+0-all-args] Mark the storage parameter to _adoptStorage as a +1 parameter.
This fixes the optionset test with +0 enabled. It is now re-enabled.

rdar://38152291
2018-03-27 18:25:39 -07:00
Karoy Lorentey
08c3f8a610 [stdlib] Use _Hasher in conditional Hashable implementations
Implement _hash(into:) rather than hashValue.
2018-03-23 19:09:28 +00:00
Karoy Lorentey
6530c8870c [stdlib] Remove unnecessary attributes and clarify comments 2018-03-23 19:09:28 +00:00
Xiaodi Wu
549282734a [stdlib] Remove unnecessary type annotations in hashValue 2018-03-23 19:09:28 +00:00
Xiaodi Wu
c56882a26c [stdlib] Remove unnecessary doc comments from hashValue implementations
When implementing a protocol requirement, additional doc comments are
unnecessary unless there are additional semantics peculiar to the specific
implementation.

The manually propagated documentation had several problems, including copypasta
and inconsistent terminology.

Therefore, if `T.==` doesn't have any doc comments and the implementation of
`T.hashValue` is unremarkable, remove the unnecessary doc comment.
2018-03-23 19:09:27 +00:00
Karoy Lorentey
94e59a3112 [stdlib] Describe availability of new conformances and members
This assumes these will land in Swift 4.1; the attributes need to be adjusted if that turns out not to be the case.

It seems @available for protocol conformances is not yet functional. I added attributes for those anyway, marked with FIXME(conformance-availability).

# Conflicts:
#	stdlib/public/core/ExistentialCollection.swift.gyb
#	stdlib/public/core/Mirror.swift
2018-03-23 19:09:04 +00:00
Morten Bek Ditlevsen
c9337114d2 [WIP] Conditional conformance to Hashable for Optional, Dictionary and Array types. (#14247)
* Add conditional Hashable conformance to Optional, Dictionary, Array, ArraySlice and ContiguousArray

* Modified hashValue implementations
The hashValues are now calculated similar to the automatically synthesized values when conforming to Hashable.
This entails using _combineHashValues as values of the collections are iterated - as well as calling _mixInt before returning the hash.

* Added FIXMEs as suggested by Max Moiseev

* Use checkHashable to check Hashable conformance

* Use 2 space indentation

* Hashing of Dictionary is now independent of traversal order

* Added a test to proof failure of (previous) wrong implementation of Dictionary hashValue. Unfortunately it does not work.

* Removed '_mixInt' from 'hashValue' implementation of Optional and Array types based on recommendations from lorentey

* Another attempt at detecting bad hashing due to traversal order

* Dictionary Hashable validation tests now detect bad hashing due to dependence on traversal order

* Removed superfluous initial _mixInt call for Dictionary hashValue implementation.

* Add more elements to dictionary in test to increase the number of possible permutations - making it more likely to detect order-dependent hashes

* Added Hashable conformance to CollectionOfOne, EmptyCollection and Range types

* Fix indirect referral to the only member of CollectionOfOne

* Re-added Hashable conformance to Range after merge from master

* Change hashValue based on comment from @lorentey

* Remove tests for conditional Hashable conformance for Range types. This is left for a followup PR

* Added tests for CollectionOfOne and EmptyCollection

* Added conditional conformance fo Equatable and Hashable for DictionaryLiteral. Added tests too.

* Added conditional Equatable and Hashable conformance to Slice

* Use 'elementsEqual' for Slice equality operator

* Fixed documentation comment and indentation

* Fix DictionaryLiteral equality implementation

* Revert "Fix DictionaryLiteral equality implementation"

This reverts commit 7fc1510bc3.

* Fix DictionaryLiteral equality implementation

* Use equalElements(:by:) to compare DictionaryLiteral elements

* Added conditional conformance for Equatable and Hashable to AnyCollection

* Revert "Use 'elementsEqual' for Slice equality operator"

This reverts commit 0ba2278b96.

* Revert "Added conditional Equatable and Hashable conformance to Slice"

This reverts commit 84f9934bb4.

* Added conditional conformance for Equatable and Hashable for ClosedRange
2018-03-23 19:08:38 +00:00
Michael Gottesman
e567bc9028 [+0-all-args] Enable +0 normal arguments.
rdar://34222540
2018-03-19 20:25:31 -07:00
Lance Parker
32146274e7 [stdlib] Isolate Array bridging behavior for ABI stability (#14717)
Isolate Array bridging behavior for ABI stability
2018-02-27 13:47:30 -08:00
Nate Cook
642cbbad7c [stdlib] Documentation revisions and expansions
- Adding docs for unbounded ranges
- Filling in missing docs for range-expression subscripts
- Equality operators for arrays
- Fix issues with range discussions
- Fill in missing integer docs
2018-02-19 11:49:58 -06:00
Ben Cohen
77e417f1d0 [stdlib] Hoist Array.popLast to RangeReplaceableCollection (#14392)
* Move Array.popLast to RangeReplaceableCollection

* Remove popLast from Array completion tests
2018-02-04 20:11:51 -08:00
Ben Cohen
cfaff1dc7d [stdlib] Move _copyBuffer to be an init on _ArrayBufferProtocol (#14222)
* Move _copyBuffer to be an init on _ArrayBufferProtocol

* Make init(copying:) inlineable, even though its inline(never), to allow specialization.

* Delete old array swap test, as swap on arrays is no longer valid.

* Delete the old static method
2018-02-02 10:42:45 -08: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
Ben Cohen
dd5e6b64ea Add custom implementations of removeLast and remove(at:) to Array (#14273) 2018-01-31 22:05:19 +01:00
Jordan Rose
1a30ffdbd7 Revert "[stdlib] Add custom implementations of removeLast and remove(at:) to Array (#14212)"
This reverts commit 5ed4afe50b. It
doesn't appear to be correct when the client is compiled with
optimizations (as in, there's a failing bot).
2018-01-28 21:26:55 -08:00
Ben Cohen
5ed4afe50b [stdlib] Add custom implementations of removeLast and remove(at:) to Array (#14212)
* Add custom implementations of removeLast and remove(at:) to Array
2018-01-28 04:55:33 -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
Ben Cohen
e2cc88269e Remove underscore from ArrayProtocol 2018-01-14 20:23:20 -08:00
Ben Cohen
c7e05cb21e [stdlib][Gardening] Delete few rogue IndexDistance numericCasts that slipped through (#13684) 2018-01-03 15:53:28 -08:00
ben-cohen
6d22ded529 Part the first 2017-11-30 20:11:18 -08:00
Huon Wilson
39e0a951b8 [stdlib] Make Optional, Array and Dictionary conditionally Equatable. 2017-11-27 21:09:49 -08:00
swift-ci
53ddcb5079 Merge pull request #13000 from gottesmm/pr-6a0399e1ebd7ccad1979a2af165d0b09595fb2cb 2017-11-18 20:55:27 -08:00
Michael Gottesman
89cefe0a70 [stdlib] Use a different access pattern to check uniqueness to work around more conservative SILGen codegen.
Using && here causes us to go down a SILGen path that guarantees that self will
be evaluated over the entire && expression instead of just the LHS. This cause
the uniqueness check to always return false at -Onone. At -O, the optimizer is
smart enough to remove this issue.

rdar://33358110
2017-11-18 20:16:28 -07:00
Huon Wilson
48baa3f472 [stdlib] Move Array and Optional == and != into static methods. 2017-11-17 16:09:20 -08:00
Greg Parker
e8475cc130 Revert "Use conditional conformances to implement Equatable for Optional, Array and Dictionary" 2017-11-15 14:17:22 -08:00
Huon Wilson
8524379352 [stdlib] Make Optional, Array and Dictionary conditionally Equatable. 2017-11-14 16:23:20 -08:00
Nate Cook
0b62b0608d [stdlib] Doc revisions
- Add missing docs & parameter lists
- Remove deprecated `characters` usage in examples
- Revise documentation for Mirror and CVarArg
- Revise documentation for swap(_:_:)
- Various typo and grammar fixes
2017-11-07 11:11:23 -06:00
Karoy Lorentey
e4ef5203d2 [stdlib] Extract Array._makeDescription into standalone function
This enables its use for collection types unrelated to Arrays.
Use the new function to replace Set’s implementation of
Custom[Debug]StringConvertible.
2017-10-04 12:40:00 +01:00
Arnold Schwaighofer
cc176ef8d9 stdlib: Fix an assert that triggers after uniqueness hoisting
makeUnique hoisting can create a situation where we hit an assert in
_reserveCapacityAssumingUniqueBuffer that the buffer is not unique if we use
_makeMutableAndUniqueOrPinned to replace
_makeUniqueAndReserveCapacityIfNotUnique.

It is actually fine do to the replacement because we will make the buffer unique
_reserveCapacityAssumingUniqueBuffer if the capacity is zero so adjust the
assert accordingly.

do {
  if (someCond) {
    // array.append(...)
    _makeUniqueAndReserveCapacityIfNotUnique(&array)
    _reserveCapacityAssumingUniqueBuffer(&array)
    _appendElementAssumeUniqueAndCapacity(&array, …)
  } else {
   // array[i] = …
   _makeMutableAndUniqueOrPinned(&array)
   addr = _getElementAddress(&array)
   store 1, addr
  }
} while();

to:

_makeMutableAndUniqueOrPinned(&array) // does not replace empty arrays.
do {
  if (someCond) {
    // array.append(...)
    _reserveCapacityAssumingUniqueBuffer(&array) // hit the assert.
    _appendElementAssumeUniqueAndCapacity(&array, …)
  } else {
   // array[i] = …
   addr = _getElementAddress(&array)
   store 1, addr
  }
} while();

Tested by the performance test if we build the stdlib with assertions.

rdar://34149935
2017-10-02 14:23:17 -07:00
Max Moiseev
568dfc75f6 More missing _inlineable's and deinit's 2017-09-29 11:26:56 -07:00
Max Moiseev
53b8419279 [stdlib] Make all the stdlib APIs @_inlineable
This change in theory should allow us to remove a special stdlib-only
sil-serialize-all compilation mode.

<rdar://problem/34138683>
2017-09-29 11:26:56 -07:00
Maxim Moiseev
6c7d93491f Merge pull request #11627 from moiseev/swift-2-artifacts
[stdlib] Remove the Grand Renaming artifacts of Swift 3 era
2017-09-05 11:41:18 -07:00
Mark Lacey
b64551b853 [stdlib] Restore signatures to use UnsafeMutableBufferPointer.
Resolves rdar://problem/21933004.
2017-08-31 22:33:36 -07:00
Kuba (Brecka) Mracek
d03a575279 Unify the capitalization across all user-visible error messages (#11599)
* Unify the capitalization across all user-visible error messages (fatal errors, assertion failures, precondition failures) produced by the runtime, standard library and the compiler.

* Update some more tests to the new expectations.
2017-08-29 12:16:04 -07:00
Maxim Moiseev
ee5fb33656 [stdlib] Remove the Grand Renaming artifacts of Swift 3 era 2017-08-28 15:54:11 -07:00
Ben Cohen
4d7ae8ca85 [stdlib] Fix array slice self-assignment bug (#10958)
* Fix bug where assigning from self wasn't checking bounds of the assigned slice matched

* break up if statement
2017-07-17 13:09:35 -07:00
Nate Cook
825e9d077d [stdlib] More documentation revisions / consistency fixes. 2017-06-13 14:08:00 -05:00
Nate Cook
b7af9bfe83 [stdlib] Remove SeeAlso tags 2017-06-13 11:23:51 -05:00
Max Moiseev
5590872b35 [stdlib] Moving the Array.filter to _ArrayProtocol
Resolves ambiguity in the following expression

  _ = Array(0..<10).lazy.flatMap { .some($0) }.filter { _ in false }

Fixes: <rdar://problem/32316948>
2017-05-23 17:32:23 -07:00
Max Moiseev
fd2ac31c6e [stdlib] Adding RangeReplaceable.filter returning Self
This overload allows `String.filter` to return a `String`, and not
`[Character]`.

In the other hand, introduction of this overload makes `[123].filter`
somewhat ambiguous in a sence, that the compiler will now prefer an
implementatin from a more concrete protocol, which is less efficient for
arrays, therefore extra work is needed to make sure Array types fallback
to the `Sequence.filter`.

Implements: <rdar://problem/32209927>
2017-05-18 12:24:13 -07:00
Nate Cook
817a1efa3b [stdlib] Documentation revisions
- remove additional 'characters' references from String docs
- improved language around escaping pointer arguments
- key path type abstracts
- codable type abstract revisions
- a few more NSString API fixes
2017-05-17 11:58:08 -05:00
Ben Cohen
ea2f64cad2 [stdlib] Add Sequence.Element, change ExpressibleByArrayLiteral.Element to ArrayLiteralElement (#8990)
* Give Sequence a top-level Element, constrain Iterator to match

* Remove many instances of Iterator.

* Fixed various hard-coded tests

* XFAIL a few tests that need further investigation

* Change assoc type for arrayLiteralConvertible

* Mop up remaining "better expressed as a where clause" warnings

* Fix UnicodeDecoders prototype test

* Fix UIntBuffer

* Fix hard-coded Element identifier in CSDiag

* Fix up more tests

* Account for flatMap changes
2017-05-14 06:33:25 -07:00
Nate Cook
dafe368220 Address @dabrahams’s feedback 2017-05-13 12:25:42 -05:00