-
Notifications
You must be signed in to change notification settings - Fork 605
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
Ensure unreachable branch is eliminated #2708
Conversation
4a89f42
to
678b2dd
Compare
unwrap_unchecked
to ensure unreachable branch is eliminated
Hmm, given that opt-level=s works, I feel this is like a compiler bug. https://godbolt.org/z/sPTdMo1Kd |
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.
Unless the performance gains are critical, I'd tend to err on keeping the safer version, and hoping that the compiler can be made smart enough eventually.
It seems that the |
678b2dd
to
adb5a5d
Compare
adb5a5d
to
1b85cac
Compare
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.
Thanks! The new approach looks good to me. (It is enough simple and has no unsafe code)
With #2704, I introduced two
unwrap()
calls inSelect::poll
, but I found that withopt-level=z
, the compiler won’t be able to optimize theseunwrap()
calls, so maybe changing them tounwrap_unchecked()
is a better idea? See https://godbolt.org/z/cef118zKe for comparison withopt-level=z
.Also, since
unwrap_unchecked()
is introduced in Rust 1.58.0, I have to implement this function manually.