Skip to content

Commit 8f31749

Browse files
committed
Use "memory safety"; name the guarantees
Incorporates feedback from Félix Cloutier <fcloutier@apple.com>.
1 parent c202b31 commit 8f31749

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

TSPL.docc/LanguageGuide/TheBasics.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Type safety enables you to be clear about
3737
the types of values your code works with.
3838
If part of your code requires a `String`,
3939
type safety prevents you from passing it an `Int` by mistake.
40-
Data safety ensures that you work with valid data only,
40+
Memory safety ensures that you work with valid data only,
4141
not uninitialized memory or deinitialized objects,
4242
and ensures that you work with that data in safe ways ---
4343
even in programs that run multiple pieces of code at the same time.
@@ -1796,22 +1796,26 @@ if let definiteString = assumedString {
17961796
```
17971797
-->
17981798

1799-
## Data Safety
1799+
## Memory Safety
18001800

18011801
In addition to the checks that prevent type mismatches,
18021802
described above in <doc:TheBasics#Type-Safety-and-Type-Inference>,
18031803
Swift also protects code against working with invalid memory.
1804-
This protection is known as *data safety* or *memory safety*
1804+
This protection is known as *memory safety*
18051805
and includes the following requirements:
18061806

1807-
- Values are set before being read;
1808-
code doesn't interact with uninitialized regions of memory.
1809-
- Arrays and buffers are accessed only at valid indexes,
1810-
never out of bounds.
1807+
- Values are set before being read.
1808+
The protection against interacting with uninitialized regions of memory
1809+
is also known as *definite initialization*.
1810+
- Arrays and buffers are accessed only at valid indexes.
1811+
The protection against out-of-bounds access
1812+
is also known as *bounds safety*.
18111813
- Memory is accessed only during the value’s lifetime,
1812-
preventing use-after-free errors.
1813-
- Access to memory overlaps only in provably safe ways;
1814-
concurrent code doesn't create possible data races.
1814+
The protection against use-after-free errors
1815+
is also known as *lifetime safety*.
1816+
- Access to memory overlaps only in provably safe ways.
1817+
The protection against possible data races in concurrent code
1818+
is also known as *thread safety*.
18151819

18161820
If you've worked in languages that don't provide these guarantees,
18171821
you may be familiar with some of the errors and bugs
@@ -1820,7 +1824,7 @@ If you haven't encountered these issues, that's ok;
18201824
safe code in Swift avoids these problems.
18211825
For information about how Swift ensures you set initial values,
18221826
see <doc:Initialization>,
1823-
and for information about how Swift checks data safety in concurrent code,
1827+
and for information about how Swift checks memory safety in concurrent code,
18241828
see <doc:Concurrency>.
18251829

18261830
Sometimes you need to work outside of the bounds of safety ---

0 commit comments

Comments
 (0)