Skip to content

[Concurrency] Suggest adding a method, when mutating actor property cross isolation #75922

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 2 commits into from
Aug 22, 2024

Conversation

ktoso
Copy link
Contributor

@ktoso ktoso commented Aug 16, 2024

This comes as an idea from the Why do not actor-isolated properties support 'await' setter thread.

The note that

Actor-isolated property 'colorFill' can not be mutated from the main actor

Leads people to assume that this is somehow "broken" while they could add a metho to perform the mutation and move on.

A developer comments that:

So I just assumed that this meant that it was fundamentally wrong to
mutate this actor's properties from another actor, while all I actually
needed was... a 3 line setter.

resolves rdar://134041422

@ktoso ktoso force-pushed the wip-note-for-mutating-actor-properties branch from 9e30c7b to e0673c9 Compare August 16, 2024 11:39
return actorInstance.get<NominalTypeDecl *>();
}

NominalTypeDecl *ActorIsolation::getActorOrNullPtr() const {
Copy link
Contributor Author

@ktoso ktoso Aug 16, 2024

Choose a reason for hiding this comment

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

You added this one recently but it seems to be a copy paste of the other and it is not used so I removed it @gottesmm if we should keep it let me know.

return actorType
->getReferenceStorageReferent()->getAnyActor();
if (getKind() == GlobalActor) {
return getGlobalActor()->getAnyNominal();
Copy link
Contributor Author

@ktoso ktoso Aug 16, 2024

Choose a reason for hiding this comment

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

ActorIsolation::getActor() used to return garbage if it contained a GlobalActor before this fix.

We initialize the globalActor property but fall through to returning the actorInstance.get<NominalTypeDecl *>(); which is just some uninitialized memory for the global actor case.

This is fixed now, we properly handle both kinds of isolations the method claimed to support.

Just FYI @hborla


if (auto actor = isolation.getActor()) {
// TODO: isolation is printing without the type name for instance actors,
// it'd be nicer to print with type name and avoid this switch
Copy link
Contributor Author

@ktoso ktoso Aug 16, 2024

Choose a reason for hiding this comment

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

The ways the isolation is printed ended up not work with the sentence too well; we always want to offer the actor name, while actorIsolation printing did not print that for instance isolation, so for now this workaround (rather than fixing tons of tests)

@@ -2,7 +2,7 @@ public struct Globals {
public static let integerConstant = 0
public static var integerMutable = 0

public static nonisolated(unsafe) let nonisolatedUnsafeIntegerConstant = 0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this caused an un-necessary warning we're not testing for; removed the warning

…ross isolation

This comes as an idea from the [Why do not actor-isolated properties
support 'await'
setter](https://forums.swift.org/t/why-do-not-actor-isolated-properties-support-await-setter/73867/26) thread.

The note that
> Actor-isolated property 'colorFill' can not be mutated from the main actor

Leads people to assume that this is somehow "broken" while they could
add a metho to perform the mutation and move on.

A developer comments that:

> So I just assumed that this meant that it was fundamentally wrong to
> mutate this actor's properties from another actor, while all I actually
> needed was... a 3 line setter.
@ktoso ktoso force-pushed the wip-note-for-mutating-actor-properties branch from e0673c9 to 50d221a Compare August 16, 2024 11:44
@ktoso ktoso requested a review from gottesmm August 16, 2024 11:44
@ktoso
Copy link
Contributor Author

ktoso commented Aug 16, 2024

@swift-ci please smoke test

@ktoso ktoso added the concurrency Feature: umbrella label for concurrency language features label Aug 16, 2024
@ktoso
Copy link
Contributor Author

ktoso commented Aug 22, 2024

@swift-ci please smoke test

@ktoso ktoso merged commit 1861375 into swiftlang:main Aug 22, 2024
3 checks passed
@ktoso ktoso deleted the wip-note-for-mutating-actor-properties branch August 22, 2024 11:24
memberLoc,
diag::note_consider_method_for_isolated_property_mutation,
actor);
// } else if (isolation.getKind() == swift::ActorIsolation::GlobalActor) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Was the commented out code here and above meant to be left in? NominalTypeDecl *actorTy is also unused

andrurogerz pushed a commit to andrurogerz/swift that referenced this pull request Sep 3, 2024
andrurogerz pushed a commit to andrurogerz/swift that referenced this pull request Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
concurrency Feature: umbrella label for concurrency language features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants