Skip to content

Commit

Permalink
Make Unit an owned value
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Apr 6, 2020
1 parent 3476f53 commit 28cf4c2
Show file tree
Hide file tree
Showing 17 changed files with 225 additions and 213 deletions.
13 changes: 7 additions & 6 deletions src/cargo/core/compiler/build_context/target_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,13 @@ impl TargetInfo {
.args(&rustflags)
.env_remove("RUSTC_LOG");

let mut embed_bitcode_test = process.clone();
embed_bitcode_test.arg("-Cembed-bitcode");
let supports_embed_bitcode = match kind {
CompileKind::Host => Some(rustc.cached_output(&embed_bitcode_test).is_ok()),
_ => None,
};
// let mut embed_bitcode_test = process.clone();
// embed_bitcode_test.arg("-Cembed-bitcode");
// let supports_embed_bitcode = match kind {
// CompileKind::Host => Some(rustc.cached_output(&embed_bitcode_test).is_ok()),
// _ => None,
// };
let supports_embed_bitcode = Some(false);

if let CompileKind::Target(target) = kind {
process.arg("--target").arg(target.rustc_target());
Expand Down
5 changes: 2 additions & 3 deletions src/cargo/core/compiler/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::collections::{BTreeSet, HashMap, HashSet};
use std::env;
use std::ffi::{OsStr, OsString};
use std::path::PathBuf;
use std::rc::Rc;

use cargo_platform::CfgExpr;
use semver::Version;
Expand All @@ -17,7 +16,7 @@ pub struct Doctest {
/// The package being doc-tested.
pub package: Package,
/// The target being tested (currently always the package's lib).
pub target: Rc<Target>,
pub target: Target,
/// Arguments needed to pass to rustdoc to run this test.
pub args: Vec<OsString>,
/// Whether or not -Zunstable-options is needed.
Expand All @@ -28,7 +27,7 @@ pub struct Doctest {
pub struct Compilation<'cfg> {
/// An array of all tests created during this compilation.
/// `(package, target, path_to_test_exe)`
pub tests: Vec<(Package, Rc<Target>, PathBuf)>,
pub tests: Vec<(Package, Target, PathBuf)>,

/// An array of all binaries created.
pub binaries: Vec<PathBuf>,
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/context/compilation_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ fn metadata_of<'a, 'cfg>(
) -> Option<Metadata> {
if !metas.contains_key(unit) {
let meta = compute_metadata(unit, cx, metas);
metas.insert(*unit, meta);
metas.insert(unit.clone(), meta);
for dep in cx.unit_deps(unit) {
metadata_of(&dep.unit, cx, metas);
}
Expand Down
9 changes: 4 additions & 5 deletions src/cargo/core/compiler/context/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![allow(deprecated)]
use std::collections::{BTreeSet, HashMap, HashSet};
use std::path::PathBuf;
use std::rc::Rc;
use std::sync::{Arc, Mutex};

use filetime::FileTime;
Expand Down Expand Up @@ -168,7 +167,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
if unit.mode == CompileMode::Test {
self.compilation.tests.push((
unit.pkg.clone(),
Rc::clone(&unit.target),
unit.target.clone(),
output.path.clone(),
));
} else if unit.target.is_executable() {
Expand Down Expand Up @@ -201,7 +200,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
let args = compiler::extern_args(&self, unit, &mut unstable_opts)?;
self.compilation.to_doc_test.push(compilation::Doctest {
package: unit.pkg.clone(),
target: Rc::clone(&unit.target),
target: unit.target.clone(),
args,
unstable_opts,
});
Expand Down Expand Up @@ -343,7 +342,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
unit_dep.unit.mode.is_run_custom_build()
&& unit_dep.unit.pkg.package_id() == unit.pkg.package_id()
})
.map(|unit_dep| unit_dep.unit)
.map(|unit_dep| unit_dep.unit.clone())
}

/// Returns the metadata hash for the RunCustomBuild Unit associated with
Expand Down Expand Up @@ -488,7 +487,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
for (key, deps) in self.bcx.unit_graph.iter() {
for dep in deps {
if self.only_requires_rmeta(key, &dep.unit) {
self.rmeta_required.insert(dep.unit);
self.rmeta_required.insert(dep.unit.clone());
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/cargo/core/compiler/custom_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ pub fn build_map<'b, 'cfg>(cx: &mut Context<'b, 'cfg>) -> CargoResult<()> {
// If a package has a build script, add itself as something to inspect for linking.
if !unit.target.is_custom_build() && unit.pkg.has_custom_build() {
let script_meta = cx
.find_build_script_metadata(*unit)
.find_build_script_metadata(unit.clone())
.expect("has_custom_build should have RunCustomBuild");
add_to_link(&mut ret, unit.pkg.package_id(), script_meta);
}
Expand All @@ -736,7 +736,8 @@ pub fn build_map<'b, 'cfg>(cx: &mut Context<'b, 'cfg>) -> CargoResult<()> {
// to rustc invocation caching schemes, so be sure to generate the same
// set of build script dependency orderings via sorting the targets that
// come out of the `Context`.
let mut dependencies: Vec<Unit<'_>> = cx.unit_deps(unit).iter().map(|d| d.unit).collect();
let mut dependencies: Vec<Unit<'_>> =
cx.unit_deps(unit).iter().map(|d| d.unit.clone()).collect();
dependencies.sort_by_key(|u| u.pkg.package_id());

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

match out.entry(*unit) {
match out.entry(unit.clone()) {
Entry::Vacant(entry) => Ok(entry.insert(ret)),
Entry::Occupied(_) => panic!("cyclic dependencies in `build_map`"),
}
Expand All @@ -773,7 +774,7 @@ pub fn build_map<'b, 'cfg>(cx: &mut Context<'b, 'cfg>) -> CargoResult<()> {
let output_file = script_run_dir.join("output");
let (prev_output, _) = prev_build_output(cx, unit);
let deps = BuildDeps::new(&output_file, prev_output.as_ref());
cx.build_explicit_deps.insert(*unit, deps);
cx.build_explicit_deps.insert(unit.clone(), deps);
Ok(())
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ fn calculate<'a, 'cfg>(
fingerprint.check_filesystem(&mut cx.mtime_cache, unit.pkg.root(), &target_root)?;

let fingerprint = Arc::new(fingerprint);
cx.fingerprints.insert(*unit, Arc::clone(&fingerprint));
cx.fingerprints.insert(unit.clone(), Arc::clone(&fingerprint));
Ok(fingerprint)
}

Expand Down
18 changes: 9 additions & 9 deletions src/cargo/core/compiler/job_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> {
} else {
Artifact::All
};
(dep.unit, artifact)
(dep.unit.clone(), artifact)
})
.collect::<HashMap<_, _>>();

Expand All @@ -329,7 +329,7 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> {
// transitively contains the `Metadata` edge.
if unit.requires_upstream_objects() {
for dep in dependencies {
depend_on_deps_of_deps(cx, &mut queue_deps, dep.unit);
depend_on_deps_of_deps(cx, &mut queue_deps, dep.unit.clone());
}

fn depend_on_deps_of_deps<'a>(
Expand All @@ -338,14 +338,14 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> {
unit: Unit<'a>,
) {
for dep in cx.unit_deps(&unit) {
if deps.insert(dep.unit, Artifact::All).is_none() {
depend_on_deps_of_deps(cx, deps, dep.unit);
if deps.insert(dep.unit.clone(), Artifact::All).is_none() {
depend_on_deps_of_deps(cx, deps, dep.unit.clone());
}
}
}
}

self.queue.queue(*unit, job, queue_deps);
self.queue.queue(unit.clone(), job, queue_deps);
*self.counts.entry(unit.pkg.package_id()).or_insert(0) += 1;
Ok(())
}
Expand Down Expand Up @@ -500,7 +500,7 @@ impl<'a, 'cfg> DrainState<'a, 'cfg> {
.config
.shell()
.verbose(|c| c.status("Running", &cmd))?;
self.timings.unit_start(id, self.active[&id]);
self.timings.unit_start(id, self.active[&id].clone());
}
Message::BuildPlanMsg(module_name, cmd, filenames) => {
plan.update(&module_name, &cmd, &filenames)?;
Expand Down Expand Up @@ -542,7 +542,7 @@ impl<'a, 'cfg> DrainState<'a, 'cfg> {
// in there as we'll get another `Finish` later on.
Artifact::Metadata => {
info!("end (meta): {:?}", id);
self.active[&id]
self.active[&id].clone()
}
};
info!("end ({:?}): {:?}", unit, result);
Expand Down Expand Up @@ -778,7 +778,7 @@ impl<'a, 'cfg> DrainState<'a, 'cfg> {

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

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

let messages = self.messages.clone();
Expand Down Expand Up @@ -856,7 +856,7 @@ impl<'a, 'cfg> DrainState<'a, 'cfg> {
cx: &mut Context<'a, '_>,
) -> CargoResult<()> {
let outputs = cx.build_script_outputs.lock().unwrap();
let metadata = match cx.find_build_script_metadata(*unit) {
let metadata = match cx.find_build_script_metadata(unit.clone()) {
Some(metadata) => metadata,
None => return Ok(()),
};
Expand Down
8 changes: 4 additions & 4 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fn compile<'a, 'cfg: 'a>(
) -> CargoResult<()> {
let bcx = cx.bcx;
let build_plan = bcx.build_config.build_plan;
if !cx.compiled.insert(*unit) {
if !cx.compiled.insert(unit.clone()) {
return Ok(());
}

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

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

Ok(Work::new(move |state| {
if let Some(script_metadata) = script_metadata {
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/core/compiler/output_depinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn add_deps_for_unit<'a, 'b>(
unit: &Unit<'a>,
visited: &mut HashSet<Unit<'a>>,
) -> CargoResult<()> {
if !visited.insert(*unit) {
if !visited.insert(unit.clone()) {
return Ok(());
}

Expand All @@ -80,7 +80,7 @@ fn add_deps_for_unit<'a, 'b>(
}

// Add rerun-if-changed dependencies
if let Some(metadata) = cx.find_build_script_metadata(*unit) {
if let Some(metadata) = cx.find_build_script_metadata(unit.clone()) {
if let Some(output) = cx
.build_script_outputs
.lock()
Expand Down
6 changes: 3 additions & 3 deletions src/cargo/core/compiler/timings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl<'a, 'cfg> Timings<'a, 'cfg> {
let t = d_as_f64(self.start.elapsed());
unit_time.rmeta_time = Some(t - unit_time.start);
assert!(unit_time.unlocked_rmeta_units.is_empty());
unit_time.unlocked_rmeta_units.extend(unlocked);
unit_time.unlocked_rmeta_units.extend(unlocked.iter().cloned().cloned());
}

/// Mark that a unit has finished running.
Expand All @@ -209,7 +209,7 @@ impl<'a, 'cfg> Timings<'a, 'cfg> {
let t = d_as_f64(self.start.elapsed());
unit_time.duration = t - unit_time.start;
assert!(unit_time.unlocked_units.is_empty());
unit_time.unlocked_units.extend(unlocked);
unit_time.unlocked_units.extend(unlocked.iter().cloned().cloned());
if self.report_info {
let msg = format!(
"{}{} in {:.1}s",
Expand Down Expand Up @@ -460,7 +460,7 @@ impl<'a, 'cfg> Timings<'a, 'cfg> {
.unit_times
.iter()
.enumerate()
.map(|(i, ut)| (ut.unit, i))
.map(|(i, ut)| (ut.unit.clone(), i))
.collect();
#[derive(serde::Serialize)]
struct UnitData {
Expand Down
Loading

0 comments on commit 28cf4c2

Please sign in to comment.