swiftlang / swift-book

The Swift Programming Language book
Apache License 2.0
1.72k stars 159 forks source link

Concurrency > Sendable Types — Clarify intro about non-sendable data #285

Open Diggory opened 6 months ago

Diggory commented 6 months ago

Location

https://docs.swift.org/swift-book/documentation/the-swift-programming-language/concurrency/#Sendable-Types

Description

The last sentence of the first para of the section about Sendable Types is (to me, an uninformed reader) confusingly written and could be ideally be clearer.

The text currently reads:

Some kinds of data can’t be shared between concurrency domains, because that data contains mutable state, but it doesn’t protect against overlapping access.

Perhaps it's just me, but that sentence is confusing. The first part is a negative statement (data cannot be shared) then there's a 'but', so I'm expecting an opposing clause, but instead there's another negative clause (doesn't protect.)

The 'but' is confusing. Should I be expecting the non-sharability to protect 'overlapping access'? (not sure what that term means either.)

Maybe I'm being dim, but I come out of reading that sentence with more questions...

Correction

I'm not sure what the docs should say here. Please clarify why these two concepts are related, and what 'overlapping access' means. Thanks!

Diggory commented 6 months ago

I see that 'overlapping access' is defined later in the book under the 'memory safety' section.

However, I still find the sentence confusing.

amartini51 commented 6 months ago

This sentence should avoid the phrase "overlapping access" — the meaning here isn't exactly the same as how Memory Safety later uses it. Here we mean access from different parts of the program that are running concurrently.

Diggory commented 6 months ago

So, would the following version of the sentence be more suitable?

Some kinds of data can’t be shared between concurrency domains, because that data contains mutable state, and is not protected against concurrent access.

amartini51 commented 6 months ago

I'm looking at the paragraph, and I wonder if we need this sentence at all. I think I wrote it to introduce the problem before showing the solution, but maybe it better for me to rewrite and remove this.

A paragraph later, we say essentially the same thing:

In contrast, some types aren’t safe to pass across concurrency domains.