Skip to content

Commit 3fd0fc9

Browse files
committed
slightly clarify unit graph sharing
1 parent 634e9f4 commit 3fd0fc9

File tree

1 file changed

+11
-2
lines changed
  • src/cargo/ops/cargo_compile

1 file changed

+11
-2
lines changed

src/cargo/ops/cargo_compile/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,8 +1265,17 @@ fn traverse_and_share(
12651265
}
12661266
})
12671267
.collect();
1268+
// Here, we have recursively traversed this unit's dependencies, and hashed them: we can
1269+
// finalize the dep hash.
12681270
let new_dep_hash = dep_hash.finish();
1269-
let new_kind = if unit.kind == to_host {
1271+
1272+
// This is the key part of the sharing process: if the unit is a runtime dependency, whose
1273+
// target is the same as the host, we canonicalize the compile kind to `CompileKind::Host`.
1274+
// A possible host dependency counterpart to this unit would have that kind, and if such a unit
1275+
// exists in the current `unit_graph`, they will unify in the new unit graph map `new_graph`.
1276+
// The resulting unit graph will have be optimized with less units, thanks to sharing these host
1277+
// dependencies.
1278+
let canonical_kind = if unit.kind == to_host {
12701279
CompileKind::Host
12711280
} else {
12721281
unit.kind
@@ -1311,7 +1320,7 @@ fn traverse_and_share(
13111320
&unit.pkg,
13121321
&unit.target,
13131322
profile,
1314-
new_kind,
1323+
canonical_kind,
13151324
unit.mode,
13161325
unit.features.clone(),
13171326
unit.is_std,

0 commit comments

Comments
 (0)