Commit Graph

113 Commits

Author SHA1 Message Date
Garth Snyder
610d07e9ed [stdlib] Fix doc comment refs to subranges(where:), now called indices(where:) (#78512)
Doc comments for DiscontiguousSlice, MutableCollection, RangeSet, and
RangeReplaceableCollection all refer to a Collection method subranges(where:)
which is intended to return a RangeSet of matching ranges. I believe this is
likely an old or formerly-contemplated spelling of the method now known as
indices(where:). This commit changes "subranges" to "indices".
2025-01-16 13:54:02 -08:00
Mishal Shah
af112c1591 Update the Swift version to 6.0 from 5.11 2024-02-19 17:47:16 -08:00
Jeremy Schonfeld
2404013f78 [SE-0270] Add Collection Operations on Noncontiguous Elements (#69766)
* Adds RangeSet/DiscontiguousSlice to the stdlib

* Remove redundant DiscontiguousSlice.Index: Comparable conformance

* Attempt to fix embedded build

* Attempt to fix macOS test failures

* Fix Constaints/members.swift failure on linux

* Add exceptions to ABI/source checker to fix macOS tests

* Fix incremental dependency test failure

* Remove inlining/unfreeze implementation for future improvements

* Simplify indices(where:) implementation

* Address review feedback

* Add test for underscored, public slice members

* Address feedback on inlining, hashing, and initializing with unordered arrays

* Fix ABI checker issues

* Remove MutableCollection extension for DiscontiguousSlice

* Make insertion return a discardable Bool

* Fix ABI checker tests

* Fix other ABI checker tests due to dropping MutableCollection subscript
2024-01-09 14:02:19 -08:00
David Smith
dade932a85 Revert "Try using withContiguousStorageIfAvailable in RangeReplaceableCollection.append(contentsOf:) before falling back to a slow element-by-element loop. Fixes rdar://109059874" (#67842)
This reverts commit 465aa22b81.
2023-08-10 01:39:20 -07:00
David Smith
e342ac4ee3 Don't reserveCapacity in append(contentsOf:), it breaks API guarantees of asymptotic complexity (#65927)
Don't reserveCapacity in append(contentsOf:), it breaks API guarantees of asymptotic complexity. Fixes rdar://109577273
2023-05-19 12:13:55 -07:00
David Smith
5efc2da08d _onFastPath, in inlineable code, will end up applying to the caller. We don't want that, so omit it 2023-05-15 12:53:58 -07:00
David Smith
465aa22b81 Try using withContiguousStorageIfAvailable in RangeReplaceableCollection.append(contentsOf:) before falling back to a slow element-by-element loop. Fixes rdar://109059874 2023-05-08 17:03:35 -07:00
Karoy Lorentey
7a7ebd8970 [stdlib] Adopt primary associated types in the stdlib 2022-05-09 18:06:17 -07:00
Philip Turner
80c97da156 Change argument label 2022-01-29 12:41:45 -05:00
Guillaume Lessard
6b219a9c56 [stdlib] fix another accidental infinite-recursion bug (#38950)
fixes: SR-6501, SR-11516
2021-08-23 11:06:27 -04:00
Nate Cook
c35b567001 Temporary removal of RangeSet/DiscontiguousSlice (#35076) 2020-12-14 08:42:01 -06:00
Ben Rimmington
824e4d0cad [SE-0270] Reset availability of RangeSet APIs (#34567) 2020-11-04 16:49:18 -06:00
Nate Cook
ba968d40e3 [stdlib] Fix removeLast(_:) performance for non-random-access collections (#32599)
This replaces the `count` comparison precondition with a limited index
offset, which converts the method from O(n) to O(k).
2020-07-01 03:06:32 -05:00
swift-ci
e25934fa4b Merge pull request #32451 from stephencelis/patch-1 2020-06-28 10:45:46 -07:00
Mishal Shah
272c466e47 Update master to build with Xcode 12 beta 2020-06-22 15:43:20 -07:00
Stephen Celis
e150b377f9 Others 2020-06-19 08:07:25 -04:00
Valeriy Van
a0b6517272 Fixes filter function of RangeReplaceableCollection. Addresses ticket SR-12648 2020-05-20 14:08:26 +02:00
Ben Rimmington
ff264da966 [stdlib] Remove unneeded numericCasts 2020-05-08 06:03:49 +01:00
Alex Martini
011a115d85 Group operators explicitly.
The '+' operator binds tighter than the '...' operator.

Fixes rdar://problem/59833804
2020-03-05 11:18:03 -08:00
Nate Cook
c6183ee71b Add RangeSet and discontiguous collection operations (#28161)
This adds the RangeSet and DiscontiguousSlice types, as well as collection
operations for working with discontiguous ranges of elements. This also adds
a COWLoggingArray type to the test suite to verify that mutable collection
algorithms don't perform unexpected copy-on-write operations when mutating
slices mid-operation.
2020-02-22 15:33:03 -06:00
Nate Cook
8bfe519413 [stdlib] Use RRC.filter in removeAll(where: _) (#18825) 2019-11-15 16:24:27 -06:00
Paul Hudson
06f82a53b5 Replaced the majority of ' : ' with ': '. 2019-07-18 20:46:07 +01:00
John McCall
8be4ec32e6 Protocol requirement overrides must match in mutating-ness.
Without this change, SILGen will crash when compiling a use of the
derived protocol's requirement: it will instead attempt to use
the base protocol's requirement, but the code will have been
type-checked incorrectly for that.

This has a potential for source-compatibility impact if anyone's
using explicit override checking for their protocol requirements:
reasonable idioms like overriding a mutating requirement with a
non-mutating one will no longer count as an override.  However,
this is arguably a bug-fix, because the current designed intent
of protocol override checking is to not allow any differences in
type, even "covariant" changes like making a mutating requirement
non-mutating.  Moreover, we believe explicit override checking in
protocols is quite uncommon, so the overall compatibility impact
will be low.

This also has a potential for ABI impact whenever something that
was once an override becomes a non-override and thus requires a
new entry.  It might require a contrived test case to demonstrate
that while using the derived entry, but it's quite possible to
imagine a situation where the derived entry is not used directly
but nonetheless has ABI impact.

Furthermore, as part of developing this patch (earlier versions of
which used stricter rules in places), I discovered a number of
places where the standard library was unintentionally introducing
a new requirement in a derived protocol when it intended only to
guide associated type deduction.  Fixing that (as I have in this
patch) *definitely* has ABI impact.
2019-01-30 01:33:09 -05:00
Ben Cohen
ae6f5dd604 [stdlib] Add consuming/owned annotations to Collection implementations (#19360)
* Add consuming/owned annotations to Collection implementations

* Update SILOptimizer tests

* Fix access_marker_verify test

* XFAIL reconstruct_type_from_mangled_name
2018-09-21 12:06:56 -07:00
Doug Gregor
7bc7b1e22e [Standard library] Downgrade non-ABI ABI FIXMEs to FIXMEs.
Now that we have removed overriding protocol requirements from witness
tables, they no longer have any effect on the ABI. Replace the FIXME
(ABI) comments with normal FIXMEs: there is no more ABI work to do
here.
2018-09-05 22:01:06 -07:00
Doug Gregor
f8e53d9129 [Standard library] Audit protocol member overrides in protocols.
Add the `-warn-implicit-overrides` flag when building the standard library
and overlays, so that each protocol member that overrides a member of an
inherited protocol will produce a warning unless annotated with either
‘override’ or ‘@_nonoverride’.

An annotation of `override` will mean that the overriding requirement will be treated identically to the overridden declaration. If for some reason a concrete type’s conformance to the inheriting protocol provides a different witness for the overriding requirement than the conformance to the inherited protocol’s witness for the overridden requirement, the witness for the inheriting (more-specialized) protocol will be ignored. A protocol requirement marked ‘override’ only makes sense when the declaration is needed to help associated type inference, which is why the ‘override’ annotations correlate so closely with ABI FIXMEs.

An annotation of `@_nonoverride` means that the two protocol requirements will be treated independently, and may be bound to different witnesses. Use `@_nonoverride` when we might need different witnesses, e.g., because the semantics of the potentially-overriding declaration differ from that of the potentially-overridden declaration. `BidirectionalCollection.index(_:offsetBy:)` is the most obvious example, because the `BidirectionalCollection` ’s version of `index(_:offsetBy:)` allows negative indices. `RandomAccessCollection` ’s version is also marked `@_nonoverride` because it is required to be asymptotically faster than the `Collection` or `BidirectionalCollection` versions.
2018-09-05 13:51:26 -07:00
Graydon Hoare
d8140bc652 Revert "Remove some FIXME(ABI) redundant entries from the Collection hierarchy (#18830)"
This reverts commit b3c17bd333.
2018-08-20 14:38:30 -07:00
Ben Cohen
b3c17bd333 Remove some FIXME(ABI) redundant entries from the Collection hierarchy (#18830) 2018-08-20 07:11:40 -06:00
ezura
388879fc8a [stdlib] Use RRC.filter in removeAll(where: _) 2018-08-19 10:23:51 +09:00
Kyle Murray
29c8329bee [stdlib] Document that removeAll(where:) doesn't reorder the remaining elements. (#18803)
* Document that removeAll(where:) doesn't reorder the remaining elements.

Per Swift Forums discussion on the topic:
"Does removeAll(where:) on arrays guarantee preserved order of elements?"

* Copy docs from the first default impl up to the protocol requirement.

Per Nate's feedback on PR#18803.

The protocol requirement was missing a few extra sentences and a
code example.

* Fix a code example that would fail to remove negative odd integers.

Per feedback on the forums from Jens,
swap `== 1` with `!= 0` so that negative odd numbers would be
removed, too, if the example were modified to include some negative
numbers in the input array.
2018-08-18 11:03:33 -06:00
Nate Cook
3d7dfc232b [stdlib] Update complexity docs for seq/collection algorithms (#17254)
* [stdlib] Update complexity docs for seq/collection algorithms

This corrects and standardizes the complexity documentation for Sequence
and Collection methods. The use of constants is more consistent, with `n`
equal to the length of the target collection, `m` equal to the length of
a collection passed in as a parameter, and `k` equal to any other passed
or calculated constant.

* Apply notes from @brentdax about complexity nomenclature

* Change `n` to `distance` in `index(_:offsetBy:)`

* Use equivalency language more places; sync across array types

* Use k instead of n for parameter names

* Slight changes to index(_:offsetBy:) discussion.

* Update tests with new parameter names
2018-07-24 01:01:34 -05:00
Ben Cohen
a4230ab2ad [stdlib] Update stdlib to 4.0 and reorganize compatibility shims (#17580)
* Update stdlib to 4.0 and move all compatibility shims into a dedicated source file
2018-06-29 06:26:52 -07:00
Joe Groff
46cd1b786b stdlib: Make data structure protocols ready for future move-only types.
We would like to eventually extend Array, Dictionary, and Set to support move-only element types when the language does. To that end, we need to get the `consuming`-ness of protocol requirements on Sequence, Collection, and related protocols right for forward compatibility so that a future version of Swift that extends these types to support move-only data structures remains ABI- and API-compatible with older versions of the language. Mark requirements as `__consuming` where it would be necessary for a move-only implementation of one of these types.
2018-06-19 14:23:24 -07:00
Dave Abrahams
0c7a091390 Use _halfStablePartition to implement partition and removeAll(where:) 2018-06-07 08:43:08 -07:00
Nate Cook
7a4e0a32f6 [stdlib] Revise documentation
This includes various revisions to the APIs landing in Swift 4.2, including:
- Random and other randomness APIs
- Hashable changes
- MemoryLayout.offset(of:)
2018-05-18 11:31:54 -05:00
Dave Abrahams
ec9b402605 Slightly clarify removeAll(where:) (#16459)
* Slightly clarify removeAll(where:)

Improve parameter naming, use "guard" to reduce nesting
2018-05-09 07:57:28 -07:00
Nate Cook
58933d88c5 [stdlib] Rename index(...) methods to firstIndex(...)
A la SE-204.
2018-04-21 18:07:25 -05: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
14654590dc stdlib: remove some @_inlineable that snuck in recently 2018-04-09 18:00:58 -07:00
swift-ci
3430f38563 Merge pull request #11576 from airspeedswift/remove-elements 2018-04-06 17:45:54 -07:00
Slava Pestov
e1f50b2d36 SE-0193: Rename @_inlineable to @inlinable, @_versioned to @usableFromInline 2018-03-30 21:55:30 -07:00
Ben Cohen
ba11a23901 Add removeAll(where:) to RangeReplaceableCollection 2018-03-26 13:49:50 -07:00
Ben Cohen
898dce6f5b Add an ambiguity breaker for RRC.popLast 2018-03-02 13:11:59 -08: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
Pavel Yaskevich
12980335cd [CSRanking] Fix self types to be unrelated when comparing operator decls
Such declarations should already have self bound as one of the parameters
which would enforce subtype relationship.

Resolves: rdar://problem/36333688
2018-01-05 23:24:24 -08:00
Max Moiseev
9bf8d773ab [stdlib] Rearrange + on RangeReplaceableCollection/Sequence once again 2018-01-04 13:58:45 -08:00
Max Moiseev
fe48e8c662 [stdlib] Free function + into static func + 2018-01-03 14:09:14 -08:00
Doug Gregor
a55adb2622 [Standard library] Remove extraneous associated type defaults.
These are no longer required by associated type inference.
2017-12-19 13:03:51 -08:00
Ben Cohen
4ddac3fbbd [stdlib] Eradicate IndexDistance associated type (#12641)
* Eradicate IndexDistance associated type, replacing with Int everywhere

* Consistently use Int for ExistentialCollection’s IndexDistance type.

* Fix test for IndexDistance removal

* Remove a handful of no-longer-needed explicit types

* Add compatibility shims for non-Int index distances

* Test compatibility shim

* Move IndexDistance typealias into the Collection protocol
2017-12-08 12:00:23 -08:00
Max Moiseev
42eb45347b [stdlib] Conditional gardening 2017-12-05 16:33:48 -08:00