Update Rust crate bincode to v2 (#18188)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
renovate[bot] 2025-05-19 08:57:09 +02:00 committed by GitHub
parent 9f743d1b9f
commit 38c332fe23
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 49 additions and 20 deletions

View File

@ -411,7 +411,7 @@ cargo install hyperfine
To benchmark the release build: To benchmark the release build:
```shell ```shell
cargo build --release && hyperfine --warmup 10 \ cargo build --release --bin ruff && hyperfine --warmup 10 \
"./target/release/ruff check ./crates/ruff_linter/resources/test/cpython/ --no-cache -e" \ "./target/release/ruff check ./crates/ruff_linter/resources/test/cpython/ --no-cache -e" \
"./target/release/ruff check ./crates/ruff_linter/resources/test/cpython/ -e" "./target/release/ruff check ./crates/ruff_linter/resources/test/cpython/ -e"

27
Cargo.lock generated
View File

@ -177,11 +177,22 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
[[package]] [[package]]
name = "bincode" name = "bincode"
version = "1.3.3" version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" checksum = "36eaf5d7b090263e8150820482d5d93cd964a81e4019913c972f4edcc6edb740"
dependencies = [ dependencies = [
"bincode_derive",
"serde", "serde",
"unty",
]
[[package]]
name = "bincode_derive"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf95709a440f45e986983918d0e8a1f30a9b1df04918fc828670606804ac3c09"
dependencies = [
"virtue",
] ]
[[package]] [[package]]
@ -4260,6 +4271,12 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e9df2af067a7953e9c3831320f35c1cc0600c30d44d9f7a12b01db1cd88d6b47" checksum = "e9df2af067a7953e9c3831320f35c1cc0600c30d44d9f7a12b01db1cd88d6b47"
[[package]]
name = "unty"
version = "0.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d49784317cd0d1ee7ec5c716dd598ec5b4483ea832a2dced265471cc0f690ae"
[[package]] [[package]]
name = "url" name = "url"
version = "2.5.4" version = "2.5.4"
@ -4347,6 +4364,12 @@ version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
[[package]]
name = "virtue"
version = "0.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "051eb1abcf10076295e815102942cc58f9d5e3b4560e46e53c21e8ff6f3af7b1"
[[package]] [[package]]
name = "vt100" name = "vt100"
version = "0.15.2" version = "0.15.2"

View File

@ -52,7 +52,7 @@ anstyle = { version = "1.0.10" }
anyhow = { version = "1.0.80" } anyhow = { version = "1.0.80" }
assert_fs = { version = "1.1.0" } assert_fs = { version = "1.1.0" }
argfile = { version = "0.2.0" } argfile = { version = "0.2.0" }
bincode = { version = "1.3.3" } bincode = { version = "2.0.0" }
bitflags = { version = "2.5.0" } bitflags = { version = "2.5.0" }
bstr = { version = "1.9.1" } bstr = { version = "1.9.1" }
cachedir = { version = "0.3.1" } cachedir = { version = "0.3.1" }

View File

@ -31,7 +31,7 @@ ruff_workspace = { workspace = true }
anyhow = { workspace = true } anyhow = { workspace = true }
argfile = { workspace = true } argfile = { workspace = true }
bincode = { workspace = true } bincode = { workspace = true, features = ["serde"] }
bitflags = { workspace = true } bitflags = { workspace = true }
cachedir = { workspace = true } cachedir = { workspace = true }
clap = { workspace = true, features = ["derive", "env", "wrap_help"] } clap = { workspace = true, features = ["derive", "env", "wrap_help"] }

View File

@ -15,7 +15,6 @@ use rayon::iter::ParallelIterator;
use rayon::iter::{IntoParallelIterator, ParallelBridge}; use rayon::iter::{IntoParallelIterator, ParallelBridge};
use ruff_linter::{codes::Rule, registry::AsRule}; use ruff_linter::{codes::Rule, registry::AsRule};
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize};
use tempfile::NamedTempFile; use tempfile::NamedTempFile;
use ruff_cache::{CacheKey, CacheKeyHasher}; use ruff_cache::{CacheKey, CacheKeyHasher};
@ -118,7 +117,8 @@ impl Cache {
} }
}; };
let mut package: PackageCache = match bincode::deserialize_from(BufReader::new(file)) { let mut package: PackageCache =
match bincode::decode_from_reader(BufReader::new(file), bincode::config::standard()) {
Ok(package) => package, Ok(package) => package,
Err(err) => { Err(err) => {
warn_user!("Failed parse cache file `{}`: {err}", path.display()); warn_user!("Failed parse cache file `{}`: {err}", path.display());
@ -176,8 +176,8 @@ impl Cache {
// Serialize to in-memory buffer because hyperfine benchmark showed that it's faster than // Serialize to in-memory buffer because hyperfine benchmark showed that it's faster than
// using a `BufWriter` and our cache files are small enough that streaming isn't necessary. // using a `BufWriter` and our cache files are small enough that streaming isn't necessary.
let serialized = let serialized = bincode::encode_to_vec(&self.package, bincode::config::standard())
bincode::serialize(&self.package).context("Failed to serialize cache data")?; .context("Failed to serialize cache data")?;
temp_file temp_file
.write_all(&serialized) .write_all(&serialized)
.context("Failed to write serialized cache to temporary file.")?; .context("Failed to write serialized cache to temporary file.")?;
@ -312,7 +312,7 @@ impl Cache {
} }
/// On disk representation of a cache of a package. /// On disk representation of a cache of a package.
#[derive(Deserialize, Debug, Serialize)] #[derive(bincode::Encode, Debug, bincode::Decode)]
struct PackageCache { struct PackageCache {
/// Path to the root of the package. /// Path to the root of the package.
/// ///
@ -324,7 +324,7 @@ struct PackageCache {
} }
/// On disk representation of the cache per source file. /// On disk representation of the cache per source file.
#[derive(Deserialize, Debug, Serialize)] #[derive(bincode::Decode, Debug, bincode::Encode)]
pub(crate) struct FileCache { pub(crate) struct FileCache {
/// Key that determines if the cached item is still valid. /// Key that determines if the cached item is still valid.
key: u64, key: u64,
@ -371,7 +371,7 @@ impl FileCache {
} }
} }
#[derive(Debug, Default, Deserialize, Serialize)] #[derive(Debug, Default, bincode::Decode, bincode::Encode)]
struct FileCacheData { struct FileCacheData {
lint: Option<LintCacheData>, lint: Option<LintCacheData>,
formatted: bool, formatted: bool,
@ -409,7 +409,7 @@ pub(crate) fn init(path: &Path) -> Result<()> {
Ok(()) Ok(())
} }
#[derive(Deserialize, Debug, Serialize, PartialEq)] #[derive(bincode::Decode, Debug, bincode::Encode, PartialEq)]
pub(crate) struct LintCacheData { pub(crate) struct LintCacheData {
/// Imports made. /// Imports made.
// pub(super) imports: ImportMap, // pub(super) imports: ImportMap,
@ -422,6 +422,7 @@ pub(crate) struct LintCacheData {
/// This will be empty if `messages` is empty. /// This will be empty if `messages` is empty.
pub(super) source: String, pub(super) source: String,
/// Notebook index if this file is a Jupyter Notebook. /// Notebook index if this file is a Jupyter Notebook.
#[bincode(with_serde)]
pub(super) notebook_index: Option<NotebookIndex>, pub(super) notebook_index: Option<NotebookIndex>,
} }
@ -467,18 +468,23 @@ impl LintCacheData {
} }
/// On disk representation of a diagnostic message. /// On disk representation of a diagnostic message.
#[derive(Deserialize, Debug, Serialize, PartialEq)] #[derive(bincode::Decode, Debug, bincode::Encode, PartialEq)]
pub(super) struct CacheMessage { pub(super) struct CacheMessage {
/// The rule for the cached diagnostic. /// The rule for the cached diagnostic.
#[bincode(with_serde)]
rule: Rule, rule: Rule,
/// The message body to display to the user, to explain the diagnostic. /// The message body to display to the user, to explain the diagnostic.
body: String, body: String,
/// The message to display to the user, to explain the suggested fix. /// The message to display to the user, to explain the suggested fix.
suggestion: Option<String>, suggestion: Option<String>,
/// Range into the message's [`FileCache::source`]. /// Range into the message's [`FileCache::source`].
#[bincode(with_serde)]
range: TextRange, range: TextRange,
#[bincode(with_serde)]
parent: Option<TextSize>, parent: Option<TextSize>,
#[bincode(with_serde)]
fix: Option<Fix>, fix: Option<Fix>,
#[bincode(with_serde)]
noqa_offset: TextSize, noqa_offset: TextSize,
} }