Commit Graph

46 Commits

Author SHA1 Message Date
Erik Eckstein
abf9900be7 stdlib: loadUnaligned doesn't need stack protection for it's temporary
rdar://105231457
2023-02-15 08:20:48 +01:00
Guillaume Lessard
2689b6044b Merge pull request #41608 from glessard/se-pointer-family-initialization 2022-09-13 22:00:59 -06:00
Guillaume Lessard
831a87fd36 [stdlib] make additions non-abi 2022-08-26 17:36:40 -06:00
Guillaume Lessard
bef793dd45 [stdlib] add single-element version of initializeMemory to UMRP 2022-08-26 17:36:40 -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
bee4eaefc4 Merge pull request #60025 from glessard/rdar96841899
[stdlib] fix unaligned loads of large SIMD vectors on x86_64
2022-07-13 17:04:32 -06:00
Guillaume Lessard
b5cc4121d7 [stdlib] fix unaligned loads of 16-byte (and up) SIMD types
- this is a temporary workaround
2022-07-13 10:29:58 -06:00
Guillaume Lessard
4f87f0caa8 [gardening] fix code indentation 2022-07-12 14:50:17 -06:00
swift-ci
f542ca9a76 Merge pull request #59797 from glessard/aeic-mangled-names
[stdlib] Improve the mangled names of some @_alwaysEmitIntoClient functions
2022-06-29 22:46:23 -07:00
Guillaume Lessard
a74f22dadf [docs] fix a repeated typo 2022-06-29 18:19:34 -06:00
Guillaume Lessard
6d36a36dd9 [stdlib] improve silgen names and better document intention 2022-06-29 16:20:34 -06:00
Steven Wu
ea31a9222f stdlib: Fix the name mangling for UnsafeMutableRawPointer.storeBytes
The name mangling for storeBytes is missing `$`.

rdar://96062712
2022-06-29 09:52:51 -07:00
Guillaume Lessard
3229902990 [stdlib] state clearly the precondition of loadUnaligned 2022-04-14 17:23:53 -06:00
Guillaume Lessard
9716bc5fd2 [stdlib] update UnsafeMutableRawPointer.storeBytes
- preserve previous version for ABI and source stability.
- add new version without alignment restriction.
- add explicit POD type enforcement in new version.
2022-04-14 17:23:53 -06:00
Guillaume Lessard
d9fff5b4ec [stdlib] add unaligned loads to UnsafeRawPointer 2022-04-14 17:23:53 -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
bb05e851af [stdlib] restrict pointer arithmetic to UInt 2022-02-25 13:35:20 -07:00
Guillaume Lessard
b3f96e8cea [stdlib] alignedUp(for:) and siblings for URP and UMRP 2022-02-25 13:34:23 -07:00
Guillaume Lessard
3f67313cce [gardening] formatting adjustments 2022-02-04 16:26:11 -07:00
Guillaume Lessard
245426493c [stdlib] documentation clarifications 2022-02-03 20:02:33 -07:00
Guillaume Lessard
3de1eace23 [stdlib] add U[M]RP.withMemoryRebound 2022-02-03 20:02:33 -07:00
Doug Gregor
78e5846537 Add a feature for Builtin.assumeAlignment
Fixes rdar://86785846
2021-12-21 15:56:15 -08: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
Andrew Trick
385a85ccc1 Add assumeAlignment to UnsafeRawPointer.load()
To preserve current behavior.

I expect this builtin to be removed in the default case after
proposing the change in Swift Evolution.
2021-11-30 12:23:46 -08:00
Guillaume Lessard
7f68d6a4f5 document the requirement that allocation alignments must be powers of two. 2021-07-15 19:19:15 -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
5e3dd58e14 Fixes snippets in UnsafeRawPointer.swift 2020-04-25 21:04:15 +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
Nate Cook
15f78fc7af Document that raw copyMemory methods handle overlapping memory. 2019-08-20 13:15:20 -05: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
Ravi Kandhadai
a0277e2010 [stdlib] Fixing a buggy example in the comments in the file UnsafeRawPointer.swift 2019-01-23 13:08:47 -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
Jordan Rose
c66a445ef7 [stdlib] Make some more *Pointer operations _transparent (#21126)
Not only was this affecting performance when building from parseable
interfaces, but we'd also want these to be inlined for any sort of
bounds-checking diagnostics / static analysis we might get in the
future.
2018-12-10 13:37:15 -08:00
swift-ci
928ed50802 Merge remote-tracking branch 'origin/master' into master-next 2018-07-16 16:09:09 -07:00
Ben Cohen
57528ef458 De-gyb Stride.swift (#17956) 2018-07-16 16:02:22 -07:00
swift-ci
c7a4d5fd76 Merge remote-tracking branch 'origin/master' into master-next 2018-07-16 08:29:07 -07:00
Ben Cohen
b77b544cdc Remove remaining @ininable from @_transparent (#17968) 2018-07-16 08:12:52 -07:00
swift-ci
b3490042bf Merge remote-tracking branch 'origin/master' into master-next 2018-07-14 22:29:11 -07:00
Ben Cohen
a8328a820f Factor a couple more universal inits into _Pointer (#17952) 2018-07-14 22:14:27 -07:00
swift-ci
aef1ed620b Merge remote-tracking branch 'origin/master' into master-next 2018-07-14 07:59:20 -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