Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make package, manifest and virtualManfest sync by using Arc not Rc #14837

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading