Skip to content
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

Rollup of 6 pull requests #113505

Closed
wants to merge 64 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
05503b3
Correct the Android stat struct definitions
chriswailes Jun 20, 2023
ccb3328
Bashy Mc Bashface
oli-obk Jun 29, 2023
2039e7c
Checking for a cached value without having a cache is useless
oli-obk Jun 29, 2023
d061edd
Auto merge of #2947 - oli-obk:gha_mk_pr, r=RalfJung
bors Jun 29, 2023
db76154
add codegen-test: wasm-exceptions
mirkootter Jul 1, 2023
65aeac6
add assembly-test: wasm-exceptions
mirkootter Jul 1, 2023
6144130
test-various: update nodejs to 18.12 (LTS)
mirkootter Jul 1, 2023
211946c
add run-make test for wasm-exceptions
mirkootter Jul 1, 2023
a0bd381
test-various: run codegen and assembly tests
mirkootter Jul 1, 2023
5fa7403
cronjob auto-PR: make sure we are on a branch
RalfJung Jul 2, 2023
9e49f53
Auto merge of #2948 - RalfJung:cron, r=RalfJung
bors Jul 2, 2023
04db677
cronjob auto-PR: fetch more of the history
RalfJung Jul 2, 2023
7adf8dd
CI cleanup
RalfJung Jul 2, 2023
918f393
Auto merge of #2949 - RalfJung:cron, r=RalfJung
bors Jul 2, 2023
cc4670f
cargo-miri: better error message when RUSTC is not set
icewind1991 Jul 2, 2023
f2ce230
cron auto-PR: need to set upstream branch
RalfJung Jul 2, 2023
a6eb25a
Auto merge of #2951 - rust-lang:cron, r=RalfJung
bors Jul 2, 2023
7d12d2f
Auto merge of #2950 - icewind1991:cargo-miri-rustc-error, r=RalfJung
bors Jul 2, 2023
32168b7
cronjob auto-PR: try to fix setting the remote branch
RalfJung Jul 2, 2023
0bf13a4
Auto merge of #2952 - RalfJung:cron, r=RalfJung
bors Jul 2, 2023
2c5e076
sadly 'gh' doesnt support all git upstream branch configs
RalfJung Jul 2, 2023
f037471
Auto merge of #2953 - RalfJung:cron, r=RalfJung
bors Jul 2, 2023
4c7fbf8
more CI yml cleanup
RalfJung Jul 2, 2023
352180b
can't seem to avoid repeating the branch name...
RalfJung Jul 2, 2023
7d63d70
Auto merge of #2954 - RalfJung:cron, r=RalfJung
bors Jul 2, 2023
17e17e1
Preparing for merge from rustc
Jul 3, 2023
1505dd8
Merge from rustc
Jul 3, 2023
707afc3
fmt
Jul 3, 2023
6a21b2d
Silence clippy on FIXME'd code and fix the new lints otherwise
oli-obk Jul 3, 2023
a8b6ec1
Auto merge of #2955 - rust-lang:rustup2023-07-03, r=oli-obk
bors Jul 3, 2023
46c1e61
send link to PR to Zulip
RalfJung Jul 3, 2023
4951d5f
remove outdated comment
RalfJung Jul 3, 2023
a68afa2
vec tets: ensure pointer is still writeable
RalfJung Jul 3, 2023
89c2596
Auto merge of #2959 - RalfJung:vectest, r=RalfJung
bors Jul 3, 2023
2b3fae1
Auto merge of #2957 - RalfJung:zulip, r=oli-obk
bors Jul 4, 2023
812f9b2
better error on missing #[start]
RalfJung Jul 4, 2023
da98baa
Restore test filtering by substring.
oli-obk Jul 4, 2023
8fa4894
Auto merge of #2963 - RalfJung:start, r=RalfJung
bors Jul 4, 2023
7591c51
Auto merge of #2960 - oli-obk:run_filter, r=oli-obk
bors Jul 4, 2023
a4b7e14
C "memcpy" shim: ensure the pointers are valid
RalfJung Jul 5, 2023
a811ada
Ignore test on apple
oli-obk Jul 6, 2023
c8b3992
Auto merge of #2968 - RalfJung:memcpy, r=RalfJung
bors Jul 6, 2023
822feaa
Stop parsing ui_test annotations in `run-dep` mode
oli-obk Jul 6, 2023
a5286fc
Preparing for merge from rustc
Jul 7, 2023
b13a9fa
Merge from rustc
Jul 7, 2023
536c910
fmt
Jul 7, 2023
fa6cf3f
Auto merge of #2970 - rust-lang:rustup2023-07-07, r=oli-obk
bors Jul 7, 2023
813b56b
Silence all the boilerplate around `./miri run` and `./miri run-dep`
oli-obk Jul 7, 2023
48fe0df
Remove a now-useless flag
oli-obk Jul 7, 2023
c6f5b5f
MIRIFLAGS are already passed in the `./miri` wrapper
oli-obk Jul 7, 2023
2323ecb
Auto merge of #2969 - oli-obk:run-dep, r=RalfJung
bors Jul 7, 2023
a088e79
Remove `default_free_fn` feature
JohnTitor Jul 8, 2023
2c3cf5a
Preparing for merge from rustc
Jul 8, 2023
c182669
Merge from rustc
Jul 8, 2023
dfe0d21
Auto merge of #2971 - rust-lang:rustup2023-07-08, r=RalfJung
bors Jul 8, 2023
9ed4669
update lockfile
RalfJung Jul 8, 2023
6f8ba51
additional io::copy specializations
the8472 Jul 8, 2023
92b5d0c
Use String or Int to set the opt level
Rustin170506 Jul 3, 2023
7087164
Rollup merge of #113130 - chriswailes:android-library-defs, r=thomcc
matthiaskrgr Jul 9, 2023
1fcbe52
Rollup merge of #113247 - mirkootter:test-wasm-exceptions-nostd, r=Ma…
matthiaskrgr Jul 9, 2023
733611d
Rollup merge of #113273 - hi-rustin:rustin-patch-opt-level, r=Kobzol
matthiaskrgr Jul 9, 2023
28ed0ec
Rollup merge of #113469 - JohnTitor:rm-default-free-fn, r=Amanieu
matthiaskrgr Jul 9, 2023
80a0bdd
Rollup merge of #113488 - RalfJung:miri, r=RalfJung
matthiaskrgr Jul 9, 2023
1fce13a
Rollup merge of #113493 - the8472:spec-iocopy-slice, r=Mark-Simulacrum
matthiaskrgr Jul 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 79 additions & 2 deletions library/std/src/io/copy.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use super::{BorrowedBuf, BufReader, BufWriter, ErrorKind, Read, Result, Write, DEFAULT_BUF_SIZE};
use crate::alloc::Allocator;
use crate::cmp;
use crate::collections::VecDeque;
use crate::io::IoSlice;
use crate::mem::MaybeUninit;

#[cfg(test)]
Expand Down Expand Up @@ -86,7 +90,7 @@ where

/// Specialization of the read-write loop that reuses the internal
/// buffer of a BufReader. If there's no buffer then the writer side
/// should be used intead.
/// should be used instead.
trait BufferedReaderSpec {
fn buffer_size(&self) -> usize;

Expand All @@ -104,7 +108,39 @@ where
}

default fn copy_to(&mut self, _to: &mut (impl Write + ?Sized)) -> Result<u64> {
unimplemented!("only called from specializations");
unreachable!("only called from specializations")
}
}

impl BufferedReaderSpec for &[u8] {
fn buffer_size(&self) -> usize {
// prefer this specialization since the source "buffer" is all we'll ever need,
// even if it's small
usize::MAX
}

fn copy_to(&mut self, to: &mut (impl Write + ?Sized)) -> Result<u64> {
let len = self.len();
to.write_all(self)?;
*self = &self[len..];
Ok(len as u64)
}
}

impl<A: Allocator> BufferedReaderSpec for VecDeque<u8, A> {
fn buffer_size(&self) -> usize {
// prefer this specialization since the source "buffer" is all we'll ever need,
// even if it's small
usize::MAX
}

fn copy_to(&mut self, to: &mut (impl Write + ?Sized)) -> Result<u64> {
let len = self.len();
let (front, back) = self.as_slices();
let bufs = &mut [IoSlice::new(front), IoSlice::new(back)];
to.write_all_vectored(bufs)?;
self.clear();
Ok(len as u64)
}
}

Expand Down Expand Up @@ -218,6 +254,47 @@ impl<I: Write + ?Sized> BufferedWriterSpec for BufWriter<I> {
}
}

impl<A: Allocator> BufferedWriterSpec for Vec<u8, A> {
fn buffer_size(&self) -> usize {
cmp::max(DEFAULT_BUF_SIZE, self.capacity() - self.len())
}

fn copy_from<R: Read + ?Sized>(&mut self, reader: &mut R) -> Result<u64> {
let mut bytes = 0;

// avoid allocating before we have determined that there's anything to read
if self.capacity() == 0 {
bytes = stack_buffer_copy(&mut reader.take(DEFAULT_BUF_SIZE as u64), self)?;
if bytes == 0 {
return Ok(0);
}
}

loop {
self.reserve(DEFAULT_BUF_SIZE);
let mut buf: BorrowedBuf<'_> = self.spare_capacity_mut().into();
match reader.read_buf(buf.unfilled()) {
Ok(()) => {}
Err(e) if e.kind() == ErrorKind::Interrupted => continue,
Err(e) => return Err(e),
};

let read = buf.filled().len();
if read == 0 {
break;
}

// SAFETY: BorrowedBuf guarantees all of its filled bytes are init
// and the number of read bytes can't exceed the spare capacity since
// that's what the buffer is borrowing from.
unsafe { self.set_len(self.len() + read) };
bytes += read as u64;
}

Ok(bytes)
}
}

fn stack_buffer_copy<R: Read + ?Sized, W: Write + ?Sized>(
reader: &mut R,
writer: &mut W,
Expand Down
38 changes: 37 additions & 1 deletion library/std/src/io/copy/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::cmp::{max, min};
use crate::collections::VecDeque;
use crate::io;
use crate::io::*;

#[test]
Expand All @@ -19,7 +21,7 @@ struct ShortReader {

impl Read for ShortReader {
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
let bytes = min(self.cap, self.read_size);
let bytes = min(self.cap, self.read_size).min(buf.len());
self.cap -= bytes;
self.observed_buffer = max(self.observed_buffer, buf.len());
Ok(bytes)
Expand Down Expand Up @@ -78,6 +80,40 @@ fn copy_specializes_bufreader() {
);
}

#[test]
fn copy_specializes_to_vec() {
let cap = 123456;
let mut source = ShortReader { cap, observed_buffer: 0, read_size: 1337 };
let mut sink = Vec::new();
assert_eq!(cap as u64, io::copy(&mut source, &mut sink).unwrap());
assert!(
source.observed_buffer > DEFAULT_BUF_SIZE,
"expected a large buffer to be provided to the reader"
);
}

#[test]
fn copy_specializes_from_vecdeque() {
let mut source = VecDeque::with_capacity(100 * 1024);
for _ in 0..20 * 1024 {
source.push_front(0);
}
for _ in 0..20 * 1024 {
source.push_back(0);
}
let mut sink = WriteObserver { observed_buffer: 0 };
assert_eq!(40 * 1024u64, io::copy(&mut source, &mut sink).unwrap());
assert_eq!(20 * 1024, sink.observed_buffer);
}

#[test]
fn copy_specializes_from_slice() {
let mut source = [1; 60 * 1024].as_slice();
let mut sink = WriteObserver { observed_buffer: 0 };
assert_eq!(60 * 1024u64, io::copy(&mut source, &mut sink).unwrap());
assert_eq!(60 * 1024, sink.observed_buffer);
}

#[cfg(unix)]
mod io_benches {
use crate::fs::File;
Expand Down