File tree Expand file tree Collapse file tree 1 file changed +26
-3
lines changed Expand file tree Collapse file tree 1 file changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -734,11 +734,11 @@ First, let's add a mutable method to `Span`:
734
734
735
735
``` swift
736
736
extension Span {
737
- mutating func droppingPrefix (length : Int ) -> /* dependsOn(self) */ Span<T> {
738
- let result = Span (base : base, count : length)
737
+ mutating func removePrefix (length : Int ) -> /* dependsOn(self) */ Span<T> {
738
+ let prefix = Span (base : base, count : length)
739
739
self .base += length
740
740
self .count -= length
741
- return result
741
+ return prefix
742
742
}
743
743
}
744
744
```
@@ -807,6 +807,29 @@ do {
807
807
parse (span) // 🛑 Error: 'span' escapes the scope of 'a2'
808
808
```
809
809
810
+ #### Escapable properties in a nonescapable type
811
+
812
+ An escapable type inevitably contains nonescapable properties. In our ` Span ` example, the ` base ` pointer and ` count `
813
+ length are both escapable. Accessing an escapable property drops the dependence:
814
+
815
+ ``` swift
816
+ let pointer: UnsafePointer <T>
817
+ do {
818
+ let span = Span (unsafeBaseAddress : pointer, count : 1 )
819
+ pointer = span.base
820
+ }
821
+ _ = pointer // ✅ OK: pointer has no lifetime dependence
822
+ ```
823
+
824
+ Internal mutation of a nonescapable type does not create any new dependence and does not require any annotation:
825
+
826
+ ``` swift
827
+ mutating /* dependsOn(self: self) */ func skipPrefix (length : Int ) {
828
+ self .base += length // ✅ OK: assigns `base` to a copy of the temporary value
829
+ self .count -= length // ✅ OK: assigns `count` to a copy of the temporary value
830
+ }
831
+ ```
832
+
810
833
## Source compatibility
811
834
812
835
Everything discussed here is additive to the existing Swift grammar and type system.
You can’t perform that action at this time.
0 commit comments