Skip to content

Commit

Permalink
Remove read-initializer feature
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Dec 18, 2021
1 parent 97ee8e6 commit b41761f
Show file tree
Hide file tree
Showing 16 changed files with 2 additions and 159 deletions.
1 change: 0 additions & 1 deletion futures-io/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ std = []
# These features are outside of the normal semver guarantees and require the
# `unstable` feature as an explicit opt-in to unstable API.
unstable = []
read-initializer = []

[dependencies]

Expand Down
45 changes: 0 additions & 45 deletions futures-io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
//! All items of this library are only available when the `std` feature of this
//! library is activated, and it is activated by default.
#![cfg_attr(all(feature = "read-initializer", feature = "std"), feature(read_initializer))]
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(missing_debug_implementations, missing_docs, rust_2018_idioms, unreachable_pub)]
// It cannot be included in the published code because this lints have false positives in the minimum required version.
Expand All @@ -22,9 +21,6 @@
))]
#![cfg_attr(docsrs, feature(doc_cfg))]

#[cfg(all(feature = "read-initializer", not(feature = "unstable")))]
compile_error!("The `read-initializer` feature requires the `unstable` feature as an explicit opt-in to unstable features");

#[cfg(feature = "std")]
mod if_std {
use std::io;
Expand All @@ -34,11 +30,6 @@ mod if_std {

// Re-export some types from `std::io` so that users don't have to deal
// with conflicts when `use`ing `futures::io` and `std::io`.
#[cfg(feature = "read-initializer")]
#[cfg_attr(docsrs, doc(cfg(feature = "read-initializer")))]
#[doc(no_inline)]
#[allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/57411
pub use io::Initializer;
#[allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/57411
#[doc(no_inline)]
pub use io::{Error, ErrorKind, IoSlice, IoSliceMut, Result, SeekFrom};
Expand All @@ -51,27 +42,6 @@ mod if_std {
/// for wakeup and return if data is not yet available, rather than blocking
/// the calling thread.
pub trait AsyncRead {
/// Determines if this `AsyncRead`er can work with buffers of
/// uninitialized memory.
///
/// The default implementation returns an initializer which will zero
/// buffers.
///
/// This method is only available when the `read-initializer` feature of this
/// library is activated.
///
/// # Safety
///
/// This method is `unsafe` because an `AsyncRead`er could otherwise
/// return a non-zeroing `Initializer` from another `AsyncRead` type
/// without an `unsafe` block.
#[cfg(feature = "read-initializer")]
#[cfg_attr(docsrs, doc(cfg(feature = "read-initializer")))]
#[inline]
unsafe fn initializer(&self) -> Initializer {
Initializer::zeroing()
}

/// Attempt to read from the `AsyncRead` into `buf`.
///
/// On success, returns `Poll::Ready(Ok(num_bytes_read))`.
Expand Down Expand Up @@ -329,11 +299,6 @@ mod if_std {

macro_rules! deref_async_read {
() => {
#[cfg(feature = "read-initializer")]
unsafe fn initializer(&self) -> Initializer {
(**self).initializer()
}

fn poll_read(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
Expand Down Expand Up @@ -365,11 +330,6 @@ mod if_std {
P: DerefMut + Unpin,
P::Target: AsyncRead,
{
#[cfg(feature = "read-initializer")]
unsafe fn initializer(&self) -> Initializer {
(**self).initializer()
}

fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
Expand All @@ -389,11 +349,6 @@ mod if_std {

macro_rules! delegate_async_read_to_stdio {
() => {
#[cfg(feature = "read-initializer")]
unsafe fn initializer(&self) -> Initializer {
io::Read::initializer(self)
}

fn poll_read(
mut self: Pin<&mut Self>,
_: &mut Context<'_>,
Expand Down
1 change: 0 additions & 1 deletion futures-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ channel = ["std", "futures-channel"]
# `unstable` feature as an explicit opt-in to unstable API.
unstable = ["futures-core/unstable", "futures-task/unstable"]
bilock = []
read-initializer = ["io", "futures-io/read-initializer", "futures-io/unstable"]
write-all-vectored = ["io"]

# These features are no longer used.
Expand Down
12 changes: 0 additions & 12 deletions futures-util/src/compat/compat01as03.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,6 @@ unsafe impl UnsafeNotify01 for NotifyWaker {
#[cfg_attr(docsrs, doc(cfg(feature = "io-compat")))]
mod io {
use super::*;
#[cfg(feature = "read-initializer")]
use futures_io::Initializer;
use futures_io::{AsyncRead as AsyncRead03, AsyncWrite as AsyncWrite03};
use std::io::Error;
use tokio_io::{AsyncRead as AsyncRead01, AsyncWrite as AsyncWrite01};
Expand Down Expand Up @@ -416,16 +414,6 @@ mod io {
impl<W: AsyncWrite01> AsyncWrite01CompatExt for W {}

impl<R: AsyncRead01> AsyncRead03 for Compat01As03<R> {
#[cfg(feature = "read-initializer")]
unsafe fn initializer(&self) -> Initializer {
// check if `prepare_uninitialized_buffer` needs zeroing
if self.inner.get_ref().prepare_uninitialized_buffer(&mut [1]) {
Initializer::zeroing()
} else {
Initializer::nop()
}
}

fn poll_read(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
Expand Down
12 changes: 1 addition & 11 deletions futures-util/src/compat/compat03as01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,17 +236,7 @@ mod io {
}
}

impl<R: AsyncRead03 + Unpin> AsyncRead01 for Compat<R> {
#[cfg(feature = "read-initializer")]
unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [u8]) -> bool {
let initializer = self.inner.initializer();
let does_init = initializer.should_initialize();
if does_init {
initializer.initialize(buf);
}
does_init
}
}
impl<R: AsyncRead03 + Unpin> AsyncRead01 for Compat<R> {}

impl<W: AsyncWrite03 + Unpin> std::io::Write for Compat<W> {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
Expand Down
10 changes: 0 additions & 10 deletions futures-util/src/future/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,6 @@ mod if_std {

use core::pin::Pin;
use core::task::{Context, Poll};
#[cfg(feature = "read-initializer")]
use futures_io::Initializer;
use futures_io::{
AsyncBufRead, AsyncRead, AsyncSeek, AsyncWrite, IoSlice, IoSliceMut, Result, SeekFrom,
};
Expand All @@ -195,14 +193,6 @@ mod if_std {
A: AsyncRead,
B: AsyncRead,
{
#[cfg(feature = "read-initializer")]
unsafe fn initializer(&self) -> Initializer {
match self {
Either::Left(x) => x.initializer(),
Either::Right(x) => x.initializer(),
}
}

fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
Expand Down
11 changes: 0 additions & 11 deletions futures-util/src/io/allow_std.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use futures_core::task::{Context, Poll};
#[cfg(feature = "read-initializer")]
use futures_io::Initializer;
use futures_io::{AsyncBufRead, AsyncRead, AsyncSeek, AsyncWrite, IoSlice, IoSliceMut, SeekFrom};
use std::pin::Pin;
use std::{fmt, io};
Expand Down Expand Up @@ -121,10 +119,6 @@ where
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
self.0.read_vectored(bufs)
}
#[cfg(feature = "read-initializer")]
unsafe fn initializer(&self) -> Initializer {
self.0.initializer()
}
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
self.0.read_to_end(buf)
}
Expand Down Expand Up @@ -155,11 +149,6 @@ where
) -> Poll<io::Result<usize>> {
Poll::Ready(Ok(try_with_interrupt!(self.0.read_vectored(bufs))))
}

#[cfg(feature = "read-initializer")]
unsafe fn initializer(&self) -> Initializer {
self.0.initializer()
}
}

impl<T> io::Seek for AllowStdIo<T>
Expand Down
8 changes: 0 additions & 8 deletions futures-util/src/io/buf_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use super::DEFAULT_BUF_SIZE;
use futures_core::future::Future;
use futures_core::ready;
use futures_core::task::{Context, Poll};
#[cfg(feature = "read-initializer")]
use futures_io::Initializer;
use futures_io::{AsyncBufRead, AsyncRead, AsyncSeek, AsyncWrite, IoSliceMut, SeekFrom};
use pin_project_lite::pin_project;
use std::io::{self, Read};
Expand Down Expand Up @@ -144,12 +142,6 @@ impl<R: AsyncRead> AsyncRead for BufReader<R> {
self.consume(nread);
Poll::Ready(Ok(nread))
}

// we can't skip unconditionally because of the large buffer case in read.
#[cfg(feature = "read-initializer")]
unsafe fn initializer(&self) -> Initializer {
self.inner.initializer()
}
}

impl<R: AsyncRead> AsyncBufRead for BufReader<R> {
Expand Down
12 changes: 0 additions & 12 deletions futures-util/src/io/chain.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use futures_core::ready;
use futures_core::task::{Context, Poll};
#[cfg(feature = "read-initializer")]
use futures_io::Initializer;
use futures_io::{AsyncBufRead, AsyncRead, IoSliceMut};
use pin_project_lite::pin_project;
use std::fmt;
Expand Down Expand Up @@ -111,16 +109,6 @@ where
}
this.second.poll_read_vectored(cx, bufs)
}

#[cfg(feature = "read-initializer")]
unsafe fn initializer(&self) -> Initializer {
let initializer = self.first.initializer();
if initializer.should_initialize() {
initializer
} else {
self.second.initializer()
}
}
}

impl<T, U> AsyncBufRead for Chain<T, U>
Expand Down
8 changes: 0 additions & 8 deletions futures-util/src/io/empty.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use futures_core::task::{Context, Poll};
#[cfg(feature = "read-initializer")]
use futures_io::Initializer;
use futures_io::{AsyncBufRead, AsyncRead};
use std::fmt;
use std::io;
Expand Down Expand Up @@ -43,12 +41,6 @@ impl AsyncRead for Empty {
) -> Poll<io::Result<usize>> {
Poll::Ready(Ok(0))
}

#[cfg(feature = "read-initializer")]
#[inline]
unsafe fn initializer(&self) -> Initializer {
Initializer::nop()
}
}

impl AsyncBufRead for Empty {
Expand Down
12 changes: 1 addition & 11 deletions futures-util/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ use std::{pin::Pin, ptr};
// Re-export some types from `std::io` so that users don't have to deal
// with conflicts when `use`ing `futures::io` and `std::io`.
#[doc(no_inline)]
#[cfg(feature = "read-initializer")]
#[cfg_attr(docsrs, doc(cfg(feature = "read-initializer")))]
pub use std::io::Initializer;
#[doc(no_inline)]
pub use std::io::{Error, ErrorKind, IoSlice, IoSliceMut, Result, SeekFrom};

pub use futures_io::{AsyncBufRead, AsyncRead, AsyncSeek, AsyncWrite};
Expand All @@ -40,15 +36,9 @@ const DEFAULT_BUF_SIZE: usize = 8 * 1024;

/// Initializes a buffer if necessary.
///
/// A buffer is always initialized if `read-initializer` feature is disabled.
/// A buffer is currently always initialized.
#[inline]
unsafe fn initialize<R: AsyncRead>(_reader: &R, buf: &mut [u8]) {
#[cfg(feature = "read-initializer")]
{
if !_reader.initializer().should_initialize() {
return;
}
}
ptr::write_bytes(buf.as_mut_ptr(), 0, buf.len())
}

Expand Down
8 changes: 0 additions & 8 deletions futures-util/src/io/repeat.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use futures_core::ready;
use futures_core::task::{Context, Poll};
#[cfg(feature = "read-initializer")]
use futures_io::Initializer;
use futures_io::{AsyncRead, IoSliceMut};
use std::fmt;
use std::io;
Expand Down Expand Up @@ -59,12 +57,6 @@ impl AsyncRead for Repeat {
}
Poll::Ready(Ok(nwritten))
}

#[cfg(feature = "read-initializer")]
#[inline]
unsafe fn initializer(&self) -> Initializer {
Initializer::nop()
}
}

impl fmt::Debug for Repeat {
Expand Down
7 changes: 0 additions & 7 deletions futures-util/src/io/take.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use futures_core::ready;
use futures_core::task::{Context, Poll};
#[cfg(feature = "read-initializer")]
use futures_io::Initializer;
use futures_io::{AsyncBufRead, AsyncRead};
use pin_project_lite::pin_project;
use std::pin::Pin;
Expand Down Expand Up @@ -100,11 +98,6 @@ impl<R: AsyncRead> AsyncRead for Take<R> {
*this.limit -= n as u64;
Poll::Ready(Ok(n))
}

#[cfg(feature = "read-initializer")]
unsafe fn initializer(&self) -> Initializer {
self.inner.initializer()
}
}

impl<R: AsyncBufRead> AsyncBufRead for Take<R> {
Expand Down
9 changes: 0 additions & 9 deletions futures-util/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Combinators and utilities for working with `Future`s, `Stream`s, `Sink`s,
//! and the `AsyncRead` and `AsyncWrite` traits.
#![cfg_attr(feature = "read-initializer", feature(read_initializer))]
#![cfg_attr(feature = "write-all-vectored", feature(io_slice_advance))]
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(
Expand All @@ -23,9 +22,6 @@
#[cfg(all(feature = "bilock", not(feature = "unstable")))]
compile_error!("The `bilock` feature requires the `unstable` feature as an explicit opt-in to unstable features");

#[cfg(all(feature = "read-initializer", not(feature = "unstable")))]
compile_error!("The `read-initializer` feature requires the `unstable` feature as an explicit opt-in to unstable features");

#[cfg(feature = "alloc")]
extern crate alloc;

Expand Down Expand Up @@ -148,11 +144,6 @@ macro_rules! delegate_async_write {
#[cfg(feature = "std")]
macro_rules! delegate_async_read {
($field:ident) => {
#[cfg(feature = "read-initializer")]
unsafe fn initializer(&self) -> $crate::io::Initializer {
self.$field.initializer()
}

fn poll_read(
self: core::pin::Pin<&mut Self>,
cx: &mut core::task::Context<'_>,
Expand Down
1 change: 0 additions & 1 deletion futures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ thread-pool = ["executor", "futures-executor/thread-pool"]
# `unstable` feature as an explicit opt-in to unstable API.
unstable = ["futures-core/unstable", "futures-task/unstable", "futures-channel/unstable", "futures-io/unstable", "futures-util/unstable"]
bilock = ["futures-util/bilock"]
read-initializer = ["futures-io/read-initializer", "futures-util/read-initializer"]
write-all-vectored = ["futures-util/write-all-vectored"]

# These features are no longer used.
Expand Down
Loading

0 comments on commit b41761f

Please sign in to comment.