Commit Graph

139 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
ccdc218cbd [stdlib] _Hasher: append => combine 2018-04-18 14:18:44 +01:00
Ben Cohen
ca7aea02e9 [stdlib] Add compatibility typealias for CountablePartialRangeFrom (#15989)
* Add compatibility typealias for CountablePartialRangeFrom
2018-04-17 15:48:54 -07:00
Nate Cook
b6a0d9ed26 [stdlib] Documentation revisions
- Make RawRepresentable Codable abstracts distinguishable
- Make the UnboundedRange example a little more user friendly
- Correct the RangeReplaceableCollection example description
- Revise CaseIterable discussion
2018-04-11 11:34:51 -05: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
Doug Gregor
e0d423a506 Add appropriate bounds to CountableClosedRange and CountableRange.
Previously, both CountableRange and CountableClosedRange required
their bound types to be Strideable with a Stride type that conforms to
SignedInteger. Those constraints were not present on the generic
typealiases that replaced these structs. Add them back now, which
fixes the GRDB source compatibility regression.

Fixes https://bugs.swift.org/browse/SR-6907 / rdar://problem/29066394.
2018-03-26 09:04:08 -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
Xiaodi Wu
fd0c387ea8 [stdlib] Mix lowerBound a little in Range.hashValue and ClosedRange.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
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
Jordan Rose
9034ba617b Ban @_fixed_layout on enums in favor of @_frozen
In theory there could be a "fixed-layout" enum that's not exhaustive
but promises not to add any more cases with payloads, but we don't
need that distinction today.

(Note that @objc enums are still "fixed-layout" in the actual sense of
"having a compile-time known layout". There's just no special way to
spell that.)
2018-03-20 14:49:10 -07:00
Ben Cohen
d8d7edf89d [stdlib][NFC] Warning cleanup (#14727)
* Remove Countable use from _ArrayBufferProtocol

* Mark _SwiftNativeNSArrayWithContiguousStorage's init @nonobjc

* Give {Closed}Range a _customIndexOfEquatableElement, supressing warning for _customContainsEquatableElement near-miss

* Eliminate CharacterView.init warning, since it's hard to supress and these things warn constantly.
2018-02-20 11:42:32 -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
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
Dmitri Gribenko
8e886a3bdd stdlib: ranges: remove range protocols
The RangeProtocol was a very weak and fragile abstraction because it
didn't specify the interpretation of the endpoints.  To write a
non-trivial algorithm, one usually needed to consult that information.
The standard library code only actually worked correctly with half-open
and closed ranges (and didn't handle fully open ranges, for example).

The other two protocols, HalfOpenRangeProtocol and ClosedRangeProtocol,
were only used for code sharing, and present an ABI burden.  We can use
gyb instead.
2016-04-22 18:15:06 -07:00
Dave Abrahams
47a870cc50 [stdlib] Use location/formLocation for all index movement 2016-04-21 17:13:41 -07:00
Dmitri Gribenko
41e94ac655 stdlib: fix a bug in CountableClosedRange._customContainsEquatableElement() and add better tests for range types
The tests are still not thorough enough, but this is a start.
2016-04-21 14:00:18 -07:00
Dmitri Gribenko
6bd5a979e4 stdlib: ranges: remove requirements from RangeProtocol that only have one implementation 2016-04-20 15:08:34 -07:00
Dmitri Gribenko
26b24d000d stdlib: ranges: add @warn_unused_result and propagate documentation from other places 2016-04-20 14:59:10 -07:00
Dmitri Gribenko
14bb1ebf03 stdlib: ranges: move common printing and reflection code to protocols that exist solely for implementation sharing
We usually don't put descriptions and mirrors into default
implementations, but these protocols are special because users are not
allowed to declare conformances to them.
2016-04-20 11:37:39 -07:00
Dmitri Gribenko
94964eccb8 stdlib: ranges: remove duplicate code
These definitions already exist in protocols for ranges.
2016-04-20 11:01:47 -07:00
Dmitri Gribenko
1aeccae6e8 stdlib: ranges: add the cheapest possible implementations of isEmpty
These methods are not protocol extensions because the protocol
extensions would need ambiguity breakers between Collection and range
protocols anyway.
2016-04-20 10:37:01 -07:00
Dave Abrahams
3dec7c1fb8 [stdlib] Improve a doc comment 2016-04-19 11:16:01 -07:00
Dmitri Gribenko
3d4378c86c stdlib: add ABI fixmes 2016-04-18 17:15:09 -07:00
Dmitri Gribenko
10697f939f Merge commit '510f29abf77e202780c11d5f6c7449313c819030' into swift-3-indexing-model 2016-04-14 13:45:27 -07:00
Dave Abrahams
4bbcf34d31 [stdlib] Generic conversion between range types 2016-04-12 17:43:24 -07:00
Dave Abrahams
df81c3e4ca [stdlib] 80-column fixes 2016-04-12 16:57:49 -07:00
Dave Abrahams
ed25c811aa [stdlib] Keep uncheckedBounds out of examples.
We should go out of our way not to encourage its use.
2016-04-12 16:55:07 -07:00
Dave Abrahams
48fbd6b974 [stdlib] Reorder protocol conformances 2016-04-10 11:54:33 -07:00
Dave Abrahams
6e75d97f00 [stdlib] Clean up redundant protocol conformance 2016-04-10 11:50:19 -07:00
Nate Cook
97b048171c [New indexing model] Hide Range/CountableRange subscripts
Prevents the overloads that cause ambiguity conflicts for integer-based
ranges from being included in the stdlib generated header.
2016-04-08 16:32:20 -05:00
Nate Cook
f947c7c81c [New indexing model] Finish documentation revisions
- Replaced RandomAccessIndex mentions from Strideable documentation
  with stronger guarantees if Stride conforms to Integer.
- Other cleanup and revisions.
2016-04-08 14:04:34 -05:00
Nate Cook
afd064a335 [New indexing model] Revisions to range documentation 2016-04-08 00:59:26 -05:00
Nate Cook
d072b23ffa [New indexing model] Revise documentation for ranges 2016-04-07 16:53:56 -05:00
Dave Abrahams
94771b4a39 [stdlib] Update indexing model doc comments
Also fix some diagnostics
2016-04-06 17:34:00 -07:00
Manav Gabhawala
7928140f79 [SE-0046] Implements consistent function parameter labels by discarding extraneous parameter names and adding _ where necessary 2016-04-06 20:21:58 -04:00
Dave Abrahams
be46928ceb [stdlib] Make Range == more generic
This enables equality comparison of Range<T> and CountableRange<T>.
2016-04-06 11:03:04 -07:00
Dave Abrahams
94e944ba33 [stdlib] Update Range comments 2016-04-06 11:03:04 -07:00
Dave Abrahams
5864117b1b [stdlib] De-underscore Range.init(uncheckedBounds:) 2016-04-06 09:20:30 -07:00
Dave Abrahams
8e5c9726cc Kill an obsolete FIXME 2016-04-05 16:34:37 -07:00
Dave Abrahams
d417680993 [stdlib] Kill mistakenly committed requirement 2016-04-05 16:33:06 -07:00
Dave Abrahams
db03708a3d [stdlib] De-underscore Range protocols
There's really no excuse for keeping these hidden; they appear in public
APIs.
2016-04-05 16:32:15 -07:00
Slava Pestov
86d4c456f9 Sema: Assert that we don't try to do direct-to-storage access of properties in resilient types
Right now, the rule is that any access of a stored property from a
constructor or destructor through 'self' must go directly to storage,
skipping observers or getter/setter overrides.

This means that in particular, constructors of resilient types cannot
be @_transparent, or defined in an extension in another module.

Previously, this was only caught in IRGen when the @_transparent
function was inlined into a function from another module, which made
debugging difficult.

Now, we hit an assert in Sema in this case. Of course it should be a
diagnostic; we'll get there eventually.

We could partially lift the restriction, allowing convenience
initializers to be defined @_transparent or be added in extensions,
by having accesses of stored properties from convenience inits go
through accessors. This would be safe, because at that point, we must
already have performed a self.init() delegation, however it would
potentially break existing code in subtle ways.

Also, this patch marks the RangeIterator and Range types @_fixed_layout,
since they define @_transparent initializers and this tripped the
new assert. Furthermore, note that the @_transparent initializer
must be versioned because it is inlined into another versioned
@_transparent function.
2016-04-04 21:08:02 -07:00
Slava Pestov
7b91cbd551 stdlib: Add @_versioned attributes needed for resilient build 2016-04-01 13:07:18 -07:00
Slava Pestov
bd8459c433 stdlib: Add some @inline(__always) annotations to make optimizer tests pass when the library is built without -sil-serialize-all 2016-03-28 20:08:12 -07:00
Dave Abrahams
a5c3c63c3d [stdlib] Indexing model: nix RangeOfStrideable
Instead, use CountableRange which is constrained to have a Strideable
Bound whose Stride conforms to Integer.
2016-03-28 17:06:09 -07:00
Dave Abrahams
8d9e62b274 [stdlib] indexing model: rename next/previous
I'm not too satisfied with the names for the updating: versions, but
this is a start.
2016-03-22 17:13:54 -07:00