From bfa9cddb6a35f17b6933385f41cff60f28b2f045 Mon Sep 17 00:00:00 2001 From: Will Crichton Date: Fri, 15 Jul 2022 15:50:44 -0700 Subject: [PATCH] Don't use nightly, just use rayon --- .github/workflows/main.yml | 2 +- Cargo.lock | 101 +++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/main.rs | 4 -- src/processor.rs | 14 ++--- 5 files changed, 110 insertions(+), 12 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 959b22e..4ce39a4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,7 +8,7 @@ jobs: - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: nightly + toolchain: stable components: clippy - uses: Swatinem/rust-cache@v1 - name: Install JS dependencies diff --git a/Cargo.lock b/Cargo.lock index 9fe4be0..dc564bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -190,6 +190,51 @@ dependencies = [ "os_str_bytes", ] +[[package]] +name = "crossbeam-channel" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c02a4d71819009c192cf4872265391563fd6a84c81ff2c0f2a7026ca4c1d85c" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" +dependencies = [ + "cfg-if", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07db9d94cbd326813772c968ccd25999e5f8ae22f4f8d1b11effa37ef6ce281d" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "memoffset", + "once_cell", + "scopeguard", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d82ee10ce34d7bc12c2122495e7593a9c41347ecdd64185af4ecf72cb1a7f83" +dependencies = [ + "cfg-if", + "once_cell", +] + [[package]] name = "digest" version = "0.8.1" @@ -199,6 +244,12 @@ dependencies = [ "generic-array", ] +[[package]] +name = "either" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f107b87b6afc2a64fd13cac55fe06d6c8859f12d4b14cbcdd2c67d0976781be" + [[package]] name = "env_logger" version = "0.7.1" @@ -383,6 +434,7 @@ dependencies = [ "html-escape", "lazy_static", "mdbook", + "rayon", "regex", "semver", "serde_json", @@ -396,6 +448,15 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +[[package]] +name = "memoffset" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +dependencies = [ + "autocfg", +] + [[package]] name = "miniz_oxide" version = "0.5.3" @@ -424,6 +485,16 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_cpus" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +dependencies = [ + "hermit-abi", + "libc", +] + [[package]] name = "object" version = "0.28.4" @@ -563,6 +634,30 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rayon" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd99e5772ead8baa5215278c9b15bf92087709e9c1b2d1f97cdb5a183c933a7d" +dependencies = [ + "autocfg", + "crossbeam-deque", + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "num_cpus", +] + [[package]] name = "redox_syscall" version = "0.2.13" @@ -616,6 +711,12 @@ version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + [[package]] name = "semver" version = "1.0.10" diff --git a/Cargo.toml b/Cargo.toml index be0fe79..28a66d7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ regex = "1" html-escape = "0.2" toml = "0.5" lazy_static = "1.4" +rayon = {version = "1.5", default-features = false} [dev-dependencies] tempfile = "3" diff --git a/src/main.rs b/src/main.rs index 5e3578a..e6c3bf4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,3 @@ -// TODO: remove this once Rust 1.63 is released -#![feature(scoped_threads)] -#![allow(stable_features)] - use std::{io, process}; use clap::{Parser, Subcommand}; diff --git a/src/processor.rs b/src/processor.rs index 058c93e..f4ea908 100644 --- a/src/processor.rs +++ b/src/processor.rs @@ -4,7 +4,6 @@ use std::{ fs, path::{Path, PathBuf}, process::Command, - thread, }; use anyhow::{bail, Context, Result}; @@ -228,15 +227,16 @@ impl Preprocessor for QuizProcessor { }; processor.copy_js_files()?; - thread::scope(|s| { - fn for_each_mut<'scope, 'a: 'scope, 'b: 'scope, 'c: 'scope>( - s: &'a thread::Scope<'scope, '_>, - processor: &'b QuizProcessorRef, - items: impl IntoIterator, + // TODO: use std::thread::Scope once that gets stabilized + rayon::scope(|s| { + fn for_each_mut<'scope, 'proc: 'scope, 'item: 'scope>( + s: &rayon::Scope<'scope>, + processor: &'proc QuizProcessorRef, + items: impl IntoIterator, ) { for item in items { if let BookItem::Chapter(chapter) = item { - s.spawn(|| { + s.spawn(|_| { let chapter_path = processor.src_dir.join(chapter.path.as_ref().unwrap()); let chapter_dir = chapter_path.parent().unwrap(); processor