Skip to content

Commit f8a31c6

Browse files
authored
Merge pull request #85573 from kavon/document-escapable
Doc: add explainer for `Escapable`
2 parents 7ce79f2 + 7e9608c commit f8a31c6

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 type whose values can persist beyond their immediate local scope.
243+
///
244+
/// Escapable values can be assigned to global or static variables, returned from functions, captured by escaping
245+
/// closures, and so on. 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)