Skip to content

Commit 5ba40a8

Browse files
committed
feat: make package sync by using Arc not Rc
1 parent adf9b6a commit 5ba40a8

File tree

3 files changed

+30
-31
lines changed

3 files changed

+30
-31
lines changed

src/cargo/core/manifest.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::collections::{BTreeMap, HashMap};
33
use std::fmt;
44
use std::hash::{Hash, Hasher};
55
use std::path::{Path, PathBuf};
6-
use std::rc::Rc;
76
use std::sync::Arc;
87

98
use anyhow::Context as _;
@@ -62,10 +61,10 @@ impl EitherManifest {
6261
#[derive(Clone, Debug)]
6362
pub struct Manifest {
6463
// alternate forms of manifests:
65-
contents: Rc<String>,
66-
document: Rc<toml_edit::ImDocument<String>>,
67-
original_toml: Rc<TomlManifest>,
68-
normalized_toml: Rc<TomlManifest>,
64+
contents: Arc<String>,
65+
document: Arc<toml_edit::ImDocument<String>>,
66+
original_toml: Arc<TomlManifest>,
67+
normalized_toml: Arc<TomlManifest>,
6968
summary: Summary,
7069

7170
// this form of manifest:
@@ -108,10 +107,10 @@ pub struct Warnings(Vec<DelayedWarning>);
108107
#[derive(Clone, Debug)]
109108
pub struct VirtualManifest {
110109
// alternate forms of manifests:
111-
contents: Rc<String>,
112-
document: Rc<toml_edit::ImDocument<String>>,
113-
original_toml: Rc<TomlManifest>,
114-
normalized_toml: Rc<TomlManifest>,
110+
contents: Arc<String>,
111+
document: Arc<toml_edit::ImDocument<String>>,
112+
original_toml: Arc<TomlManifest>,
113+
normalized_toml: Arc<TomlManifest>,
115114

116115
// this form of manifest:
117116
replace: Vec<(PackageIdSpec, Dependency)>,
@@ -484,10 +483,10 @@ compact_debug! {
484483

485484
impl Manifest {
486485
pub fn new(
487-
contents: Rc<String>,
488-
document: Rc<toml_edit::ImDocument<String>>,
489-
original_toml: Rc<TomlManifest>,
490-
normalized_toml: Rc<TomlManifest>,
486+
contents: Arc<String>,
487+
document: Arc<toml_edit::ImDocument<String>>,
488+
original_toml: Arc<TomlManifest>,
489+
normalized_toml: Arc<TomlManifest>,
491490
summary: Summary,
492491

493492
default_kind: Option<CompileKind>,
@@ -726,10 +725,10 @@ impl Manifest {
726725

727726
impl VirtualManifest {
728727
pub fn new(
729-
contents: Rc<String>,
730-
document: Rc<toml_edit::ImDocument<String>>,
731-
original_toml: Rc<TomlManifest>,
732-
normalized_toml: Rc<TomlManifest>,
728+
contents: Arc<String>,
729+
document: Arc<toml_edit::ImDocument<String>>,
730+
original_toml: Arc<TomlManifest>,
731+
normalized_toml: Arc<TomlManifest>,
733732
replace: Vec<(PackageIdSpec, Dependency)>,
734733
patch: HashMap<Url, Vec<Dependency>>,
735734
workspace: WorkspaceConfig,

src/cargo/core/package.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::fmt;
55
use std::hash;
66
use std::mem;
77
use std::path::{Path, PathBuf};
8-
use std::rc::Rc;
8+
use std::sync::Arc;
99
use std::time::{Duration, Instant};
1010

1111
use anyhow::Context as _;
@@ -42,7 +42,7 @@ use crate::util::{self, internal, GlobalContext, Progress, ProgressStyle};
4242
/// A package is a `Cargo.toml` file plus all the files that are part of it.
4343
#[derive(Clone)]
4444
pub struct Package {
45-
inner: Rc<PackageInner>,
45+
inner: Arc<PackageInner>,
4646
}
4747

4848
#[derive(Clone)]
@@ -101,7 +101,7 @@ impl Package {
101101
/// Creates a package from a manifest and its location.
102102
pub fn new(manifest: Manifest, manifest_path: &Path) -> Package {
103103
Package {
104-
inner: Rc::new(PackageInner {
104+
inner: Arc::new(PackageInner {
105105
manifest,
106106
manifest_path: manifest_path.to_path_buf(),
107107
}),
@@ -118,7 +118,7 @@ impl Package {
118118
}
119119
/// Gets the manifest.
120120
pub fn manifest_mut(&mut self) -> &mut Manifest {
121-
&mut Rc::make_mut(&mut self.inner).manifest
121+
&mut Arc::make_mut(&mut self.inner).manifest
122122
}
123123
/// Gets the path to the manifest.
124124
pub fn manifest_path(&self) -> &Path {
@@ -179,7 +179,7 @@ impl Package {
179179

180180
pub fn map_source(self, to_replace: SourceId, replace_with: SourceId) -> Package {
181181
Package {
182-
inner: Rc::new(PackageInner {
182+
inner: Arc::new(PackageInner {
183183
manifest: self.manifest().clone().map_source(to_replace, replace_with),
184184
manifest_path: self.manifest_path().to_owned(),
185185
}),

src/cargo/util/toml/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use std::borrow::Cow;
33
use std::collections::{BTreeMap, BTreeSet, HashMap};
44
use std::ffi::OsStr;
55
use std::path::{Path, PathBuf};
6-
use std::rc::Rc;
76
use std::str::{self, FromStr};
7+
use std::sync::Arc;
88

99
use crate::core::summary::MissingDependencyError;
1010
use crate::AlreadyPrintedError;
@@ -1751,10 +1751,10 @@ pub fn to_real_manifest(
17511751
let default_run = normalized_package.default_run.clone();
17521752
let metabuild = normalized_package.metabuild.clone().map(|sov| sov.0);
17531753
let manifest = Manifest::new(
1754-
Rc::new(contents),
1755-
Rc::new(document),
1756-
Rc::new(original_toml),
1757-
Rc::new(normalized_toml),
1754+
Arc::new(contents),
1755+
Arc::new(document),
1756+
Arc::new(original_toml),
1757+
Arc::new(normalized_toml),
17581758
summary,
17591759
default_kind,
17601760
forced_kind,
@@ -1930,10 +1930,10 @@ fn to_virtual_manifest(
19301930
bail!("virtual manifests must be configured with [workspace]");
19311931
}
19321932
let manifest = VirtualManifest::new(
1933-
Rc::new(contents),
1934-
Rc::new(document),
1935-
Rc::new(original_toml),
1936-
Rc::new(normalized_toml),
1933+
Arc::new(contents),
1934+
Arc::new(document),
1935+
Arc::new(original_toml),
1936+
Arc::new(normalized_toml),
19371937
replace,
19381938
patch,
19391939
workspace_config,

0 commit comments

Comments
 (0)