Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into remove-race
Browse files Browse the repository at this point in the history
  • Loading branch information
Coder-256 committed Dec 20, 2024
2 parents 769c520 + 00283fb commit 2c34469
Show file tree
Hide file tree
Showing 40 changed files with 809 additions and 376 deletions.
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,18 @@ updates:
commit-message:
prefix: ''
labels: []
groups:
cargo:
patterns:
- '*'
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
commit-message:
prefix: ''
labels: []
groups:
github-actions:
patterns:
- '*'
22 changes: 16 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ jobs:
matrix:
# aarch64/x86_64 macOS and aarch64 Linux are tested on Cirrus CI
include:
- rust: '1.61'
- rust: '1.63'
os: ubuntu-latest
- rust: '1.61'
- rust: '1.63'
os: windows-latest
- rust: stable
os: ubuntu-latest
Expand All @@ -62,6 +62,10 @@ jobs:
- rust: nightly
os: ubuntu-latest
target: armv5te-unknown-linux-gnueabi
# Test target without stable inline asm support.
- rust: stable
os: ubuntu-latest
target: sparc64-unknown-linux-gnu
runs-on: ${{ matrix.os }}
timeout-minutes: 60
steps:
Expand Down Expand Up @@ -135,10 +139,10 @@ jobs:
if ! git diff --exit-code; then
git add .
git commit -m "Update no_atomic.rs"
echo "::set-output name=success::false"
echo 'success=false' >>"${GITHUB_OUTPUT}"
fi
if: github.repository_owner == 'crossbeam-rs' && github.event_name == 'schedule'
- uses: peter-evans/create-pull-request@v5
- uses: peter-evans/create-pull-request@v7
with:
title: Update no_atomic.rs
body: |
Expand Down Expand Up @@ -170,18 +174,24 @@ jobs:
- name: Install Rust
run: rustup update stable
- name: clippy
run: cargo clippy --all --tests --examples
run: cargo clippy --all --all-features --tests --examples

# Run miri.
miri:
strategy:
fail-fast: false
matrix:
group:
- channel
- others
runs-on: ubuntu-latest
timeout-minutes: 120 # TODO
steps:
- uses: taiki-e/checkout-action@v1
- name: Install Rust
run: rustup toolchain install nightly --component miri && rustup default nightly
- name: miri
run: ci/miri.sh
run: ci/miri.sh ${{ matrix.group }}

# Run cargo-careful.
careful:
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ crossbeam-channel = { version = "0.5.10", path = "crossbeam-channel", default-fe
crossbeam-deque = { version = "0.8.4", path = "crossbeam-deque", default-features = false, optional = true }
crossbeam-epoch = { version = "0.9.17", path = "crossbeam-epoch", default-features = false, optional = true }
crossbeam-queue = { version = "0.3.10", path = "crossbeam-queue", default-features = false, optional = true }
crossbeam-utils = { version = "0.8.18", path = "crossbeam-utils", default-features = false }
crossbeam-utils = { version = "0.8.18", path = "crossbeam-utils", default-features = false, features = ["atomic"] }

[dev-dependencies]
rand = "0.8"
Expand Down Expand Up @@ -72,4 +72,5 @@ unreachable_pub = "warn"
[workspace.lints.clippy]
# Suppress buggy or noisy clippy lints
declare_interior_mutable_const = { level = "allow", priority = 1 } # https://github.com/rust-lang/rust-clippy/issues/7665
incompatible_msrv = { level = "allow", priority = 1 } # buggy: doesn't consider cfg, https://github.com/rust-lang/rust-clippy/issues/12280, https://github.com/rust-lang/rust-clippy/issues/12257#issuecomment-2093667187
lint_groups_priority = { level = "allow", priority = 1 } # https://github.com/rust-lang/rust-clippy/issues/12920
5 changes: 4 additions & 1 deletion ci/check-features.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ cd "$(dirname "$0")"/..
# * `--no-dev-deps` - build without dev-dependencies to avoid https://github.com/rust-lang/cargo/issues/4866
# * `--exclude benchmarks` - benchmarks doesn't published.
if [[ "${RUST_VERSION}" == "msrv" ]]; then
cargo hack build --all --feature-powerset --no-dev-deps --exclude benchmarks --rust-version
cargo hack build --all --feature-powerset --no-dev-deps --exclude crossbeam-utils --exclude benchmarks --rust-version
# atomic feature requires Rust 1.60.
cargo hack build -p crossbeam-utils --feature-powerset --no-dev-deps --rust-version --exclude-features atomic
cargo +1.60 hack build -p crossbeam-utils --feature-powerset --no-dev-deps
else
cargo hack build --all --feature-powerset --no-dev-deps --exclude benchmarks
fi
Expand Down
62 changes: 36 additions & 26 deletions ci/miri.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,46 @@ set -euxo pipefail
IFS=$'\n\t'
cd "$(dirname "$0")"/..

group=$1

# We need 'ts' for the per-line timing
sudo apt-get -y install moreutils
echo

export RUSTFLAGS="${RUSTFLAGS:-} -Z randomize-layout"
export RUSTDOCFLAGS="${RUSTDOCFLAGS:-} -Z randomize-layout"
export MIRIFLAGS="${MIRIFLAGS:-} -Zmiri-strict-provenance -Zmiri-symbolic-alignment-check -Zmiri-disable-isolation"

MIRIFLAGS="-Zmiri-strict-provenance -Zmiri-symbolic-alignment-check -Zmiri-disable-isolation" \
MIRI_LEAK_CHECK='1' \
cargo miri test \
-p crossbeam-channel \
-p crossbeam-queue \
-p crossbeam-utils 2>&1 | ts -i '%.s '

# -Zmiri-ignore-leaks is needed because we use detached threads in tests in tests/golang.rs: https://github.com/rust-lang/miri/issues/1371
MIRIFLAGS="-Zmiri-strict-provenance -Zmiri-symbolic-alignment-check -Zmiri-disable-isolation -Zmiri-ignore-leaks" \
cargo miri test \
-p crossbeam-channel --test golang 2>&1 | ts -i '%.s '

# Use Tree Borrows instead of Stacked Borrows because epoch is not compatible with Stacked Borrows: https://github.com/crossbeam-rs/crossbeam/issues/545#issuecomment-1192785003
MIRIFLAGS="-Zmiri-strict-provenance -Zmiri-symbolic-alignment-check -Zmiri-disable-isolation -Zmiri-tree-borrows" \
cargo miri test \
-p crossbeam-epoch \
-p crossbeam-skiplist \
-p crossbeam 2>&1 | ts -i '%.s '

# Use Tree Borrows instead of Stacked Borrows because epoch is not compatible with Stacked Borrows: https://github.com/crossbeam-rs/crossbeam/issues/545#issuecomment-1192785003
# -Zmiri-compare-exchange-weak-failure-rate=0.0 is needed because some sequential tests (e.g.,
# doctest of Stealer::steal) incorrectly assume that sequential weak CAS will never fail.
# -Zmiri-preemption-rate=0 is needed because this code technically has UB and Miri catches that.
MIRIFLAGS="-Zmiri-strict-provenance -Zmiri-symbolic-alignment-check -Zmiri-disable-isolation -Zmiri-tree-borrows -Zmiri-compare-exchange-weak-failure-rate=0.0 -Zmiri-preemption-rate=0" \
cargo miri test \
-p crossbeam-deque 2>&1 | ts -i '%.s '
case "${group}" in
channel)
MIRI_LEAK_CHECK='1' \
cargo miri test --all-features \
-p crossbeam-channel 2>&1 | ts -i '%.s '
# -Zmiri-ignore-leaks is needed because we use detached threads in tests in tests/golang.rs: https://github.com/rust-lang/miri/issues/1371
MIRIFLAGS="${MIRIFLAGS} -Zmiri-ignore-leaks" \
cargo miri test --all-features \
-p crossbeam-channel --test golang 2>&1 | ts -i '%.s '
;;
others)
cargo miri test --all-features \
-p crossbeam-queue \
-p crossbeam-utils 2>&1 | ts -i '%.s '
# Use Tree Borrows instead of Stacked Borrows because epoch is not compatible with Stacked Borrows: https://github.com/crossbeam-rs/crossbeam/issues/545#issuecomment-1192785003
MIRIFLAGS="${MIRIFLAGS} -Zmiri-tree-borrows" \
cargo miri test --all-features \
-p crossbeam-epoch \
-p crossbeam-skiplist \
-p crossbeam 2>&1 | ts -i '%.s '
# Use Tree Borrows instead of Stacked Borrows because epoch is not compatible with Stacked Borrows: https://github.com/crossbeam-rs/crossbeam/issues/545#issuecomment-1192785003
# -Zmiri-compare-exchange-weak-failure-rate=0.0 is needed because some sequential tests (e.g.,
# doctest of Stealer::steal) incorrectly assume that sequential weak CAS will never fail.
# -Zmiri-preemption-rate=0 is needed because this code technically has UB and Miri catches that.
MIRIFLAGS="${MIRIFLAGS} -Zmiri-tree-borrows -Zmiri-compare-exchange-weak-failure-rate=0.0 -Zmiri-preemption-rate=0" \
cargo miri test --all-features \
-p crossbeam-deque 2>&1 | ts -i '%.s '
;;
*)
echo "unknown crate group '${group}'"
exit 1
;;
esac
47 changes: 13 additions & 34 deletions ci/no_atomic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,24 @@ cd "$(dirname "$0")"/..
# Usage:
# ./ci/no_atomic.sh

file="no_atomic.rs"
file=no_atomic.rs

no_atomic=()
for target_spec in $(RUSTC_BOOTSTRAP=1 rustc +stable -Z unstable-options --print all-target-specs-json | jq -c '. | to_entries | .[]'); do
target=$(jq <<<"${target_spec}" -r '.key')
target_spec=$(jq <<<"${target_spec}" -c '.value')
res=$(jq <<<"${target_spec}" -r 'select(."atomic-cas" == false)')
[[ -z "${res}" ]] || no_atomic_cas+=("${target}")
max_atomic_width=$(jq <<<"${target_spec}" -r '."max-atomic-width"')
min_atomic_width=$(jq <<<"${target_spec}" -r '."min-atomic-width"')
case "${max_atomic_width}" in
# `"max-atomic-width" == 0` means that atomic is not supported at all.
# We do not have a cfg for targets with {8,16}-bit atomic only, so
# for now we treat them the same as targets that do not support atomic.
0) no_atomic+=("${target}") ;;
# It is not clear exactly what `"max-atomic-width" == null` means, but they
# actually seem to have the same max-atomic-width as the target-pointer-width.
# The targets currently included in this group are "mipsel-sony-psp",
# "thumbv4t-none-eabi", "thumbv6m-none-eabi", all of which are
# `"target-pointer-width" == "32"`, so assuming them `"max-atomic-width" == 32`
# for now.
null | 8 | 16 | 32 | 64 | 128) ;;
*) exit 1 ;;
esac
case "${min_atomic_width}" in
8 | null) ;;
*) no_atomic+=("${target}") ;;
esac
done
# `"max-atomic-width" == 0` means that atomic is not supported at all.
# We do not have a cfg for targets with {8,16}-bit atomic only, so
# for now we treat them the same as targets that do not support atomic.
# It is not clear exactly what `"max-atomic-width" == null` means, but they
# actually seem to have the same max-atomic-width as the target-pointer-width.
# The targets currently included in this group are "mipsel-sony-psp",
# "thumbv4t-none-eabi", "thumbv6m-none-eabi", all of which are
# `"target-pointer-width" == "32"`, so assuming them `"max-atomic-width" == 32`
# for now.
no_atomic=$(RUSTC_BOOTSTRAP=1 rustc +stable -Z unstable-options --print all-target-specs-json | jq -r '. | to_entries[] | select((.value."max-atomic-width" == 0) or (.value."min-atomic-width" and .value."min-atomic-width" != 8)) | " \"" + .key + "\","')

cat >"${file}" <<EOF
// This file is @generated by $(basename "$0").
// This file is @generated by ${0##*/}.
// It is not intended for manual editing.
const NO_ATOMIC: &[&str] = &[
EOF
for target in "${no_atomic[@]}"; do
echo " \"${target}\"," >>"${file}"
done
cat >>"${file}" <<EOF
${no_atomic}
];
EOF
7 changes: 4 additions & 3 deletions ci/san.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ rustup component add rust-src
# `--cfg crossbeam_sanitize`.
cargo clean
RUSTFLAGS="${RUSTFLAGS:-} -Z sanitizer=address --cfg crossbeam_sanitize" \
cargo test -Z build-std --all --release --target x86_64-unknown-linux-gnu --tests --exclude benchmarks -- --test-threads=1
cargo test -Z build-std --all --all-features --release --target x86_64-unknown-linux-gnu --tests --exclude benchmarks -- --test-threads=1

RUSTFLAGS="${RUSTFLAGS:-} -Z sanitizer=address --cfg crossbeam_sanitize" \
cargo run -Z build-std \
--all-features \
--release \
--target x86_64-unknown-linux-gnu \
--example sanitize \
Expand All @@ -27,10 +28,10 @@ RUSTFLAGS="${RUSTFLAGS:-} -Z sanitizer=address --cfg crossbeam_sanitize" \
# Run memory sanitizer
cargo clean
RUSTFLAGS="${RUSTFLAGS:-} -Z sanitizer=memory --cfg crossbeam_sanitize" \
cargo test -Z build-std --all --release --target x86_64-unknown-linux-gnu --tests --exclude benchmarks -- --test-threads=1
cargo test -Z build-std --all --all-features --release --target x86_64-unknown-linux-gnu --tests --exclude benchmarks -- --test-threads=1

# Run thread sanitizer
cargo clean
TSAN_OPTIONS="suppressions=$(pwd)/ci/tsan" \
RUSTFLAGS="${RUSTFLAGS:-} -Z sanitizer=thread --cfg crossbeam_sanitize" \
cargo test -Z build-std --all --release --target x86_64-unknown-linux-gnu --tests --exclude benchmarks -- --test-threads=1
cargo test -Z build-std --all --all-features --release --target x86_64-unknown-linux-gnu --tests --exclude benchmarks -- --test-threads=1
6 changes: 3 additions & 3 deletions ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ cd "$(dirname "$0")"/..

# shellcheck disable=SC2086
if [[ -n "${RUST_TARGET:-}" ]]; then
cargo test --all --target "$RUST_TARGET" --exclude benchmarks ${DOCTEST_XCOMPILE:-} -- --test-threads=1
cargo test --all --target "$RUST_TARGET" --exclude benchmarks --release ${DOCTEST_XCOMPILE:-} -- --test-threads=1
cargo test --all --all-features --target "$RUST_TARGET" --exclude benchmarks ${DOCTEST_XCOMPILE:-} -- --test-threads=1
cargo test --all --all-features --target "$RUST_TARGET" --exclude benchmarks --release ${DOCTEST_XCOMPILE:-} -- --test-threads=1

# For now, the non-host target only runs tests.
exit 0
Expand All @@ -18,5 +18,5 @@ cargo test --all --all-features --exclude benchmarks --release -- --test-threads

if [[ "$RUST_VERSION" == "nightly"* ]]; then
# Benchmarks are only checked on nightly because depending on unstable features.
cargo check --all --all-targets
cargo check --all --all-features --all-targets
fi
7 changes: 7 additions & 0 deletions crossbeam-channel/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Version 0.5.14

- Fix stack overflow when sending large value to unbounded channel. (#1146, #1147)
- Add `Select::new_biased` function. (#1150)
- Remove inefficient spinning. (#1154)
- Suppress buggy `clippy::zero_repeat_side_effects` lint in macro generated code. (#1123)

# Version 0.5.13

- Add `select_biased!` macro. (#1040)
Expand Down
4 changes: 2 additions & 2 deletions crossbeam-channel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name = "crossbeam-channel"
# - Update CHANGELOG.md
# - Update README.md (when increasing major or minor version)
# - Run './tools/publish.sh crossbeam-channel <version>'
version = "0.5.13"
version = "0.5.14"
edition = "2021"
rust-version = "1.60"
license = "MIT OR Apache-2.0"
Expand All @@ -24,7 +24,7 @@ default = ["std"]
std = ["crossbeam-utils/std"]

[dependencies]
crossbeam-utils = { version = "0.8.18", path = "../crossbeam-utils", default-features = false }
crossbeam-utils = { version = "0.8.18", path = "../crossbeam-utils", default-features = false, features = ["atomic"] }

[dev-dependencies]
num_cpus = "1.13.0"
Expand Down
15 changes: 0 additions & 15 deletions crossbeam-channel/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,6 @@ impl Context {
/// If the deadline is reached, `Selected::Aborted` will be selected.
#[inline]
pub fn wait_until(&self, deadline: Option<Instant>) -> Selected {
// Spin for a short time, waiting until an operation is selected.
let backoff = Backoff::new();
loop {
let sel = Selected::from(self.inner.select.load(Ordering::Acquire));
if sel != Selected::Waiting {
return sel;
}

if backoff.is_completed() {
break;
} else {
backoff.snooze();
}
}

loop {
// Check whether an operation has been selected.
let sel = Selected::from(self.inner.select.load(Ordering::Acquire));
Expand Down
Loading

0 comments on commit 2c34469

Please sign in to comment.