swift-book icon indicating copy to clipboard operation
swift-book copied to clipboard

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

Open Diggory opened this issue 11 months ago • 4 comments

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 avatar Mar 10 '24 11:03 Diggory

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

However, I still find the sentence confusing.

Diggory avatar Mar 10 '24 13:03 Diggory

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.

amartini51 avatar Mar 12 '24 22:03 amartini51

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.

Diggory avatar Mar 13 '24 12:03 Diggory

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.

amartini51 avatar Mar 13 '24 16:03 amartini51