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-11249] Using @_effects(releasenone) is tricky with shadow protocols #53650

Open
Catfish-Man opened this issue Aug 2, 2019 · 3 comments
Open
Labels
improvement performance standard library Area: Standard library umbrella

Comments

@Catfish-Man
Copy link
Member

Previous ID SR-11249
Radar rdar://problem/53845980
Original Reporter @Catfish-Man
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Improvement, Performance
Assignee None
Priority Medium

md5: 7a6b9d196fddd63e3fcebbb14fcad133

relates to:

  • SR-11268 Builtins for objc_msgSend/objc_msgSend_super

Issue Description:

The standard library has a trick it uses where it declares an @objc protocol with some selectors, and then unsafeBitCasts things to it to get swiftc to generate objc_msgSends without having to link the libraries that declare those methods.

This works great up until you attempt to get ARC to stop defensively retaining the receiver:

* Putting @_effects(releasenone) on the function that does the bit cast doesn't work because the bit cast loses the object identity

* Putting @_effects(releasenone) on the protocol doesn't work, presumably because protocols don't support that

* Putting @_effects(releasenone) on a second "thunk" function that takes the protocol type does work, and is what I'm doing in #26422 but is pretty clunky

Could we have a nicer way to do this? A few possible ideas, which I have no preference between:

* Could make @_effects work on protocol declarations

* Could teach ARC that unsafeBitCasting from a reference type to an @objc protocol type maintains object identity and maintains @_effects relevant to that identity

* Could provide a builtin or something for calling objc methods that the compiler doesn't statically know about, instead of unsafeBitCasting to a fake protocol

@Catfish-Man
Copy link
Member Author

@swift-ci create

@belkadan
Copy link
Contributor

belkadan commented Aug 2, 2019

In your case, _unsafeReferenceCast?

@Catfish-Man
Copy link
Member Author

I filed https://bugs.swift.org/browse/SR-11268 with an alternative request that would supersede this

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement performance standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

2 participants