From ca776d267dca7d99dc27418873b1cb4245838734 Mon Sep 17 00:00:00 2001 From: Hana Date: Thu, 15 Aug 2024 14:48:35 +0800 Subject: [PATCH 01/10] perf: init --- .github/workflows/ci.yml | 1 + build.rs | 6 ++++++ src/lib.rs | 16 ++++++++++++---- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 59f576ea84..15e179e100 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,6 +51,7 @@ jobs: - 1.63 - nightly-2022-12-14 - 1.68 + - 1.74 - stable exclude: # These versions started failing with "archive member 'lib.rmeta' with length 26456 is not diff --git a/build.rs b/build.rs index 25cb382496..23e300d1c0 100644 --- a/build.rs +++ b/build.rs @@ -18,6 +18,7 @@ fn main() { println!("cargo:rustc-check-cfg=cfg(path_buf_capacity)"); println!("cargo:rustc-check-cfg=cfg(shrink_to)"); println!("cargo:rustc-check-cfg=cfg(try_reserve_2)"); + println!("cargo:rustc-check-cfg=cfg(os_str_bytes)"); let compiler = match rustc_version() { Some(compiler) => compiler, @@ -49,6 +50,11 @@ fn main() { { println!("cargo:rustc-cfg=path_buf_deref_mut"); } + // os_str_bytes was added in a 1.74 stable. + if (compiler.minor >= 74 && compiler.channel == ReleaseChannel::Stable) || compiler.minor >= 75 + { + println!("cargo:rustc-cfg=os_str_bytes"); + } // Catch situations where the actual features aren't enabled. Currently, they're only shown with // `-vv` output, but maybe that will be noticed. diff --git a/src/lib.rs b/src/lib.rs index e9a115f20c..48cfda5769 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3067,9 +3067,17 @@ impl_cmp_os_str!(&'a Utf8Path, OsString); // invariant: OsStr must be guaranteed to be utf8 data #[inline] unsafe fn str_assume_utf8(string: &OsStr) -> &str { - // Adapted from the source code for Option::unwrap_unchecked. - match string.to_str() { - Some(val) => val, - None => std::hint::unreachable_unchecked(), + #[cfg(os_str_bytes)] + { + // SAFETY: OsStr is guaranteed to be utf8 data from the invariant + unsafe { std::str::from_utf8_unchecked(string.as_encoded_bytes()) } + } + #[cfg(not(os_str_bytes))] + { + // Adapted from the source code for Option::unwrap_unchecked. + match string.to_str() { + Some(val) => val, + None => std::hint::unreachable_unchecked(), + } } } From 0b3c118bacf96c8c4b4903a1c29e7d821c501a1b Mon Sep 17 00:00:00 2001 From: Hana Date: Thu, 15 Aug 2024 15:43:09 +0800 Subject: [PATCH 02/10] clippy --- src/lib.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 48cfda5769..7d510bdf7d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -701,10 +701,10 @@ impl Utf8Path { /// the current directory. /// /// * On Unix, a path is absolute if it starts with the root, so - /// `is_absolute` and [`has_root`] are equivalent. + /// `is_absolute` and [`has_root`] are equivalent. /// /// * On Windows, a path is absolute if it has a prefix and starts with the - /// root: `c:\windows` is absolute, while `c:temp` and `\temp` are not. + /// root: `c:\windows` is absolute, while `c:temp` and `\temp` are not. /// /// # Examples /// @@ -3070,7 +3070,12 @@ unsafe fn str_assume_utf8(string: &OsStr) -> &str { #[cfg(os_str_bytes)] { // SAFETY: OsStr is guaranteed to be utf8 data from the invariant - unsafe { std::str::from_utf8_unchecked(string.as_encoded_bytes()) } + unsafe { + std::str::from_utf8_unchecked( + #[allow(clippy::incompatible_msrv)] + string.as_encoded_bytes(), + ) + } } #[cfg(not(os_str_bytes))] { From 5943d4240b6f9f72ed6f7dce27c794844c4ce3bf Mon Sep 17 00:00:00 2001 From: Hana Date: Thu, 15 Aug 2024 19:34:20 +0800 Subject: [PATCH 03/10] bench --- Cargo.toml | 5 +++++ benches/bench.rs | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 benches/bench.rs diff --git a/Cargo.toml b/Cargo.toml index e2c1403045..2c431caa91 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,10 @@ authors = [ edition = "2018" exclude = [".cargo/**/*", ".github/**/*"] +[[bench]] +name = "bench" +harness = false + [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg=doc_cfg"] @@ -32,6 +36,7 @@ serde = { version = "1", features = ["derive"], optional = true } [dev-dependencies] bincode = "1" serde_bytes = "0.11.8" +criterion = "0.5.1" [features] serde1 = ["serde"] diff --git a/benches/bench.rs b/benches/bench.rs new file mode 100644 index 0000000000..1f1bf3b1e1 --- /dev/null +++ b/benches/bench.rs @@ -0,0 +1,19 @@ +use criterion::*; + +use camino::Utf8PathBuf; + +fn bench_path(c: &mut Criterion) { + let mut group = c.benchmark_group("Path"); + for i in [10, 100, 1000, 10000] { + let p = "i".repeat(i); + let buf = Utf8PathBuf::from(black_box(p)); + group.bench_with_input(BenchmarkId::new("Utf8PathBuf::as_str", i), &buf, |b, i| { + b.iter(|| { + let _ = black_box(&i).as_str(); + }) + }); + } +} + +criterion_group!(benches, bench_path); +criterion_main!(benches); From 861dc5bbcbdeebc5a2533a73001c10f2d9635560 Mon Sep 17 00:00:00 2001 From: Hana Date: Thu, 15 Aug 2024 20:16:06 +0800 Subject: [PATCH 04/10] fix dep --- camino-examples/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/camino-examples/Cargo.toml b/camino-examples/Cargo.toml index 58b7845c3b..cddbab654c 100644 --- a/camino-examples/Cargo.toml +++ b/camino-examples/Cargo.toml @@ -8,7 +8,7 @@ publish = false [dependencies] anyhow = "1.0.38" camino = { path = "..", features = ["serde1"] } -clap = { version = "3.0.7", features = ["derive"] } +clap = { version = "4", features = ["derive"] } serde = { version = "1", features = ["derive"] } serde_json = { version = "1.0.62" } From 79af350a0edb88e26657a0568eeea43aae355d77 Mon Sep 17 00:00:00 2001 From: Hana Date: Thu, 15 Aug 2024 20:25:23 +0800 Subject: [PATCH 05/10] fix dep --- Cargo.toml | 2 +- camino-examples/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2c431caa91..9d7259da74 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,7 @@ serde = { version = "1", features = ["derive"], optional = true } [dev-dependencies] bincode = "1" serde_bytes = "0.11.8" -criterion = "0.5.1" +criterion = "0.4" [features] serde1 = ["serde"] diff --git a/camino-examples/Cargo.toml b/camino-examples/Cargo.toml index cddbab654c..58b7845c3b 100644 --- a/camino-examples/Cargo.toml +++ b/camino-examples/Cargo.toml @@ -8,7 +8,7 @@ publish = false [dependencies] anyhow = "1.0.38" camino = { path = "..", features = ["serde1"] } -clap = { version = "4", features = ["derive"] } +clap = { version = "3.0.7", features = ["derive"] } serde = { version = "1", features = ["derive"] } serde_json = { version = "1.0.62" } From 3943d87309df13cbe656aef50e10a7612dd62115 Mon Sep 17 00:00:00 2001 From: Hana Date: Thu, 15 Aug 2024 21:02:24 +0800 Subject: [PATCH 06/10] do not install criterion --- Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 9d7259da74..e6cc1d5580 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,6 @@ serde = { version = "1", features = ["derive"], optional = true } [dev-dependencies] bincode = "1" serde_bytes = "0.11.8" -criterion = "0.4" [features] serde1 = ["serde"] From 11b76aa2adfa3eec1c9f63c1449a22b292e31e9b Mon Sep 17 00:00:00 2001 From: Hana Date: Thu, 15 Aug 2024 21:05:53 +0800 Subject: [PATCH 07/10] remove --- .github/workflows/ci.yml | 3 +++ Cargo.toml | 1 + 2 files changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 15e179e100..5bd623779a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -85,6 +85,9 @@ jobs: run: cp Cargo.lock.rust134 Cargo.lock - name: Build the library run: cargo build + # Remove criterion to support testing with earlier versions + - name: Remove criterion + run: cargo remove --dev criterion - name: Test run: cargo test - name: Build all targets with all features diff --git a/Cargo.toml b/Cargo.toml index e6cc1d5580..9d7259da74 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,7 @@ serde = { version = "1", features = ["derive"], optional = true } [dev-dependencies] bincode = "1" serde_bytes = "0.11.8" +criterion = "0.4" [features] serde1 = ["serde"] From 92d69ed701268f56d9a264b0aff2cc2af11f3d81 Mon Sep 17 00:00:00 2001 From: Hana Date: Thu, 15 Aug 2024 21:16:57 +0800 Subject: [PATCH 08/10] use cargo-edit --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5bd623779a..f6fb56a9b7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -80,6 +80,8 @@ jobs: echo CARGO_REGISTRIES_CRATES_IO_PROTOCOL=git >> $GITHUB_ENV - name: Install cargo-hack uses: taiki-e/install-action@cargo-hack + - name: Install cargo-rm + run: cargo install cargo-edit --version 0.11.0 - name: Use pinned Cargo.lock for Rust 1.34 and 1.44 if: ${{ matrix.rust-version == 1.34 || matrix.rust-version == 1.44 }} run: cp Cargo.lock.rust134 Cargo.lock @@ -87,7 +89,7 @@ jobs: run: cargo build # Remove criterion to support testing with earlier versions - name: Remove criterion - run: cargo remove --dev criterion + run: cargo-rm rm --dev criterion - name: Test run: cargo test - name: Build all targets with all features From 205060a01e6fd40cb5d6f9e3fba23466f525f5a3 Mon Sep 17 00:00:00 2001 From: Rain Date: Thu, 15 Aug 2024 12:45:09 -0700 Subject: [PATCH 09/10] move benchmark to camino-examples, update criterion, simplify CI --- .github/workflows/ci.yml | 9 ++------- Cargo.toml | 5 ----- camino-examples/Cargo.toml | 7 +++++++ {benches => camino-examples/benches}/bench.rs | 7 ++++++- 4 files changed, 15 insertions(+), 13 deletions(-) rename {benches => camino-examples/benches}/bench.rs (68%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f6fb56a9b7..7c62f1b808 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -80,26 +80,21 @@ jobs: echo CARGO_REGISTRIES_CRATES_IO_PROTOCOL=git >> $GITHUB_ENV - name: Install cargo-hack uses: taiki-e/install-action@cargo-hack - - name: Install cargo-rm - run: cargo install cargo-edit --version 0.11.0 - name: Use pinned Cargo.lock for Rust 1.34 and 1.44 if: ${{ matrix.rust-version == 1.34 || matrix.rust-version == 1.44 }} run: cp Cargo.lock.rust134 Cargo.lock - name: Build the library run: cargo build - # Remove criterion to support testing with earlier versions - - name: Remove criterion - run: cargo-rm rm --dev criterion - name: Test run: cargo test - name: Build all targets with all features # Some optional features are not compatible with earlier versions if: ${{ matrix.rust-version == 'stable' }} - run: cargo hack --feature-powerset build --workspace + run: cargo hack --feature-powerset build --workspace --all-targets - name: Test all targets with all features # Some optional features are not compatible with earlier versions if: ${{ matrix.rust-version == 'stable' }} - run: cargo hack --feature-powerset test --workspace + run: cargo hack --feature-powerset test --workspace --all-targets miri: name: Check unsafe code against miri diff --git a/Cargo.toml b/Cargo.toml index 9d7259da74..e2c1403045 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,10 +21,6 @@ authors = [ edition = "2018" exclude = [".cargo/**/*", ".github/**/*"] -[[bench]] -name = "bench" -harness = false - [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg=doc_cfg"] @@ -36,7 +32,6 @@ serde = { version = "1", features = ["derive"], optional = true } [dev-dependencies] bincode = "1" serde_bytes = "0.11.8" -criterion = "0.4" [features] serde1 = ["serde"] diff --git a/camino-examples/Cargo.toml b/camino-examples/Cargo.toml index 58b7845c3b..1c344102b9 100644 --- a/camino-examples/Cargo.toml +++ b/camino-examples/Cargo.toml @@ -12,5 +12,12 @@ clap = { version = "3.0.7", features = ["derive"] } serde = { version = "1", features = ["derive"] } serde_json = { version = "1.0.62" } +[dev-dependencies] +criterion = "0.5.1" + [[bin]] name = "serde" + +[[bench]] +name = "bench" +harness = false diff --git a/benches/bench.rs b/camino-examples/benches/bench.rs similarity index 68% rename from benches/bench.rs rename to camino-examples/benches/bench.rs index 1f1bf3b1e1..1c924f1b86 100644 --- a/benches/bench.rs +++ b/camino-examples/benches/bench.rs @@ -1,6 +1,11 @@ -use criterion::*; +// Copyright (c) The camino Contributors +// SPDX-License-Identifier: MIT OR Apache-2.0 + +// This benchmark is here because criterion has a higher MSRV than camino -- camino-examples is only +// tested on stable, which is good enough. use camino::Utf8PathBuf; +use criterion::*; fn bench_path(c: &mut Criterion) { let mut group = c.benchmark_group("Path"); From c684dc7ad86e3d9b848f726be8e98b4b5c903b34 Mon Sep 17 00:00:00 2001 From: Rain Date: Thu, 15 Aug 2024 13:15:02 -0700 Subject: [PATCH 10/10] move camino-examples into its own workspace --- .github/workflows/ci.yml | 14 ++++++++++++++ Cargo.toml | 2 +- camino-examples/.gitignore | 1 + camino-examples/Cargo.toml | 5 +++++ 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 camino-examples/.gitignore diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7c62f1b808..c9cc6994ca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,8 +26,14 @@ jobs: components: rustfmt, clippy - name: Lint (clippy) run: cargo clippy --workspace --all-features --all-targets + - name: Lint (clippy in camino-examples) + run: | + cd camino-examples && cargo clippy --all-features --all-targets - name: Lint (rustfmt) run: cargo xfmt --check + - name: Lint (rustfmt in camino-examples) + run: | + cd camino-examples && cargo xfmt --check - name: Check for differences run: git diff --exit-code @@ -95,6 +101,14 @@ jobs: # Some optional features are not compatible with earlier versions if: ${{ matrix.rust-version == 'stable' }} run: cargo hack --feature-powerset test --workspace --all-targets + - name: Build camino-examples + if: ${{ matrix.rust-version == 'stable' }} + run: | + cd camino-examples && cargo build + - name: Test camino-examples + if: ${{ matrix.rust-version == 'stable' }} + run: | + cd camino-examples && cargo test miri: name: Check unsafe code against miri diff --git a/Cargo.toml b/Cargo.toml index e2c1403045..c5f261384d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = [".", "camino-examples"] +members = ["."] [package] name = "camino" diff --git a/camino-examples/.gitignore b/camino-examples/.gitignore new file mode 100644 index 0000000000..ea8c4bf7f3 --- /dev/null +++ b/camino-examples/.gitignore @@ -0,0 +1 @@ +/target diff --git a/camino-examples/Cargo.toml b/camino-examples/Cargo.toml index 1c344102b9..2c9a07ae56 100644 --- a/camino-examples/Cargo.toml +++ b/camino-examples/Cargo.toml @@ -1,3 +1,8 @@ +[workspace] +# camino-examples pulls in crates that aren't supported by old versions of Rust, so make it its own +# workspace. +members = ["."] + [package] name = "camino-examples" description = "Examples for camino"