Skip to content

Commit 55eaed5

Browse files
committed
Doc: add explainer for Escapable
resolves rdar://146331729
1 parent e39a31a commit 55eaed5

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

stdlib/public/core/Misc.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,20 @@ func _rethrowsViaClosure(_ fn: () throws -> ()) rethrows {
239239
/// Extensions to the `Copyable` protocol are not allowed.
240240
@_marker public protocol Copyable/*: ~Escapable*/ {}
241241

242-
@_documentation(visibility: internal)
242+
/// A protocol representing types whose values can persist beyond the immediate local context.
243+
///
244+
/// They may be freely assigned to global or static variables, returned from functions, or captured by escaping
245+
/// closures, etc. All Swift types implicitly conform to this protocol by default, allowing them to be moved across
246+
/// scopes freely because they lack any lifetime dependencies.
247+
///
248+
/// In contrast, values of types that suppress their implicit conformance to `Escapable` (by writing `~Escapable`)
249+
/// carry a lifetime dependency. These dependencies ensure the `~Escapable` value does not live longer than the value it
250+
/// depends on. Explicit lifetime dependency annotations may be required when working with these types.
251+
///
252+
/// In generic contexts, `~Escapable` works much in the same way as `~Copyable`. It allows functions and types to work
253+
/// with values that may or may not be Escapable, and types can be conditionally Escapable based on their generic
254+
/// arguments. A conformance requirement for Escapable is automatically inferred in extensions and for generic type
255+
/// parameters, unless suppressed with `~Escapable`.
243256
@_marker public protocol Escapable/*: ~Copyable*/ {}
244257

245258
@_marker public protocol BitwiseCopyable: ~Escapable { }

0 commit comments

Comments
 (0)