Commit Graph

47 Commits

Author SHA1 Message Date
Guillaume Lessard
1ccc36cbd2 Merge pull request #61082 from glessard/source-equals-destination 2022-10-03 14:50:25 -07:00
Guillaume Lessard
2689b6044b Merge pull request #41608 from glessard/se-pointer-family-initialization 2022-09-13 22:00:59 -06:00
Guillaume Lessard
874cd336ab [stdlib] avoid work when source and destination are the same 2022-09-13 16:15:42 -06:00
Guillaume Lessard
805da6d8ad [stdlib] improve note about subscripts and initialization 2022-08-31 17:24:23 -06:00
Guillaume Lessard
1f4ed8d976 Update stdlib/public/core/UnsafePointer.swift
Co-authored-by: Ben Rimmington <me@benrimmington.com>
2022-08-31 14:19:26 -06:00
Guillaume Lessard
d24b749ac2 [se-0370] improve silgen names for renamed symbols 2022-08-30 18:44:03 -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
a7326d0353 [gardening] improve doc-comments in UnsafeMutablePointer 2022-08-26 17:36:39 -06:00
Guillaume Lessard
304a422c3e [stdlib] add single-element assign to UnsafeMutablePointer 2022-08-26 17:36:39 -06:00
Guillaume Lessard
1bba62ec13 Merge pull request #60613 from glessard/pointer-arithmetic-overflow-checks
[stdlib] add overflow checks for some pointer arithmetic
2022-08-25 14:37:44 -06:00
Guillaume Lessard
45b81f6456 [stdlib] add overflow checks for some pointer arithmetic
- Overflow checks added for recent additions to pointer arithmetic (rounding and property pointers).
- The basic `advanced(by:)` functions will need to be dealt with separately.
2022-08-22 09:51:10 -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
Guillaume Lessard
ce7d8134a6 [stdlib] remove preconditions from compatibility entry point
- The old implementation of `UnsafePointer.withMemoryRebound` had no preconditions.
- When implementing SE-0333, we forwarded the old entry point to the new implementation, which has preconditions.
- This change removes the precondition from the compatibility entry point, reverting it to its previous behaviour.
- This resolves rdar://90462471
2022-03-28 18:30:11 -06:00
Guillaume Lessard
f4d56d3734 Merge pull request #41679 from amartini51/trailing_double_tab
Remove trailing double tabs
2022-03-05 13:16:24 -07:00
Alex Martini
17d3b01b48 Remove trailing double tabs. 2022-03-01 14:46:40 -08:00
Guillaume Lessard
577015f5be Merge pull request #39639 from glessard/se-pointer-convenience
SE-0334: Pointer API Usability Improvements
2022-03-01 13:24:25 -07:00
Stephen Canon
b520063e53 || has higher precedence than the ternary operator, so this check didn't work. 2022-02-28 15:33:27 -05:00
Guillaume Lessard
5c10c67a01 [stdlib] pointer(to property:) for UP and UMP 2022-02-25 13:34:23 -07:00
Guillaume Lessard
9ead7d039d [stdlib] relax stride check in UnsafePointer.withMemoryRebound (#41553)
* [stdlib] relax stride check

- The stride check in `UnsafePointer.withMemoryRebound` makes less sense when rebinding memory for a single element.
- This skips the stride-matching portion of the `_debugPrecondition` in `withMemoryRebound` when `count == 1`.

* [test] UnsafePointer.withMemoryRebound with capacity 1
2022-02-25 09:54:32 -05:00
Guillaume Lessard
82fa4b0ea8 [stdlib] relax stride check
- The stride check in `UnsafePointer.withMemoryRebound` makes less sense when rebinding memory for a single element.
- This skips the stride-matching portion of the `_debugPrecondition` in `withMemoryRebound` when `count == 1`.
2022-02-24 18:57:51 -07:00
Guillaume Lessard
3f67313cce [gardening] formatting adjustments 2022-02-04 16:26:11 -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
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
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
5ef8c544e9 [docs] clarify todo about deinitializing a single element 2021-11-11 09:41:41 -07:00
Guillaume Lessard
2bcc6a7f72 [doc] update doc-comment references to a long-renamed function
fixes SR-12938
2021-06-08 15:05:13 -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
Valeriy Van
ad1c957b8d Fixes example snippets in UnsafePointer.swift 2020-04-25 22:51:37 +02:00
Hamish Knight
1bc56dcc11 [stdlib] Mark some parameters @_nonEphemeral
These include the pointer-to-pointer and pointer-to-buffer-pointer
initialiser parameters amongst a couple of others, such as
`Unmanaged.fromOpaque`, and the source for the `move[...]` family of
methods.
2019-11-03 08:42:26 -08: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
351c1291a9 Restore concrete initializers on Unsafe{Raw}Pointer 2019-01-31 17:11:16 -08:00
Andrew Trick
0b5fa792e1 Force manual allocation (via Unsafe*Pointer) to use >= 16 alignment.
This fixes the Windows platform, where the aligned allocation path is
not malloc-compatible. It won't have any observable difference on
Darwin or Linux, aside from manually allocated memory on Linux now
being consistently 16-byte aligned (heap objects will still be 8-byte
aligned on Linux).

It is unfortunate that we can't guarantee Swift-allocated memory via
Unsafe*Pointer is malloc compatible on Windows. It would have been
nice for that to be a cross platform guarantee since it's normal to
allocate in C and deallocate in Swift or vice-versa. Now we have to
tell developers to always use _aligned_malloc/_aligned_free when
transitioning between Swift/C if they expect their code to work on
Windows.

Even though this fix isn't required today on Darwin/Linux, it makes
good sense to guarantee that the allocation/deallocation paths are
consistent.

This is done by specifying a constant that stdlib can use to round up
alignment, _swift_MinAllocationAlignment. The runtime asserts that
this constant is greater than MALLOC_ALIGN_MASK for all platforms.
This way, manually allocated buffers will always use the aligned
allocation path. If users specify an alignment less than m

round up so users don't need
to pass the same alignment to deallocate the buffer). This constant
does not need to be ABI.

Alternatives are:

1. Require users of Unsafe*Pointer to specify the same alignment
   during deallocation. This is obviously madness.

2. Introduce new runtime entry points:
   swift_alignedAlloc/swift_alignedDealloc, introduce corresponding
   new builtins, and have Unsafe*Pointer always call those. This would
   make the runtime API a little more obvious but would introduce
   complexity in other areas of the compiler and it doesn't have any
   other significant benefit. Less than 16-byte alignment of manually
   allocated buffers on Linux is a non-goal.
2019-01-03 12:35:51 -08:00
Saleem Abdulrasool
381cae6df0 stdlib: pass along alignment for dealloc
Ensure that UnsafeMutablePointer.deallocate has the alignment that was
used when invoking UnsafeMutablePointer.allocate.  This is required to
ensure that the appropriate `free` function is invoked.  We would
previously fail on Windows as the allocation would use `malloc` and due
to the value being `-1`, use `_aligned_free` instead when deallocating.
2018-11-20 14:05:13 -08:00
Nate Cook
efb0415a61 [stdlib] More documentation revisions (#18263)
- Fix error in `last(where:)` example
- Improve MemoryLayout, UnsafePointer, and integer operator discussions
- Clean up ranges and random APIs
- Revisions to overflow operators and the SignedNumeric requirements
- Standardize on 'nonoptional' in remaining uses
2018-08-08 00:25:09 -05:00
Nate Cook
2536277362 [stdlib] Various documentation improvements (#18013)
- Revise Bool.toggle() discussion and fix attribute placement
- Revise to Hasher abstracts and discussions
- Correct the name of the remainder operator
- Clean up deprecations and paste-os w/in UnsafePointer
2018-07-18 12:41:22 -05:00
Ben Cohen
a8328a820f Factor a couple more universal inits into _Pointer (#17952) 2018-07-14 22:14:27 -07:00
Ben Cohen
436b8610e7 [stdlib][WIP] Factor out common parts of pointer types and de-gyb (#17951)
* Add conformances to _Pointer and remove from pointer types

* De-gyb pointer files
2018-07-14 07:36:45 -07:00