Skip to content

Commit fbd34a6

Browse files
alexcrichtonehuss
authored andcommitted
Hide Rc<Package> under Package
1 parent e0bd9e2 commit fbd34a6

File tree

7 files changed

+56
-47
lines changed

7 files changed

+56
-47
lines changed

src/cargo/core/compiler/compilation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::util::{self, config, join_paths, process, CargoResult, Config, Proces
1515
/// Structure with enough information to run `rustdoc --test`.
1616
pub struct Doctest {
1717
/// The package being doc-tested.
18-
pub package: Rc<Package>,
18+
pub package: Package,
1919
/// The target being tested (currently always the package's lib).
2020
pub target: Rc<Target>,
2121
/// Arguments needed to pass to rustdoc to run this test.
@@ -28,7 +28,7 @@ pub struct Doctest {
2828
pub struct Compilation<'cfg> {
2929
/// An array of all tests created during this compilation.
3030
/// `(package, target, path_to_test_exe)`
31-
pub tests: Vec<(Rc<Package>, Rc<Target>, PathBuf)>,
31+
pub tests: Vec<(Package, Rc<Target>, PathBuf)>,
3232

3333
/// An array of all binaries created.
3434
pub binaries: Vec<PathBuf>,

src/cargo/core/compiler/context/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
167167

168168
if unit.mode == CompileMode::Test {
169169
self.compilation.tests.push((
170-
Rc::clone(&unit.pkg),
170+
unit.pkg.clone(),
171171
Rc::clone(&unit.target),
172172
output.path.clone(),
173173
));
@@ -200,7 +200,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
200200
let mut unstable_opts = false;
201201
let args = compiler::extern_args(&self, unit, &mut unstable_opts)?;
202202
self.compilation.to_doc_test.push(compilation::Doctest {
203-
package: Rc::clone(&unit.pkg),
203+
package: unit.pkg.clone(),
204204
target: Rc::clone(&unit.target),
205205
args,
206206
unstable_opts,

src/cargo/core/compiler/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ fn build_base_args<'a, 'cfg>(
786786
}
787787

788788
let prefer_dynamic = (unit.target.for_host() && !unit.target.is_custom_build())
789-
|| (crate_types.contains(&"dylib") && bcx.ws.members().any(|p| p != &*unit.pkg));
789+
|| (crate_types.contains(&"dylib") && bcx.ws.members().any(|p| *p != unit.pkg));
790790
if prefer_dynamic {
791791
cmd.arg("-C").arg("prefer-dynamic");
792792
}

src/cargo/core/compiler/unit.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub struct Unit<'a> {
3333
pub struct UnitInner {
3434
/// Information about available targets, which files to include/exclude, etc. Basically stuff in
3535
/// `Cargo.toml`.
36-
pub pkg: Rc<Package>,
36+
pub pkg: Package,
3737
/// Information about the specific target to build, out of the possible targets in `pkg`. Not
3838
/// to be confused with *target-triple* (or *target architecture* ...), the target arch for a
3939
/// build.
@@ -142,7 +142,7 @@ impl UnitInterner {
142142
/// be the exact same instance.
143143
pub fn intern(
144144
&self,
145-
pkg: &Rc<Package>,
145+
pkg: &Package,
146146
target: &Rc<Target>,
147147
profile: Profile,
148148
kind: CompileKind,
@@ -172,7 +172,7 @@ impl UnitInterner {
172172
_ => Rc::clone(target),
173173
};
174174
let inner = self.intern_inner(&UnitInner {
175-
pkg: Rc::clone(pkg),
175+
pkg: pkg.clone(),
176176
target,
177177
profile,
178178
kind,

src/cargo/core/compiler/unit_dependencies.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ fn check_or_build_mode(mode: CompileMode, target: &Target) -> CompileMode {
581581
fn new_unit_dep<'unit>(
582582
state: &State<'_, 'unit, '_>,
583583
parent: &Unit<'unit>,
584-
pkg: &Rc<Package>,
584+
pkg: &Package,
585585
target: &Rc<Target>,
586586
unit_for: UnitFor,
587587
kind: CompileKind,
@@ -597,7 +597,7 @@ fn new_unit_dep<'unit>(
597597
fn new_unit_dep_with_profile<'unit>(
598598
state: &State<'_, 'unit, '_>,
599599
parent: &Unit<'unit>,
600-
pkg: &Rc<Package>,
600+
pkg: &Package,
601601
target: &Rc<Target>,
602602
unit_for: UnitFor,
603603
kind: CompileKind,
@@ -735,7 +735,7 @@ impl<'a, 'unit, 'cfg> State<'a, 'unit, 'cfg> {
735735
features.activated_features(pkg_id, features_for)
736736
}
737737

738-
fn get(&self, id: PackageId) -> &'a Rc<Package> {
738+
fn get(&self, id: PackageId) -> &'a Package {
739739
self.package_set
740740
.get_one(id)
741741
.unwrap_or_else(|_| panic!("expected {} to be downloaded", id))

src/cargo/core/package.rs

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ use crate::util::{self, internal, Config, Progress, ProgressStyle};
3838
// TODO: is `manifest_path` a relic?
3939
#[derive(Clone)]
4040
pub struct Package {
41+
inner: Rc<PackageInner>,
42+
}
43+
44+
#[derive(Clone)]
45+
struct PackageInner {
4146
/// The package's manifest.
4247
manifest: Manifest,
4348
/// The root of the package.
@@ -88,9 +93,9 @@ impl ser::Serialize for Package {
8893
where
8994
S: ser::Serializer,
9095
{
91-
let summary = self.manifest.summary();
96+
let summary = self.manifest().summary();
9297
let package_id = summary.package_id();
93-
let manmeta = self.manifest.metadata();
98+
let manmeta = self.manifest().metadata();
9499
let license = manmeta.license.as_deref();
95100
let license_file = manmeta.license_file.as_deref();
96101
let description = manmeta.description.as_deref();
@@ -103,7 +108,7 @@ impl ser::Serialize for Package {
103108
// detail that is probably not relevant externally. There's also not a
104109
// real path to show in `src_path`, and this avoids changing the format.
105110
let targets: Vec<&Target> = self
106-
.manifest
111+
.manifest()
107112
.targets()
108113
.iter()
109114
.filter(|t| t.src_path().is_path())
@@ -121,16 +126,16 @@ impl ser::Serialize for Package {
121126
dependencies: summary.dependencies(),
122127
targets,
123128
features: summary.features(),
124-
manifest_path: &self.manifest_path,
125-
metadata: self.manifest.custom_metadata(),
129+
manifest_path: self.manifest_path(),
130+
metadata: self.manifest().custom_metadata(),
126131
authors,
127132
categories,
128133
keywords,
129134
readme,
130135
repository,
131-
edition: &self.manifest.edition().to_string(),
132-
links: self.manifest.links(),
133-
metabuild: self.manifest.metabuild(),
136+
edition: &self.manifest().edition().to_string(),
137+
links: self.manifest().links(),
138+
metabuild: self.manifest().metabuild(),
134139
publish: self.publish().as_ref(),
135140
}
136141
.serialize(s)
@@ -141,58 +146,60 @@ impl Package {
141146
/// Creates a package from a manifest and its location.
142147
pub fn new(manifest: Manifest, manifest_path: &Path) -> Package {
143148
Package {
144-
manifest,
145-
manifest_path: manifest_path.to_path_buf(),
149+
inner: Rc::new(PackageInner {
150+
manifest,
151+
manifest_path: manifest_path.to_path_buf(),
152+
}),
146153
}
147154
}
148155

149156
/// Gets the manifest dependencies.
150157
pub fn dependencies(&self) -> &[Dependency] {
151-
self.manifest.dependencies()
158+
self.manifest().dependencies()
152159
}
153160
/// Gets the manifest.
154161
pub fn manifest(&self) -> &Manifest {
155-
&self.manifest
162+
&self.inner.manifest
156163
}
157164
/// Gets the manifest.
158165
pub fn manifest_mut(&mut self) -> &mut Manifest {
159-
&mut self.manifest
166+
&mut Rc::make_mut(&mut self.inner).manifest
160167
}
161168
/// Gets the path to the manifest.
162169
pub fn manifest_path(&self) -> &Path {
163-
&self.manifest_path
170+
&self.inner.manifest_path
164171
}
165172
/// Gets the name of the package.
166173
pub fn name(&self) -> InternedString {
167174
self.package_id().name()
168175
}
169176
/// Gets the `PackageId` object for the package (fully defines a package).
170177
pub fn package_id(&self) -> PackageId {
171-
self.manifest.package_id()
178+
self.manifest().package_id()
172179
}
173180
/// Gets the root folder of the package.
174181
pub fn root(&self) -> &Path {
175-
self.manifest_path.parent().unwrap()
182+
self.manifest_path().parent().unwrap()
176183
}
177184
/// Gets the summary for the package.
178185
pub fn summary(&self) -> &Summary {
179-
self.manifest.summary()
186+
self.manifest().summary()
180187
}
181188
/// Gets the targets specified in the manifest.
182189
pub fn targets(&self) -> &[Rc<Target>] {
183-
self.manifest.targets()
190+
self.manifest().targets()
184191
}
185192
/// Gets the current package version.
186193
pub fn version(&self) -> &Version {
187194
self.package_id().version()
188195
}
189196
/// Gets the package authors.
190197
pub fn authors(&self) -> &Vec<String> {
191-
&self.manifest.metadata().authors
198+
&self.manifest().metadata().authors
192199
}
193200
/// Returns `true` if the package is set to publish.
194201
pub fn publish(&self) -> &Option<Vec<String>> {
195-
self.manifest.publish()
202+
self.manifest().publish()
196203
}
197204
/// Returns `true` if this package is a proc-macro.
198205
pub fn proc_macro(&self) -> bool {
@@ -206,8 +213,10 @@ impl Package {
206213

207214
pub fn map_source(self, to_replace: SourceId, replace_with: SourceId) -> Package {
208215
Package {
209-
manifest: self.manifest.map_source(to_replace, replace_with),
210-
manifest_path: self.manifest_path,
216+
inner: Rc::new(PackageInner {
217+
manifest: self.manifest().clone().map_source(to_replace, replace_with),
218+
manifest_path: self.manifest_path().to_owned(),
219+
}),
211220
}
212221
}
213222

@@ -276,7 +285,7 @@ impl hash::Hash for Package {
276285
/// This is primarily used to convert a set of `PackageId`s to `Package`s. It
277286
/// will download as needed, or used the cached download if available.
278287
pub struct PackageSet<'cfg> {
279-
packages: HashMap<PackageId, LazyCell<Rc<Package>>>,
288+
packages: HashMap<PackageId, LazyCell<Package>>,
280289
sources: RefCell<SourceMap<'cfg>>,
281290
config: &'cfg Config,
282291
multi: Multi,
@@ -440,7 +449,7 @@ impl<'cfg> PackageSet<'cfg> {
440449
})
441450
}
442451

443-
pub fn get_one(&self, id: PackageId) -> CargoResult<&Rc<Package>> {
452+
pub fn get_one(&self, id: PackageId) -> CargoResult<&Package> {
444453
if let Some(pkg) = self.packages.get(&id).and_then(|slot| slot.borrow()) {
445454
return Ok(pkg);
446455
}
@@ -450,7 +459,7 @@ impl<'cfg> PackageSet<'cfg> {
450459
pub fn get_many(
451460
&self,
452461
ids: impl IntoIterator<Item = PackageId>,
453-
) -> CargoResult<Vec<&Rc<Package>>> {
462+
) -> CargoResult<Vec<&Package>> {
454463
let mut pkgs = Vec::new();
455464
let mut downloads = self.enable_download()?;
456465
for id in ids {
@@ -576,13 +585,13 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
576585
/// Returns `None` if the package is queued up for download and will
577586
/// eventually be returned from `wait_for_download`. Returns `Some(pkg)` if
578587
/// the package is ready and doesn't need to be downloaded.
579-
pub fn start(&mut self, id: PackageId) -> CargoResult<Option<&'a Rc<Package>>> {
588+
pub fn start(&mut self, id: PackageId) -> CargoResult<Option<&'a Package>> {
580589
Ok(self
581590
.start_inner(id)
582591
.chain_err(|| format!("failed to download `{}`", id))?)
583592
}
584593

585-
fn start_inner(&mut self, id: PackageId) -> CargoResult<Option<&'a Rc<Package>>> {
594+
fn start_inner(&mut self, id: PackageId) -> CargoResult<Option<&'a Package>> {
586595
// First up see if we've already cached this package, in which case
587596
// there's nothing to do.
588597
let slot = self
@@ -607,7 +616,7 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
607616
let (url, descriptor) = match pkg {
608617
MaybePackage::Ready(pkg) => {
609618
debug!("{} doesn't need a download", id);
610-
assert!(slot.fill(Rc::new(pkg)).is_ok());
619+
assert!(slot.fill(pkg).is_ok());
611620
return Ok(Some(slot.borrow().unwrap()));
612621
}
613622
MaybePackage::Download { url, descriptor } => (url, descriptor),
@@ -720,7 +729,7 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
720729
/// # Panics
721730
///
722731
/// This function will panic if there are no remaining downloads.
723-
pub fn wait(&mut self) -> CargoResult<&'a Rc<Package>> {
732+
pub fn wait(&mut self) -> CargoResult<&'a Package> {
724733
let (dl, data) = loop {
725734
assert_eq!(self.pending.len(), self.pending_ids.len());
726735
let (token, result) = self.wait_for_curl()?;
@@ -833,7 +842,7 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
833842
.set(self.next_speed_check.get() + finish_dur);
834843

835844
let slot = &self.set.packages[&dl.id];
836-
assert!(slot.fill(Rc::new(pkg)).is_ok());
845+
assert!(slot.fill(pkg).is_ok());
837846
Ok(slot.borrow().unwrap())
838847
}
839848

src/cargo/ops/cargo_compile.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ impl CompileFilter {
679679
/// not the target requires its features to be present.
680680
#[derive(Debug)]
681681
struct Proposal<'a> {
682-
pkg: &'a Rc<Package>,
682+
pkg: &'a Package,
683683
target: &'a Rc<Target>,
684684
/// Indicates whether or not all required features *must* be present. If
685685
/// false, and the features are not available, then it will be silently
@@ -693,7 +693,7 @@ struct Proposal<'a> {
693693
/// compile. Dependencies for these targets are computed later in `unit_dependencies`.
694694
fn generate_targets<'unit>(
695695
ws: &Workspace<'_>,
696-
packages: &[&Rc<Package>],
696+
packages: &[&Package],
697697
filter: &CompileFilter,
698698
default_arch_kind: CompileKind,
699699
mode: CompileMode,
@@ -705,7 +705,7 @@ fn generate_targets<'unit>(
705705
) -> CargoResult<Vec<Unit<'unit>>> {
706706
let config = ws.config();
707707
// Helper for creating a `Unit` struct.
708-
let new_unit = |pkg: &Rc<Package>, target: &Rc<Target>, target_mode: CompileMode| {
708+
let new_unit = |pkg: &Package, target: &Rc<Target>, target_mode: CompileMode| {
709709
let unit_for = if target_mode.is_any_test() {
710710
// NOTE: the `UnitFor` here is subtle. If you have a profile
711711
// with `panic` set, the `panic` flag is cleared for
@@ -1009,7 +1009,7 @@ fn filter_default_targets(targets: &[Rc<Target>], mode: CompileMode) -> Vec<&Rc<
10091009

10101010
/// Returns a list of proposed targets based on command-line target selection flags.
10111011
fn list_rule_targets<'a>(
1012-
packages: &[&'a Rc<Package>],
1012+
packages: &[&'a Package],
10131013
rule: &FilterRule,
10141014
target_desc: &'static str,
10151015
is_expected_kind: fn(&Target) -> bool,
@@ -1037,7 +1037,7 @@ fn list_rule_targets<'a>(
10371037

10381038
/// Finds the targets for a specifically named target.
10391039
fn find_named_targets<'a>(
1040-
packages: &[&'a Rc<Package>],
1040+
packages: &[&'a Package],
10411041
target_name: &str,
10421042
target_desc: &'static str,
10431043
is_expected_kind: fn(&Target) -> bool,
@@ -1063,7 +1063,7 @@ fn find_named_targets<'a>(
10631063
}
10641064

10651065
fn filter_targets<'a>(
1066-
packages: &[&'a Rc<Package>],
1066+
packages: &[&'a Package],
10671067
predicate: impl Fn(&Target) -> bool,
10681068
requires_features: bool,
10691069
mode: CompileMode,

0 commit comments

Comments
 (0)