swift-book
swift-book copied to clipboard
Clarify Actor Semantics and Provide References Where Omitted
Location
https://docs.swift.org/swift-book/documentation/the-swift-programming-language/concurrency#Actors https://docs.swift.org/swift-book/documentation/the-swift-programming-language/types https://docs.swift.org/swift-book/documentation/the-swift-programming-language/extensions https://docs.swift.org/swift-book/documentation/the-swift-programming-language/extensions#Initializers https://docs.swift.org/swift-book/documentation/the-swift-programming-language/protocols https://docs.swift.org/swift-book/documentation/the-swift-programming-language/generics#Generic-Types https://docs.swift.org/swift-book/documentation/the-swift-programming-language/automaticreferencecounting https://docs.swift.org/swift-book/documentation/the-swift-programming-language/types#Metatype-Type
Description
The first two sentences in the second paragraph of the Actors subsection read:
Like classes, actors are reference types, so the comparison of value types and reference types in Classes Are Reference Types applies to actors as well as classes. Unlike classes, actors allow only one task to access their mutable state at a time, which makes it safe for code in multiple tasks to interact with the same instance of an actor.
This implies that actors support type casting, inheritance, deininitializers, and ARC. Per Xcode, actors do not support inheritance (so type casting is probably not applicable as well), but do allow deinitializers, although there is some question as to whether or not they function as intended. As actors are a reference type, they probably support ARC.
While the correct information is given in the Language Reference, this verbage, as it stands, is misleading.
Also, actors are not identified as one of the named types in the introduction to the Types section in the Language Reference.
Also, extensions may be applied to actors, but may not contain deinitializers.
Also, actors may adopt protocols.
Also, an actor may be a generic type.
Correction
Replace the third sentence in the second paragraph in the Actors subsection of the Concurrency section with:
Unlike classes, actors don't inherit, can't be type cast, and allow only one task to access their mutable state at a time. This last characteristic makes it safe for code in multiple tasks to interact with the same instance of an actor.
Also, in the third sentence in the first paragraph in the Types section, add actors to the list of named types.
Also, in the first sentence in the first paragraph in the Extensions section, add actors to the list of types that may be extended by extensions.
Also, after the second paragraph in the Initializers subsection of the Extensions section, add the following paragraph:
Similarly, an extension can add new initializers to an actor.
Also, in the second sentence in the first paragraph in the Protocols section, add actors to the list of types that may adopt protocols. Actors may also be added to the list of types in the first sentence in the Protocols Syntax subsection.
Also, in the second sentence in the first paragraph is the Generic Types subsection, add actors to the list of types that may be generic.
Also, reword the first sentence in the final paragraph of the Automatic Reference Counting introduction to: Reference counting applies only to instances of actors and classes.
Also, in the first sentence in the second paragraph in the Metatype Type subsection, add actors to the list of types whose names that may have .Type appended to access their metadata.