Skip to content

Commit 3f36fcb

Browse files
committed
feat: make package sync by using Arc not Rc
1 parent d73d2ca commit 3f36fcb

File tree

3 files changed

+30
-31
lines changed

3 files changed

+30
-31
lines changed

src/cargo/core/manifest.rs

+16-17
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)>,
@@ -500,10 +499,10 @@ compact_debug! {
500499

501500
impl Manifest {
502501
pub fn new(
503-
contents: Rc<String>,
504-
document: Rc<toml_edit::ImDocument<String>>,
505-
original_toml: Rc<TomlManifest>,
506-
normalized_toml: Rc<TomlManifest>,
502+
contents: Arc<String>,
503+
document: Arc<toml_edit::ImDocument<String>>,
504+
original_toml: Arc<TomlManifest>,
505+
normalized_toml: Arc<TomlManifest>,
507506
summary: Summary,
508507

509508
default_kind: Option<CompileKind>,
@@ -742,10 +741,10 @@ impl Manifest {
742741

743742
impl VirtualManifest {
744743
pub fn new(
745-
contents: Rc<String>,
746-
document: Rc<toml_edit::ImDocument<String>>,
747-
original_toml: Rc<TomlManifest>,
748-
normalized_toml: Rc<TomlManifest>,
744+
contents: Arc<String>,
745+
document: Arc<toml_edit::ImDocument<String>>,
746+
original_toml: Arc<TomlManifest>,
747+
normalized_toml: Arc<TomlManifest>,
749748
replace: Vec<(PackageIdSpec, Dependency)>,
750749
patch: HashMap<Url, Vec<Dependency>>,
751750
workspace: WorkspaceConfig,

src/cargo/core/package.rs

+5-5
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

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use annotate_snippets::{Level, Snippet};
22
use std::collections::{BTreeMap, BTreeSet, HashMap};
33
use std::ffi::OsStr;
44
use std::path::{Path, PathBuf};
5-
use std::rc::Rc;
65
use std::str::{self, FromStr};
6+
use std::sync::Arc;
77

88
use crate::core::summary::MissingDependencyError;
99
use crate::AlreadyPrintedError;
@@ -1569,10 +1569,10 @@ pub fn to_real_manifest(
15691569
let default_run = normalized_package.default_run.clone();
15701570
let metabuild = normalized_package.metabuild.clone().map(|sov| sov.0);
15711571
let manifest = Manifest::new(
1572-
Rc::new(contents),
1573-
Rc::new(document),
1574-
Rc::new(original_toml),
1575-
Rc::new(normalized_toml),
1572+
Arc::new(contents),
1573+
Arc::new(document),
1574+
Arc::new(original_toml),
1575+
Arc::new(normalized_toml),
15761576
summary,
15771577
default_kind,
15781578
forced_kind,
@@ -1748,10 +1748,10 @@ fn to_virtual_manifest(
17481748
bail!("virtual manifests must be configured with [workspace]");
17491749
}
17501750
let manifest = VirtualManifest::new(
1751-
Rc::new(contents),
1752-
Rc::new(document),
1753-
Rc::new(original_toml),
1754-
Rc::new(normalized_toml),
1751+
Arc::new(contents),
1752+
Arc::new(document),
1753+
Arc::new(original_toml),
1754+
Arc::new(normalized_toml),
17551755
replace,
17561756
patch,
17571757
workspace_config,

0 commit comments

Comments
 (0)