Commit Graph

157 Commits

Author SHA1 Message Date
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
Karoy Lorentey
8ed81ae063 [stdlib] Adopt availability macros 2021-10-31 15:00:58 -07:00
Doug Gregor
9579390024 [SE-0304] Rename ConcurrentValue to Sendable 2021-03-18 22:48:20 -07:00
Doug Gregor
f81621f2e1 Fix AutoreleasingUnsafeMutablePointer conformance 2021-02-04 12:31:15 -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
Luciano Almeida
338faab324 [test] Adjusting stdlib ocurrences where class syntax is used for protocol inheritance 2020-11-29 21:44:42 -03:00
Hamish Knight
f2564d5126 [stdlib] Add a couple of missing @_nonEphemeral attributes 2020-04-16 10:17:16 -07:00
Mishal Shah
e7cd5ab17f Update master to build with Xcode 11.4 2020-03-24 11:30:45 -07: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
David Smith
1cce12f20c Add an Array-based NSMutableArray subclass 2019-09-24 18:15:33 -07:00
David Smith
90037745ad Add C calling convention shims for creating arrays and strings from buffers 2019-09-24 13:06:54 -07:00
David Smith
1efa946caf Remove stdlib and runtime dependencies on Foundation and CF 2019-09-12 18:03:14 -07:00
Karoy Lorentey
b8dc0f4735 [stdlib] AutoreleasingMutableUnsafePointer: switch to _unsafeReferenceCast for extra validation 2019-08-22 14:25:19 -07:00
Karoy Lorentey
88630e8ea3 [stdlib] AutoreleasingUnsafeMutablePointer: use typed pointers rather than UnsafeRawPointer
This improves code generation in -Onone mode. (UnsafeRawPointer.load/.storeBytes isn’t @_transparent and it doesn’t get specialized in unoptimized builds.)
2019-08-21 18:43:57 -07:00
Karoy Lorentey
61c5ac118d [stdlib] AutoreleasingUnsafeMutablePointer: update docs 2019-08-21 18:25:55 -07:00
Karoy Lorentey
6a92bb9e2e [stdlib] AutoreleasingUnsafeMutablePointer: eliminate questionable pointer use
AutoreleasingUnsafeMutablePointer is pointing to a +0 reference, but in its pointee property’s getter/setter implementations, it is loading the pointer into regular Unsafe[Mutable]Pointers. Those are assuming that the addressed memory contain a +1 reference, which can mislead the compiler into doing optimizations that aren’t valid.

Change the getter/setter implementations so that they use UnsafeRawPointer and load/store Unmanaged values instead. As long as Unmanaged.passUnretained(_:) and Unmanaged.takeUnretainedValue() do the right thing, then AutoreleasingUnsafeMutablePointer won’t have issues, either. (This boils down to ensuring that loading a strong reference out of an unmanaged(unsafe) value works correctly.)
2019-08-20 20:15:49 -07:00
Paul Hudson
06f82a53b5 Replaced the majority of ' : ' with ': '. 2019-07-18 20:46:07 +01:00
David Smith
460a5213fc Revert "[stdlib] AutoreleasingUnsafeMutablePointer: Switch subscripts to _read accessors"
This was an ABI break, since it didn't make it into 5.0. Using _read here is unimportant, so we're just going to revert rather than try being fancy.

This reverts commit 04586e3916.
2019-06-24 11:33:36 -07: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
Karoy Lorentey
04586e3916 [stdlib] AutoreleasingUnsafeMutablePointer: Switch subscripts to _read accessors 2018-12-03 16:22:33 +00:00
Ben Cohen
1673c12d78 [stdlib] Replace "sanityCheck" with "internalInvariant" (#20616)
* Replace "sanityCheck" with "internalInvariant"
2018-11-15 20:50:22 -08:00
Karoy Lorentey
08c813769a [stdlib] Make _Unwrappable internal and rename func unwrap() to _unwrap()
_Unwrappable isn’t used in inlinable context.
2018-11-12 16:57:59 +00:00
Maxim Moiseev
ef1050f3fd [stdlib] Audit inlinability in BridgeObjectiveC
<rdar://problem/45949961>
2018-11-09 21:26:07 -08:00
Ben Cohen
c23215bd63 _getBridgedObjectiveCType and _isBridgedNonVerbatimToObjectiveC 2018-10-29 07:42:07 -07:00
Ben Cohen
4762b37222 Remove inlining of _BridgeableMetatype 2018-10-29 07:42:07 -07:00
Erik Eckstein
6e6aae8d61 Mark all _unconditionallyBridgeFromObjectiveC functions as @_effects(readonly)
This enables removal of those bridging calls for dead parameters. Read-only lets the optimizer remove such a call if the result is not used.
Note that "readonly" means: no observable write operations. It's okay to allocate and initialize new objects.

rdar://problem/44944094
2018-10-10 08:24:26 -07:00
Mike Ash
b05c9e95cf [Stdlib] Make the !_runtime(_ObjC) version of _bridgeAnythingToObjectiveC non-inlinable as it calls an internal function. 2018-10-04 16:27:56 -04:00
Mike Ash
798edb9d0e [Runtime][Stdlib][Overlays] Rename various Objective-C classes and methods that would conflict when loading old Swift libraries into a process alongside ABI-stable libraries.
rdar://problem/35768222
2018-09-13 16:55:10 -04:00
Saleem Abdulrasool
82ef1abe59 stdlib: remove unused variable _nilNativeObject (NFC) 2018-09-05 18:31:38 -07:00
Karoy Lorentey
c599572e56 [stdlib] _CocoaFastEnumerationStackBuf: make internal
_CocoaFastEnumerationStackBuf is now only used by Set and Dictionary, in code that isn’t exposed in the ABI. Remove @usableFromInline.
2018-07-17 16:00:12 +01:00
Ben Cohen
b77b544cdc Remove remaining @ininable from @_transparent (#17968) 2018-07-16 08:12:52 -07: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
Ben Cohen
a6952decab [stdlib] Remove inlineable annotation from transparent functions (#17800)
* Remove inlineable annotation from transparent functions
2018-07-07 08:47:02 -07:00
David Zarzycki
75b0d3c70b [stdlib] NFC: Fix var to let warning 2018-06-30 18:53:39 -04:00
Slava Pestov
4e0e462d23 Rename a few remaining @_inlineable => @inlinable, @_versioned => @usableFromInline 2018-06-09 22:41:54 -07:00
Lily Vulcano
f7a28a8054 Strongly reduce the number of _typeByName() calls — cache the Foundation type, remove assertions. 2018-05-30 17:52:00 -07:00
Lily Vulcano
1377ab7d7e Turn on ‘as’ bridging on Darwin. 2018-05-30 15:07:22 -07:00
Ben Langmuir
628b6a1fc7 Revert "Turn on ‘as’ bridging on Linux." 2018-05-17 14:54:35 -07:00
Lily Vulcano
7b8db8f1fd Remove last vestige of printf debugging. 2018-05-17 10:03:40 -07:00
Lily Vulcano
b9455930ee Turn on ‘as’ bridging on Darwin. 2018-05-17 09:59:39 -07:00
Michael Gottesman
c31033c525 [+0-all-args] Make _bridgeAnythingNonVerbatimToObjectiveC() take its parameter at +1.
This hoists out the retain into Swift code from the casting runtime and along a
few paths in the runtime allows us to eliminate a dynamic retain release.

rdar://38196046
rdar://38771331
2018-04-30 11:05:00 -07:00
Slava Pestov
2e5aef9c8d stdlib: Remove redundant @usableFromInline attributes 2018-04-06 00:02:30 -07:00
Slava Pestov
e1f50b2d36 SE-0193: Rename @_inlineable to @inlinable, @_versioned to @usableFromInline 2018-03-30 21:55:30 -07:00
Greg Parker
415b36dddc [runtime] Clean up symbol exports in casting and class introspection. (#13005) 2017-12-01 17:48:48 -08:00
ben-cohen
6d22ded529 Part the first 2017-11-30 20:11:18 -08: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
Maxim Moiseev
ee5fb33656 [stdlib] Remove the Grand Renaming artifacts of Swift 3 era 2017-08-28 15:54:11 -07:00
Nate Cook
ca5c65f93c [stdlib] Nest some additional operators (#9646) 2017-05-17 19:44:08 -07:00