Skip to content

Commit ccd7deb

Browse files
committed
improve comments
1 parent 3fd0fc9 commit ccd7deb

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

src/cargo/core/profiles.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -440,19 +440,15 @@ impl ProfileMaker {
440440
profile.codegen_units = None;
441441

442442
// For build dependencies, we usually don't need debuginfo, and
443-
// removing it will compile faster, much like the default opt-level
444-
// of 0 is chosen for faster builds. However, that can conflict with
443+
// removing it will compile faster. However, that can conflict with
445444
// a unit graph optimization, reusing units that are shared between
446445
// build dependencies and runtime dependencies: when the runtime
447446
// target is the same as the build host, we only need to build a
448447
// dependency once and reuse the results, instead of building twice.
449-
// If we then also change the default debuginfo level for build
450-
// dependencies, we can lose the sharing: build dependencies will be
451-
// built without debuginfo, while runtime dependencies require it by
452-
// default. So we allow cargo to weaken the debuginfo level: only if
453-
// there is not sharing already, will we disable debuginfo: if there
454-
// is no sharing, we will use the preferred value, and if there is
455-
// sharing we will use the explicit value set.
448+
// We defer the choice of the debuginfo level until we can check if
449+
// a unit is shared. If that's the case, we'll use the deferred value
450+
// below so the unit can be reused, otherwise we can avoid emitting
451+
// the unit's debuginfo.
456452
if let Some(debuginfo) = profile.debuginfo.to_option() {
457453
profile.debuginfo = DebugInfo::Deferred(debuginfo);
458454
}
@@ -726,9 +722,10 @@ impl Profile {
726722
}
727723
}
728724

729-
/// The debuginfo level in a given profile. This is semantically an
730-
/// `Option<u32>`, and should be used as so via the `to_option` method for all
731-
/// intents and purposes:
725+
/// The debuginfo level setting.
726+
///
727+
/// This is semantically an `Option<u32>`, and should be used as so via the
728+
/// [DebugInfo::to_option] method for all intents and purposes:
732729
/// - `DebugInfo::None` corresponds to `None`
733730
/// - `DebugInfo::Explicit(u32)` and `DebugInfo::Deferred` correspond to
734731
/// `Option<u32>::Some`
@@ -742,16 +739,19 @@ impl Profile {
742739
/// the unit is only built once and the unit graph is still optimized.
743740
#[derive(Debug, Copy, Clone)]
744741
pub enum DebugInfo {
745-
/// No debuginfo
742+
/// No debuginfo level was set.
746743
None,
747-
/// A debuginfo level that is explicitly set.
744+
/// A debuginfo level that is explicitly set, by a profile or a user.
748745
Explicit(u32),
749746
/// For internal purposes: a deferred debuginfo level that can be optimized
750-
/// away but has a default value otherwise.
751-
/// Behaves like `Explicit` in all situations except when dependencies are
752-
/// shared between build dependencies and runtime dependencies. The former
753-
/// case can be optimized, in all other situations this level value will be
754-
/// the one to use.
747+
/// away, but has this value otherwise.
748+
///
749+
/// Behaves like `Explicit` in all situations except for the default build
750+
/// dependencies profile: whenever a build dependency is not shared with
751+
/// runtime dependencies, this level is weakened to a lower level that is
752+
/// faster to build (see [DebugInfo::weaken]).
753+
///
754+
/// In all other situations, this level value will be the one to use.
755755
Deferred(u32),
756756
}
757757

src/cargo/ops/cargo_compile/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ fn traverse_and_share(
12731273
// target is the same as the host, we canonicalize the compile kind to `CompileKind::Host`.
12741274
// A possible host dependency counterpart to this unit would have that kind, and if such a unit
12751275
// 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
1276+
// The resulting unit graph will be optimized with less units, thanks to sharing these host
12771277
// dependencies.
12781278
let canonical_kind = if unit.kind == to_host {
12791279
CompileKind::Host
@@ -1287,12 +1287,12 @@ fn traverse_and_share(
12871287
// its debuginfo level to optimize build times.
12881288
if unit.kind.is_host() && profile.debuginfo.is_deferred() {
12891289
// We create a "probe" test to see if a unit with the same explicit debuginfo level exists
1290-
// in the graph. This is the level we'd expect if it was set manually, or a default set by
1291-
// a profile for a runtime dependency: its canonical value.
1290+
// in the graph. This is the level we'd expect if it was set manually or the default value
1291+
// set by a profile for a runtime dependency: its canonical value.
12921292
let canonical_debuginfo = profile.debuginfo.finalize();
12931293
let mut canonical_profile = profile.clone();
12941294
canonical_profile.debuginfo = canonical_debuginfo;
1295-
let explicit_unit_probe = interner.intern(
1295+
let unit_probe = interner.intern(
12961296
&unit.pkg,
12971297
&unit.target,
12981298
canonical_profile,
@@ -1305,7 +1305,7 @@ fn traverse_and_share(
13051305
);
13061306

13071307
// We can now turn the deferred value into its actual final value.
1308-
profile.debuginfo = if unit_graph.contains_key(&explicit_unit_probe) {
1308+
profile.debuginfo = if unit_graph.contains_key(&unit_probe) {
13091309
// The unit is present in both build time and runtime subgraphs: we canonicalize its
13101310
// level to the other unit's, thus ensuring reuse between the two to optimize build times.
13111311
canonical_debuginfo

0 commit comments

Comments
 (0)