Commit Graph

41 Commits

Author SHA1 Message Date
Guillaume Lessard
dfb2e2f12e [stdlib] annotate uses of Range.init(_uncheckedBounds:) 2025-03-05 18:52:11 -08:00
Doug Gregor
22eecacc35 Adopt unsafe annotations throughout the standard library 2025-02-26 14:28:01 -08:00
Karoy Lorentey
f7c674ed55 [stdlib] Slice._bounds, Range<String.Index>._encodedOffsetRange: New helpers 2022-04-05 20:47:42 -07:00
Guillaume Lessard
0d1d49da4f [gardening] fix copy-pasta 2021-11-03 04:50:04 -06:00
Guillaume Lessard
3302750fa2 [stdlib] avoid ABI impact 2021-08-02 12:20:24 -06:00
Guillaume Lessard
f6f36fa6d1 [stdlib] simplify indexing 2021-08-02 12:20:24 -06:00
Guillaume Lessard
2bc053f815 [stdlib] implement _copyContents for Slice
`Sequence._copyContents(initializing:)` is the function relied on by
`UnsafeMutableBufferPointer` for performant initialization from Collections.
Until now, `Slice<Base: Collection>` has not had its own implementation,
and therefore fell back to the default version implemented on `Sequence`.

This implementation adds an attempted fast path, using
`withContiguousStorageIfAvailable`. If that fails, the `Sequence`
algorithm is used, as before.

This resolves https://bugs.swift.org/browse/SR-14491
2021-07-28 15:23:03 -06:00
Doug Gregor
9579390024 [SE-0304] Rename ConcurrentValue to Sendable 2021-03-18 22:48:20 -07:00
Doug Gregor
1a1f79c0de Introduce safety checkin for ConcurrentValue conformance.
Introduce checking of ConcurrentValue conformances:
- For structs, check that each stored property conforms to ConcurrentValue
- For enums, check that each associated value conforms to ConcurrentValue
- For classes, check that each stored property is immutable and conforms
  to ConcurrentValue

Because all of the stored properties / associated values need to be
visible for this check to work, limit ConcurrentValue conformances to
be in the same source file as the type definition.

This checking can be disabled by conforming to a new marker protocol,
UnsafeConcurrentValue, that refines ConcurrentValue.
UnsafeConcurrentValue otherwise his no specific meaning. This allows
both "I know what I'm doing" for types that manage concurrent access
themselves as well as enabling retroactive conformance, both of which
are fundamentally unsafe but also quite necessary.

The bulk of this change ended up being to the standard library, because
all conformances of standard library types to the ConcurrentValue
protocol needed to be sunk down into the standard library so they
would benefit from the checking above. There were numerous little
mistakes in the initial pass through the stsandard library types that
have now been corrected.
2021-02-04 03:45:09 -08:00
Matt Zanchelli
be13b470aa Fix typos
becuase -> because
preceeds -> precedes
initalizer -> initializer
intialize -> initialize
libary -> library
notfication -> notification
reciever -> receiver
collecton -> collection
exlcusive -> exclusive
techincal -> technical
compatability -> compatibility
setps -> steps
accomodate -> accommodate
brakcet -> bracket
fraciton -> fraction
programm -> program
concequently -> consequently
ecoding -> encoding
timeIntervalforSelfEnd -> timeIntervalForSelfEnd
2020-12-21 18:44:03 -05:00
Valeriy Van
68ee82c132 Fixes example snippet in Slice.swift 2020-05-11 23:42:24 +02:00
Ben Rimmington
ff264da966 [stdlib] Remove unneeded numericCasts 2020-05-08 06:03:49 +01:00
Karoy Lorentey
b7e08accb1 [stdlib] Slice: customize withContiguous[Mutable]StorageIfAvailable (#28883)
* [stdlib] Slice: customize withContiguous[Mutable]StorageIfAvailable

We can easily make an UnsafeBufferPointer that slices another UnsafeBufferPointer, so let’s allow Slice to vend a slice of the base collection’s contiguous storage, if it provides access to one.

We need to do some index distance calculations to implement this, but those will be constant-time in the usual case where the base collection is a RAC.

https://bugs.swift.org/browse/SR-11957
rdar://58090587

* [test] UnsafeBufferPointer: fix some warnings

* [stdlib] Slice: don’t calculate index distances unless the base provides contiguous mutable storage
2020-01-06 12:32:30 -05:00
Paul Hudson
06f82a53b5 Replaced the majority of ' : ' with ': '. 2019-07-18 20:46:07 +01:00
Ben Cohen
e9d4687e31 De-underscore @frozen, apply it to structs (#24185)
* De-underscore @frozen for enums

* Add @frozen for structs, deprecate @_fixed_layout for them

* Switch usage from _fixed_layout to frozen
2019-05-30 17:55:37 -07:00
Ben Cohen
412a045f71 [stdlib] JAFIA (#19074)
* Lazy/generic types needing specialization

* Move DictionaryLiteral typealias to compatibility shims file

* Static String is mainly transparent so needs no inlining

* UnboundedRange hack doesn't need inlining

* Unmanaged needs unsafe performance

* Onone enum namespace

* Output stream specialize-never and calls to lock/unlock don't need inlining

* no need for @_frozen on internal enum

* DropWhile needs lazy-performance
2018-09-19 19:41:06 -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
Slava Pestov
e1f50b2d36 SE-0193: Rename @_inlineable to @inlinable, @_versioned to @usableFromInline 2018-03-30 21:55:30 -07: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
Nate Cook
0782b482b3 [stdlib] Documentation improvements
- Revise Equatable and Hashable for synthesized requirements
- Complete Strideable and stride(from:...:by:) documentation
- Revise DoubleWidth type docs
- Add complexity notes for Set.index(of:) and .contains(_:)
- Fix typos in Set.formUnion docs
- Add missing axioms for SetAlgebra (SR-6319)
- Improve guidance for description and debugDescription
- Add note about the result of passing duplicate keys to
  Dictionary(uniqueKeysWithValues:)
- Fix typo in BinaryInteger docs
- Update Substring docs with better conversion example
- Improve docs for withMemoryRebound and isKnownUniquelyReferenced
- Add missing docs not propagated from protocols
2018-01-05 17:06:44 -06: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
ben-cohen
e7b668e705 Part the third 2017-12-01 12:40:19 -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
Dmitri Hrybenko
d9088afe4b stdlib: add MutableSlice
See doc comments on MutableSlice for more information about what it is.

MutableSlice was one of the reasons to clarify and tighten index
invalidation rules.  After that change, existing MinimalCollection
test types were performing checks that are too strict according to the
model.  Existing algorithms and collections could provide them, but not
MutableSlice.  This commit updates MinimalCollection types to perform
index invalidation checks that correspond to new rules.

Part of rdar://20722366.  This commit adds the type, but does not wire
it up completely yet.

Swift SVN r30839
2015-07-31 03:21:56 +00:00
Dmitri Hrybenko
e5e4335fad stdlib: Slice: trap on out-of-bounds indices
rdar://21822657

Swift SVN r30269
2015-07-16 18:22:40 +00:00
Dmitri Hrybenko
b4ec45d625 stdlib: make Slice.init(base:bounds:) public
Swift SVN r30113
2015-07-11 05:58:06 +00:00
Dmitri Hrybenko
be5ef02bd0 Revert "stdlib: make Slice.init(base:bounds:) public"
This reverts commit 30111.  It broke the buildbots.

Swift SVN r30112
2015-07-11 05:34:05 +00:00
Dmitri Hrybenko
26ebe14178 stdlib: make Slice.init(base:bounds:) public
Swift SVN r30111
2015-07-11 05:20:41 +00:00
Dmitri Hrybenko
1edcc49ff9 stdlib: remove Slice.Element typealias
It is misleading in generic code.  A testcase that was failing:

  expectEqualType(C.Generator.Element.self, Slice<C>.Element.self)

Swift SVN r29887
2015-07-02 06:44:38 +00:00
Dmitri Hrybenko
a3f74461fb stdlib: remove an explicit Slice.generate(), it is supplied by a protocol extension
Swift SVN r29848
2015-07-01 18:44:59 +00:00
Dmitri Hrybenko
fc0fa96371 stdlib: de-underscore Indexable and add tests for it
Swift SVN r29847
2015-07-01 18:31:31 +00:00
Dmitri Hrybenko
76f5706b50 stdlib: de-underscore the Slice type and add tests for it
Swift SVN r29846
2015-07-01 18:31:29 +00:00
Dmitri Hrybenko
80b1380fe8 stdlib: fold Sliceable into CollectionType and de-underscore SubSequence
Swift SVN r29845
2015-07-01 18:31:25 +00:00
Dave Abrahams
f77d6d47a0 [stdlib] Quick fix
Missed updating Slice.swift in my last commit.

Swift SVN r29727
2015-06-26 01:36:45 +00:00
Dave Abrahams
8e0b5bd553 [stdlib] Cleanups based on commit-list feedback
Thanks, Dmitri!

Swift SVN r29724
2015-06-26 01:15:50 +00:00
Dave Abrahams
1c5f805074 [stdlib] Protocol Extension-ize CollectionType
Eliminates _CollectionDefaultsType and _CollectionGeneratorDefaultsType
and creates sanity that should allow us to Protocol Extension-ize the
lazy operations, which have been blocked on inscrutable errors due in
part to the existing complexity.

Note: names beginning with "_prext_" are intended to be public after API
review and removal of the "_prext_" prefix.

Swift SVN r29689
2015-06-25 21:34:28 +00:00
Dmitri Hrybenko
8b2a1b4e1e stdlib: remove _CollectionSliceDefaultsType
The newest type checker improvements fix the underlying issue.

Swift SVN r27670
2015-04-24 02:42:08 +00:00
Dmitri Hrybenko
7afe30ec7d stdlib: make all collections sliceable, first steps
This commit adds a minimally working Slice type and minimal tests.  Even
though it might seem logical how the new protocol requirements are
injected in the CollectionType hierarchy, it is very fragile and
required many attempts to get the typechecker to finally accept it.
Because I want to ensure that the type checker does not regress, I'm
commiting a patch that does not do much yet.

Swift SVN r27665
2015-04-24 01:27:15 +00:00
Dmitri Hrybenko
005c76ba07 Revert "stdlib: make all collections sliceable, first steps"
This reverts commit r27617.  Too late, it crashes the type checker now.

Swift SVN r27618
2015-04-23 00:56:30 +00:00
Dmitri Hrybenko
0cdf289c9c stdlib: make all collections sliceable, first steps
This commit adds a minimally working Slice type and minimal tests.  Even
though it might seem logical how the new protocol requirements are
injected in the CollectionType hierarchy, it is very fragile and
required many attempts to get the typechecker to finally accept it.
Because I want to ensure that the type checker does not regress, I'm
commiting a patch that does not do much yet.

Swift SVN r27617
2015-04-23 00:26:08 +00:00