Commit Graph

174 Commits

Author SHA1 Message Date
Kyle Murray
1f0b2e59fa Remove a stale fixme comment.
Per Ben's feedback in the PR.
2023-01-30 10:42:42 -05:00
Kyle Murray
15ebec6e23 [stdlib] NFS: Restore documentation comment for Unsafe[Mutable]BufferPointer
Moves a `//` comment up above a `///` documentation comment, since the latter needs to be attached directly to the declaration or it won't be picked up as documentation.
2023-01-28 12:57:41 -05:00
Guillaume Lessard
03d37a9538 [stdlib] use _copyContents after all
- originally had avoided `_copyContents` because all the standard library fast paths were already covered.
- however Swift Collections piecewise-contiguous collections still rely on `_copyContents` to accelerate copies.
2022-09-14 16:23:21 -06:00
Guillaume Lessard
7f4caede90 [stdlib] avoid primary associated type for the time being 2022-09-13 13:31:44 -06:00
Guillaume Lessard
ffa7b0e78c [se-0370] add notes regarding overlapping memory regions 2022-09-08 18:23:45 -06:00
Guillaume Lessard
559e5ed54b [stdlib] use the internal precondition calls 2022-09-07 16:47:08 -06:00
Guillaume Lessard
44a349f8e0 [se-0370] edit doc-comments for consistency 2022-09-07 15:22:49 -06:00
Guillaume Lessard
805da6d8ad [stdlib] improve note about subscripts and initialization 2022-08-31 17:24:23 -06:00
Guillaume Lessard
99505d0819 [stdlib] simplify update(from:)
- one fewer variable, one fewer return point
- thanks @benrimmington
2022-08-31 11:49:06 -06:00
Guillaume Lessard
aabf2e2843 Update stdlib/public/core/UnsafeBufferPointer.swift.gyb
Co-authored-by: YR Chen <stevapple@icloud.com>
2022-08-31 10:50:25 -06:00
Guillaume Lessard
285984e3ae [stdlib] simplify update(fromContentsOf:)
- one fewer variable, one fewer return point
2022-08-31 10:46:36 -06:00
Guillaume Lessard
d24b749ac2 [se-0370] improve silgen names for renamed symbols 2022-08-30 18:44:03 -06:00
Guillaume Lessard
c2c432c9d2 [se-0370] re-implement in accordance with updated proposal 2022-08-30 11:05:41 -06:00
Guillaume Lessard
f5ffe09c53 [se-0370] fix editing errors 2022-08-26 17:36:40 -06:00
Guillaume Lessard
0a78756bf4 [se-0370] add element labels to a returned tuple
- this is technically source-breaking,
  but the risk seems to be very low.
2022-08-26 17:36:40 -06:00
Guillaume Lessard
26e5c43aa3 [se-0370] update documentation to track proposal
for the functions involving `fromContentsOf:`.
2022-08-26 17:36:40 -06:00
Guillaume Lessard
d63747f13d [stdlib] remove the single-element update functions
- as per an update to the proposal
2022-08-26 17:36:40 -06:00
Guillaume Lessard
831a87fd36 [stdlib] make additions non-abi 2022-08-26 17:36:40 -06:00
Guillaume Lessard
cc16a9f997 [stdlib] assign → update 2022-08-26 17:36:40 -06:00
Guillaume Lessard
cff3012b37 [stdlib] additions to UMBP
- add initialization from a Collection
- assign to a UMBP from a Sequence or a Collection
- add `moveInitialize` and `moveAssign` to UMBP
- deinitialize UMBP
- add single-element memory state functions in a buffer
2022-08-26 17:36:40 -06:00
Guillaume Lessard
94d53871af [gardening] remove outdated recommendation 2022-08-26 17:36:39 -06:00
Guillaume Lessard
99d957fa1e [gardening] improve summary line 2022-08-26 17:36:39 -06:00
Guillaume Lessard
92087a8f62 [stdlib] add explanations to _debugPrecondition calls 2022-08-18 15:37:25 -06:00
Guillaume Lessard
a74f22dadf [docs] fix a repeated typo 2022-06-29 18:19:34 -06:00
Guillaume Lessard
e353e2f568 [stdlib] document compatibility entry point silgen names better 2022-06-29 16:21:55 -06:00
Guillaume Lessard
6d36a36dd9 [stdlib] improve silgen names and better document intention 2022-06-29 16:20:34 -06:00
Josh Soref
a0d2cabda6 Spelling stdlib/public/core (#42441)
* spelling: available

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: components

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: conjunction

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: conversion

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: enforce

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: guarantee

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: interchangeable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: satisfied

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: superfluous

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-19 14:02:24 -07:00
Guillaume Lessard
1161f92bd7 Merge pull request #39529 from glessard/se-withMemoryRebound 2022-02-05 09:01:05 -07:00
Guillaume Lessard
ba416cd008 [abi] forward calls made to the old withMemoryRebound symbols 2022-02-04 16:07:52 -07:00
Guillaume Lessard
2a9fa0c8dd [abi] make the compatibility symbols internal 2022-02-04 15:48:19 -07:00
Karoy Lorentey
8533b4295b Merge pull request #37424 from Lukasa/cb-fewer-checks-in-ubp
Remove as much checked math as possible from buffer pointers.
2022-02-04 10:40:24 -08:00
Guillaume Lessard
245426493c [stdlib] documentation clarifications 2022-02-03 20:02:33 -07:00
Guillaume Lessard
5f5c75d21a [abi] preserve original implementations of withMemoryRebound 2022-02-03 20:02:33 -07:00
Karoy Lorentey
0a82ef8e13 Re-add debug-mode overflow check in index(_:,_offsetBy:limit:) 2022-02-03 11:40:41 -08:00
Karoy Lorentey
a3fdcfa43f Reword note on wrapping arithmetic 2022-02-03 11:39:44 -08:00
Guillaume Lessard
c2dfb94f88 [stdlib] update existing withMemoryRebound
- updated documentation and adjust implementations
2022-02-02 15:33:28 -07:00
Andrew Trick
47cc279960 Unsafe*Pointer types should not be Sendable.
To send them across actors, they need to be wrapped in an '@unchecked
Sendable' type. Typically such a wrapper type would be be responsible
for ensuring its uniqueness or immutability.

Inferring Sendability for arbitrary types that contain Unsafe*Pointers
would introduce race conditions without warning or any explicit
acknoledgement from the programmer that the pointer is in fact unique.
2021-12-06 15:52:50 -08:00
Guillaume Lessard
0d1d49da4f [gardening] fix copy-pasta 2021-11-03 04:50:04 -06:00
Karoy Lorentey
dd40ff2929 [stdlib][NFC] Put stored properties & primary initializers before other members in struct declarations 2021-10-05 22:01:35 -07:00
Guillaume Lessard
e946cd02c0 remove duplicated code
- call `UnsafeMutablePointer.allocate(capacity:)` from
  `UnsafeMutableBufferPointer.allocate(capacity:)`.
- This was a straight code duplication.
2021-07-16 12:18:33 -06:00
Cory Benfield
b1683c89be Remove as much checked math as possible from buffer pointers.
This patch removes as much checked math as I was able to find from the
unsafe buffer pointers types. In particular, I removed two kinds of
checked math:

1. Checked math that was provably unable to trap due to prior operations
   done in the same function, or in a function that must have been
   called before the current one. For example, in
   index(_:offsetBy:limitedBy:), when we do the final index addition we
   have already validated that it must be in-bounds. Therefore, it
   cannot overflow.
2. Checked math that can only fail if the user is misusing the indices.
   As previously discussed with Karoy and Andrew, the unsafe raw buffer
   types are not obligated to crash if you misuse their indices, they
   are free to invoke undefined behaviour. In these cases, I added
   defensive overflow checks in debug mode.

The result of this change should be reductions in code size in almost
all usage sites of the raw buffer types.
2021-05-21 09:25:32 +01:00
Doug Gregor
9579390024 [SE-0304] Rename ConcurrentValue to Sendable 2021-03-18 22:48:20 -07:00
Karoy Lorentey
0836707303 [stdlib] Deprecate MutableCollection._withUnsafeMutableBufferPointerIfSupported (#36003)
* [stdlib] Deprecate MutableCollection._withUnsafeMutableBufferPointerIfSupported

In Swift 5.0, [SE-0237] introduced the public `MutableCollection.withContiguousMutableStorageIfAvailable` method. It’s time we migrated off the old, underscored variant and deprecated it.

The default `MutableCollection.sort` and `.partition(by:)` implementations are currently calling this hidden method rather than the documented interface, preventing custom Collection implementations from achieving good performance, even if they have contiguous storage.

[SE-0237]: https://github.com/apple/swift-evolution/blob/master/proposals/0237-contiguous-collection.md

* [test] Update tests for stdlib behavior changes

* Update stdlib/private/StdlibCollectionUnittest/CheckMutableCollectionType.swift

Co-authored-by: Nate Cook <natecook@apple.com>

* Update stdlib/private/StdlibCollectionUnittest/CheckMutableCollectionType.swift

Co-authored-by: Nate Cook <natecook@apple.com>

* Apply suggestions from code review

Co-authored-by: Nate Cook <natecook@apple.com>

* [test] LoggingMutableCollection: Fix logging targets

* [stdlib] Fix warning by restoring original workaround

Co-authored-by: Nate Cook <natecook@apple.com>
2021-02-26 11:32:27 -08: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
Karoy Lorentey
94a7eeebe5 [stdlib] Document sources of code bloat 2020-12-11 18:31:00 -08:00
Karoy Lorentey
1f92df093c [stdlib] Add an unsafe U[M]BP initializer to work around some inliner test failures 2020-12-09 19:31:28 -08:00
Karoy Lorentey
282a1408de [stdlib] U[R]BP: Restore compile-time condition lost with removed precondition 2020-12-08 22:25:16 -08:00
Karoy Lorentey
27978d16b9 [stdlib] Eliminate an overflow check in U[M]BP.distance 2020-12-04 02:06:22 -08:00
Karoy Lorentey
d52cd8243a [stdlib] Add a missing debug mode check to U*BP.init(rebasing:)
`Slice` does not technically guarantee that its indices are valid in its base, so these initializers accidentally allowed the creation of obviously out-of-bounds buffers.
2020-12-04 02:06:22 -08:00
Karl
74a8254d40 Make UBP nil/count checks debug-mode only
Every other Unsafe(Mutable)BufferPointer precondition in this file is debug-mode only.

This information is already part of the documentation for this function, and it's really hard to get rid of these branches and traps otherwise.
2020-12-04 02:06:21 -08:00