Skip to content

Commit

Permalink
feat: make package sync by using Arc not Rc
Browse files Browse the repository at this point in the history
  • Loading branch information
washanhanzi committed Jan 14, 2025
1 parent d73d2ca commit 3f36fcb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 31 deletions.
33 changes: 16 additions & 17 deletions src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,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 _;
Expand Down Expand Up @@ -62,10 +61,10 @@ impl EitherManifest {
#[derive(Clone, Debug)]
pub struct Manifest {
// alternate forms of manifests:
contents: Rc<String>,
document: Rc<toml_edit::ImDocument<String>>,
original_toml: Rc<TomlManifest>,
normalized_toml: Rc<TomlManifest>,
contents: Arc<String>,
document: Arc<toml_edit::ImDocument<String>>,
original_toml: Arc<TomlManifest>,
normalized_toml: Arc<TomlManifest>,
summary: Summary,

// this form of manifest:
Expand Down Expand Up @@ -108,10 +107,10 @@ pub struct Warnings(Vec<DelayedWarning>);
#[derive(Clone, Debug)]
pub struct VirtualManifest {
// alternate forms of manifests:
contents: Rc<String>,
document: Rc<toml_edit::ImDocument<String>>,
original_toml: Rc<TomlManifest>,
normalized_toml: Rc<TomlManifest>,
contents: Arc<String>,
document: Arc<toml_edit::ImDocument<String>>,
original_toml: Arc<TomlManifest>,
normalized_toml: Arc<TomlManifest>,

// this form of manifest:
replace: Vec<(PackageIdSpec, Dependency)>,
Expand Down Expand Up @@ -500,10 +499,10 @@ compact_debug! {

impl Manifest {
pub fn new(
contents: Rc<String>,
document: Rc<toml_edit::ImDocument<String>>,
original_toml: Rc<TomlManifest>,
normalized_toml: Rc<TomlManifest>,
contents: Arc<String>,
document: Arc<toml_edit::ImDocument<String>>,
original_toml: Arc<TomlManifest>,
normalized_toml: Arc<TomlManifest>,
summary: Summary,

default_kind: Option<CompileKind>,
Expand Down Expand Up @@ -742,10 +741,10 @@ impl Manifest {

impl VirtualManifest {
pub fn new(
contents: Rc<String>,
document: Rc<toml_edit::ImDocument<String>>,
original_toml: Rc<TomlManifest>,
normalized_toml: Rc<TomlManifest>,
contents: Arc<String>,
document: Arc<toml_edit::ImDocument<String>>,
original_toml: Arc<TomlManifest>,
normalized_toml: Arc<TomlManifest>,
replace: Vec<(PackageIdSpec, Dependency)>,
patch: HashMap<Url, Vec<Dependency>>,
workspace: WorkspaceConfig,
Expand Down
10 changes: 5 additions & 5 deletions src/cargo/core/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _;
Expand Down Expand Up @@ -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<PackageInner>,
inner: Arc<PackageInner>,
}

#[derive(Clone)]
Expand Down Expand Up @@ -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(),
}),
Expand All @@ -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 {
Expand Down Expand Up @@ -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(),
}),
Expand Down
18 changes: 9 additions & 9 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1569,10 +1569,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,
Expand Down Expand Up @@ -1748,10 +1748,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,
Expand Down

0 comments on commit 3f36fcb

Please sign in to comment.