-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Remove Select
structure; implement inline select!
macro
#17601
Conversation
The old `Select` structure was very inefficient and required the user to use unsafe code (and manually maintain a "this variable will never move" invariant). Searching through several popular repositories, the only instance I found of it being used was in servo --- to avoid the setup cost of putting `select!` in a loop, which would create a new `Select` on every iteration. This commit deletes the `Select` structure entirely and moves all of its code into the `select!` macro. The benefit of this is that there is no more need for allocations, no more need for unsafe code, and no setup costs (so servo can now use `select!` directly). This also changes the interface to select! to fix rust-lang#12902. Fixes rust-lang#12902. [breaking-change]
#[allow(unused_imports)] | ||
mod test { | ||
use std::prelude::*; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many of these tests are still valid and most likely appropriate to keep. Updating them may be as simple as changing the select! invocations to use the new syntax.
Great work, thanks! It's a bit of a shame we have to let the limitations of macros-by-example drive the syntactical changes but since the macro would probably still stay experimental, it's not a huge problem. For the record, have you considered using a procedural macro as a wrapper for the macro-by-example to keep the old syntax and have it work properly with the receiver being an arbitrary expression? |
Thanks @jakub-. Should I move the deleted tests to Regarding a procedural macro, it did cross my mind, but I've never written one (that I recall), and I don't think this would be an appropriate place for a first attempt :). |
Servo's usage of Select is actually a bit more complicated than you make out - http://mxr.mozilla.org/servo/source/components/script/script_task.rs#425 . In particular, we have conditional inclusion based on other variables now. |
I use the Select struct in one of my projects to select over a |
@lucidd That's correct, People on IRC are telling me that the select/io stuff is slated to be rewritten. So maybe this is too big a breaking change if we are just going to break again in the next month or two? @jdm Oops! I need to update my copy of servo then, that |
I will review this tomorrow. |
($($name:pat from $rx:expr => $code:expr),+) => { | ||
select!{ $($name from $rx using recv => $code),+ } | ||
}; | ||
($($name:pat from $rx:expr using $meth:ident => $code:expr),+) => ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally was somewhat wary of using syntax like this because it's pretty alien with respect to the rest of rust code. That being said it was unfortunate that $expr.$ident()
didn't quite work out as I expected.
I was under the impression that using
This is a bit of an interesting pro because none of the usage of the macro previously had any unsafe code, only when you used the
Out of curiosity, have you measured this? The only setup cost was designed to be maintenance of a simple linked list, which I wouldn't expect to have any lasting impact. I definitely agree that
It seems like #12902 is largely just about the macro rather than the |
After discussion with @alexcrichton on IRC, I have decided to close this. It is too much of a burden on |
Fix incorrect encoding of literals in the proc-macro-api on version 4 Quick follow up on rust-lang/rust-analyzer#17559 breaking things
The old
Select
structure was very inefficient and required the userto use unsafe code (and manually maintain a "this variable will never
move" invariant). Searching through several popular repositories, the
only instance I found of it being used was in servo --- to avoid the
setup cost of putting
select!
in a loop, which would create a newSelect
on every iteration.This commit deletes the
Select
structure entirely and moves all ofits code into the
select!
macro. The benefit of this is that thereis no more need for allocations, no more need for unsafe code, and
no setup costs (so servo can now use
select!
directly).This also changes the interface to select! to fix #12902.
Fixes #12902.
[breaking-change]