Skip to content

[Concurrency] Split up the non-Sendable diagnostics and improve wording. #75687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 6, 2024

Conversation

hborla
Copy link
Member

@hborla hborla commented Aug 5, 2024

This change splits up the Sendable diagnostics for parameters, results, and property types. The old mega-diagnostic was difficult for me to piece together based on the various diagnostic arguments. Separate diagnostics makes it a bit easier to visualize what the resulting diagnostic will say for a given set of arguments.

The wording of the error message now puts the problem -- crossing an isolation boundary -- at the center of the message instead of at the end, and attempts to clarify how the value crosses an isolation boundary. E.g. for the witness diagnostics, the value crosses an isolation boundary when calling the witness through the protocol requirement in generic code. I also eliminated some of the jargon like "implicitly asynchronous" because I don't think it's insightful for understanding this particular set of diagnostics.

For example:

class NotSendable {}

protocol P {
  func f(_: NotSendable) async
}

actor A: P {
  func f(_: NotSendable) {}
}

Currently, the compiler produces the following error:

 7 | actor A: P {
 8 |   func f(_: NotSendable) {}
   |        `- error: non-sendable type 'NotSendable' in parameter of the protocol requirement satisfied by actor-isolated instance method 'f' cannot cross actor boundary
 9 | }
10 | 

The above error is not ideal for 2 reasons:

  1. The problem -- the fact that the value crosses an isolation boundary -- is at the very end of the message
  2. It's not clear how an isolation boundary is crossed

With this change, the following error is produced:

 7 | actor A: P {
 8 |   func f(_: NotSendable) {}
   |        `- error: non-sendable parameter type 'NotSendable' cannot be sent from caller of protocol requirement 'f' into actor-isolated implementation
 9 | }
10 | 

This change (hopefully) clarifies that the problem occurs when you call the method through the nonisolated protocol requirement, because an isolation boundary is crossed when calling through to the underlying actor-isolated implementation.

This change does not add any additional information to the diagnostics, but it'd be valuable to show both the source and destination isolation.

Resolves: rdar://133215909

wording.

Splitting up the diagnostic into separate diagnostics based on the reference
kind is easier for me to read. The wording of the error message now puts
the problem -- crossing an isolation boundary -- at the center of the message,
and attempts to clarify how the value crosses an isolation boundary. E.g. for
the witness diagnostics, the value crosses an isolation boundary when calling
the witness through the protocol requirement in generic code.

This change does not add any additional information to the diagnostics, but it'd
be valuable to show both the source and destination isolation.
@hborla hborla force-pushed the sendable-param-diagnostics branch from 95fb0f0 to 933f8eb Compare August 5, 2024 15:23
@hborla hborla changed the title [Concurrency] Split up the non-Sendable argument diagnostics and improve wording. [Concurrency] Split up the non-Sendable diagnostics and improve wording. Aug 5, 2024
@hborla hborla marked this pull request as ready for review August 5, 2024 22:04
@hborla
Copy link
Member Author

hborla commented Aug 5, 2024

@swift-ci please smoke test

@hborla hborla requested a review from kavon as a code owner August 5, 2024 23:28
@hborla
Copy link
Member Author

hborla commented Aug 5, 2024

@swift-ci please smoke test

@hborla hborla force-pushed the sendable-param-diagnostics branch from 6d1c756 to 7dbec84 Compare August 6, 2024 00:26
@hborla
Copy link
Member Author

hborla commented Aug 6, 2024

@swift-ci please smoke test

Copy link
Contributor

@ktoso ktoso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good improvement, the case remains pretty confusing but this is better than before :)

@hborla
Copy link
Member Author

hborla commented Aug 6, 2024

the case remains pretty confusing but this is better than before :)

Yeah agreed, I find the protocol witness and overriding cases particularly hard to explain in a one-line diagnostic. I suppose I should write educational notes for all of these!

@hborla hborla merged commit 9319102 into swiftlang:main Aug 6, 2024
3 checks passed
@hborla hborla deleted the sendable-param-diagnostics branch August 6, 2024 04:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants