Conversation
Owner
Author
|
|
Owner
Author
|
A bit unsure where autogenerated I'll need to dig up some good examples to see what would be nicest? |
This was referenced Apr 21, 2023
3e6d97f to
937ad35
Compare
Owner
Author
|
We still need to figure out how to handle |
937ad35 to
fb21bfb
Compare
edcae4d to
69cce30
Compare
69cce30 to
53e3cc4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Swift recently implemented a better concept of sendability, see
NS_SWIFT_SENDABLEandNS_SWIFT_UI_ACTORinFoundation/NSObjCRuntime.h.Using these attributes, we can automatically mark
NSError,NSDate,NSFileHandleand so onSend + Sync. (ThatNSLockand subclasses are marked sendable seems a bit like a bug? But it shouldn't matter much, since the methods on it isunsafeanyhow, and deallocation on other threads is definitely safe).More importantly, we can automatically mark subclasses of
NSResponder(NSView,NSWindow, ...) asMainThreadOnly.To finalize the safety of that, it would be nice to run an algorithm like this on every function/method:
(Note here the difference between
includes_ns_swift_ui_actorandis_ns_swift_ui_actor;includes_returns true forNSArray<NSView>orOption<NSView>, whileis_doesn't).So e.g.
NSView::new() -> Id<Self>would becomeNSView::new(_mtm: MainThreadMarker), whileNSWindow::view(&self) -> Id<NSView>would stay as-is.I checked if we could make
atomicattributes safe to access from any thread, and it turns out, we cannot, Swift still requires anawaitaround these, so we must as well (can be tested on https://online.swiftplayground.run/):If the property is marked
nonisolatedthough, then it is possible.