Skip to content

[PrintAsObjC] Use 'unsafe_unretained' to print 'unowned', not 'assign' #19167

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
Sep 10, 2018

Conversation

jrose-apple
Copy link
Contributor

@jrose-apple jrose-apple commented Sep 6, 2018

The ObjC generator previously preserved a subtle difference between unowned and unowned(unsafe) / Unmanaged by printing the former as assign and the latter as unsafe_unretained. Upstream Clang, however, has gotten a new warning to discourage the use of assign with reference-countable types at all. Since it was always a subtle distinction, just go with the new convention and print unsafe_unretained for unowned properties as well.

rdar://problem/44290715

@jrose-apple
Copy link
Contributor Author

@swift-ci Please test source compatibility

@jrose-apple
Copy link
Contributor Author

@swift-ci Please smoke test Linux

@jrose-apple
Copy link
Contributor Author

@swift-ci Please test macOS

// We treat "unowned" as "unsafe_unretained" (even though it's more like
// "safe_unretained") because we want people to think twice about
// allowing that object to disappear. "unowned(unsafe)" (and Unmanaged,
// handled below) really are "unsafe_unretained".
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this reasonably be turned into an exhaustive switch over reference storage kinds?

Copy link
Contributor

@rjmccall rjmccall left a comment

Choose a reason for hiding this comment

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

Comment aside, LGTM. I filed rdar://44290715 before I caught up on my code-review inbox and saw that you'd done work on this, though, sorry.

The ObjC generator previously preserved a subtle difference between
'unowned' and 'unowned(unsafe)' / Unmanaged by printing the former as
'assign' and the latter as 'unsafe_unretained'. Upstream Clang,
however, has gotten a new warning to discourage the use of 'assign'
with reference-countable types at all. Since it was always a subtle
distinction, just go with the new convention and print
'unsafe_unretained' for 'unowned' properties as well.

rdar://problem/44290715
Exhaustively switch over reference types, so that we'll know if any
new ones are added, and factor out a repeated check to see if
something's a retainable object type.

No functionality change.
@jrose-apple jrose-apple force-pushed the proper-property-properties branch from a0e711b to 340090c Compare September 10, 2018 21:33
@jrose-apple
Copy link
Contributor Author

Good suggestion, spotted another reasonable cleanup while I was doing that.

@swift-ci Please smoke test

@jrose-apple jrose-apple merged commit f680544 into swiftlang:master Sep 10, 2018
@jrose-apple jrose-apple deleted the proper-property-properties branch September 10, 2018 23:15
bob-wilson added a commit that referenced this pull request Feb 15, 2019
…type

The issue was fixed in #19167 so we
no longer need to disable this warning.
rdar://problem/47777548
bob-wilson added a commit that referenced this pull request Feb 15, 2019
…type

The issue was fixed in #19167 so we
no longer need to disable this warning.
rdar://problem/47777548
bob-wilson added a commit that referenced this pull request Feb 17, 2019
…type

The issue was fixed in #19167 so we
no longer need to disable this warning.
rdar://problem/47777548
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