Skip to content

Commit 45d4957

Browse files
alexcrichtonehuss
authored andcommitted
Make Unit an owned value
1 parent fbd34a6 commit 45d4957

File tree

17 files changed

+225
-213
lines changed

17 files changed

+225
-213
lines changed

src/cargo/core/compiler/build_context/target_info.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,13 @@ impl TargetInfo {
104104
.args(&rustflags)
105105
.env_remove("RUSTC_LOG");
106106

107-
let mut embed_bitcode_test = process.clone();
108-
embed_bitcode_test.arg("-Cembed-bitcode");
109-
let supports_embed_bitcode = match kind {
110-
CompileKind::Host => Some(rustc.cached_output(&embed_bitcode_test).is_ok()),
111-
_ => None,
112-
};
107+
// let mut embed_bitcode_test = process.clone();
108+
// embed_bitcode_test.arg("-Cembed-bitcode");
109+
// let supports_embed_bitcode = match kind {
110+
// CompileKind::Host => Some(rustc.cached_output(&embed_bitcode_test).is_ok()),
111+
// _ => None,
112+
// };
113+
let supports_embed_bitcode = Some(false);
113114

114115
if let CompileKind::Target(target) = kind {
115116
process.arg("--target").arg(target.rustc_target());

src/cargo/core/compiler/compilation.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::collections::{BTreeSet, HashMap, HashSet};
22
use std::env;
33
use std::ffi::{OsStr, OsString};
44
use std::path::PathBuf;
5-
use std::rc::Rc;
65

76
use cargo_platform::CfgExpr;
87
use semver::Version;
@@ -17,7 +16,7 @@ pub struct Doctest {
1716
/// The package being doc-tested.
1817
pub package: Package,
1918
/// The target being tested (currently always the package's lib).
20-
pub target: Rc<Target>,
19+
pub target: Target,
2120
/// Arguments needed to pass to rustdoc to run this test.
2221
pub args: Vec<OsString>,
2322
/// Whether or not -Zunstable-options is needed.
@@ -28,7 +27,7 @@ pub struct Doctest {
2827
pub struct Compilation<'cfg> {
2928
/// An array of all tests created during this compilation.
3029
/// `(package, target, path_to_test_exe)`
31-
pub tests: Vec<(Package, Rc<Target>, PathBuf)>,
30+
pub tests: Vec<(Package, Target, PathBuf)>,
3231

3332
/// An array of all binaries created.
3433
pub binaries: Vec<PathBuf>,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ fn metadata_of<'a, 'cfg>(
526526
) -> Option<Metadata> {
527527
if !metas.contains_key(unit) {
528528
let meta = compute_metadata(unit, cx, metas);
529-
metas.insert(*unit, meta);
529+
metas.insert(unit.clone(), meta);
530530
for dep in cx.unit_deps(unit) {
531531
metadata_of(&dep.unit, cx, metas);
532532
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![allow(deprecated)]
22
use std::collections::{BTreeSet, HashMap, HashSet};
33
use std::path::PathBuf;
4-
use std::rc::Rc;
54
use std::sync::{Arc, Mutex};
65

76
use filetime::FileTime;
@@ -168,7 +167,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
168167
if unit.mode == CompileMode::Test {
169168
self.compilation.tests.push((
170169
unit.pkg.clone(),
171-
Rc::clone(&unit.target),
170+
unit.target.clone(),
172171
output.path.clone(),
173172
));
174173
} else if unit.target.is_executable() {
@@ -201,7 +200,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
201200
let args = compiler::extern_args(&self, unit, &mut unstable_opts)?;
202201
self.compilation.to_doc_test.push(compilation::Doctest {
203202
package: unit.pkg.clone(),
204-
target: Rc::clone(&unit.target),
203+
target: unit.target.clone(),
205204
args,
206205
unstable_opts,
207206
});
@@ -343,7 +342,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
343342
unit_dep.unit.mode.is_run_custom_build()
344343
&& unit_dep.unit.pkg.package_id() == unit.pkg.package_id()
345344
})
346-
.map(|unit_dep| unit_dep.unit)
345+
.map(|unit_dep| unit_dep.unit.clone())
347346
}
348347

349348
/// Returns the metadata hash for the RunCustomBuild Unit associated with
@@ -488,7 +487,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
488487
for (key, deps) in self.bcx.unit_graph.iter() {
489488
for dep in deps {
490489
if self.only_requires_rmeta(key, &dep.unit) {
491-
self.rmeta_required.insert(dep.unit);
490+
self.rmeta_required.insert(dep.unit.clone());
492491
}
493492
}
494493
}

src/cargo/core/compiler/custom_build.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ pub fn build_map<'b, 'cfg>(cx: &mut Context<'b, 'cfg>) -> CargoResult<()> {
722722
// If a package has a build script, add itself as something to inspect for linking.
723723
if !unit.target.is_custom_build() && unit.pkg.has_custom_build() {
724724
let script_meta = cx
725-
.find_build_script_metadata(*unit)
725+
.find_build_script_metadata(unit.clone())
726726
.expect("has_custom_build should have RunCustomBuild");
727727
add_to_link(&mut ret, unit.pkg.package_id(), script_meta);
728728
}
@@ -736,7 +736,8 @@ pub fn build_map<'b, 'cfg>(cx: &mut Context<'b, 'cfg>) -> CargoResult<()> {
736736
// to rustc invocation caching schemes, so be sure to generate the same
737737
// set of build script dependency orderings via sorting the targets that
738738
// come out of the `Context`.
739-
let mut dependencies: Vec<Unit<'_>> = cx.unit_deps(unit).iter().map(|d| d.unit).collect();
739+
let mut dependencies: Vec<Unit<'_>> =
740+
cx.unit_deps(unit).iter().map(|d| d.unit.clone()).collect();
740741
dependencies.sort_by_key(|u| u.pkg.package_id());
741742

742743
for dep_unit in dependencies.iter() {
@@ -751,7 +752,7 @@ pub fn build_map<'b, 'cfg>(cx: &mut Context<'b, 'cfg>) -> CargoResult<()> {
751752
}
752753
}
753754

754-
match out.entry(*unit) {
755+
match out.entry(unit.clone()) {
755756
Entry::Vacant(entry) => Ok(entry.insert(ret)),
756757
Entry::Occupied(_) => panic!("cyclic dependencies in `build_map`"),
757758
}
@@ -773,7 +774,7 @@ pub fn build_map<'b, 'cfg>(cx: &mut Context<'b, 'cfg>) -> CargoResult<()> {
773774
let output_file = script_run_dir.join("output");
774775
let (prev_output, _) = prev_build_output(cx, unit);
775776
let deps = BuildDeps::new(&output_file, prev_output.as_ref());
776-
cx.build_explicit_deps.insert(*unit, deps);
777+
cx.build_explicit_deps.insert(unit.clone(), deps);
777778
Ok(())
778779
}
779780
}

src/cargo/core/compiler/fingerprint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ fn calculate<'a, 'cfg>(
11931193
fingerprint.check_filesystem(&mut cx.mtime_cache, unit.pkg.root(), &target_root)?;
11941194

11951195
let fingerprint = Arc::new(fingerprint);
1196-
cx.fingerprints.insert(*unit, Arc::clone(&fingerprint));
1196+
cx.fingerprints.insert(unit.clone(), Arc::clone(&fingerprint));
11971197
Ok(fingerprint)
11981198
}
11991199

src/cargo/core/compiler/job_queue.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> {
301301
} else {
302302
Artifact::All
303303
};
304-
(dep.unit, artifact)
304+
(dep.unit.clone(), artifact)
305305
})
306306
.collect::<HashMap<_, _>>();
307307

@@ -328,7 +328,7 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> {
328328
// transitively contains the `Metadata` edge.
329329
if unit.requires_upstream_objects() {
330330
for dep in dependencies {
331-
depend_on_deps_of_deps(cx, &mut queue_deps, dep.unit);
331+
depend_on_deps_of_deps(cx, &mut queue_deps, dep.unit.clone());
332332
}
333333

334334
fn depend_on_deps_of_deps<'a>(
@@ -337,14 +337,14 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> {
337337
unit: Unit<'a>,
338338
) {
339339
for dep in cx.unit_deps(&unit) {
340-
if deps.insert(dep.unit, Artifact::All).is_none() {
341-
depend_on_deps_of_deps(cx, deps, dep.unit);
340+
if deps.insert(dep.unit.clone(), Artifact::All).is_none() {
341+
depend_on_deps_of_deps(cx, deps, dep.unit.clone());
342342
}
343343
}
344344
}
345345
}
346346

347-
self.queue.queue(*unit, job, queue_deps);
347+
self.queue.queue(unit.clone(), job, queue_deps);
348348
*self.counts.entry(unit.pkg.package_id()).or_insert(0) += 1;
349349
Ok(())
350350
}
@@ -499,7 +499,7 @@ impl<'a, 'cfg> DrainState<'a, 'cfg> {
499499
.config
500500
.shell()
501501
.verbose(|c| c.status("Running", &cmd))?;
502-
self.timings.unit_start(id, self.active[&id]);
502+
self.timings.unit_start(id, self.active[&id].clone());
503503
}
504504
Message::BuildPlanMsg(module_name, cmd, filenames) => {
505505
plan.update(&module_name, &cmd, &filenames)?;
@@ -541,7 +541,7 @@ impl<'a, 'cfg> DrainState<'a, 'cfg> {
541541
// in there as we'll get another `Finish` later on.
542542
Artifact::Metadata => {
543543
info!("end (meta): {:?}", id);
544-
self.active[&id]
544+
self.active[&id].clone()
545545
}
546546
};
547547
info!("end ({:?}): {:?}", unit, result);
@@ -784,7 +784,7 @@ impl<'a, 'cfg> DrainState<'a, 'cfg> {
784784

785785
info!("start {}: {:?}", id, unit);
786786

787-
assert!(self.active.insert(id, *unit).is_none());
787+
assert!(self.active.insert(id, unit.clone()).is_none());
788788
*self.counts.get_mut(&unit.pkg.package_id()).unwrap() -= 1;
789789

790790
let messages = self.messages.clone();
@@ -862,7 +862,7 @@ impl<'a, 'cfg> DrainState<'a, 'cfg> {
862862
cx: &mut Context<'a, '_>,
863863
) -> CargoResult<()> {
864864
let outputs = cx.build_script_outputs.lock().unwrap();
865-
let metadata = match cx.find_build_script_metadata(*unit) {
865+
let metadata = match cx.find_build_script_metadata(unit.clone()) {
866866
Some(metadata) => metadata,
867867
None => return Ok(()),
868868
};

src/cargo/core/compiler/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ fn compile<'a, 'cfg: 'a>(
109109
) -> CargoResult<()> {
110110
let bcx = cx.bcx;
111111
let build_plan = bcx.build_config.build_plan;
112-
if !cx.compiled.insert(*unit) {
112+
if !cx.compiled.insert(unit.clone()) {
113113
return Ok(());
114114
}
115115

@@ -226,7 +226,7 @@ fn rustc<'a, 'cfg>(
226226
.unwrap_or_else(|| cx.bcx.config.cwd())
227227
.to_path_buf();
228228
let fingerprint_dir = cx.files().fingerprint_dir(unit);
229-
let script_metadata = cx.find_build_script_metadata(*unit);
229+
let script_metadata = cx.find_build_script_metadata(unit.clone());
230230

231231
return Ok(Work::new(move |state| {
232232
// Only at runtime have we discovered what the extra -L and -l
@@ -550,7 +550,7 @@ fn prepare_rustc<'a, 'cfg>(
550550
let client = cx.new_jobserver()?;
551551
base.inherit_jobserver(&client);
552552
base.arg("-Zjobserver-token-requests");
553-
assert!(cx.rustc_clients.insert(*unit, client).is_none());
553+
assert!(cx.rustc_clients.insert(unit.clone(), client).is_none());
554554
} else {
555555
base.inherit_jobserver(&cx.jobserver);
556556
}
@@ -602,7 +602,7 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult
602602
let target = Target::clone(&unit.target);
603603
let mut output_options = OutputOptions::new(cx, unit);
604604
let pkg_id = unit.pkg.package_id();
605-
let script_metadata = cx.find_build_script_metadata(*unit);
605+
let script_metadata = cx.find_build_script_metadata(unit.clone());
606606

607607
Ok(Work::new(move |state| {
608608
if let Some(script_metadata) = script_metadata {

src/cargo/core/compiler/output_depinfo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn add_deps_for_unit<'a, 'b>(
5454
unit: &Unit<'a>,
5555
visited: &mut HashSet<Unit<'a>>,
5656
) -> CargoResult<()> {
57-
if !visited.insert(*unit) {
57+
if !visited.insert(unit.clone()) {
5858
return Ok(());
5959
}
6060

@@ -80,7 +80,7 @@ fn add_deps_for_unit<'a, 'b>(
8080
}
8181

8282
// Add rerun-if-changed dependencies
83-
if let Some(metadata) = cx.find_build_script_metadata(*unit) {
83+
if let Some(metadata) = cx.find_build_script_metadata(unit.clone()) {
8484
if let Some(output) = cx
8585
.build_script_outputs
8686
.lock()

src/cargo/core/compiler/timings.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl<'a, 'cfg> Timings<'a, 'cfg> {
193193
let t = d_as_f64(self.start.elapsed());
194194
unit_time.rmeta_time = Some(t - unit_time.start);
195195
assert!(unit_time.unlocked_rmeta_units.is_empty());
196-
unit_time.unlocked_rmeta_units.extend(unlocked);
196+
unit_time.unlocked_rmeta_units.extend(unlocked.iter().cloned().cloned());
197197
}
198198

199199
/// Mark that a unit has finished running.
@@ -209,7 +209,7 @@ impl<'a, 'cfg> Timings<'a, 'cfg> {
209209
let t = d_as_f64(self.start.elapsed());
210210
unit_time.duration = t - unit_time.start;
211211
assert!(unit_time.unlocked_units.is_empty());
212-
unit_time.unlocked_units.extend(unlocked);
212+
unit_time.unlocked_units.extend(unlocked.iter().cloned().cloned());
213213
if self.report_info {
214214
let msg = format!(
215215
"{}{} in {:.1}s",
@@ -460,7 +460,7 @@ impl<'a, 'cfg> Timings<'a, 'cfg> {
460460
.unit_times
461461
.iter()
462462
.enumerate()
463-
.map(|(i, ut)| (ut.unit, i))
463+
.map(|(i, ut)| (ut.unit.clone(), i))
464464
.collect();
465465
#[derive(serde::Serialize)]
466466
struct UnitData {

0 commit comments

Comments
 (0)