diff -Nru rust-rayon-1.5.3/build.rs rust-rayon-1.6.1/build.rs --- rust-rayon-1.5.3/build.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/build.rs 1970-01-01 00:00:00.000000000 +0000 @@ -1,12 +0,0 @@ -fn main() { - let ac = autocfg::new(); - if ac.probe_expression("(0..10).step_by(2).rev()") { - autocfg::emit("has_step_by_rev"); - } - if ac.probe_expression("{ fn _foo() {} }") { - autocfg::emit("has_min_const_generics"); - } - if ac.probe_path("std::ops::ControlFlow") { - autocfg::emit("has_control_flow"); - } -} diff -Nru rust-rayon-1.5.3/Cargo.lock rust-rayon-1.6.1/Cargo.lock --- rust-rayon-1.5.3/Cargo.lock 1970-01-01 00:00:01.000000000 +0000 +++ rust-rayon-1.6.1/Cargo.lock 1970-01-01 00:00:00.000000000 +0000 @@ -1,290 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "crossbeam-channel" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cfg-if 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "crossbeam-deque" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cfg-if 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-epoch 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "autocfg 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "memoffset 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "scopeguard 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cfg-if 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "docopt" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.5.5 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.137 (registry+https://github.com/rust-lang/crates.io-index)", - "strsim 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "either" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "getrandom" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cfg-if 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.125 (registry+https://github.com/rust-lang/crates.io-index)", - "wasi 0.10.2+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.125 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "libc" -version = "0.2.125" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "memoffset" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "autocfg 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "num_cpus" -version = "1.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "hermit-abi 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.125 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "ppv-lite86" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "proc-macro2" -version = "1.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "unicode-xid 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "quote" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.125 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_chacha 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "ppv-lite86 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rand_core" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "getrandom 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rand_xorshift" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "rand_core 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rayon" -version = "1.5.3" -dependencies = [ - "autocfg 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-deque 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", - "docopt 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "either 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_xorshift 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rayon-core 1.9.3 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.137 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rayon-core" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "crossbeam-channel 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-deque 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.13.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "regex" -version = "1.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "regex-syntax 0.6.25 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "regex-syntax" -version = "0.6.25" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "serde" -version = "1.0.137" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "serde_derive 1.0.137 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "serde_derive" -version = "1.0.137" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.94 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "strsim" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "syn" -version = "1.0.94" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "unicode-xid" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" - - -[metadata] -"checksum autocfg 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" -"checksum cfg-if 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -"checksum crossbeam-channel 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5aaa7bd5fb665c6864b5f963dd9097905c54125909c7aa94c9e18507cdbe6c53" -"checksum crossbeam-deque 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" -"checksum crossbeam-epoch 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)" = "1145cf131a2c6ba0615079ab6a638f7e1973ac9c2634fcbeaaad6114246efe8c" -"checksum crossbeam-utils 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)" = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38" -"checksum docopt 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7f3f119846c823f9eafcf953a8f6ffb6ed69bf6240883261a7f13b634579a51f" -"checksum either 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" -"checksum getrandom 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad" -"checksum hermit-abi 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)" = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -"checksum libc 0.2.125 (registry+https://github.com/rust-lang/crates.io-index)" = "5916d2ae698f6de9bfb891ad7a8d65c09d232dc58cc4ac433c7da3b2fd84bc2b" -"checksum memoffset 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" -"checksum num_cpus 1.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" -"checksum ppv-lite86 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" -"checksum proc-macro2 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)" = "9027b48e9d4c9175fa2218adf3557f91c1137021739951d4932f5f8268ac48aa" -"checksum quote 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)" = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" -"checksum rand 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)" = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -"checksum rand_chacha 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -"checksum rand_core 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" -"checksum rand_xorshift 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" -"checksum rayon-core 1.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f" -"checksum regex 1.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1a11647b6b25ff05a515cb92c365cec08801e83423a235b51e231e1808747286" -"checksum regex-syntax 0.6.25 (registry+https://github.com/rust-lang/crates.io-index)" = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" -"checksum scopeguard 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" -"checksum serde 1.0.137 (registry+https://github.com/rust-lang/crates.io-index)" = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" -"checksum serde_derive 1.0.137 (registry+https://github.com/rust-lang/crates.io-index)" = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be" -"checksum strsim 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" -"checksum syn 1.0.94 (registry+https://github.com/rust-lang/crates.io-index)" = "a07e33e919ebcd69113d5be0e4d70c5707004ff45188910106854f38b960df4a" -"checksum unicode-xid 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" -"checksum wasi 0.10.2+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" diff -Nru rust-rayon-1.5.3/Cargo.toml rust-rayon-1.6.1/Cargo.toml --- rust-rayon-1.5.3/Cargo.toml 1970-01-01 00:00:01.000000000 +0000 +++ rust-rayon-1.6.1/Cargo.toml 1970-01-01 00:00:01.000000000 +0000 @@ -10,9 +10,10 @@ # See Cargo.toml.orig for the original contents. [package] -edition = "2018" +edition = "2021" +rust-version = "1.56" name = "rayon" -version = "1.5.3" +version = "1.6.1" authors = [ "Niko Matsakis ", "Josh Stone ", @@ -37,18 +38,12 @@ license = "MIT OR Apache-2.0" repository = "https://github.com/rayon-rs/rayon" -[dependencies.crossbeam-deque] -version = "0.8.1" - [dependencies.either] version = "1.0" default-features = false [dependencies.rayon-core] -version = "1.9.2" - -[dev-dependencies.docopt] -version = "1" +version = "1.10.0" [dev-dependencies.lazy_static] version = "1" @@ -58,10 +53,3 @@ [dev-dependencies.rand_xorshift] version = "0.3" - -[dev-dependencies.serde] -version = "1.0.85" -features = ["derive"] - -[build-dependencies.autocfg] -version = "1" diff -Nru rust-rayon-1.5.3/Cargo.toml.orig rust-rayon-1.6.1/Cargo.toml.orig --- rust-rayon-1.5.3/Cargo.toml.orig 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/Cargo.toml.orig 2006-07-24 01:21:28.000000000 +0000 @@ -1,11 +1,11 @@ [package] name = "rayon" -# Reminder to update html_rool_url in lib.rs when updating version -version = "1.5.3" +version = "1.6.1" authors = ["Niko Matsakis ", "Josh Stone "] description = "Simple work-stealing parallelism for Rust" -edition = "2018" +rust-version = "1.56" +edition = "2021" license = "MIT OR Apache-2.0" repository = "https://github.com/rayon-rs/rayon" documentation = "https://docs.rs/rayon/" @@ -19,8 +19,7 @@ exclude = ["ci"] [dependencies] -rayon-core = { version = "1.9.2", path = "rayon-core" } -crossbeam-deque = "0.8.1" +rayon-core = { version = "1.10.0", path = "rayon-core" } # This is a public dependency! [dependencies.either] @@ -28,14 +27,6 @@ default-features = false [dev-dependencies] -docopt = "1" lazy_static = "1" rand = "0.8" rand_xorshift = "0.3" - -[dev-dependencies.serde] -version = "1.0.85" -features = ["derive"] - -[build-dependencies] -autocfg = "1" diff -Nru rust-rayon-1.5.3/.cargo_vcs_info.json rust-rayon-1.6.1/.cargo_vcs_info.json --- rust-rayon-1.5.3/.cargo_vcs_info.json 1970-01-01 00:00:01.000000000 +0000 +++ rust-rayon-1.6.1/.cargo_vcs_info.json 1970-01-01 00:00:01.000000000 +0000 @@ -1,6 +1,6 @@ { "git": { - "sha1": "5b6adbbf5c6944ec42b54530820ee8c0ad0e35a9" + "sha1": "d5e18e34ae9ace4fe723ba280f254ef01d540a82" }, "path_in_vcs": "" } \ No newline at end of file diff -Nru rust-rayon-1.5.3/debian/cargo-checksum.json rust-rayon-1.6.1/debian/cargo-checksum.json --- rust-rayon-1.5.3/debian/cargo-checksum.json 2022-05-21 20:09:12.000000000 +0000 +++ rust-rayon-1.6.1/debian/cargo-checksum.json 2022-12-14 01:47:28.000000000 +0000 @@ -1 +1 @@ -{"package":"bd99e5772ead8baa5215278c9b15bf92087709e9c1b2d1f97cdb5a183c933a7d","files":{}} +{"package":"6db3a213adf02b3bcfd2d3846bb41cb22857d131789e01df434fb7e7bc0759b7","files":{}} diff -Nru rust-rayon-1.5.3/debian/changelog rust-rayon-1.6.1/debian/changelog --- rust-rayon-1.5.3/debian/changelog 2022-05-21 20:09:12.000000000 +0000 +++ rust-rayon-1.6.1/debian/changelog 2022-12-14 01:47:28.000000000 +0000 @@ -1,3 +1,10 @@ +rust-rayon (1.6.1-1) unstable; urgency=medium + + * Team upload. + * Package rayon 1.6.1 from crates.io using debcargo 2.6.0 (Closes: #1025946) + + -- Peter Michael Green Wed, 14 Dec 2022 01:47:28 +0000 + rust-rayon (1.5.3-1) unstable; urgency=medium * Team upload. diff -Nru rust-rayon-1.5.3/debian/control rust-rayon-1.6.1/debian/control --- rust-rayon-1.5.3/debian/control 2022-05-21 20:09:12.000000000 +0000 +++ rust-rayon-1.6.1/debian/control 2022-12-14 01:47:28.000000000 +0000 @@ -6,17 +6,16 @@ cargo:native , rustc:native , libstd-rust-dev , - librust-autocfg-1+default-dev , - librust-crossbeam-deque-0.8+default-dev (>= 0.8.1-~~) , librust-either-1-dev , - librust-rayon-core-1+default-dev (>= 1.9.2-~~) + librust-rayon-core-1+default-dev (>= 1.10.0-~~) Maintainer: Debian Rust Maintainers Uploaders: Wolfgang Silbermayr , kpcyrd -Standards-Version: 4.5.1 +Standards-Version: 4.6.1 Vcs-Git: https://salsa.debian.org/rust-team/debcargo-conf.git [src/rayon] Vcs-Browser: https://salsa.debian.org/rust-team/debcargo-conf/tree/master/src/rayon +X-Cargo-Crate: rayon Rules-Requires-Root: no Package: librust-rayon-dev @@ -24,18 +23,16 @@ Multi-Arch: same Depends: ${misc:Depends}, - librust-autocfg-1+default-dev, - librust-crossbeam-deque-0.8+default-dev (>= 0.8.1-~~), librust-either-1-dev, - librust-rayon-core-1+default-dev (>= 1.9.2-~~) + librust-rayon-core-1+default-dev (>= 1.10.0-~~) Provides: librust-rayon+default-dev (= ${binary:Version}), librust-rayon-1-dev (= ${binary:Version}), librust-rayon-1+default-dev (= ${binary:Version}), - librust-rayon-1.5-dev (= ${binary:Version}), - librust-rayon-1.5+default-dev (= ${binary:Version}), - librust-rayon-1.5.3-dev (= ${binary:Version}), - librust-rayon-1.5.3+default-dev (= ${binary:Version}) + librust-rayon-1.6-dev (= ${binary:Version}), + librust-rayon-1.6+default-dev (= ${binary:Version}), + librust-rayon-1.6.1-dev (= ${binary:Version}), + librust-rayon-1.6.1+default-dev (= ${binary:Version}) Description: Simple work-stealing parallelism for Rust - Rust source code This package contains the source for the Rust rayon crate, packaged by debcargo for use with cargo and dh-cargo. diff -Nru rust-rayon-1.5.3/debian/copyright.debcargo.hint rust-rayon-1.6.1/debian/copyright.debcargo.hint --- rust-rayon-1.5.3/debian/copyright.debcargo.hint 2022-05-21 20:09:12.000000000 +0000 +++ rust-rayon-1.6.1/debian/copyright.debcargo.hint 2022-12-14 01:47:28.000000000 +0000 @@ -16,7 +16,7 @@ be correct information so you should review and fix this before uploading to the archive. -Files: ./LICENSE-MIT +Files: LICENSE-MIT Copyright: 2010 The Rust Project Developers License: UNKNOWN-LICENSE; FIXME (overlay) Comment: diff -Nru rust-rayon-1.5.3/debian/tests/control rust-rayon-1.6.1/debian/tests/control --- rust-rayon-1.5.3/debian/tests/control 2022-05-21 20:09:12.000000000 +0000 +++ rust-rayon-1.6.1/debian/tests/control 2022-12-14 01:47:28.000000000 +0000 @@ -1,14 +1,14 @@ -Test-Command: /usr/share/cargo/bin/cargo-auto-test rayon 1.5.3 --all-targets --all-features +Test-Command: /usr/share/cargo/bin/cargo-auto-test rayon 1.6.1 --all-targets --all-features Features: test-name=rust-rayon:@ -Depends: dh-cargo (>= 18), librust-docopt-1+default-dev, librust-lazy-static-1+default-dev, librust-rand-0.8+default-dev, librust-rand-xorshift-0.3+default-dev, librust-serde-1+default-dev (>= 1.0.85-~~), librust-serde-1+derive-dev (>= 1.0.85-~~), @ +Depends: dh-cargo (>= 18), librust-lazy-static-1+default-dev, librust-rand-0.8+default-dev, librust-rand-xorshift-0.3+default-dev, @ Restrictions: allow-stderr, skip-not-installable -Test-Command: /usr/share/cargo/bin/cargo-auto-test rayon 1.5.3 --all-targets +Test-Command: /usr/share/cargo/bin/cargo-auto-test rayon 1.6.1 --all-targets Features: test-name=librust-rayon-dev:default -Depends: dh-cargo (>= 18), librust-docopt-1+default-dev, librust-lazy-static-1+default-dev, librust-rand-0.8+default-dev, librust-rand-xorshift-0.3+default-dev, librust-serde-1+default-dev (>= 1.0.85-~~), librust-serde-1+derive-dev (>= 1.0.85-~~), @ +Depends: dh-cargo (>= 18), librust-lazy-static-1+default-dev, librust-rand-0.8+default-dev, librust-rand-xorshift-0.3+default-dev, @ Restrictions: allow-stderr, skip-not-installable -Test-Command: /usr/share/cargo/bin/cargo-auto-test rayon 1.5.3 --all-targets --no-default-features +Test-Command: /usr/share/cargo/bin/cargo-auto-test rayon 1.6.1 --all-targets --no-default-features Features: test-name=librust-rayon-dev: -Depends: dh-cargo (>= 18), librust-docopt-1+default-dev, librust-lazy-static-1+default-dev, librust-rand-0.8+default-dev, librust-rand-xorshift-0.3+default-dev, librust-serde-1+default-dev (>= 1.0.85-~~), librust-serde-1+derive-dev (>= 1.0.85-~~), @ +Depends: dh-cargo (>= 18), librust-lazy-static-1+default-dev, librust-rand-0.8+default-dev, librust-rand-xorshift-0.3+default-dev, @ Restrictions: allow-stderr, skip-not-installable diff -Nru rust-rayon-1.5.3/examples/cpu_monitor.rs rust-rayon-1.6.1/examples/cpu_monitor.rs --- rust-rayon-1.5.3/examples/cpu_monitor.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/examples/cpu_monitor.rs 1970-01-01 00:00:00.000000000 +0000 @@ -1,81 +0,0 @@ -use docopt::Docopt; -use std::io; -use std::process; - -const USAGE: &str = " -Usage: cpu_monitor [options] - cpu_monitor --help - -A test for monitoring how much CPU usage Rayon consumes under various -scenarios. This test is intended to be executed interactively, like so: - - cargo run --example cpu_monitor -- tasks_ended - -The list of scenarios you can try are as follows: - -- tasks_ended: after all tasks have finished, go to sleep -- task_stall_root: a root task stalls for a very long time -- task_stall_scope: a task in a scope stalls for a very long time - -Options: - -h, --help Show this message. - -d N, --depth N Control how hard the dummy task works [default: 27] -"; - -#[derive(serde::Deserialize)] -pub struct Args { - arg_scenario: String, - flag_depth: usize, -} - -fn main() { - let args: &Args = &Docopt::new(USAGE) - .and_then(|d| d.deserialize()) - .unwrap_or_else(|e| e.exit()); - - match &args.arg_scenario[..] { - "tasks_ended" => tasks_ended(args), - "task_stall_root" => task_stall_root(args), - "task_stall_scope" => task_stall_scope(args), - _ => { - println!("unknown scenario: `{}`", args.arg_scenario); - println!("try --help"); - process::exit(1); - } - } -} - -fn wait_for_user() { - let mut input = String::new(); - io::stdin().read_line(&mut input).unwrap(); -} - -fn task(args: &Args) { - fn join_recursively(n: usize) { - if n == 0 { - return; - } - rayon::join(|| join_recursively(n - 1), || join_recursively(n - 1)); - } - - println!("Starting heavy work at depth {}...wait.", args.flag_depth); - join_recursively(args.flag_depth); - println!("Heavy work done; check top. You should see CPU usage drop to zero soon."); - println!("Press to quit..."); -} - -fn tasks_ended(args: &Args) { - task(args); - wait_for_user(); -} - -fn task_stall_root(args: &Args) { - rayon::join(|| task(args), wait_for_user); -} - -fn task_stall_scope(args: &Args) { - rayon::scope(|scope| { - scope.spawn(move |_| task(args)); - scope.spawn(move |_| wait_for_user()); - }); -} diff -Nru rust-rayon-1.5.3/examples/README.md rust-rayon-1.6.1/examples/README.md --- rust-rayon-1.5.3/examples/README.md 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/examples/README.md 1970-01-01 00:00:00.000000000 +0000 @@ -1,3 +0,0 @@ -We use this directory for interactive tests that can't be run in an -automatic fashion. For examples of how to use Rayon, or benchmarks, -see `rayon-demo`. diff -Nru rust-rayon-1.5.3/README.md rust-rayon-1.6.1/README.md --- rust-rayon-1.5.3/README.md 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/README.md 2006-07-24 01:21:28.000000000 +0000 @@ -2,7 +2,7 @@ [![Rayon crate](https://img.shields.io/crates/v/rayon.svg)](https://crates.io/crates/rayon) [![Rayon documentation](https://docs.rs/rayon/badge.svg)](https://docs.rs/rayon) -![minimum rustc 1.36](https://img.shields.io/badge/rustc-1.36+-red.svg) +![minimum rustc 1.56](https://img.shields.io/badge/rustc-1.56+-red.svg) [![build status](https://github.com/rayon-rs/rayon/workflows/master/badge.svg)](https://github.com/rayon-rs/rayon/actions) [![Join the chat at https://gitter.im/rayon-rs/Lobby](https://badges.gitter.im/rayon-rs/Lobby.svg)](https://gitter.im/rayon-rs/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) @@ -84,7 +84,7 @@ use rayon::prelude::*; ``` -Rayon currently requires `rustc 1.36.0` or greater. +Rayon currently requires `rustc 1.56.0` or greater. ### Usage with WebAssembly @@ -129,5 +129,5 @@ Rayon is distributed under the terms of both the MIT license and the Apache License (Version 2.0). See [LICENSE-APACHE](LICENSE-APACHE) and -[LICENSE-MIT](LICENSE-MIT) for details. Opening a pull requests is +[LICENSE-MIT](LICENSE-MIT) for details. Opening a pull request is assumed to signal agreement with these licensing terms. diff -Nru rust-rayon-1.5.3/RELEASES.md rust-rayon-1.6.1/RELEASES.md --- rust-rayon-1.5.3/RELEASES.md 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/RELEASES.md 2006-07-24 01:21:28.000000000 +0000 @@ -1,3 +1,48 @@ +# Release rayon 1.6.1 (2022-12-09) + +- Simplified `par_bridge` to only pull one item at a time from the iterator, + without batching. Threads that are waiting for iterator items will now block + appropriately rather than spinning CPU. (Thanks @njaard!) +- Added protection against recursion in `par_bridge`, so iterators that also + invoke rayon will not cause mutex recursion deadlocks. + +# Release rayon-core 1.10.1 (2022-11-18) + +- Fixed a race condition with threads going to sleep while a broadcast starts. + +# Release rayon 1.6.0 / rayon-core 1.10.0 (2022-11-18) + +- The minimum supported `rustc` is now 1.56. +- The new `IndexedParallelIterator::fold_chunks` and `fold_chunks_with` methods + work like `ParallelIterator::fold` and `fold_with` with fixed-size chunks of + items. This may be useful for predictable batching performance, without the + allocation overhead of `IndexedParallelIterator::chunks`. +- New "broadcast" methods run a given function on all threads in the pool. + These run at a sort of reduced priority after each thread has exhausted their + local work queue, but before they attempt work-stealing from other threads. + - The global `broadcast` function and `ThreadPool::broadcast` method will + block until completion, returning a `Vec` of all return values. + - The global `spawn_broadcast` function and methods on `ThreadPool`, `Scope`, + and `ScopeFifo` will run detached, without blocking the current thread. +- Panicking methods now use `#[track_caller]` to report the caller's location. +- Fixed a truncated length in `vec::Drain` when given an empty range. + +## Contributors + +Thanks to all of the contributors for this release! + +- @cuviper +- @idanmuze +- @JoeyBF +- @JustForFun88 +- @kianmeng +- @kornelski +- @ritchie46 +- @ryanrussell +- @steffahn +- @TheIronBorn +- @willcrozi + # Release rayon 1.5.3 (2022-05-13) - The new `ParallelSliceMut::par_sort_by_cached_key` is a stable sort that caches diff -Nru rust-rayon-1.5.3/src/array.rs rust-rayon-1.6.1/src/array.rs --- rust-rayon-1.5.3/src/array.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/array.rs 2006-07-24 01:21:28.000000000 +0000 @@ -1,11 +1,8 @@ -#![cfg(has_min_const_generics)] //! Parallel iterator types for [arrays] (`[T; N]`) //! //! You will rarely need to interact with this module directly unless you need //! to name one of the iterator types. //! -//! Everything in this module requires const generics, stabilized in Rust 1.51. -//! //! [arrays]: https://doc.rust-lang.org/std/primitive.array.html use crate::iter::plumbing::*; @@ -14,7 +11,6 @@ use crate::vec::DrainProducer; use std::mem::ManuallyDrop; -/// This implementation requires const generics, stabilized in Rust 1.51. impl<'data, T: Sync + 'data, const N: usize> IntoParallelIterator for &'data [T; N] { type Item = &'data T; type Iter = Iter<'data, T>; @@ -24,7 +20,6 @@ } } -/// This implementation requires const generics, stabilized in Rust 1.51. impl<'data, T: Send + 'data, const N: usize> IntoParallelIterator for &'data mut [T; N] { type Item = &'data mut T; type Iter = IterMut<'data, T>; @@ -34,7 +29,6 @@ } } -/// This implementation requires const generics, stabilized in Rust 1.51. impl IntoParallelIterator for [T; N] { type Item = T; type Iter = IntoIter; diff -Nru rust-rayon-1.5.3/src/collections/mod.rs rust-rayon-1.6.1/src/collections/mod.rs --- rust-rayon-1.5.3/src/collections/mod.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/collections/mod.rs 2006-07-24 01:21:28.000000000 +0000 @@ -56,7 +56,7 @@ pub(super) fn new(collection: &'a mut C) -> Self { Self { // Temporarily steal the inner `Vec` so we can drain in place. - vec: Vec::from(mem::replace(collection, C::default())), + vec: Vec::from(mem::take(collection)), collection, } } @@ -65,7 +65,7 @@ impl<'a, T, C: From>> Drop for DrainGuard<'a, T, C> { fn drop(&mut self) { // Restore the collection from the `Vec` with its original capacity. - *self.collection = C::from(mem::replace(&mut self.vec, Vec::new())); + *self.collection = C::from(mem::take(&mut self.vec)); } } diff -Nru rust-rayon-1.5.3/src/compile_fail/cannot_collect_filtermap_data.rs rust-rayon-1.6.1/src/compile_fail/cannot_collect_filtermap_data.rs --- rust-rayon-1.5.3/src/compile_fail/cannot_collect_filtermap_data.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/compile_fail/cannot_collect_filtermap_data.rs 2006-07-24 01:21:28.000000000 +0000 @@ -5,12 +5,10 @@ // zip requires data of exact size, but filter yields only bounded // size, so check that we cannot apply it. -fn main() { - let a: Vec = (0..1024).collect(); - let mut v = vec![]; - a.par_iter() - .filter_map(|&x| Some(x as f32)) - .collect_into_vec(&mut v); //~ ERROR no method -} +let a: Vec = (0..1024).collect(); +let mut v = vec![]; +a.par_iter() + .filter_map(|&x| Some(x as f32)) + .collect_into_vec(&mut v); //~ ERROR no method ``` */ diff -Nru rust-rayon-1.5.3/src/compile_fail/cannot_zip_filtered_data.rs rust-rayon-1.6.1/src/compile_fail/cannot_zip_filtered_data.rs --- rust-rayon-1.5.3/src/compile_fail/cannot_zip_filtered_data.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/compile_fail/cannot_zip_filtered_data.rs 2006-07-24 01:21:28.000000000 +0000 @@ -5,12 +5,10 @@ // zip requires data of exact size, but filter yields only bounded // size, so check that we cannot apply it. -fn main() { - let mut a: Vec = (0..1024).rev().collect(); - let b: Vec = (0..1024).collect(); +let mut a: Vec = (0..1024).rev().collect(); +let b: Vec = (0..1024).collect(); - a.par_iter() - .zip(b.par_iter().filter(|&&x| x > 3)); //~ ERROR -} +a.par_iter() + .zip(b.par_iter().filter(|&&x| x > 3)); //~ ERROR ``` */ diff -Nru rust-rayon-1.5.3/src/compile_fail/cell_par_iter.rs rust-rayon-1.6.1/src/compile_fail/cell_par_iter.rs --- rust-rayon-1.5.3/src/compile_fail/cell_par_iter.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/compile_fail/cell_par_iter.rs 2006-07-24 01:21:28.000000000 +0000 @@ -5,11 +5,9 @@ use rayon::prelude::*; use std::cell::Cell; -fn main() { - let c = Cell::new(42_i32); - (0_i32..1024).into_par_iter() - .map(|_| c.get()) //~ ERROR E0277 - .min(); -} +let c = Cell::new(42_i32); +(0_i32..1024).into_par_iter() + .map(|_| c.get()) //~ ERROR E0277 + .min(); ``` */ diff -Nru rust-rayon-1.5.3/src/compile_fail/must_use.rs rust-rayon-1.6.1/src/compile_fail/must_use.rs --- rust-rayon-1.5.3/src/compile_fail/must_use.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/compile_fail/must_use.rs 2006-07-24 01:21:28.000000000 +0000 @@ -33,6 +33,8 @@ step_by /** v.par_iter().step_by(2); */ chain /** v.par_iter().chain(&v); */ chunks /** v.par_iter().chunks(2); */ + fold_chunks /** v.par_iter().fold_chunks(2, || 0, |x, _| x); */ + fold_chunks_with /** v.par_iter().fold_chunks_with(2, 0, |x, _| x); */ cloned /** v.par_iter().cloned(); */ copied /** v.par_iter().copied(); */ enumerate /** v.par_iter().enumerate(); */ diff -Nru rust-rayon-1.5.3/src/compile_fail/no_send_par_iter.rs rust-rayon-1.6.1/src/compile_fail/no_send_par_iter.rs --- rust-rayon-1.5.3/src/compile_fail/no_send_par_iter.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/compile_fail/no_send_par_iter.rs 2006-07-24 01:21:28.000000000 +0000 @@ -10,13 +10,11 @@ unsafe impl Sync for NoSend {} -fn main() { - let x = Some(NoSend(null())); +let x = Some(NoSend(null())); - x.par_iter() - .map(|&x| x) //~ ERROR - .count(); //~ ERROR -} +x.par_iter() + .map(|&x| x) //~ ERROR + .count(); //~ ERROR ``` */ mod map {} @@ -31,13 +29,11 @@ unsafe impl Sync for NoSend {} -fn main() { - let x = Some(NoSend(null())); +let x = Some(NoSend(null())); - x.par_iter() - .filter_map(|&x| Some(x)) //~ ERROR - .count(); //~ ERROR -} +x.par_iter() + .filter_map(|&x| Some(x)) //~ ERROR + .count(); //~ ERROR ``` */ mod filter_map {} @@ -52,13 +48,11 @@ unsafe impl Sync for NoSend {} -fn main() { - let x = Some(NoSend(null())); +let x = Some(NoSend(null())); - x.par_iter() - .cloned() //~ ERROR - .count(); //~ ERROR -} +x.par_iter() + .cloned() //~ ERROR + .count(); //~ ERROR ``` */ mod cloned {} diff -Nru rust-rayon-1.5.3/src/compile_fail/rc_par_iter.rs rust-rayon-1.6.1/src/compile_fail/rc_par_iter.rs --- rust-rayon-1.5.3/src/compile_fail/rc_par_iter.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/compile_fail/rc_par_iter.rs 2006-07-24 01:21:28.000000000 +0000 @@ -6,12 +6,10 @@ use rayon::prelude::*; use std::rc::Rc; -fn main() { - let x = vec![Rc::new(22), Rc::new(23)]; - let mut y = vec![]; - x.into_par_iter() //~ ERROR no method named `into_par_iter` - .map(|rc| *rc) - .collect_into_vec(&mut y); -} +let x = vec![Rc::new(22), Rc::new(23)]; +let mut y = vec![]; +x.into_par_iter() //~ ERROR no method named `into_par_iter` + .map(|rc| *rc) + .collect_into_vec(&mut y); ``` */ diff -Nru rust-rayon-1.5.3/src/iter/chunks.rs rust-rayon-1.6.1/src/iter/chunks.rs --- rust-rayon-1.5.3/src/iter/chunks.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/iter/chunks.rs 2006-07-24 01:21:28.000000000 +0000 @@ -90,38 +90,46 @@ where P: Producer, { - self.callback.callback(ChunkProducer { - chunk_size: self.size, - len: self.len, - base, - }) + let producer = ChunkProducer::new(self.size, self.len, base, Vec::from_iter); + self.callback.callback(producer) } } } } -struct ChunkProducer

-where - P: Producer, -{ +pub(super) struct ChunkProducer { chunk_size: usize, len: usize, base: P, + map: F, +} + +impl ChunkProducer { + pub(super) fn new(chunk_size: usize, len: usize, base: P, map: F) -> Self { + Self { + chunk_size, + len, + base, + map, + } + } } -impl

Producer for ChunkProducer

+impl Producer for ChunkProducer where P: Producer, + F: Fn(P::IntoIter) -> T + Send + Clone, { - type Item = Vec; - type IntoIter = ChunkSeq

; + type Item = T; + type IntoIter = std::iter::Map, F>; fn into_iter(self) -> Self::IntoIter { - ChunkSeq { + let chunks = ChunkSeq { chunk_size: self.chunk_size, len: self.len, inner: if self.len > 0 { Some(self.base) } else { None }, - } + }; + chunks.map(self.map) } fn split_at(self, index: usize) -> (Self, Self) { @@ -132,11 +140,13 @@ chunk_size: self.chunk_size, len: elem_index, base: left, + map: self.map.clone(), }, ChunkProducer { chunk_size: self.chunk_size, len: self.len - elem_index, base: right, + map: self.map, }, ) } @@ -150,7 +160,7 @@ } } -struct ChunkSeq

{ +pub(super) struct ChunkSeq

{ chunk_size: usize, len: usize, inner: Option

, @@ -160,7 +170,7 @@ where P: Producer, { - type Item = Vec; + type Item = P::IntoIter; fn next(&mut self) -> Option { let producer = self.inner.take()?; @@ -168,11 +178,11 @@ let (left, right) = producer.split_at(self.chunk_size); self.inner = Some(right); self.len -= self.chunk_size; - Some(left.into_iter().collect()) + Some(left.into_iter()) } else { debug_assert!(self.len > 0); self.len = 0; - Some(producer.into_iter().collect()) + Some(producer.into_iter()) } } @@ -206,11 +216,11 @@ let (left, right) = producer.split_at(self.len - size); self.inner = Some(left); self.len -= size; - Some(right.into_iter().collect()) + Some(right.into_iter()) } else { debug_assert!(self.len > 0); self.len = 0; - Some(producer.into_iter().collect()) + Some(producer.into_iter()) } } } diff -Nru rust-rayon-1.5.3/src/iter/filter_map.rs rust-rayon-1.6.1/src/iter/filter_map.rs --- rust-rayon-1.5.3/src/iter/filter_map.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/iter/filter_map.rs 2006-07-24 01:21:28.000000000 +0000 @@ -98,7 +98,7 @@ P: Fn(T) -> Option + Sync + 'p, { fn split_off_left(&self) -> Self { - FilterMapConsumer::new(self.base.split_off_left(), &self.filter_op) + FilterMapConsumer::new(self.base.split_off_left(), self.filter_op) } fn to_reducer(&self) -> Self::Reducer { diff -Nru rust-rayon-1.5.3/src/iter/filter.rs rust-rayon-1.6.1/src/iter/filter.rs --- rust-rayon-1.5.3/src/iter/filter.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/iter/filter.rs 2006-07-24 01:21:28.000000000 +0000 @@ -97,7 +97,7 @@ P: Fn(&T) -> bool + Sync, { fn split_off_left(&self) -> Self { - FilterConsumer::new(self.base.split_off_left(), &self.filter_op) + FilterConsumer::new(self.base.split_off_left(), self.filter_op) } fn to_reducer(&self) -> Self::Reducer { diff -Nru rust-rayon-1.5.3/src/iter/find.rs rust-rayon-1.6.1/src/iter/find.rs --- rust-rayon-1.5.3/src/iter/find.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/iter/find.rs 2006-07-24 01:21:28.000000000 +0000 @@ -94,7 +94,7 @@ self.item = iter .into_iter() // stop iterating if another thread has found something - .take_while(not_full(&self.found)) + .take_while(not_full(self.found)) .find(self.find_op); if self.item.is_some() { self.found.store(true, Ordering::Relaxed) diff -Nru rust-rayon-1.5.3/src/iter/fold_chunks.rs rust-rayon-1.6.1/src/iter/fold_chunks.rs --- rust-rayon-1.5.3/src/iter/fold_chunks.rs 1970-01-01 00:00:00.000000000 +0000 +++ rust-rayon-1.6.1/src/iter/fold_chunks.rs 2006-07-24 01:21:28.000000000 +0000 @@ -0,0 +1,236 @@ +use std::fmt::{self, Debug}; + +use super::chunks::ChunkProducer; +use super::plumbing::*; +use super::*; +use crate::math::div_round_up; + +/// `FoldChunks` is an iterator that groups elements of an underlying iterator and applies a +/// function over them, producing a single value for each group. +/// +/// This struct is created by the [`fold_chunks()`] method on [`IndexedParallelIterator`] +/// +/// [`fold_chunks()`]: trait.IndexedParallelIterator.html#method.fold_chunks +/// [`IndexedParallelIterator`]: trait.IndexedParallelIterator.html +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] +#[derive(Clone)] +pub struct FoldChunks +where + I: IndexedParallelIterator, +{ + base: I, + chunk_size: usize, + fold_op: F, + identity: ID, +} + +impl Debug for FoldChunks { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Fold") + .field("base", &self.base) + .field("chunk_size", &self.chunk_size) + .finish() + } +} + +impl FoldChunks +where + I: IndexedParallelIterator, + ID: Fn() -> U + Send + Sync, + F: Fn(U, I::Item) -> U + Send + Sync, + U: Send, +{ + /// Creates a new `FoldChunks` iterator + pub(super) fn new(base: I, chunk_size: usize, identity: ID, fold_op: F) -> Self { + FoldChunks { + base, + chunk_size, + identity, + fold_op, + } + } +} + +impl ParallelIterator for FoldChunks +where + I: IndexedParallelIterator, + ID: Fn() -> U + Send + Sync, + F: Fn(U, I::Item) -> U + Send + Sync, + U: Send, +{ + type Item = U; + + fn drive_unindexed(self, consumer: C) -> C::Result + where + C: Consumer, + { + bridge(self, consumer) + } + + fn opt_len(&self) -> Option { + Some(self.len()) + } +} + +impl IndexedParallelIterator for FoldChunks +where + I: IndexedParallelIterator, + ID: Fn() -> U + Send + Sync, + F: Fn(U, I::Item) -> U + Send + Sync, + U: Send, +{ + fn len(&self) -> usize { + div_round_up(self.base.len(), self.chunk_size) + } + + fn drive(self, consumer: C) -> C::Result + where + C: Consumer, + { + bridge(self, consumer) + } + + fn with_producer(self, callback: CB) -> CB::Output + where + CB: ProducerCallback, + { + let len = self.base.len(); + return self.base.with_producer(Callback { + chunk_size: self.chunk_size, + len, + identity: self.identity, + fold_op: self.fold_op, + callback, + }); + + struct Callback { + chunk_size: usize, + len: usize, + identity: ID, + fold_op: F, + callback: CB, + } + + impl ProducerCallback for Callback + where + CB: ProducerCallback, + ID: Fn() -> U + Send + Sync, + F: Fn(U, T) -> U + Send + Sync, + { + type Output = CB::Output; + + fn callback

(self, base: P) -> CB::Output + where + P: Producer, + { + let identity = &self.identity; + let fold_op = &self.fold_op; + let fold_iter = move |iter: P::IntoIter| iter.fold(identity(), fold_op); + let producer = ChunkProducer::new(self.chunk_size, self.len, base, fold_iter); + self.callback.callback(producer) + } + } + } +} + +#[cfg(test)] +mod test { + use super::*; + use std::ops::Add; + + #[test] + fn check_fold_chunks() { + let words = "bishbashbosh!" + .chars() + .collect::>() + .into_par_iter() + .fold_chunks(4, String::new, |mut s, c| { + s.push(c); + s + }) + .collect::>(); + + assert_eq!(words, vec!["bish", "bash", "bosh", "!"]); + } + + // 'closure' values for tests below + fn id() -> i32 { + 0 + } + fn sum(x: T, y: U) -> T + where + T: Add, + { + x + y + } + + #[test] + #[should_panic(expected = "chunk_size must not be zero")] + fn check_fold_chunks_zero_size() { + let _: Vec = vec![1, 2, 3] + .into_par_iter() + .fold_chunks(0, id, sum) + .collect(); + } + + #[test] + fn check_fold_chunks_even_size() { + assert_eq!( + vec![1 + 2 + 3, 4 + 5 + 6, 7 + 8 + 9], + (1..10) + .into_par_iter() + .fold_chunks(3, id, sum) + .collect::>() + ); + } + + #[test] + fn check_fold_chunks_empty() { + let v: Vec = vec![]; + let expected: Vec = vec![]; + assert_eq!( + expected, + v.into_par_iter() + .fold_chunks(2, id, sum) + .collect::>() + ); + } + + #[test] + fn check_fold_chunks_len() { + assert_eq!(4, (0..8).into_par_iter().fold_chunks(2, id, sum).len()); + assert_eq!(3, (0..9).into_par_iter().fold_chunks(3, id, sum).len()); + assert_eq!(3, (0..8).into_par_iter().fold_chunks(3, id, sum).len()); + assert_eq!(1, (&[1]).par_iter().fold_chunks(3, id, sum).len()); + assert_eq!(0, (0..0).into_par_iter().fold_chunks(3, id, sum).len()); + } + + #[test] + fn check_fold_chunks_uneven() { + let cases: Vec<(Vec, usize, Vec)> = vec![ + ((0..5).collect(), 3, vec![0 + 1 + 2, 3 + 4]), + (vec![1], 5, vec![1]), + ((0..4).collect(), 3, vec![0 + 1 + 2, 3]), + ]; + + for (i, (v, n, expected)) in cases.into_iter().enumerate() { + let mut res: Vec = vec![]; + v.par_iter() + .fold_chunks(n, || 0, sum) + .collect_into_vec(&mut res); + assert_eq!(expected, res, "Case {} failed", i); + + res.truncate(0); + v.into_par_iter() + .fold_chunks(n, || 0, sum) + .rev() + .collect_into_vec(&mut res); + assert_eq!( + expected.into_iter().rev().collect::>(), + res, + "Case {} reversed failed", + i + ); + } + } +} diff -Nru rust-rayon-1.5.3/src/iter/fold_chunks_with.rs rust-rayon-1.6.1/src/iter/fold_chunks_with.rs --- rust-rayon-1.5.3/src/iter/fold_chunks_with.rs 1970-01-01 00:00:00.000000000 +0000 +++ rust-rayon-1.6.1/src/iter/fold_chunks_with.rs 2006-07-24 01:21:28.000000000 +0000 @@ -0,0 +1,231 @@ +use std::fmt::{self, Debug}; + +use super::chunks::ChunkProducer; +use super::plumbing::*; +use super::*; +use crate::math::div_round_up; + +/// `FoldChunksWith` is an iterator that groups elements of an underlying iterator and applies a +/// function over them, producing a single value for each group. +/// +/// This struct is created by the [`fold_chunks_with()`] method on [`IndexedParallelIterator`] +/// +/// [`fold_chunks_with()`]: trait.IndexedParallelIterator.html#method.fold_chunks +/// [`IndexedParallelIterator`]: trait.IndexedParallelIterator.html +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] +#[derive(Clone)] +pub struct FoldChunksWith +where + I: IndexedParallelIterator, +{ + base: I, + chunk_size: usize, + item: U, + fold_op: F, +} + +impl Debug for FoldChunksWith { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Fold") + .field("base", &self.base) + .field("chunk_size", &self.chunk_size) + .field("item", &self.item) + .finish() + } +} + +impl FoldChunksWith +where + I: IndexedParallelIterator, + U: Send + Clone, + F: Fn(U, I::Item) -> U + Send + Sync, +{ + /// Creates a new `FoldChunksWith` iterator + pub(super) fn new(base: I, chunk_size: usize, item: U, fold_op: F) -> Self { + FoldChunksWith { + base, + chunk_size, + item, + fold_op, + } + } +} + +impl ParallelIterator for FoldChunksWith +where + I: IndexedParallelIterator, + U: Send + Clone, + F: Fn(U, I::Item) -> U + Send + Sync, +{ + type Item = U; + + fn drive_unindexed(self, consumer: C) -> C::Result + where + C: Consumer, + { + bridge(self, consumer) + } + + fn opt_len(&self) -> Option { + Some(self.len()) + } +} + +impl IndexedParallelIterator for FoldChunksWith +where + I: IndexedParallelIterator, + U: Send + Clone, + F: Fn(U, I::Item) -> U + Send + Sync, +{ + fn len(&self) -> usize { + div_round_up(self.base.len(), self.chunk_size) + } + + fn drive(self, consumer: C) -> C::Result + where + C: Consumer, + { + bridge(self, consumer) + } + + fn with_producer(self, callback: CB) -> CB::Output + where + CB: ProducerCallback, + { + let len = self.base.len(); + return self.base.with_producer(Callback { + chunk_size: self.chunk_size, + len, + item: self.item, + fold_op: self.fold_op, + callback, + }); + + struct Callback { + chunk_size: usize, + len: usize, + item: T, + fold_op: F, + callback: CB, + } + + impl ProducerCallback for Callback + where + CB: ProducerCallback, + U: Send + Clone, + F: Fn(U, T) -> U + Send + Sync, + { + type Output = CB::Output; + + fn callback

(self, base: P) -> CB::Output + where + P: Producer, + { + let item = self.item; + let fold_op = &self.fold_op; + let fold_iter = move |iter: P::IntoIter| iter.fold(item.clone(), fold_op); + let producer = ChunkProducer::new(self.chunk_size, self.len, base, fold_iter); + self.callback.callback(producer) + } + } + } +} + +#[cfg(test)] +mod test { + use super::*; + use std::ops::Add; + + #[test] + fn check_fold_chunks_with() { + let words = "bishbashbosh!" + .chars() + .collect::>() + .into_par_iter() + .fold_chunks_with(4, String::new(), |mut s, c| { + s.push(c); + s + }) + .collect::>(); + + assert_eq!(words, vec!["bish", "bash", "bosh", "!"]); + } + + // 'closure' value for tests below + fn sum(x: T, y: U) -> T + where + T: Add, + { + x + y + } + + #[test] + #[should_panic(expected = "chunk_size must not be zero")] + fn check_fold_chunks_zero_size() { + let _: Vec = vec![1, 2, 3] + .into_par_iter() + .fold_chunks_with(0, 0, sum) + .collect(); + } + + #[test] + fn check_fold_chunks_even_size() { + assert_eq!( + vec![1 + 2 + 3, 4 + 5 + 6, 7 + 8 + 9], + (1..10) + .into_par_iter() + .fold_chunks_with(3, 0, sum) + .collect::>() + ); + } + + #[test] + fn check_fold_chunks_with_empty() { + let v: Vec = vec![]; + let expected: Vec = vec![]; + assert_eq!( + expected, + v.into_par_iter() + .fold_chunks_with(2, 0, sum) + .collect::>() + ); + } + + #[test] + fn check_fold_chunks_len() { + assert_eq!(4, (0..8).into_par_iter().fold_chunks_with(2, 0, sum).len()); + assert_eq!(3, (0..9).into_par_iter().fold_chunks_with(3, 0, sum).len()); + assert_eq!(3, (0..8).into_par_iter().fold_chunks_with(3, 0, sum).len()); + assert_eq!(1, (&[1]).par_iter().fold_chunks_with(3, 0, sum).len()); + assert_eq!(0, (0..0).into_par_iter().fold_chunks_with(3, 0, sum).len()); + } + + #[test] + fn check_fold_chunks_uneven() { + let cases: Vec<(Vec, usize, Vec)> = vec![ + ((0..5).collect(), 3, vec![0 + 1 + 2, 3 + 4]), + (vec![1], 5, vec![1]), + ((0..4).collect(), 3, vec![0 + 1 + 2, 3]), + ]; + + for (i, (v, n, expected)) in cases.into_iter().enumerate() { + let mut res: Vec = vec![]; + v.par_iter() + .fold_chunks_with(n, 0, sum) + .collect_into_vec(&mut res); + assert_eq!(expected, res, "Case {} failed", i); + + res.truncate(0); + v.into_par_iter() + .fold_chunks_with(n, 0, sum) + .rev() + .collect_into_vec(&mut res); + assert_eq!( + expected.into_iter().rev().collect::>(), + res, + "Case {} reversed failed", + i + ); + } + } +} diff -Nru rust-rayon-1.5.3/src/iter/inspect.rs rust-rayon-1.6.1/src/iter/inspect.rs --- rust-rayon-1.5.3/src/iter/inspect.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/iter/inspect.rs 2006-07-24 01:21:28.000000000 +0000 @@ -209,7 +209,7 @@ F: Fn(&T) + Sync, { fn split_off_left(&self) -> Self { - InspectConsumer::new(self.base.split_off_left(), &self.inspect_op) + InspectConsumer::new(self.base.split_off_left(), self.inspect_op) } fn to_reducer(&self) -> Self::Reducer { diff -Nru rust-rayon-1.5.3/src/iter/interleave.rs rust-rayon-1.6.1/src/iter/interleave.rs --- rust-rayon-1.5.3/src/iter/interleave.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/iter/interleave.rs 2006-07-24 01:21:28.000000000 +0000 @@ -310,16 +310,16 @@ { #[inline] fn next_back(&mut self) -> Option { - if self.i.len() == self.j.len() { - if self.i_next { - self.i.next_back() - } else { - self.j.next_back() + match self.i.len().cmp(&self.j.len()) { + Ordering::Less => self.j.next_back(), + Ordering::Equal => { + if self.i_next { + self.i.next_back() + } else { + self.j.next_back() + } } - } else if self.i.len() < self.j.len() { - self.j.next_back() - } else { - self.i.next_back() + Ordering::Greater => self.i.next_back(), } } } diff -Nru rust-rayon-1.5.3/src/iter/map.rs rust-rayon-1.6.1/src/iter/map.rs --- rust-rayon-1.5.3/src/iter/map.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/iter/map.rs 2006-07-24 01:21:28.000000000 +0000 @@ -213,7 +213,7 @@ R: Send, { fn split_off_left(&self) -> Self { - MapConsumer::new(self.base.split_off_left(), &self.map_op) + MapConsumer::new(self.base.split_off_left(), self.map_op) } fn to_reducer(&self) -> Self::Reducer { diff -Nru rust-rayon-1.5.3/src/iter/mod.rs rust-rayon-1.6.1/src/iter/mod.rs --- rust-rayon-1.5.3/src/iter/mod.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/iter/mod.rs 2006-07-24 01:21:28.000000000 +0000 @@ -119,6 +119,8 @@ mod flatten; mod flatten_iter; mod fold; +mod fold_chunks; +mod fold_chunks_with; mod for_each; mod from_par_iter; mod inspect; @@ -140,6 +142,7 @@ mod rev; mod skip; mod splitter; +mod step_by; mod sum; mod take; mod try_fold; @@ -165,6 +168,8 @@ flatten::Flatten, flatten_iter::FlattenIter, fold::{Fold, FoldWith}, + fold_chunks::FoldChunks, + fold_chunks_with::FoldChunksWith, inspect::Inspect, interleave::Interleave, interleave_shortest::InterleaveShortest, @@ -181,6 +186,7 @@ rev::Rev, skip::Skip, splitter::{split, Split}, + step_by::StepBy, take::Take, try_fold::{TryFold, TryFoldWith}, update::Update, @@ -189,10 +195,6 @@ zip_eq::ZipEq, }; -mod step_by; -#[cfg(has_step_by_rev)] -pub use self::step_by::StepBy; - /// `IntoParallelIterator` implements the conversion to a [`ParallelIterator`]. /// /// By implementing `IntoParallelIterator` for a type, you define how it will @@ -1124,7 +1126,7 @@ /// multiple sums. The number of results is nondeterministic, as /// is the point where the breaks occur. /// - /// So if did the same parallel fold (`fold(0, |a,b| a+b)`) on + /// So if we did the same parallel fold (`fold(0, |a,b| a+b)`) on /// our example list, we might wind up with a sequence of two numbers, /// like so: /// @@ -2241,6 +2243,8 @@ /// those points. /// /// **Note:** Not implemented for `u64`, `i64`, `u128`, or `i128` ranges +// Waiting for `ExactSizeIterator::is_empty` to be stabilized. See rust-lang/rust#35428 +#[allow(clippy::len_without_is_empty)] pub trait IndexedParallelIterator: ParallelIterator { /// Collects the results of the iterator into the specified /// vector. The vector is always truncated before execution @@ -2339,13 +2343,18 @@ /// // we should never get here /// assert_eq!(1, zipped.len()); /// ``` + #[track_caller] fn zip_eq(self, zip_op: Z) -> ZipEq where Z: IntoParallelIterator, Z::Iter: IndexedParallelIterator, { let zip_op_iter = zip_op.into_par_iter(); - assert_eq!(self.len(), zip_op_iter.len()); + assert_eq!( + self.len(), + zip_op_iter.len(), + "iterators must have the same length" + ); ZipEq::new(self, zip_op_iter) } @@ -2415,6 +2424,89 @@ Chunks::new(self, chunk_size) } + /// Splits an iterator into fixed-size chunks, performing a sequential [`fold()`] on + /// each chunk. + /// + /// Returns an iterator that produces a folded result for each chunk of items + /// produced by this iterator. + /// + /// This works essentially like: + /// + /// ```text + /// iter.chunks(chunk_size) + /// .map(|chunk| + /// chunk.into_iter() + /// .fold(identity, fold_op) + /// ) + /// ``` + /// + /// except there is no per-chunk allocation overhead. + /// + /// [`fold()`]: std::iter::Iterator#method.fold + /// + /// **Panics** if `chunk_size` is 0. + /// + /// # Examples + /// + /// ``` + /// use rayon::prelude::*; + /// let nums = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + /// let chunk_sums = nums.into_par_iter().fold_chunks(2, || 0, |a, n| a + n).collect::>(); + /// assert_eq!(chunk_sums, vec![3, 7, 11, 15, 19]); + /// ``` + #[track_caller] + fn fold_chunks( + self, + chunk_size: usize, + identity: ID, + fold_op: F, + ) -> FoldChunks + where + ID: Fn() -> T + Send + Sync, + F: Fn(T, Self::Item) -> T + Send + Sync, + T: Send, + { + assert!(chunk_size != 0, "chunk_size must not be zero"); + FoldChunks::new(self, chunk_size, identity, fold_op) + } + + /// Splits an iterator into fixed-size chunks, performing a sequential [`fold()`] on + /// each chunk. + /// + /// Returns an iterator that produces a folded result for each chunk of items + /// produced by this iterator. + /// + /// This works essentially like `fold_chunks(chunk_size, || init.clone(), fold_op)`, + /// except it doesn't require the `init` type to be `Sync`, nor any other form of + /// added synchronization. + /// + /// [`fold()`]: std::iter::Iterator#method.fold + /// + /// **Panics** if `chunk_size` is 0. + /// + /// # Examples + /// + /// ``` + /// use rayon::prelude::*; + /// let nums = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + /// let chunk_sums = nums.into_par_iter().fold_chunks_with(2, 0, |a, n| a + n).collect::>(); + /// assert_eq!(chunk_sums, vec![3, 7, 11, 15, 19]); + /// ``` + #[track_caller] + fn fold_chunks_with( + self, + chunk_size: usize, + init: T, + fold_op: F, + ) -> FoldChunksWith + where + T: Send + Clone, + F: Fn(T, Self::Item) -> T + Send + Sync, + { + assert!(chunk_size != 0, "chunk_size must not be zero"); + FoldChunksWith::new(self, chunk_size, init, fold_op) + } + /// Lexicographically compares the elements of this `ParallelIterator` with those of /// another. /// @@ -2601,11 +2693,6 @@ /// /// assert_eq!(result, [3, 6, 9]) /// ``` - /// - /// # Compatibility - /// - /// This method is only available on Rust 1.38 or greater. - #[cfg(has_step_by_rev)] fn step_by(self, step: usize) -> StepBy { StepBy::new(self, step) } @@ -3146,20 +3233,9 @@ /// stable clone of the standard library's `Try` trait, as yet unstable. mod private { use std::convert::Infallible; + use std::ops::ControlFlow::{self, Break, Continue}; use std::task::Poll; - #[cfg(has_control_flow)] - pub(crate) use std::ops::ControlFlow; - - #[cfg(not(has_control_flow))] - #[allow(missing_debug_implementations)] - pub enum ControlFlow { - Continue(C), - Break(B), - } - - use self::ControlFlow::{Break, Continue}; - /// Clone of `std::ops::Try`. /// /// Implementing this trait is not permitted outside of `rayon`. @@ -3176,7 +3252,6 @@ fn branch(self) -> ControlFlow; } - #[cfg(has_control_flow)] impl Try for ControlFlow { private_impl! {} diff -Nru rust-rayon-1.5.3/src/iter/par_bridge.rs rust-rayon-1.6.1/src/iter/par_bridge.rs --- rust-rayon-1.5.3/src/iter/par_bridge.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/iter/par_bridge.rs 2006-07-24 01:21:28.000000000 +0000 @@ -1,12 +1,9 @@ -use crossbeam_deque::{Steal, Stealer, Worker}; - use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; -use std::sync::{Mutex, TryLockError}; -use std::thread::yield_now; +use std::sync::Mutex; -use crate::current_num_threads; use crate::iter::plumbing::{bridge_unindexed, Folder, UnindexedConsumer, UnindexedProducer}; use crate::iter::ParallelIterator; +use crate::{current_num_threads, current_thread_index}; /// Conversion trait to convert an `Iterator` to a `ParallelIterator`. /// @@ -78,71 +75,46 @@ where C: UnindexedConsumer, { - let split_count = AtomicUsize::new(current_num_threads()); - let worker = Worker::new_fifo(); - let stealer = worker.stealer(); - let done = AtomicBool::new(false); - let iter = Mutex::new((self.iter, worker)); + let num_threads = current_num_threads(); + let threads_started: Vec<_> = (0..num_threads).map(|_| AtomicBool::new(false)).collect(); bridge_unindexed( - IterParallelProducer { - split_count: &split_count, - done: &done, - iter: &iter, - items: stealer, + &IterParallelProducer { + split_count: AtomicUsize::new(num_threads), + iter: Mutex::new(self.iter.fuse()), + threads_started: &threads_started, }, consumer, ) } } -struct IterParallelProducer<'a, Iter: Iterator> { - split_count: &'a AtomicUsize, - done: &'a AtomicBool, - iter: &'a Mutex<(Iter, Worker)>, - items: Stealer, -} - -// manual clone because T doesn't need to be Clone, but the derive assumes it should be -impl<'a, Iter: Iterator + 'a> Clone for IterParallelProducer<'a, Iter> { - fn clone(&self) -> Self { - IterParallelProducer { - split_count: self.split_count, - done: self.done, - iter: self.iter, - items: self.items.clone(), - } - } +struct IterParallelProducer<'a, Iter> { + split_count: AtomicUsize, + iter: Mutex>, + threads_started: &'a [AtomicBool], } -impl<'a, Iter: Iterator + Send + 'a> UnindexedProducer for IterParallelProducer<'a, Iter> -where - Iter::Item: Send, -{ +impl UnindexedProducer for &IterParallelProducer<'_, Iter> { type Item = Iter::Item; fn split(self) -> (Self, Option) { let mut count = self.split_count.load(Ordering::SeqCst); loop { - // Check if the iterator is exhausted *and* we've consumed every item from it. - let done = self.done.load(Ordering::SeqCst) && self.items.is_empty(); - - match count.checked_sub(1) { - Some(new_count) if !done => { - match self.split_count.compare_exchange_weak( - count, - new_count, - Ordering::SeqCst, - Ordering::SeqCst, - ) { - Ok(_) => return (self.clone(), Some(self)), - Err(last_count) => count = last_count, - } - } - _ => { - return (self, None); + // Check if the iterator is exhausted + if let Some(new_count) = count.checked_sub(1) { + match self.split_count.compare_exchange_weak( + count, + new_count, + Ordering::SeqCst, + Ordering::SeqCst, + ) { + Ok(_) => return (self, Some(self)), + Err(last_count) => count = last_count, } + } else { + return (self, None); } } } @@ -151,66 +123,39 @@ where F: Folder, { + // Guard against work-stealing-induced recursion, in case `Iter::next()` + // calls rayon internally, so we don't deadlock our mutex. We might also + // be recursing via `folder` methods, which doesn't present a mutex hazard, + // but it's lower overhead for us to just check this once, rather than + // updating additional shared state on every mutex lock/unlock. + // (If this isn't a rayon thread, then there's no work-stealing anyway...) + if let Some(i) = current_thread_index() { + // Note: If the number of threads in the pool ever grows dynamically, then + // we'll end up sharing flags and may falsely detect recursion -- that's + // still fine for overall correctness, just not optimal for parallelism. + let thread_started = &self.threads_started[i % self.threads_started.len()]; + if thread_started.swap(true, Ordering::Relaxed) { + // We can't make progress with a nested mutex, so just return and let + // the outermost loop continue with the rest of the iterator items. + return folder; + } + } + loop { - match self.items.steal() { - Steal::Success(it) => { + if let Ok(mut iter) = self.iter.lock() { + if let Some(it) = iter.next() { + drop(iter); folder = folder.consume(it); if folder.full() { return folder; } + } else { + return folder; } - Steal::Empty => { - // Don't storm the mutex if we're already done. - if self.done.load(Ordering::SeqCst) { - // Someone might have pushed more between our `steal()` and `done.load()` - if self.items.is_empty() { - // The iterator is out of items, no use in continuing - return folder; - } - } else { - // our cache is out of items, time to load more from the iterator - match self.iter.try_lock() { - Ok(mut guard) => { - // Check `done` again in case we raced with the previous lock - // holder on its way out. - if self.done.load(Ordering::SeqCst) { - if self.items.is_empty() { - return folder; - } - continue; - } - - let count = current_num_threads(); - let count = (count * count) * 2; - - let (ref mut iter, ref worker) = *guard; - - // while worker.len() < count { - // FIXME the new deque doesn't let us count items. We can just - // push a number of items, but that doesn't consider active - // stealers elsewhere. - for _ in 0..count { - if let Some(it) = iter.next() { - worker.push(it); - } else { - self.done.store(true, Ordering::SeqCst); - break; - } - } - } - Err(TryLockError::WouldBlock) => { - // someone else has the mutex, just sit tight until it's ready - yield_now(); //TODO: use a thread-pool-aware yield? (#548) - } - Err(TryLockError::Poisoned(_)) => { - // any panics from other threads will have been caught by the pool, - // and will be re-thrown when joined - just exit - return folder; - } - } - } - } - Steal::Retry => (), + } else { + // any panics from other threads will have been caught by the pool, + // and will be re-thrown when joined - just exit + return folder; } } } diff -Nru rust-rayon-1.5.3/src/iter/plumbing/README.md rust-rayon-1.6.1/src/iter/plumbing/README.md --- rust-rayon-1.5.3/src/iter/plumbing/README.md 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/iter/plumbing/README.md 2006-07-24 01:21:28.000000000 +0000 @@ -124,7 +124,7 @@ The `bridge` function will then connect the consumer, which is handling the `flat_map` and `for_each`, with the producer, which is -handling the `zip` and its preecessors. It will split down until the +handling the `zip` and its predecessors. It will split down until the chunks seem reasonably small, then pull items from the producer and feed them to the consumer. diff -Nru rust-rayon-1.5.3/src/iter/step_by.rs rust-rayon-1.6.1/src/iter/step_by.rs --- rust-rayon-1.5.3/src/iter/step_by.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/iter/step_by.rs 2006-07-24 01:21:28.000000000 +0000 @@ -1,4 +1,3 @@ -#![cfg(has_step_by_rev)] use std::cmp::min; use super::plumbing::*; diff -Nru rust-rayon-1.5.3/src/iter/test.rs rust-rayon-1.6.1/src/iter/test.rs --- rust-rayon-1.5.3/src/iter/test.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/iter/test.rs 2006-07-24 01:21:28.000000000 +0000 @@ -117,13 +117,10 @@ let r1 = (0_i32..32) .into_par_iter() .with_max_len(1) - .fold( - || vec![], - |mut v, e| { - v.push(e); - v - }, - ) + .fold(Vec::new, |mut v, e| { + v.push(e); + v + }) .map(|v| vec![v]) .reduce_with(|mut v_a, v_b| { v_a.extend(v_b); @@ -394,7 +391,7 @@ #[test] fn check_vec_indexed() { let a = vec![1, 2, 3]; - is_indexed(a.clone().into_par_iter()); + is_indexed(a.into_par_iter()); } #[test] @@ -1371,10 +1368,10 @@ let counter = AtomicUsize::new(0); let value: Option = (0_i32..2048).into_par_iter().find_any(|&p| { counter.fetch_add(1, Ordering::SeqCst); - p >= 1024 && p < 1096 + (1024..1096).contains(&p) }); let q = value.unwrap(); - assert!(q >= 1024 && q < 1096); + assert!((1024..1096).contains(&q)); assert!(counter.load(Ordering::SeqCst) < 2048); // should not have visited every single one } @@ -1892,7 +1889,7 @@ // try an indexed iterator let left: E = Either::Left(v.clone().into_par_iter()); - assert!(left.enumerate().eq(v.clone().into_par_iter().enumerate())); + assert!(left.enumerate().eq(v.into_par_iter().enumerate())); } #[test] @@ -2063,7 +2060,7 @@ assert_eq!(4, (0..8).into_par_iter().chunks(2).len()); assert_eq!(3, (0..9).into_par_iter().chunks(3).len()); assert_eq!(3, (0..8).into_par_iter().chunks(3).len()); - assert_eq!(1, (&[1]).par_iter().chunks(3).len()); + assert_eq!(1, [1].par_iter().chunks(3).len()); assert_eq!(0, (0..0).into_par_iter().chunks(3).len()); } diff -Nru rust-rayon-1.5.3/src/iter/try_fold.rs rust-rayon-1.6.1/src/iter/try_fold.rs --- rust-rayon-1.5.3/src/iter/try_fold.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/iter/try_fold.rs 2006-07-24 01:21:28.000000000 +0000 @@ -2,10 +2,9 @@ use super::ParallelIterator; use super::Try; -use super::private::ControlFlow::{self, Break, Continue}; - use std::fmt::{self, Debug}; use std::marker::PhantomData; +use std::ops::ControlFlow::{self, Break, Continue}; impl TryFold where diff -Nru rust-rayon-1.5.3/src/iter/try_reduce.rs rust-rayon-1.6.1/src/iter/try_reduce.rs --- rust-rayon-1.5.3/src/iter/try_reduce.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/iter/try_reduce.rs 2006-07-24 01:21:28.000000000 +0000 @@ -2,8 +2,7 @@ use super::ParallelIterator; use super::Try; -use super::private::ControlFlow::{self, Break, Continue}; - +use std::ops::ControlFlow::{self, Break, Continue}; use std::sync::atomic::{AtomicBool, Ordering}; pub(super) fn try_reduce(pi: PI, identity: ID, reduce_op: R) -> T diff -Nru rust-rayon-1.5.3/src/iter/try_reduce_with.rs rust-rayon-1.6.1/src/iter/try_reduce_with.rs --- rust-rayon-1.5.3/src/iter/try_reduce_with.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/iter/try_reduce_with.rs 2006-07-24 01:21:28.000000000 +0000 @@ -2,8 +2,7 @@ use super::ParallelIterator; use super::Try; -use super::private::ControlFlow::{self, Break, Continue}; - +use std::ops::ControlFlow::{self, Break, Continue}; use std::sync::atomic::{AtomicBool, Ordering}; pub(super) fn try_reduce_with(pi: PI, reduce_op: R) -> Option diff -Nru rust-rayon-1.5.3/src/iter/update.rs rust-rayon-1.6.1/src/iter/update.rs --- rust-rayon-1.5.3/src/iter/update.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/iter/update.rs 2006-07-24 01:21:28.000000000 +0000 @@ -210,7 +210,7 @@ F: Fn(&mut T) + Send + Sync, { fn split_off_left(&self) -> Self { - UpdateConsumer::new(self.base.split_off_left(), &self.update_op) + UpdateConsumer::new(self.base.split_off_left(), self.update_op) } fn to_reducer(&self) -> Self::Reducer { diff -Nru rust-rayon-1.5.3/src/lib.rs rust-rayon-1.6.1/src/lib.rs --- rust-rayon-1.5.3/src/lib.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/lib.rs 2006-07-24 01:21:28.000000000 +0000 @@ -1,4 +1,3 @@ -#![doc(html_root_url = "https://docs.rs/rayon/1.5")] #![deny(missing_debug_implementations)] #![deny(missing_docs)] #![deny(unreachable_pub)] @@ -114,6 +113,7 @@ pub use rayon_core::ThreadPool; pub use rayon_core::ThreadPoolBuildError; pub use rayon_core::ThreadPoolBuilder; +pub use rayon_core::{broadcast, spawn_broadcast, BroadcastContext}; pub use rayon_core::{current_num_threads, current_thread_index, max_num_threads}; pub use rayon_core::{in_place_scope, scope, Scope}; pub use rayon_core::{in_place_scope_fifo, scope_fifo, ScopeFifo}; @@ -136,6 +136,13 @@ // SAFETY: !Sync for raw pointers is not for safety, just as a lint unsafe impl Sync for SendPtr {} +impl SendPtr { + // Helper to avoid disjoint captures of `send_ptr.0` + fn get(self) -> *mut T { + self.0 + } +} + // Implement Clone without the T: Clone bound from the derive impl Clone for SendPtr { fn clone(&self) -> Self { diff -Nru rust-rayon-1.5.3/src/math.rs rust-rayon-1.6.1/src/math.rs --- rust-rayon-1.5.3/src/math.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/math.rs 2006-07-24 01:21:28.000000000 +0000 @@ -1,7 +1,7 @@ use std::ops::{Bound, Range, RangeBounds}; /// Divide `n` by `divisor`, and round up to the nearest integer -/// if not evenly divisable. +/// if not evenly divisible. #[inline] pub(super) fn div_round_up(n: usize, divisor: usize) -> usize { debug_assert!(divisor != 0, "Division by zero!"); diff -Nru rust-rayon-1.5.3/src/slice/chunks.rs rust-rayon-1.6.1/src/slice/chunks.rs --- rust-rayon-1.5.3/src/slice/chunks.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/slice/chunks.rs 2006-07-24 01:21:28.000000000 +0000 @@ -317,7 +317,7 @@ /// returned by the iterator. The returned slice has at most `chunk_size-1` /// elements. Subsequent calls will return an empty slice. pub fn take_remainder(&mut self) -> &'data mut [T] { - std::mem::replace(&mut self.rem, &mut []) + std::mem::take(&mut self.rem) } } diff -Nru rust-rayon-1.5.3/src/slice/mergesort.rs rust-rayon-1.6.1/src/slice/mergesort.rs --- rust-rayon-1.5.3/src/slice/mergesort.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/slice/mergesort.rs 2006-07-24 01:21:28.000000000 +0000 @@ -205,9 +205,8 @@ impl Drop for MergeHole { fn drop(&mut self) { // `T` is not a zero-sized type, so it's okay to divide by its size. - let len = (self.end as usize - self.start as usize) / size_of::(); unsafe { - // TODO 1.47: let len = self.end.offset_from(self.start) as usize; + let len = self.end.offset_from(self.start) as usize; ptr::copy_nonoverlapping(self.start, self.dest, len); } } @@ -491,8 +490,8 @@ let dest_l = SendPtr(dest); let dest_r = SendPtr(dest.add(left_l.len() + right_l.len())); rayon_core::join( - || par_merge(left_l, right_l, dest_l.0, is_less), - || par_merge(left_r, right_r, dest_r.0, is_less), + move || par_merge(left_l, right_l, dest_l.get(), is_less), + move || par_merge(left_r, right_r, dest_r.get(), is_less), ); } // Finally, `s` gets dropped if we used sequential merge, thus copying the remaining elements @@ -570,7 +569,7 @@ // After recursive calls finish we'll have to merge chunks `(start, mid)` and `(mid, end)` from // `src` into `dest`. If the current invocation has to store the result into `buf`, we'll - // merge chunks from `v` into `buf`, and viceversa. + // merge chunks from `v` into `buf`, and vice versa. // // Recursive calls flip `into_buf` at each level of recursion. More concretely, `par_merge` // merges chunks from `buf` into `v` at the first level, from `v` into `buf` at the second @@ -593,8 +592,8 @@ let v = SendPtr(v); let buf = SendPtr(buf); rayon_core::join( - || recurse(v.0, buf.0, left, !into_buf, is_less), - || recurse(v.0, buf.0, right, !into_buf, is_less), + move || recurse(v.get(), buf.get(), left, !into_buf, is_less), + move || recurse(v.get(), buf.get(), right, !into_buf, is_less), ); // Everything went all right - recursive calls didn't panic. @@ -661,16 +660,17 @@ // Wrap pointer in SendPtr so that it can be sent to another thread // See the documentation of SendPtr for a full explanation let buf = SendPtr(buf); + let is_less = &is_less; v.par_chunks_mut(CHUNK_LENGTH) .with_max_len(1) .enumerate() - .map(|(i, chunk)| { + .map(move |(i, chunk)| { let l = CHUNK_LENGTH * i; let r = l + chunk.len(); unsafe { - let buf = buf.0.add(l); - (l, r, mergesort(chunk, buf, &is_less)) + let buf = buf.get().add(l); + (l, r, mergesort(chunk, buf, is_less)) } }) .collect::>() @@ -731,7 +731,7 @@ check(&[1, 2, 2, 2, 2, 3], &[]); check(&[], &[1, 2, 2, 2, 2, 3]); - let ref mut rng = thread_rng(); + let rng = &mut thread_rng(); for _ in 0..100 { let limit: u32 = rng.gen_range(1..21); diff -Nru rust-rayon-1.5.3/src/slice/mod.rs rust-rayon-1.6.1/src/slice/mod.rs --- rust-rayon-1.5.3/src/slice/mod.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/slice/mod.rs 2006-07-24 01:21:28.000000000 +0000 @@ -85,6 +85,7 @@ /// let chunks: Vec<_> = [1, 2, 3, 4, 5].par_chunks(2).collect(); /// assert_eq!(chunks, vec![&[1, 2][..], &[3, 4], &[5]]); /// ``` + #[track_caller] fn par_chunks(&self, chunk_size: usize) -> Chunks<'_, T> { assert!(chunk_size != 0, "chunk_size must not be zero"); Chunks::new(chunk_size, self.as_parallel_slice()) @@ -104,6 +105,7 @@ /// let chunks: Vec<_> = [1, 2, 3, 4, 5].par_chunks_exact(2).collect(); /// assert_eq!(chunks, vec![&[1, 2][..], &[3, 4]]); /// ``` + #[track_caller] fn par_chunks_exact(&self, chunk_size: usize) -> ChunksExact<'_, T> { assert!(chunk_size != 0, "chunk_size must not be zero"); ChunksExact::new(chunk_size, self.as_parallel_slice()) @@ -123,6 +125,7 @@ /// let chunks: Vec<_> = [1, 2, 3, 4, 5].par_rchunks(2).collect(); /// assert_eq!(chunks, vec![&[4, 5][..], &[2, 3], &[1]]); /// ``` + #[track_caller] fn par_rchunks(&self, chunk_size: usize) -> RChunks<'_, T> { assert!(chunk_size != 0, "chunk_size must not be zero"); RChunks::new(chunk_size, self.as_parallel_slice()) @@ -142,6 +145,7 @@ /// let chunks: Vec<_> = [1, 2, 3, 4, 5].par_rchunks_exact(2).collect(); /// assert_eq!(chunks, vec![&[4, 5][..], &[2, 3]]); /// ``` + #[track_caller] fn par_rchunks_exact(&self, chunk_size: usize) -> RChunksExact<'_, T> { assert!(chunk_size != 0, "chunk_size must not be zero"); RChunksExact::new(chunk_size, self.as_parallel_slice()) @@ -199,6 +203,7 @@ /// .for_each(|slice| slice.reverse()); /// assert_eq!(array, [2, 1, 4, 3, 5]); /// ``` + #[track_caller] fn par_chunks_mut(&mut self, chunk_size: usize) -> ChunksMut<'_, T> { assert!(chunk_size != 0, "chunk_size must not be zero"); ChunksMut::new(chunk_size, self.as_parallel_slice_mut()) @@ -220,6 +225,7 @@ /// .for_each(|slice| slice.reverse()); /// assert_eq!(array, [3, 2, 1, 4, 5]); /// ``` + #[track_caller] fn par_chunks_exact_mut(&mut self, chunk_size: usize) -> ChunksExactMut<'_, T> { assert!(chunk_size != 0, "chunk_size must not be zero"); ChunksExactMut::new(chunk_size, self.as_parallel_slice_mut()) @@ -241,6 +247,7 @@ /// .for_each(|slice| slice.reverse()); /// assert_eq!(array, [1, 3, 2, 5, 4]); /// ``` + #[track_caller] fn par_rchunks_mut(&mut self, chunk_size: usize) -> RChunksMut<'_, T> { assert!(chunk_size != 0, "chunk_size must not be zero"); RChunksMut::new(chunk_size, self.as_parallel_slice_mut()) @@ -262,6 +269,7 @@ /// .for_each(|slice| slice.reverse()); /// assert_eq!(array, [1, 2, 5, 4, 3]); /// ``` + #[track_caller] fn par_rchunks_exact_mut(&mut self, chunk_size: usize) -> RChunksExactMut<'_, T> { assert!(chunk_size != 0, "chunk_size must not be zero"); RChunksExactMut::new(chunk_size, self.as_parallel_slice_mut()) diff -Nru rust-rayon-1.5.3/src/slice/quicksort.rs rust-rayon-1.6.1/src/slice/quicksort.rs --- rust-rayon-1.5.3/src/slice/quicksort.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/slice/quicksort.rs 2006-07-24 01:21:28.000000000 +0000 @@ -191,25 +191,25 @@ // This binary heap respects the invariant `parent >= child`. let sift_down = |v: &mut [T], mut node| { loop { - // Children of `node`: - let left = 2 * node + 1; - let right = 2 * node + 2; + // Children of `node`. + let mut child = 2 * node + 1; + if child >= v.len() { + break; + } // Choose the greater child. - let greater = if right < v.len() && is_less(&v[left], &v[right]) { - right - } else { - left - }; + if child + 1 < v.len() && is_less(&v[child], &v[child + 1]) { + child += 1; + } // Stop if the invariant holds at `node`. - if greater >= v.len() || !is_less(&v[node], &v[greater]) { + if !is_less(&v[node], &v[child]) { break; } // Swap `node` with the greater child, move one step down, and continue sifting. - v.swap(node, greater); - node = greater; + v.swap(node, child); + node = child; } }; @@ -426,7 +426,7 @@ // safe. Otherwise, the debug assertions in the `is_done` case guarantee that // `width(l, r) == block_l + block_r`, namely, that the block sizes have been adjusted to account // for the smaller number of remaining elements. - l = unsafe { l.offset(block_l as isize) }; + l = unsafe { l.add(block_l) }; } if start_r == end_r { @@ -629,8 +629,7 @@ random }; let mut gen_usize = || { - // TODO 1.53: if usize::BITS <= 32 { - if mem::size_of::() <= 4 { + if usize::BITS <= 32 { gen_u32() as usize } else { (((gen_u32() as u64) << 32) | (gen_u32() as u64)) as usize @@ -676,6 +675,7 @@ let len = v.len(); // Three indices near which we are going to choose a pivot. + #[allow(clippy::identity_op)] let mut a = len / 4 * 1; let mut b = len / 4 * 2; let mut c = len / 4 * 3; @@ -850,8 +850,7 @@ } // Limit the number of imbalanced partitions to `floor(log2(len)) + 1`. - // TODO 1.53: let limit = usize::BITS - v.len().leading_zeros(); - let limit = mem::size_of::() as u32 * 8 - v.len().leading_zeros(); + let limit = usize::BITS - v.len().leading_zeros(); recurse(v, &is_less, None, limit); } @@ -864,7 +863,7 @@ #[test] fn test_heapsort() { - let ref mut rng = thread_rng(); + let rng = &mut thread_rng(); for len in (0..25).chain(500..501) { for &modulus in &[5, 10, 100] { @@ -891,8 +890,8 @@ heapsort(&mut v, &|_, _| thread_rng().gen()); heapsort(&mut v, &|a, b| a < b); - for i in 0..v.len() { - assert_eq!(v[i], i); + for (i, &entry) in v.iter().enumerate() { + assert_eq!(entry, i); } } } diff -Nru rust-rayon-1.5.3/src/slice/rchunks.rs rust-rayon-1.6.1/src/slice/rchunks.rs --- rust-rayon-1.5.3/src/slice/rchunks.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/slice/rchunks.rs 2006-07-24 01:21:28.000000000 +0000 @@ -314,7 +314,7 @@ /// returned by the iterator. The returned slice has at most `chunk_size-1` /// elements. Subsequent calls will return an empty slice. pub fn take_remainder(&mut self) -> &'data mut [T] { - std::mem::replace(&mut self.rem, &mut []) + std::mem::take(&mut self.rem) } } diff -Nru rust-rayon-1.5.3/src/slice/test.rs rust-rayon-1.6.1/src/slice/test.rs --- rust-rayon-1.5.3/src/slice/test.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/slice/test.rs 2006-07-24 01:21:28.000000000 +0000 @@ -10,7 +10,7 @@ ($f:ident, $name:ident) => { #[test] fn $name() { - let ref mut rng = thread_rng(); + let rng = &mut thread_rng(); for len in (0..25).chain(500..501) { for &modulus in &[5, 10, 100] { diff -Nru rust-rayon-1.5.3/src/str.rs rust-rayon-1.6.1/src/str.rs --- rust-rayon-1.5.3/src/str.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/str.rs 2006-07-24 01:21:28.000000000 +0000 @@ -689,11 +689,7 @@ #[inline] fn no_carriage_return(line: &str) -> &str { - if line.ends_with('\r') { - &line[..line.len() - 1] - } else { - line - } + line.strip_suffix('\r').unwrap_or(line) } impl<'ch> ParallelIterator for Lines<'ch> { diff -Nru rust-rayon-1.5.3/src/vec.rs rust-rayon-1.6.1/src/vec.rs --- rust-rayon-1.5.3/src/vec.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/src/vec.rs 2006-07-24 01:21:28.000000000 +0000 @@ -132,7 +132,7 @@ self.range.len() } - fn with_producer(mut self, callback: CB) -> CB::Output + fn with_producer(self, callback: CB) -> CB::Output where CB: ProducerCallback, { @@ -141,7 +141,7 @@ self.vec.set_len(self.range.start); // Create the producer as the exclusive "owner" of the slice. - let producer = DrainProducer::from_vec(&mut self.vec, self.range.len()); + let producer = DrainProducer::from_vec(self.vec, self.range.len()); // The producer will move or drop each item from the drained range. callback.callback(producer) @@ -151,22 +151,24 @@ impl<'data, T: Send> Drop for Drain<'data, T> { fn drop(&mut self) { - if self.range.len() > 0 { - let Range { start, end } = self.range; - if self.vec.len() != start { - // We must not have produced, so just call a normal drain to remove the items. - assert_eq!(self.vec.len(), self.orig_len); - self.vec.drain(start..end); - } else if end < self.orig_len { - // The producer was responsible for consuming the drained items. - // Move the tail items to their new place, then set the length to include them. - unsafe { - let ptr = self.vec.as_mut_ptr().add(start); - let tail_ptr = self.vec.as_ptr().add(end); - let tail_len = self.orig_len - end; - ptr::copy(tail_ptr, ptr, tail_len); - self.vec.set_len(start + tail_len); - } + let Range { start, end } = self.range; + if self.vec.len() == self.orig_len { + // We must not have produced, so just call a normal drain to remove the items. + self.vec.drain(start..end); + } else if start == end { + // Empty range, so just restore the length to its original state + unsafe { + self.vec.set_len(self.orig_len); + } + } else if end < self.orig_len { + // The producer was responsible for consuming the drained items. + // Move the tail items to their new place, then set the length to include them. + unsafe { + let ptr = self.vec.as_mut_ptr().add(start); + let tail_ptr = self.vec.as_ptr().add(end); + let tail_len = self.orig_len - end; + ptr::copy(tail_ptr, ptr, tail_len); + self.vec.set_len(start + tail_len); } } } @@ -181,7 +183,7 @@ impl DrainProducer<'_, T> { /// Creates a draining producer, which *moves* items from the slice. /// - /// Unsafe bacause `!Copy` data must not be read after the borrow is released. + /// Unsafe because `!Copy` data must not be read after the borrow is released. pub(crate) unsafe fn new(slice: &mut [T]) -> DrainProducer<'_, T> { DrainProducer { slice } } @@ -207,7 +209,7 @@ fn into_iter(mut self) -> Self::IntoIter { // replace the slice so we don't drop it twice - let slice = mem::replace(&mut self.slice, &mut []); + let slice = mem::take(&mut self.slice); SliceDrain { iter: slice.iter_mut(), } @@ -215,7 +217,7 @@ fn split_at(mut self, index: usize) -> (Self, Self) { // replace the slice so we don't drop it twice - let slice = mem::replace(&mut self.slice, &mut []); + let slice = mem::take(&mut self.slice); let (left, right) = slice.split_at_mut(index); unsafe { (DrainProducer::new(left), DrainProducer::new(right)) } } diff -Nru rust-rayon-1.5.3/tests/clones.rs rust-rayon-1.6.1/tests/clones.rs --- rust-rayon-1.5.3/tests/clones.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/tests/clones.rs 2006-07-24 01:21:28.000000000 +0000 @@ -130,6 +130,12 @@ check(v.par_iter().flatten_iter()); check(v.par_iter().with_max_len(1).fold(|| 0, |x, _| x)); check(v.par_iter().with_max_len(1).fold_with(0, |x, _| x)); + check(v.par_iter().with_max_len(1).fold_chunks(1, || 0, |x, _| x)); + check( + v.par_iter() + .with_max_len(1) + .fold_chunks_with(1, 0, |x, _| x), + ); check(v.par_iter().with_max_len(1).try_fold(|| 0, |_, &x| x)); check(v.par_iter().with_max_len(1).try_fold_with(0, |_, &x| x)); check(v.par_iter().inspect(|_| ())); diff -Nru rust-rayon-1.5.3/tests/debug.rs rust-rayon-1.6.1/tests/debug.rs --- rust-rayon-1.5.3/tests/debug.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/tests/debug.rs 2006-07-24 01:21:28.000000000 +0000 @@ -155,6 +155,8 @@ check(v.par_iter().map(Some).flatten_iter()); check(v.par_iter().fold(|| 0, |x, _| x)); check(v.par_iter().fold_with(0, |x, _| x)); + check(v.par_iter().fold_chunks(3, || 0, |x, _| x)); + check(v.par_iter().fold_chunks_with(3, 0, |x, _| x)); check(v.par_iter().try_fold(|| 0, |x, _| Some(x))); check(v.par_iter().try_fold_with(0, |x, _| Some(x))); check(v.par_iter().inspect(|_| ())); diff -Nru rust-rayon-1.5.3/tests/drain_vec.rs rust-rayon-1.6.1/tests/drain_vec.rs --- rust-rayon-1.5.3/tests/drain_vec.rs 1970-01-01 00:00:00.000000000 +0000 +++ rust-rayon-1.6.1/tests/drain_vec.rs 2006-07-24 01:21:28.000000000 +0000 @@ -0,0 +1,41 @@ +use rayon::prelude::*; + +#[test] +fn drain_vec_yielded() { + let mut vec_org = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; + + let yielded = vec_org.par_drain(0..5).collect::>(); + + assert_eq!(&yielded, &[0, 1, 2, 3, 4]); + assert_eq!(&vec_org, &[5, 6, 7, 8, 9]); +} + +#[test] +fn drain_vec_dropped() { + let mut vec_org = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; + + let yielded = vec_org.par_drain(0..5); + + drop(yielded); + assert_eq!(&vec_org, &[5, 6, 7, 8, 9]); +} + +#[test] +fn drain_vec_empty_range_yielded() { + let mut vec_org = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; + + let yielded = vec_org.par_drain(5..5).collect::>(); + + assert_eq!(&yielded, &[]); + assert_eq!(&vec_org, &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); +} + +#[test] +fn drain_vec_empty_range_dropped() { + let mut vec_org = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; + + let yielded = vec_org.par_drain(5..5); + + drop(yielded); + assert_eq!(&vec_org, &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); +} diff -Nru rust-rayon-1.5.3/tests/iter_panic.rs rust-rayon-1.6.1/tests/iter_panic.rs --- rust-rayon-1.5.3/tests/iter_panic.rs 1973-11-29 21:33:09.000000000 +0000 +++ rust-rayon-1.6.1/tests/iter_panic.rs 2006-07-24 01:21:28.000000000 +0000 @@ -47,6 +47,6 @@ assert!(count(iter.clone().panic_fuse().inspect(check)) < expected); // Try in reverse to be sure we hit the producer case. - assert!(count(iter.clone().panic_fuse().inspect(check).rev()) < expected); + assert!(count(iter.panic_fuse().inspect(check).rev()) < expected); }); } diff -Nru rust-rayon-1.5.3/tests/par_bridge_recursion.rs rust-rayon-1.6.1/tests/par_bridge_recursion.rs --- rust-rayon-1.5.3/tests/par_bridge_recursion.rs 1970-01-01 00:00:00.000000000 +0000 +++ rust-rayon-1.6.1/tests/par_bridge_recursion.rs 2006-07-24 01:21:28.000000000 +0000 @@ -0,0 +1,30 @@ +use rayon::prelude::*; +use std::iter::once_with; + +const N: usize = 100_000; + +#[test] +fn par_bridge_recursion() { + let pool = rayon::ThreadPoolBuilder::new() + .num_threads(10) + .build() + .unwrap(); + + let seq: Vec<_> = (0..N).map(|i| (i, i.to_string())).collect(); + + pool.broadcast(|_| { + let mut par: Vec<_> = (0..N) + .into_par_iter() + .flat_map(|i| { + once_with(move || { + // Using rayon within the serial iterator creates an opportunity for + // work-stealing to make par_bridge's mutex accidentally recursive. + rayon::join(move || i, move || i.to_string()) + }) + .par_bridge() + }) + .collect(); + par.par_sort_unstable(); + assert_eq!(seq, par); + }); +}