From 8042451e0dae1788e125c7bb331e1c9c07fa50d3 Mon Sep 17 00:00:00 2001 From: jingyu Date: Tue, 19 Nov 2024 18:42:21 +0800 Subject: [PATCH] feat: make package sync by using Arc not Rc --- src/cargo/core/manifest.rs | 33 ++++++++++++++++----------------- src/cargo/core/package.rs | 10 +++++----- src/cargo/util/toml/mod.rs | 18 +++++++++--------- 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/src/cargo/core/manifest.rs b/src/cargo/core/manifest.rs index d63dbd61de3..4f695cbc5de 100644 --- a/src/cargo/core/manifest.rs +++ b/src/cargo/core/manifest.rs @@ -2,7 +2,6 @@ use std::collections::{BTreeMap, HashMap}; use std::fmt; use std::hash::{Hash, Hasher}; use std::path::{Path, PathBuf}; -use std::rc::Rc; use std::sync::Arc; use anyhow::Context as _; @@ -61,10 +60,10 @@ impl EitherManifest { #[derive(Clone, Debug)] pub struct Manifest { // alternate forms of manifests: - contents: Rc, - document: Rc>, - original_toml: Rc, - normalized_toml: Rc, + contents: Arc, + document: Arc>, + original_toml: Arc, + normalized_toml: Arc, summary: Summary, // this form of manifest: @@ -107,10 +106,10 @@ pub struct Warnings(Vec); #[derive(Clone, Debug)] pub struct VirtualManifest { // alternate forms of manifests: - contents: Rc, - document: Rc>, - original_toml: Rc, - normalized_toml: Rc, + contents: Arc, + document: Arc>, + original_toml: Arc, + normalized_toml: Arc, // this form of manifest: replace: Vec<(PackageIdSpec, Dependency)>, @@ -419,10 +418,10 @@ compact_debug! { impl Manifest { pub fn new( - contents: Rc, - document: Rc>, - original_toml: Rc, - normalized_toml: Rc, + contents: Arc, + document: Arc>, + original_toml: Arc, + normalized_toml: Arc, summary: Summary, default_kind: Option, @@ -661,10 +660,10 @@ impl Manifest { impl VirtualManifest { pub fn new( - contents: Rc, - document: Rc>, - original_toml: Rc, - normalized_toml: Rc, + contents: Arc, + document: Arc>, + original_toml: Arc, + normalized_toml: Arc, replace: Vec<(PackageIdSpec, Dependency)>, patch: HashMap>, workspace: WorkspaceConfig, diff --git a/src/cargo/core/package.rs b/src/cargo/core/package.rs index 3d7c84a4266..ddb394c0021 100644 --- a/src/cargo/core/package.rs +++ b/src/cargo/core/package.rs @@ -5,7 +5,7 @@ use std::fmt; use std::hash; use std::mem; use std::path::{Path, PathBuf}; -use std::rc::Rc; +use std::sync::Arc; use std::time::{Duration, Instant}; use anyhow::Context as _; @@ -42,7 +42,7 @@ use crate::util::{self, internal, GlobalContext, Progress, ProgressStyle}; /// A package is a `Cargo.toml` file plus all the files that are part of it. #[derive(Clone)] pub struct Package { - inner: Rc, + inner: Arc, } #[derive(Clone)] @@ -101,7 +101,7 @@ impl Package { /// Creates a package from a manifest and its location. pub fn new(manifest: Manifest, manifest_path: &Path) -> Package { Package { - inner: Rc::new(PackageInner { + inner: Arc::new(PackageInner { manifest, manifest_path: manifest_path.to_path_buf(), }), @@ -118,7 +118,7 @@ impl Package { } /// Gets the manifest. pub fn manifest_mut(&mut self) -> &mut Manifest { - &mut Rc::make_mut(&mut self.inner).manifest + &mut Arc::make_mut(&mut self.inner).manifest } /// Gets the path to the manifest. pub fn manifest_path(&self) -> &Path { @@ -179,7 +179,7 @@ impl Package { pub fn map_source(self, to_replace: SourceId, replace_with: SourceId) -> Package { Package { - inner: Rc::new(PackageInner { + inner: Arc::new(PackageInner { manifest: self.manifest().clone().map_source(to_replace, replace_with), manifest_path: self.manifest_path().to_owned(), }), diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index c0f6df61d90..ed7504e904c 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -2,8 +2,8 @@ use annotate_snippets::{Level, Snippet}; use std::collections::{BTreeMap, BTreeSet, HashMap}; use std::ffi::OsStr; use std::path::{Path, PathBuf}; -use std::rc::Rc; use std::str::{self, FromStr}; +use std::sync::Arc; use crate::core::summary::MissingDependencyError; use crate::AlreadyPrintedError; @@ -1570,10 +1570,10 @@ pub fn to_real_manifest( let default_run = normalized_package.default_run.clone(); let metabuild = normalized_package.metabuild.clone().map(|sov| sov.0); let manifest = Manifest::new( - Rc::new(contents), - Rc::new(document), - Rc::new(original_toml), - Rc::new(normalized_toml), + Arc::new(contents), + Arc::new(document), + Arc::new(original_toml), + Arc::new(normalized_toml), summary, default_kind, forced_kind, @@ -1749,10 +1749,10 @@ fn to_virtual_manifest( bail!("virtual manifests must be configured with [workspace]"); } let manifest = VirtualManifest::new( - Rc::new(contents), - Rc::new(document), - Rc::new(original_toml), - Rc::new(normalized_toml), + Arc::new(contents), + Arc::new(document), + Arc::new(original_toml), + Arc::new(normalized_toml), replace, patch, workspace_config,