Skip to content
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

[SR-12477] Assignments to projected PropertyWrappers with overlapping mutations of the var itself are not considered a memory exclusivity violation #54917

Closed
swift-ci opened this issue Mar 31, 2020 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-12477
Radar rdar://problem/62201580
Original Reporter benpious (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate

Attachment: Download

Environment

Xcode 11.2.1

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: 93ad43f82fe1e8ac6327450662ceb78d

duplicates:

  • SR-12350 Projected PropertyWrappers don't trigger didSet when their wrappedValue is mutated

Issue Description:

As part of an attempt to work around SR-12350, I wrote code that amounts to
```
$myWrappedProperty.mutatingFunction {
// note: this function does not escape.
myWrappedProperty = someValue
}
```
My setter for the projection was the traditional { self = newValue }.

Initially, I expected myWrappedProperty to have a value of someValue after this code was run. In fact, however, it had a value of someValue while mutatingFunction is executing, then reverts to its original value. This is extremely confusing; especially because didSet is not run for the assignment of the projection.

To be fair, it seems to me that the compiler is actually following the letter of the law; post projection it is a different variable being mutated. But since the documentation also implies that a goal of memory exclusivity is to avoid situations where the programmer's intent is ambiguous, it seems reasonable to consider adding checks for this case.

Using _myProperty instead of $myProperty does produce a crash.

There are zero references to "wrapper" in the language reference page on memory exclusivity. I think that even if this is considered "working as intended" there should still be some documentation of how it behaves; ideally in the page for PropertyWrappers.

I've attached a sample file demonstrating the issue.

@beccadax
Copy link
Contributor

@swift-ci create

@DougGregor
Copy link
Member

This was a bug that was caused by SR-12350. Using a compiler where SR-12350 has been fixed, we get the expected memory exclusivity violation. We shouldn't need additional information about this in the language reference specifically, because property wrappers themselves are describe as a "desugaring" to something that will demonstrate the memory exclusivity violation.

@swift-ci
Copy link
Collaborator Author

Comment by Ben Pious (JIRA)

Agreed that there is no need to update the reference if this is a bug; the fix is how I would expect it to behave. My wording in the original bug report should have been "if this isn't a bug," not "even if this isn't a bug."

Thanks for looking at this.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.
Projects
None yet
Development

No branches or pull requests

3 participants