Commit Graph

82 Commits

Author SHA1 Message Date
Karoy Lorentey
7a7ebd8970 [stdlib] Adopt primary associated types in the stdlib 2022-05-09 18:06:17 -07:00
Karoy Lorentey
b8cbd4f226 [stdlib][docs] Clarify BidirectionalCollection requirements
As discussed on the forum, `BidirectionalCollection` requirements as
currently stated can be interpreted to forbid conforming types from
accepting indices that lie between valid (i.e., reachable) indices
in the collection. Among other undesirable effects, this
interpretation would render SE-0180 (String.Index overhaul)
incompatible with these requirements.

Update the wording to clarify that the requirements only apply to
valid indices. (Collection protocols do not constrain the behavior of
invalid indices — it’s up to individual collection types to implement
them as they wish.)

https://forums.swift.org/t/string-index-unification-vs-bidirectionalcollection-requirements/55946
rdar://92297280
2022-04-25 15:18:35 -07:00
Alex Martini
9bc7b8ea99 Add missing comma & slightly clarify. 2022-02-11 11:48:07 -08: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
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
dbc2e21522 Remove customization points from Sequence and Collection (#19995) 2018-10-31 18:58:00 -07: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
Maxim Moiseev
7cbfed3f3a [stdlib] Explicitly declare Collection requirements on child protocols
Fixes: <rdar://problem/42408692> and SR-8022
2018-07-25 15:12:40 -07: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
Huon Wilson
72a87a76f8 [stdlib] Work-around incorrect name resolution with conditional BidirectionalCollections.
If a type conditionally conforms to BidirectionalCollection, suffix's (and the
others) use of `index` ends up dispatching through `Collection.index` seemingly
because it is a protocol requirement. The intended function is
BidirectionalCollection's overloaded `index` (which _isn't_ connected to a
protocol requirement), which is called for non-conditional conformances. As
such, this is a work-around to stop code crashing.

Noticed in SR-8022, rdar://problem/41216424.
2018-07-19 12:22:32 +10:00
Michael Ilseman
ac09eaa8c7 [stdlib] Refactor out impl methods of BidiCollection; NFC.
Refactor out the implementation of index(_:offsetBy) and others from
BidirectionalCollection so that conformers can choose to invoke the
default implementations explicitly. This is very useful for types such
as String which have common fast-paths to check before falling back on
the general approach.
2018-07-09 10:45:04 -07:00
Ben Cohen
c6b41a5ae5 Inlineable: protocol interface only 2018-07-06 12:03:34 -07: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
Nate Cook
58933d88c5 [stdlib] Rename index(...) methods to firstIndex(...)
A la SE-204.
2018-04-21 18:07:25 -05:00
Slava Pestov
e1f50b2d36 SE-0193: Rename @_inlineable to @inlinable, @_versioned to @usableFromInline 2018-03-30 21:55:30 -07:00
Ben Cohen
c7e05cb21e [stdlib][Gardening] Delete few rogue IndexDistance numericCasts that slipped through (#13684) 2018-01-03 15:53:28 -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
Ben Cohen
c4f0b5fe94 [stdlib] Adopt conditional conformance for Indices, Slice, ReversedCollection (#12913)
* Refactor Indices and Slice to use conditional conformance

* Replace ReversedRandomAccessCollection with a conditional extension

* Refactor some types into struct+extensions

* Revise Slice documentation

* Fix test cases for adoption of conditional conformances.

* [RangeReplaceableCollection] Eliminate unnecessary slicing subscript operator.

* Add -enable-experimental-conditional-conformances to test.

* Gruesome workaround for crasher in MutableSlice tests
2017-11-30 09:10:22 -08:00
Doug Gregor
797df6e8d7 Eliminate the _*Indexable protocols.
The various _*Indexable protocols only exist to work around the lack of
recursive protocol constraints. Eliminate all of the *_Indexable protocols,
collapsing their requirements into the corresponding Collection protocol
(e.g., _MutableIndexable —> Collection).

This introduces a number of extraneous requirements into the various
Collection protocols to work around bugs in associated type
inference. Specifically, to work around the lack of "global" inference
of associated type witnesses. These hacks were implicitly present in
the *Indexable protocols; I've made marked them as ABI FIXMEs here so
we can remove them when associated type inference improves.

Fixes rdar://problem/21935030 and a number of ABI FIXMEs in the library.
2017-10-01 15:08:23 -07:00
Doug Gregor
9d2c9be04e Remove already-completed or separate-discussed ABI FIXMEs. 2017-10-01 15:08:22 -07:00
Doug Gregor
52eb618abc [Collections] Constrain Indices type to Collection.
Make the Indices types conform to the appropriate Collection protocol:
* Collection.Indices: Collection
* BidirectionalCollection.Indices: BidirectionalCollection
* RandomAccessCollection.Indices: RandomAccessCollection
2017-10-01 15:08:22 -07:00
Doug Gregor
6b51806b54 [SE-0157] Make *Collection.SubSequence conform to corresponding *Collection.
Introduce (recursive) constraints that make the *Collection constraint
of SubSequence match that of its enclosing *Collection, e.g.,
MutableCollection.SubSequence conforms to MutableCollection.

Fixes rdar://problem/20715031 and more of SR-3453.
2017-10-01 15:08:22 -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
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
Nate Cook
b7af9bfe83 [stdlib] Remove SeeAlso tags 2017-06-13 11:23:51 -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
Ben Cohen
d95704128d revert changes to stdlib 2017-05-11 12:05:47 -07:00
Ben Cohen
f6f3ed0fe7 Add Collection constraints via protocol where clauses (#9374) 2017-05-07 08:55:48 -07:00
Doug Gregor
d1d4238c40 [Stdlib] Remove ABI FIXMEs #94 and #96, which are consequences of other FIXMEs.
There isn't any work related to SE-0142 associated type where clauses
for these particular ABI FIXMEs. Rather, we get all of the constraints
we need from Collection and the recursive constraint we cannot yet
express, all of which are covered by other ABI FIXMEs.
2017-04-19 23:15:32 -07:00
practicalswift
8c2b87bce0 [gardening] Add correct copyright notices 2017-01-07 20:32:18 +01:00
Nate Cook
82811c57f0 [stdlib] Improvements to Collection doc comments 2016-12-19 13:05:19 -06:00
Nate Cook
3bc4909de8 [stdlib] Various revisions and fixes for documentation
- Fix wording for RandomAccessCollection
- Add note about array growth to reserveCapacity(_:)
- Reformat lazy flatMap discussions
- Improve Collection symbol consistency
2016-12-15 11:47:19 -06:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Doug Gregor
f786a9a230 [Standard library] Duplicate subscript requirement in BidirectionalCollection.
The BidirectionalCollection protocol has no requirements that mention
the associated type 'SubSequence', which means it cannot be easily
inferred. Duplicate the subscript requirement from Collection into
BidirectionalCollection to aid type witness inference.
2016-11-08 16:11:30 -08:00
Louis D'hauwe
f9cd8b129d Updated popLast() and removeLast() documentation. 2016-10-18 21:29:01 +02:00
Louis D'hauwe
520d0d2e12 Updated popLast() and removeLast() documentation. 2016-10-18 15:59:19 +02:00
Louis D'hauwe
ad827ccd51 Use code style in documentation for referred functions. 2016-10-18 00:30:42 +02:00
Louis D'hauwe
f1a2f22b17 Improved documentation for removeLast() 2016-10-18 00:21:18 +02:00
Louis D'hauwe
cdbfc4fb45 Improved documentation for popLast() with note about performance versus removeLast() 2016-10-17 23:47:08 +02:00
airspeedswift
ed5231b47c Numbered all FIXME(ABI) entries for tracking purposes. (#4868) 2016-09-19 16:41:41 -07:00
Dave Abrahams
5c13e35f29 [stdlib] Suppress noisy warnings
We don't have a way yet to say "this is deprecated for users, but let
the stdlib use it without complaining" so we need to do refactoring
shenanigans.
2016-08-28 15:06:42 -07:00
Maxim Moiseev
1faa41246a [stdlib] Adding radar links to the FIXME(ABI) markers (#4511) 2016-08-25 16:50:14 -07:00
Dave Abrahams
8a73f0b98e [stdlib] Change Indexable deprecation messages
It's important to let people know that, in contrast with existing
practice in other frameworks, we really are going to remove the
deprecated API, and soon.
2016-08-08 13:44:41 -07:00
Dave Abrahams
168047d0f0 Deprecate the Indexable protocols
Using them is always a mistake; the user should choose the corresponding
Collection protocol instead.
2016-08-07 22:20:27 -07:00
Nate Cook
63a4107c3c [stdlib] Fix type inference issue for BidirectionalCollection
This resolves the issue described in SR-1922, where conformance
to a bidirectional collection gives errors when implemented using
only the minimal protocol requirements.
2016-07-14 00:34:23 -05:00