From 293e2aa580e5695f179507500738a4c8fc65ad82 Mon Sep 17 00:00:00 2001 From: Haibo Huang Date: Fri, 17 Jul 2020 17:53:16 -0700 Subject: Upgrade rust/crates/bytes to 0.5.6 Change-Id: Ib95c402dc50956f33008f634e79291a91157cc8d --- .cargo_vcs_info.json | 2 +- .github/workflows/ci.yml | 7 +++++-- CHANGELOG.md | 7 +++++++ Cargo.toml | 4 ++-- Cargo.toml.orig | 4 ++-- METADATA | 4 ++-- benches/buf.rs | 2 +- benches/bytes.rs | 2 +- benches/bytes_mut.rs | 2 +- ci/tsan | 24 ------------------------ ci/tsan.sh | 4 +--- src/bytes.rs | 2 +- src/bytes_mut.rs | 17 +++++++++++------ src/lib.rs | 9 ++------- tests/test_buf.rs | 2 +- tests/test_buf_mut.rs | 2 +- tests/test_bytes.rs | 18 +++++++++++++++++- tests/test_chain.rs | 2 +- tests/test_debug.rs | 2 +- tests/test_iter.rs | 2 +- tests/test_reader.rs | 2 +- tests/test_serde.rs | 2 +- tests/test_take.rs | 2 +- 23 files changed, 62 insertions(+), 62 deletions(-) delete mode 100644 ci/tsan diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index b532ea5..dd25c50 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,5 @@ { "git": { - "sha1": "008d3e508e2247dbfbf5a73918e2fe999a4e9158" + "sha1": "6fdb7391ce83dc71ccaeda6a54211ce723e5d9a5" } } diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 164ec13..8b99832 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,7 +66,8 @@ jobs: steps: - uses: actions/checkout@v2 - name: Install Rust - run: rustup update stable && rustup default stable + # --no-self-update is necessary because the windows environment cannot self-update rustup.exe. + run: rustup update stable --no-self-update && rustup default stable - name: Test run: . ci/test-stable.sh test @@ -120,7 +121,9 @@ jobs: - uses: actions/checkout@v2 - name: Install Rust run: rustup update nightly && rustup default nightly - - name: TSAN / MSAN + - name: Install rust-src + run: rustup component add rust-src + - name: ASAN / TSAN run: . ci/tsan.sh # Loom diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e6a032..1b821da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# 0.5.6 (July 13, 2020) + +- Improve `BytesMut` to reuse buffer when fully `advance`d. +- Mark `BytesMut::{as_mut, set_len}` with `#[inline]`. +- Relax synchronization when cloning in shared vtable of `Bytes`. +- Move `loom` to `dev-dependencies`. + # 0.5.5 (June 18, 2020) ### Added diff --git a/Cargo.toml b/Cargo.toml index 0f7775a..81a7224 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ [package] edition = "2018" name = "bytes" -version = "0.5.5" +version = "0.5.6" authors = ["Carl Lerche ", "Sean McArthur "] description = "Types and traits for working with bytes" documentation = "https://docs.rs/bytes" @@ -33,5 +33,5 @@ version = "1.0" [features] default = ["std"] std = [] -[target."cfg(loom)".dependencies.loom] +[target."cfg(loom)".dev-dependencies.loom] version = "0.3" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 69b7361..bcb8f17 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -6,7 +6,7 @@ name = "bytes" # - Update CHANGELOG.md. # - Update doc URL. # - Create "v0.5.x" git tag. -version = "0.5.5" +version = "0.5.6" license = "MIT" authors = [ "Carl Lerche ", @@ -30,5 +30,5 @@ serde = { version = "1.0.60", optional = true, default-features = false, feature [dev-dependencies] serde_test = "1.0" -[target.'cfg(loom)'.dependencies] +[target.'cfg(loom)'.dev-dependencies] loom = "0.3" diff --git a/METADATA b/METADATA index 2dd2690..6a8ca63 100644 --- a/METADATA +++ b/METADATA @@ -9,11 +9,11 @@ third_party { type: GIT value: "https://github.com/tokio-rs/bytes" } - version: "0.5.5" + version: "0.5.6" license_type: NOTICE last_upgrade_date { year: 2020 month: 7 - day: 10 + day: 17 } } diff --git a/benches/buf.rs b/benches/buf.rs index 8f14aec..77b0633 100644 --- a/benches/buf.rs +++ b/benches/buf.rs @@ -1,5 +1,5 @@ #![feature(test)] -#![deny(warnings, rust_2018_idioms)] +#![warn(rust_2018_idioms)] extern crate test; diff --git a/benches/bytes.rs b/benches/bytes.rs index 1741ba0..c5b8412 100644 --- a/benches/bytes.rs +++ b/benches/bytes.rs @@ -1,5 +1,5 @@ #![feature(test)] -#![deny(warnings, rust_2018_idioms)] +#![warn(rust_2018_idioms)] extern crate test; diff --git a/benches/bytes_mut.rs b/benches/bytes_mut.rs index 8e0226c..b069436 100644 --- a/benches/bytes_mut.rs +++ b/benches/bytes_mut.rs @@ -1,5 +1,5 @@ #![feature(test)] -#![deny(warnings, rust_2018_idioms)] +#![warn(rust_2018_idioms)] extern crate test; diff --git a/ci/tsan b/ci/tsan deleted file mode 100644 index e53f9b8..0000000 --- a/ci/tsan +++ /dev/null @@ -1,24 +0,0 @@ -# TSAN suppressions file for `bytes` - -# TSAN does not understand fences and `Arc::drop` is implemented using a fence. -# This causes many false positives. -race:Arc*drop -race:arc*Weak*drop - -# `std` mpsc is not used in any Bytes code base. This race is triggered by some -# rust runtime logic. -race:std*mpsc_queue - -# Some test runtime races. Allocation should be race free -race:alloc::alloc - -# Not sure why this is warning, but it is in the test harness and not the library. -race:TestEvent*clone -race:test::run_tests_console::*closure - -# Probably more fences in std. -race:__call_tls_dtors - -# This ignores a false positive caused by `thread::park()`/`thread::unpark()`. -# See: https://github.com/rust-lang/rust/pull/54806#issuecomment-436193353 -race:pthread_cond_destroy diff --git a/ci/tsan.sh b/ci/tsan.sh index 7e5b3be..ca520bd 100644 --- a/ci/tsan.sh +++ b/ci/tsan.sh @@ -2,9 +2,7 @@ set -ex -export RUST_TEST_THREADS=1 export ASAN_OPTIONS="detect_odr_violation=0 detect_leaks=0" -export TSAN_OPTIONS="suppressions=$(pwd)/ci/tsan" # Run address sanitizer RUSTFLAGS="-Z sanitizer=address" \ @@ -12,4 +10,4 @@ cargo test --target x86_64-unknown-linux-gnu --test test_bytes --test test_buf - # Run thread sanitizer RUSTFLAGS="-Z sanitizer=thread" \ -cargo test --target x86_64-unknown-linux-gnu --test test_bytes --test test_buf --test test_buf_mut +cargo -Zbuild-std test --target x86_64-unknown-linux-gnu --test test_bytes --test test_buf --test test_buf_mut diff --git a/src/bytes.rs b/src/bytes.rs index 08bc9b3..79a09f3 100644 --- a/src/bytes.rs +++ b/src/bytes.rs @@ -928,7 +928,7 @@ const KIND_VEC: usize = 0b1; const KIND_MASK: usize = 0b1; unsafe fn shared_clone(data: &AtomicPtr<()>, ptr: *const u8, len: usize) -> Bytes { - let shared = data.load(Ordering::Acquire); + let shared = data.load(Ordering::Relaxed); shallow_clone_arc(shared as _, ptr, len) } diff --git a/src/bytes_mut.rs b/src/bytes_mut.rs index 4d0585e..a7a8e57 100644 --- a/src/bytes_mut.rs +++ b/src/bytes_mut.rs @@ -22,8 +22,12 @@ use crate::{Buf, BufMut, Bytes}; /// /// `BytesMut` represents a unique view into a potentially shared memory region. /// Given the uniqueness guarantee, owners of `BytesMut` handles are able to -/// mutate the memory. It is similar to a `Vec` but with less copies and -/// allocations. +/// mutate the memory. +/// +/// `BytesMut` can be thought of as containing a `buf: Arc>`, an offset +/// into `buf`, a slice length, and a guarantee that no other `BytesMut` for the +/// same `buf` overlaps with its slice. That guarantee means that a write lock +/// is not required. /// /// # Growth /// @@ -475,6 +479,7 @@ impl BytesMut { /// /// assert_eq!(&b[..], b"hello world"); /// ``` + #[inline] pub unsafe fn set_len(&mut self, len: usize) { debug_assert!(len <= self.cap, "set_len out of bounds"); self.len = len; @@ -558,9 +563,8 @@ impl BytesMut { unsafe { let (off, prev) = self.get_vec_pos(); - // Only reuse space if we stand to gain at least capacity/2 - // bytes of space back - if off >= additional && off >= (self.cap / 2) { + // Only reuse space if we can satisfy the requested additional space. + if self.capacity() - self.len() + off >= additional { // There's space - reuse it // // Just move the pointer back to the start after copying @@ -1025,6 +1029,7 @@ impl Deref for BytesMut { } impl AsMut<[u8]> for BytesMut { + #[inline] fn as_mut(&mut self) -> &mut [u8] { self.as_slice_mut() } @@ -1495,7 +1500,7 @@ static SHARED_VTABLE: Vtable = Vtable { }; unsafe fn shared_v_clone(data: &AtomicPtr<()>, ptr: *const u8, len: usize) -> Bytes { - let shared = data.load(Ordering::Acquire) as *mut Shared; + let shared = data.load(Ordering::Relaxed) as *mut Shared; increment_shared(shared); let data = AtomicPtr::new(shared as _); diff --git a/src/lib.rs b/src/lib.rs index accbf71..e375c01 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,14 +1,9 @@ -#![deny( - warnings, - missing_docs, - missing_debug_implementations, - rust_2018_idioms -)] +#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)] #![doc(test( no_crate_inject, attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables)) ))] -#![doc(html_root_url = "https://docs.rs/bytes/0.5.5")] +#![doc(html_root_url = "https://docs.rs/bytes/0.5.6")] #![no_std] //! Provides abstractions for working with bytes. diff --git a/tests/test_buf.rs b/tests/test_buf.rs index 26b95ae..17bdd54 100644 --- a/tests/test_buf.rs +++ b/tests/test_buf.rs @@ -1,4 +1,4 @@ -#![deny(warnings, rust_2018_idioms)] +#![warn(rust_2018_idioms)] use bytes::Buf; #[cfg(feature = "std")] diff --git a/tests/test_buf_mut.rs b/tests/test_buf_mut.rs index c70e209..b91e2e5 100644 --- a/tests/test_buf_mut.rs +++ b/tests/test_buf_mut.rs @@ -1,4 +1,4 @@ -#![deny(warnings, rust_2018_idioms)] +#![warn(rust_2018_idioms)] #[cfg(feature = "std")] use bytes::buf::IoSliceMut; diff --git a/tests/test_bytes.rs b/tests/test_bytes.rs index 106fa6f..6b106a6 100644 --- a/tests/test_bytes.rs +++ b/tests/test_bytes.rs @@ -1,4 +1,4 @@ -#![deny(warnings, rust_2018_idioms)] +#![warn(rust_2018_idioms)] use bytes::{Buf, BufMut, Bytes, BytesMut}; @@ -929,6 +929,22 @@ fn bytes_buf_mut_advance() { } } +#[test] +fn bytes_buf_mut_reuse_when_fully_consumed() { + use bytes::{Buf, BytesMut}; + let mut buf = BytesMut::new(); + buf.reserve(8192); + buf.extend_from_slice(&[0u8; 100][..]); + + let p = &buf[0] as *const u8; + buf.advance(100); + + buf.reserve(8192); + buf.extend_from_slice(b" "); + + assert_eq!(&buf[0] as *const u8, p); +} + #[test] #[should_panic] fn bytes_reserve_overflow() { diff --git a/tests/test_chain.rs b/tests/test_chain.rs index 82de7fc..6dbc45d 100644 --- a/tests/test_chain.rs +++ b/tests/test_chain.rs @@ -1,4 +1,4 @@ -#![deny(warnings, rust_2018_idioms)] +#![warn(rust_2018_idioms)] use bytes::buf::{BufExt, BufMutExt}; use bytes::{Buf, BufMut, Bytes}; diff --git a/tests/test_debug.rs b/tests/test_debug.rs index 7528bac..08d2f25 100644 --- a/tests/test_debug.rs +++ b/tests/test_debug.rs @@ -1,4 +1,4 @@ -#![deny(warnings, rust_2018_idioms)] +#![warn(rust_2018_idioms)] use bytes::Bytes; diff --git a/tests/test_iter.rs b/tests/test_iter.rs index 2302a69..a5bfddd 100644 --- a/tests/test_iter.rs +++ b/tests/test_iter.rs @@ -1,4 +1,4 @@ -#![deny(warnings, rust_2018_idioms)] +#![warn(rust_2018_idioms)] use bytes::Bytes; diff --git a/tests/test_reader.rs b/tests/test_reader.rs index b5da2c9..10b480f 100644 --- a/tests/test_reader.rs +++ b/tests/test_reader.rs @@ -1,4 +1,4 @@ -#![deny(warnings, rust_2018_idioms)] +#![warn(rust_2018_idioms)] #![cfg(feature = "std")] use std::io::{BufRead, Read}; diff --git a/tests/test_serde.rs b/tests/test_serde.rs index 36b87f2..cf4aeff 100644 --- a/tests/test_serde.rs +++ b/tests/test_serde.rs @@ -1,5 +1,5 @@ #![cfg(feature = "serde")] -#![deny(warnings, rust_2018_idioms)] +#![warn(rust_2018_idioms)] use serde_test::{assert_tokens, Token}; diff --git a/tests/test_take.rs b/tests/test_take.rs index b9b525b..0afb28b 100644 --- a/tests/test_take.rs +++ b/tests/test_take.rs @@ -1,4 +1,4 @@ -#![deny(warnings, rust_2018_idioms)] +#![warn(rust_2018_idioms)] use bytes::buf::{Buf, BufExt}; -- cgit v1.2.3