Skip to content

macOS/iOS: Fix auto trait impls of EventLoopProxy#1084

Merged
goddessfreya merged 6 commits intorust-windowing:masterfrom
yvt:patch-unsafe-proxy
Aug 9, 2019
Merged

macOS/iOS: Fix auto trait impls of EventLoopProxy#1084
goddessfreya merged 6 commits intorust-windowing:masterfrom
yvt:patch-unsafe-proxy

Conversation

@yvt
Copy link
Copy Markdown
Contributor

@yvt yvt commented Aug 1, 2019

This pull request fixes EventLoopProxy<T>'s auto trait implementations.

  • EventLoopProxy<T>: Send only if T: Send, because otherwise it would allow sending unsendable objects.
  • EventLoopProxy<T>: !Sync because of std::sync::mpsc::Sender used under the hood. This restriction is congruent with other platforms' EventLoopProxy.

  • Tested on all platforms changed
    • macOS
    • iOS — No experience with running Rust code on iOS whatsoever, can someone please test this?
  • Compilation warnings were addressed
  • cargo fmt has been run on this branch
  • Added an entry to CHANGELOG.md if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality
  • Updated feature matrix, if new features were added or implemented

`EventLoopProxy<T>` allows sending `T` from an arbitrary thread that
owns the proxy object. Thus, if `T` is `!Send`, `EventLoopProxy<T>` must
not be allowed to leave the main thread.

`EventLoopProxy<T>` uses `std::sync::mpsc::Sender` under the hood,
meaning the `!Sync` restriction of it also applies to
`EventLoopProxy<T>`. That is, even if `T` is thread-safe, a single
`EventLoopProxy` object cannot be shared between threads.
@mtak-
Copy link
Copy Markdown
Contributor

mtak- commented Aug 1, 2019

Nice catch! This breaks our build (for good reasons), but unfortunately there's no great workaround because the Clone impl on EventLoopProxy requires T: Clone. Would be great to get that fixed as well - even if it's only for the macos/ios backends.

@goddessfreya
Copy link
Copy Markdown
Contributor

Needs a changelog entry, then lgtm.

@yvt
Copy link
Copy Markdown
Contributor Author

yvt commented Aug 2, 2019

@mtak- Since EventLoopProxy wraps each platform's implementation, other platforms had to be updated as well (otherwise they'll break), so I opened a separate PR: #1086

@yvt
Copy link
Copy Markdown
Contributor Author

yvt commented Aug 4, 2019

Added a changelog entry.

@mtak-
Copy link
Copy Markdown
Contributor

mtak- commented Aug 5, 2019

Thanks!

@goddessfreya goddessfreya merged commit 31ada5a into rust-windowing:master Aug 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants