-
Notifications
You must be signed in to change notification settings - Fork 238
Replace objc with objc2?
#513
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
Conversation
|
Regarding compile-times, did a quick check, a clean build seems to be about the same (~14s) for A clean build of |
|
☔ The latest upstream changes (presumably #508) made this pull request unmergeable. Please resolve the merge conflicts. |
|
I looked a little at objc2 last night and think it's overall the right direction to be heading in. My opinion here is based on reviewing https://github.com/gfx-rs/wgpu/pull/2826/files and the need for gfx-rs/wgpu#2976. objc2 is definitely a lot more complex so I haven't had a chance to look at any details yet. |
|
I think there's a lot of potential in making things even more ergonomic, but I'll be experimenting with that in I'll try to write a bit more introductory text at some point, to make the differences between Also, at some point I'll probably submit a similar PR to this one to |
Using new objc-encode crate
Hey, macOS maintainer of
winithere!I've been working on a replacement for
objcfor around a year now, and am finally getting close to something I'm happy with, see repo, docs and reasons for fork.The selling point for your crates (
cocoaandcocoa-foundation) is... Honestly not as strong as I'd like, my improvements mostly benefit higher-level crates and users that try to make a safer API, and your crates don't really do safe. That said, there are reasons, and I think they are enough to outweigh the downsides. I'm opening this PR to get some thoughts on what it would take for you to make the switch, would love to get some feedback!Concrete improvements that directly benefit you:
"verify_message"feature (planning to enable it withdebug_assertions) now works, which is why we implementEncodefor a lot of types - this is great for catching bugs, see the first commit in this PR for a few issues I found using this.Objectstore anUnsafeCell- This enables interior mutability ofObject, meaning that if user code had a&Object, converted that to*mut Objectand sent a mutating message, this would not be immediate UB.&- Might not be sound to accessidbehind&ideven ifObjectcontainsUnsafeCell- A bit more theoretical, but every bit helps!boolinstead ofBOOL(done in follow-up PR)NSInteger/NSUIntegeris nowisize/usize(done in follow-up PR)msg_send!, hopefully new contributors will be less confused."unstable-static-sel"feature flag for now).Future improvements that could benefit you later on:
msg_send_id!. Examples: You have to manually callreleaseon the object gotten from+[NSWindow alloc]+initand-[NSMenuItem separatorItem]returns an autoreleased object that really needs to beretain'ed before use.derive(Encode, RefEncode)macro so we don't need to do it ourselves, which is error-prone. Not sure what you would think regarding the compile-time cost, so I went for defining a local helper macroimpl_Encodeinstead.objc2bindgensupport so that thecocoacrate doesn't have to be written manually any more.Downsides:
objcto help this along!objcit has still seen less real-world usage.Breaking changes (apart from the obvious "new crate, new types"):
Objectis no longerSendorSync, since it may be used to represent objects that aren't (likeNSAutoreleasePoolandNSLock).boolinstead ofBOOL(follow-up PR)NSInteger/NSUIntegeris nowisize/usize(follow-up PR)A lot of this is written assuming intimate knowledge of the existing
objccrate, happy to answer any questions you might have if something is unclear!EDIT: Have added static selectors now.
EDIT: Moved to #628.