Skip to content

Commit d657461

Browse files
committed
Minor editorial changes.
1 parent 7fc52b1 commit d657461

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

TSPL.docc/LanguageGuide/Concurrency.md

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,7 +1660,7 @@ extension Person: Equatable {
16601660
You can opt out of this inference for a global-actor-isolated type
16611661
by explicitly declaring that a protocol conformance is nonisolated.
16621662
The following code example declares
1663-
a nonisolated isolated conformance to `Equatable` in an extension:
1663+
a nonisolated conformance to `Equatable` in an extension:
16641664

16651665
```swift
16661666
@MainActor
@@ -1690,10 +1690,10 @@ A conformance requirement to `Sendable` allows generic code to send parameter
16901690
values to concurrently-executing code. If generic code accepts non-`Sendable`
16911691
types, then the generic code can only use the input values from the current
16921692
isolation domain. These generic APIs can safely accept isolated conformances
1693-
and call protocol requirement as long as the caller is on the same global
1693+
and call protocol requirements as long as the caller is on the same global
16941694
actor that the conformance is isolated to. The following code has a protocol
16951695
`P`, a class `C` with a main-actor isolated conformance to `P`, and
1696-
call-sites to the `P.perform` requirement from a main-actor
1696+
calls to the `P.perform` requirement from a main-actor
16971697
task and a concurrent task:
16981698

16991699
```swift
@@ -1732,11 +1732,12 @@ from a concurrent task results in an error,
17321732
because it would allow calling the main actor isolated implementation
17331733
of `P.perform` from outside the main actor.
17341734

1735-
Generic code can check whether a value conforms to a protocol
1735+
Abstract code that uses type parameters and `any` types
1736+
can check whether a value conforms to a protocol
17361737
through dynamic casting.
17371738
The following code has a protocol `P`,
17381739
and a method `performIfP` that accepts a parameter of type `Any`
1739-
which is dynamic cast to `any P` in the function body:
1740+
which is dynamically cast to `any P` in the function body:
17401741

17411742
```swift
17421743
protocol P {
@@ -1754,11 +1755,13 @@ Isolated conformances are only safe to use
17541755
when the code is running on the global actor
17551756
that the conformance is isolated to,
17561757
so the dynamic cast only succeeds
1757-
if the dynamic cast occurs on the global actor.
1758-
If you declare a main-actor isolated conformance to `P`
1758+
if the dynamic cast occurs on that global actor.
1759+
For example, if you declare a main-actor isolated conformance to `P`
17591760
and call `performIfP` with an instance of the conforming type,
1760-
the dynamic cast will only succeed
1761-
when `performIfP` is called from the main actor:
1761+
the dynamic cast will succeed
1762+
when `performIfP` is called in a main actor task, and it
1763+
will fail when `performIfP` is called in a concurrent
1764+
task:
17621765

17631766
```swift
17641767
@MainActor class C: @MainActor P {
@@ -1790,14 +1793,15 @@ so the dynamic cast fails and `perform` is not called.
17901793

17911794
Protocol requirements can be used
17921795
through instances of conforming types and through
1793-
instances of the conforming types themselves
1796+
instances of the conforming types themselves,
17941797
called *metatype values*.
17951798
In generic code,
17961799
a conformance requirement to `Sendable` or `SendableMetatype`
17971800
tells Swift that an instance or metatype value is safe to use concurrently.
17981801
To prevent isolated conformances from being used outside of their actor,
17991802
a type with an isolated conformance
1800-
can't be used for a type that must also satisfy a conformance requirement
1803+
can't be used as the concrete generic argument for a type
1804+
parameter that requires a conformance
18011805
to `Sendable` or `SendableMetatype`.
18021806

18031807
A conformance requirement to `Sendable` indicates
@@ -1815,7 +1819,7 @@ func performConcurrently<T: P>(_ t: T) where T: Sendable {
18151819
}
18161820
```
18171821

1818-
The above code admits data races if the conformance to `P` is isolated,
1822+
The above code would admit data races if the conformance to `P` was isolated,
18191823
because the implementation of `perform`
18201824
may access global actor isolated state.
18211825
To prevent data races,
@@ -1833,7 +1837,8 @@ The above code results in an error
18331837
because the conformance of `C` to `P` is main-actor isolated,
18341838
which can't satisfy the `Sendable` requirement of `performConcurrently`.
18351839

1836-
Protocol requirements can also be called through metatype values.
1840+
Static and initializer protocol requirements
1841+
can also be called through metatype values.
18371842
A conformance to Sendable on the metatype type,
18381843
such as `Int.Type`,
18391844
indicates that a metatype value is safe

0 commit comments

Comments
 (0)