Skip to content

Commit

Permalink
fix randomization problems by rearranging modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Xaeroxe committed Sep 15, 2022
1 parent df6583d commit ec2bf60
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 73 deletions.
2 changes: 1 addition & 1 deletion futures-macro/src/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ fn select_inner(input: TokenStream, random: bool) -> TokenStream {

let shuffle = if random {
quote! {
__futures_crate::async_await::shuffle(&mut __select_arr);
__futures_crate::shuffle(&mut __select_arr);
}
} else {
quote!()
Expand Down
2 changes: 1 addition & 1 deletion futures-macro/src/stream_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub(crate) fn stream_select(input: TokenStream) -> Result<TokenStream, syn::Erro
let mut any_pending = false;
{
let mut stream_array = [#(#field_idents.as_mut().map(|f| StreamEnum::#generic_idents(f)).unwrap_or(StreamEnum::None)),*];
__futures_crate::async_await::shuffle(&mut stream_array);
__futures_crate::shuffle(&mut stream_array);

for mut s in stream_array {
if let StreamEnum::None = s {
Expand Down
6 changes: 0 additions & 6 deletions futures-util/src/async_await/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ mod stream_select_mod;
#[cfg(feature = "async-await-macro")]
pub use self::stream_select_mod::*;

#[cfg(feature = "std")]
mod random;
#[allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/64762
#[cfg(feature = "std")]
pub use self::random::*;

#[doc(hidden)]
#[inline(always)]
pub fn assert_unpin<T: Unpin>(_: &T) {}
Expand Down
54 changes: 0 additions & 54 deletions futures-util/src/async_await/random.rs

This file was deleted.

14 changes: 8 additions & 6 deletions futures-util/src/future/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,14 @@ where
}

#[cfg(feature = "std")]
if crate::gen_index(2) == 0 {
poll_wrap!(a, b, Either::Left);
poll_wrap!(b, a, Either::Right);
} else {
poll_wrap!(b, a, Either::Right);
poll_wrap!(a, b, Either::Left);
{
if crate::gen_index(2) == 0 {
poll_wrap!(a, b, Either::Left);
poll_wrap!(b, a, Either::Right);
} else {
poll_wrap!(b, a, Either::Right);
poll_wrap!(a, b, Either::Left);
}
}

#[cfg(not(feature = "std"))]
Expand Down
4 changes: 3 additions & 1 deletion futures-util/src/future/select_ok.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ impl<Fut: TryFuture + Unpin> Future for SelectOk<Fut> {
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let Self { inner } = &mut *self;
#[cfg(feature = "std")]
crate::shuffle(inner);
{
crate::shuffle(inner);
}
// loop until we've either exhausted all errors, a success was hit, or nothing is ready
loop {
let item = inner.iter_mut().enumerate().find_map(|(i, f)| match f.try_poll_unpin(cx) {
Expand Down
10 changes: 6 additions & 4 deletions futures-util/src/future/try_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,12 @@ where
}

#[cfg(feature = "std")]
if crate::gen_index(2) == 0 {
poll_wrap!(a, b, Either::Left, Either::Right)
} else {
poll_wrap!(b, a, Either::Right, Either::Left)
{
if crate::gen_index(2) == 0 {
poll_wrap!(a, b, Either::Left, Either::Right)
} else {
poll_wrap!(b, a, Either::Right, Either::Left)
}
}

#[cfg(not(feature = "std"))]
Expand Down
6 changes: 6 additions & 0 deletions futures-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ mod async_await;
#[doc(hidden)]
pub use self::async_await::*;

#[cfg(feature = "std")]
mod random;
#[allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/64762
#[cfg(feature = "std")]
pub use self::random::*;

// Not public API.
#[cfg(feature = "async-await")]
#[doc(hidden)]
Expand Down

0 comments on commit ec2bf60

Please sign in to comment.