Skip to content

Commit 70898e5

Browse files
committed
Auto merge of #11458 - weihanglo:doc/unit-generator, r=epage
Rename `generate_units` -> `generate_root_units`
2 parents 7bdb969 + 6683e39 commit 70898e5

File tree

4 files changed

+31
-14
lines changed

4 files changed

+31
-14
lines changed

src/cargo/ops/cargo_compile/compile_filter.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ pub enum FilterRule {
2828
/// Filter to apply to the root package to select which Cargo targets will be built.
2929
/// (examples, bins, benches, tests, ...)
3030
///
31-
/// The actual filter process happens inside [`generate_units`].
31+
/// The actual filter process happens inside [`generate_root_units`].
3232
///
3333
/// Not to be confused with [`Packages`], which opts in packages to be built.
3434
///
35-
/// [`generate_units`]: super::UnitGenerator::generate_units
35+
/// [`generate_root_units`]: super::UnitGenerator::generate_root_units
3636
/// [`Packages`]: crate::ops::Packages
3737
#[derive(Debug)]
3838
pub enum CompileFilter {
@@ -175,8 +175,11 @@ impl CompileFilter {
175175
/// all targets with `tested` flag on, whereas [`CompileFilter::Default`]
176176
/// may include additional example targets to ensure they can be compiled.
177177
///
178-
/// Note that the actual behavior is subject to `filter_default_targets`
179-
/// and `generate_units` though.
178+
/// Note that the actual behavior is subject to [`filter_default_targets`]
179+
/// and [`generate_root_units`] though.
180+
///
181+
/// [`generate_root_units`]: super::UnitGenerator::generate_root_units
182+
/// [`filter_default_targets`]: super::UnitGenerator::filter_default_targets
180183
pub fn all_test_targets() -> Self {
181184
Self::Only {
182185
all_targets: false,
@@ -234,7 +237,10 @@ impl CompileFilter {
234237
}
235238

236239
/// Selects targets for "cargo run". for logic to select targets for other
237-
/// subcommands, see `generate_units` and `filter_default_targets`.
240+
/// subcommands, see [`generate_root_units`] and [`filter_default_targets`].
241+
///
242+
/// [`generate_root_units`]: super::UnitGenerator::generate_root_units
243+
/// [`filter_default_targets`]: super::UnitGenerator::filter_default_targets
238244
pub fn target_run(&self, target: &Target) -> bool {
239245
match *self {
240246
CompileFilter::Default { .. } => true,

src/cargo/ops/cargo_compile/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//! - Download any packages needed (see [`PackageSet`](crate::core::PackageSet)).
1111
//! - Generate a list of top-level "units" of work for the targets the user
1212
//! requested on the command-line. Each [`Unit`] corresponds to a compiler
13-
//! invocation. This is done in this module ([`UnitGenerator::generate_units`]).
13+
//! invocation. This is done in this module ([`UnitGenerator::generate_root_units`]).
1414
//! - Build the graph of `Unit` dependencies (see [`unit_dependencies`]).
1515
//! - Create a [`Context`] which will perform the following steps:
1616
//! - Prepare the `target` directory (see [`Layout`]).
@@ -344,7 +344,7 @@ pub fn create_bcx<'a, 'cfg>(
344344
.collect();
345345

346346
// Passing `build_config.requested_kinds` instead of
347-
// `explicit_host_kinds` here so that `generate_units` can do
347+
// `explicit_host_kinds` here so that `generate_root_units` can do
348348
// its own special handling of `CompileKind::Host`. It will
349349
// internally replace the host kind by the `explicit_host_kind`
350350
// before setting as a unit.
@@ -363,7 +363,7 @@ pub fn create_bcx<'a, 'cfg>(
363363
interner,
364364
has_dev_units,
365365
};
366-
let mut units = generator.generate_units()?;
366+
let mut units = generator.generate_root_units()?;
367367

368368
if let Some(args) = target_rustc_crate_types {
369369
override_rustc_crate_types(&mut units, args, interner)?;
@@ -375,7 +375,7 @@ pub fn create_bcx<'a, 'cfg>(
375375
mode: CompileMode::Docscrape,
376376
..generator
377377
};
378-
let all_units = scrape_generator.generate_units()?;
378+
let all_units = scrape_generator.generate_root_units()?;
379379

380380
let valid_units = all_units
381381
.into_iter()

src/cargo/ops/cargo_compile/unit_generator.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,16 @@ struct Proposal<'a> {
3333
mode: CompileMode,
3434
}
3535

36-
/// The context needed for generating units.
36+
/// The context needed for generating root units,
37+
/// which are pacakges the user has requested to compile.
38+
///
39+
/// To generate a full [`UnitGraph`],
40+
/// generally you need to call [`generate_root_units`] first,
41+
/// and then provide the output to [`build_unit_dependencies`].
42+
///
43+
/// [`generate_root_units`]: UnitGenerator::generate_root_units
44+
/// [`build_unit_dependencies`]: crate::core::compiler::unit_dependencies::build_unit_dependencies
45+
/// [`UnitGraph`]: crate::core::compiler::unit_graph::UnitGraph
3746
pub(super) struct UnitGenerator<'a, 'cfg> {
3847
pub ws: &'a Workspace<'cfg>,
3948
pub packages: &'a [&'a Package],
@@ -303,7 +312,7 @@ impl<'a> UnitGenerator<'a, '_> {
303312
Ok(proposals)
304313
}
305314

306-
/// Create a list of proposed targets given the context in `TargetGenerator`
315+
/// Create a list of proposed targets given the context in `UnitGenerator`
307316
fn create_proposals(&self) -> CargoResult<Vec<Proposal<'_>>> {
308317
let mut proposals: Vec<Proposal<'_>> = Vec::new();
309318

@@ -658,8 +667,10 @@ impl<'a> UnitGenerator<'a, '_> {
658667
}
659668

660669
/// Generates all the base units for the packages the user has requested to
661-
/// compile. Dependencies for these units are computed later in `unit_dependencies`.
662-
pub fn generate_units(&self) -> CargoResult<Vec<Unit>> {
670+
/// compile. Dependencies for these units are computed later in [`unit_dependencies`].
671+
///
672+
/// [`unit_dependencies`]: crate::core::compiler::unit_dependencies
673+
pub fn generate_root_units(&self) -> CargoResult<Vec<Unit>> {
663674
let proposals = self.create_proposals()?;
664675
self.proposals_to_units(proposals)
665676
}

src/doc/contrib/src/tests/writing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ environment. The general process is:
269269
* `/path/to/my/cargo/target/debug/cargo check`
270270
* Using a debugger like `lldb` or `gdb`:
271271
1. `lldb /path/to/my/cargo/target/debug/cargo`
272-
2. Set a breakpoint, for example: `b generate_units`
272+
2. Set a breakpoint, for example: `b generate_root_units`
273273
3. Run with arguments: `r check`
274274

275275
[`testsuite`]: https://github.com/rust-lang/cargo/tree/master/tests/testsuite/

0 commit comments

Comments
 (0)