@@ -1660,7 +1660,7 @@ extension Person: Equatable {
1660
1660
You can opt out of this inference for a global-actor-isolated type
1661
1661
by explicitly declaring that a protocol conformance is nonisolated.
1662
1662
The following code example declares
1663
- a nonisolated isolated conformance to ` Equatable ` in an extension:
1663
+ a nonisolated conformance to ` Equatable ` in an extension:
1664
1664
1665
1665
``` swift
1666
1666
@MainActor
@@ -1690,10 +1690,10 @@ A conformance requirement to `Sendable` allows generic code to send parameter
1690
1690
values to concurrently-executing code. If generic code accepts non-` Sendable `
1691
1691
types, then the generic code can only use the input values from the current
1692
1692
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
1694
1694
actor that the conformance is isolated to. The following code has a protocol
1695
1695
` 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
1697
1697
task and a concurrent task:
1698
1698
1699
1699
``` swift
@@ -1732,11 +1732,12 @@ from a concurrent task results in an error,
1732
1732
because it would allow calling the main actor isolated implementation
1733
1733
of ` P.perform ` from outside the main actor.
1734
1734
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
1736
1737
through dynamic casting.
1737
1738
The following code has a protocol ` P ` ,
1738
1739
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:
1740
1741
1741
1742
``` swift
1742
1743
protocol P {
@@ -1754,11 +1755,13 @@ Isolated conformances are only safe to use
1754
1755
when the code is running on the global actor
1755
1756
that the conformance is isolated to,
1756
1757
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 `
1759
1760
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:
1762
1765
1763
1766
``` swift
1764
1767
@MainActor class C : @MainActor P {
@@ -1790,14 +1793,15 @@ so the dynamic cast fails and `perform` is not called.
1790
1793
1791
1794
Protocol requirements can be used
1792
1795
through instances of conforming types and through
1793
- instances of the conforming types themselves
1796
+ instances of the conforming types themselves,
1794
1797
called * metatype values* .
1795
1798
In generic code,
1796
1799
a conformance requirement to ` Sendable ` or ` SendableMetatype `
1797
1800
tells Swift that an instance or metatype value is safe to use concurrently.
1798
1801
To prevent isolated conformances from being used outside of their actor,
1799
1802
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
1801
1805
to ` Sendable ` or ` SendableMetatype ` .
1802
1806
1803
1807
A conformance requirement to ` Sendable ` indicates
@@ -1815,7 +1819,7 @@ func performConcurrently<T: P>(_ t: T) where T: Sendable {
1815
1819
}
1816
1820
```
1817
1821
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,
1819
1823
because the implementation of ` perform `
1820
1824
may access global actor isolated state.
1821
1825
To prevent data races,
@@ -1833,7 +1837,8 @@ The above code results in an error
1833
1837
because the conformance of ` C ` to ` P ` is main-actor isolated,
1834
1838
which can't satisfy the ` Sendable ` requirement of ` performConcurrently ` .
1835
1839
1836
- Protocol requirements can also be called through metatype values.
1840
+ Static and initializer protocol requirements
1841
+ can also be called through metatype values.
1837
1842
A conformance to Sendable on the metatype type,
1838
1843
such as ` Int.Type ` ,
1839
1844
indicates that a metatype value is safe
0 commit comments