Skip to content

Commit 97eb606

Browse files
committed
Auto merge of #76540 - tmandry:rollup-5ogt8x0, r=tmandry
Rollup of 14 pull requests Successful merges: - #75094 (Add `-Z combine_cgu` flag) - #75984 (Improve unresolved use error message) - #76141 (Address review comments about config.toml from rustc-dev-guide PR) - #76313 (Improved the MIR spanview output) - #76430 (Add align to rustc-attrs unstable book) - #76465 (Add a script to automatically update Rust/Clang versions in documentation) - #76473 (Add missed spaces to GCC-WARNING.txt) - #76481 (Convert repetitive target_pointer_width checks to const solution.) - #76493 (Remove a stray ignore-tidy-undocumented-unsafe) - #76504 (Capitalize safety comments) - #76515 (SessionDiagnostic: Fix non-determinism in generated format string.) - #76516 (Enable GitHub Releases synchronization) - #76522 (remove redundant clones) - #76523 (Remove unused PlaceContext::NonUse(NonUseContext::Coverage)) Failed merges: r? `@ghost`
2 parents e2be5f5 + 32714eb commit 97eb606

File tree

96 files changed

+1285
-507
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+1285
-507
lines changed

compiler/rustc_codegen_llvm/src/back/lto.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -346,14 +346,14 @@ fn fat_lto(
346346
Ok(LtoModuleCodegen::Fat { module: Some(module), _serialized_bitcode: serialized_bitcode })
347347
}
348348

349-
struct Linker<'a>(&'a mut llvm::Linker<'a>);
349+
crate struct Linker<'a>(&'a mut llvm::Linker<'a>);
350350

351351
impl Linker<'a> {
352-
fn new(llmod: &'a llvm::Module) -> Self {
352+
crate fn new(llmod: &'a llvm::Module) -> Self {
353353
unsafe { Linker(llvm::LLVMRustLinkerNew(llmod)) }
354354
}
355355

356-
fn add(&mut self, bytecode: &[u8]) -> Result<(), ()> {
356+
crate fn add(&mut self, bytecode: &[u8]) -> Result<(), ()> {
357357
unsafe {
358358
if llvm::LLVMRustLinkerAdd(
359359
self.0,

compiler/rustc_codegen_llvm/src/back/write.rs

+25
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,31 @@ unsafe fn add_sanitizer_passes(config: &ModuleConfig, passes: &mut Vec<&'static
617617
}
618618
}
619619

620+
pub(crate) fn link(
621+
cgcx: &CodegenContext<LlvmCodegenBackend>,
622+
diag_handler: &Handler,
623+
mut modules: Vec<ModuleCodegen<ModuleLlvm>>,
624+
) -> Result<ModuleCodegen<ModuleLlvm>, FatalError> {
625+
use super::lto::{Linker, ModuleBuffer};
626+
// Sort the modules by name to ensure to ensure deterministic behavior.
627+
modules.sort_by(|a, b| a.name.cmp(&b.name));
628+
let (first, elements) =
629+
modules.split_first().expect("Bug! modules must contain at least one module.");
630+
631+
let mut linker = Linker::new(first.module_llvm.llmod());
632+
for module in elements {
633+
let _timer =
634+
cgcx.prof.generic_activity_with_arg("LLVM_link_module", format!("{:?}", module.name));
635+
let buffer = ModuleBuffer::new(module.module_llvm.llmod());
636+
linker.add(&buffer.data()).map_err(|()| {
637+
let msg = format!("failed to serialize module {:?}", module.name);
638+
llvm_err(&diag_handler, &msg)
639+
})?;
640+
}
641+
drop(linker);
642+
Ok(modules.remove(0))
643+
}
644+
620645
pub(crate) unsafe fn codegen(
621646
cgcx: &CodegenContext<LlvmCodegenBackend>,
622647
diag_handler: &Handler,

compiler/rustc_codegen_llvm/src/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ impl WriteBackendMethods for LlvmCodegenBackend {
130130
llvm::LLVMRustPrintPassTimings();
131131
}
132132
}
133+
fn run_link(
134+
cgcx: &CodegenContext<Self>,
135+
diag_handler: &Handler,
136+
modules: Vec<ModuleCodegen<Self::Module>>,
137+
) -> Result<ModuleCodegen<Self::Module>, FatalError> {
138+
back::write::link(cgcx, diag_handler, modules)
139+
}
133140
fn run_fat_lto(
134141
cgcx: &CodegenContext<Self>,
135142
modules: Vec<FatLTOInput<Self>>,

compiler/rustc_codegen_ssa/src/back/write.rs

+47-12
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@ impl<B: WriteBackendMethods> WorkItem<B> {
702702

703703
enum WorkItemResult<B: WriteBackendMethods> {
704704
Compiled(CompiledModule),
705+
NeedsLink(ModuleCodegen<B::Module>),
705706
NeedsFatLTO(FatLTOInput<B>),
706707
NeedsThinLTO(String, B::ThinBuffer),
707708
}
@@ -801,31 +802,28 @@ fn execute_optimize_work_item<B: ExtraBackendMethods>(
801802
None
802803
};
803804

804-
Ok(match lto_type {
805-
ComputedLtoType::No => {
806-
let module = unsafe { B::codegen(cgcx, &diag_handler, module, module_config)? };
807-
WorkItemResult::Compiled(module)
808-
}
805+
match lto_type {
806+
ComputedLtoType::No => finish_intra_module_work(cgcx, module, module_config),
809807
ComputedLtoType::Thin => {
810808
let (name, thin_buffer) = B::prepare_thin(module);
811809
if let Some(path) = bitcode {
812810
fs::write(&path, thin_buffer.data()).unwrap_or_else(|e| {
813811
panic!("Error writing pre-lto-bitcode file `{}`: {}", path.display(), e);
814812
});
815813
}
816-
WorkItemResult::NeedsThinLTO(name, thin_buffer)
814+
Ok(WorkItemResult::NeedsThinLTO(name, thin_buffer))
817815
}
818816
ComputedLtoType::Fat => match bitcode {
819817
Some(path) => {
820818
let (name, buffer) = B::serialize_module(module);
821819
fs::write(&path, buffer.data()).unwrap_or_else(|e| {
822820
panic!("Error writing pre-lto-bitcode file `{}`: {}", path.display(), e);
823821
});
824-
WorkItemResult::NeedsFatLTO(FatLTOInput::Serialized { name, buffer })
822+
Ok(WorkItemResult::NeedsFatLTO(FatLTOInput::Serialized { name, buffer }))
825823
}
826-
None => WorkItemResult::NeedsFatLTO(FatLTOInput::InMemory(module)),
824+
None => Ok(WorkItemResult::NeedsFatLTO(FatLTOInput::InMemory(module))),
827825
},
828-
})
826+
}
829827
}
830828

831829
fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
@@ -870,13 +868,26 @@ fn execute_lto_work_item<B: ExtraBackendMethods>(
870868
cgcx: &CodegenContext<B>,
871869
mut module: lto::LtoModuleCodegen<B>,
872870
module_config: &ModuleConfig,
871+
) -> Result<WorkItemResult<B>, FatalError> {
872+
let module = unsafe { module.optimize(cgcx)? };
873+
finish_intra_module_work(cgcx, module, module_config)
874+
}
875+
876+
fn finish_intra_module_work<B: ExtraBackendMethods>(
877+
cgcx: &CodegenContext<B>,
878+
module: ModuleCodegen<B::Module>,
879+
module_config: &ModuleConfig,
873880
) -> Result<WorkItemResult<B>, FatalError> {
874881
let diag_handler = cgcx.create_diag_handler();
875882

876-
unsafe {
877-
let module = module.optimize(cgcx)?;
878-
let module = B::codegen(cgcx, &diag_handler, module, module_config)?;
883+
if !cgcx.opts.debugging_opts.combine_cgu
884+
|| module.kind == ModuleKind::Metadata
885+
|| module.kind == ModuleKind::Allocator
886+
{
887+
let module = unsafe { B::codegen(cgcx, &diag_handler, module, module_config)? };
879888
Ok(WorkItemResult::Compiled(module))
889+
} else {
890+
Ok(WorkItemResult::NeedsLink(module))
880891
}
881892
}
882893

@@ -891,6 +902,10 @@ pub enum Message<B: WriteBackendMethods> {
891902
thin_buffer: B::ThinBuffer,
892903
worker_id: usize,
893904
},
905+
NeedsLink {
906+
module: ModuleCodegen<B::Module>,
907+
worker_id: usize,
908+
},
894909
Done {
895910
result: Result<CompiledModule, Option<WorkerFatalError>>,
896911
worker_id: usize,
@@ -1178,6 +1193,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
11781193
let mut compiled_modules = vec![];
11791194
let mut compiled_metadata_module = None;
11801195
let mut compiled_allocator_module = None;
1196+
let mut needs_link = Vec::new();
11811197
let mut needs_fat_lto = Vec::new();
11821198
let mut needs_thin_lto = Vec::new();
11831199
let mut lto_import_only_modules = Vec::new();
@@ -1434,6 +1450,10 @@ fn start_executing_work<B: ExtraBackendMethods>(
14341450
}
14351451
}
14361452
}
1453+
Message::NeedsLink { module, worker_id } => {
1454+
free_worker(worker_id);
1455+
needs_link.push(module);
1456+
}
14371457
Message::NeedsFatLTO { result, worker_id } => {
14381458
assert!(!started_lto);
14391459
free_worker(worker_id);
@@ -1462,6 +1482,18 @@ fn start_executing_work<B: ExtraBackendMethods>(
14621482
}
14631483
}
14641484

1485+
let needs_link = mem::take(&mut needs_link);
1486+
if !needs_link.is_empty() {
1487+
assert!(compiled_modules.is_empty());
1488+
let diag_handler = cgcx.create_diag_handler();
1489+
let module = B::run_link(&cgcx, &diag_handler, needs_link).map_err(|_| ())?;
1490+
let module = unsafe {
1491+
B::codegen(&cgcx, &diag_handler, module, cgcx.config(ModuleKind::Regular))
1492+
.map_err(|_| ())?
1493+
};
1494+
compiled_modules.push(module);
1495+
}
1496+
14651497
// Drop to print timings
14661498
drop(llvm_start_time);
14671499

@@ -1521,6 +1553,9 @@ fn spawn_work<B: ExtraBackendMethods>(cgcx: CodegenContext<B>, work: WorkItem<B>
15211553
Some(Ok(WorkItemResult::Compiled(m))) => {
15221554
Message::Done::<B> { result: Ok(m), worker_id }
15231555
}
1556+
Some(Ok(WorkItemResult::NeedsLink(m))) => {
1557+
Message::NeedsLink::<B> { module: m, worker_id }
1558+
}
15241559
Some(Ok(WorkItemResult::NeedsFatLTO(m))) => {
15251560
Message::NeedsFatLTO::<B> { result: m, worker_id }
15261561
}

compiler/rustc_codegen_ssa/src/traits/write.rs

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ pub trait WriteBackendMethods: 'static + Sized + Clone {
1313
type ThinData: Send + Sync;
1414
type ThinBuffer: ThinBufferMethods;
1515

16+
/// Merge all modules into main_module and returning it
17+
fn run_link(
18+
cgcx: &CodegenContext<Self>,
19+
diag_handler: &Handler,
20+
modules: Vec<ModuleCodegen<Self::Module>>,
21+
) -> Result<ModuleCodegen<Self::Module>, FatalError>;
1622
/// Performs fat LTO by merging all modules into a single one and returning it
1723
/// for further optimization.
1824
fn run_fat_lto(

compiler/rustc_data_structures/src/temp_dir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct MaybeTempDir {
1212

1313
impl Drop for MaybeTempDir {
1414
fn drop(&mut self) {
15-
// Safety: We are in the destructor, and no further access will
15+
// SAFETY: We are in the destructor, and no further access will
1616
// occur.
1717
let dir = unsafe { ManuallyDrop::take(&mut self.dir) };
1818
if self.keep {
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
1-
An undeclared type or module was used.
1+
An undeclared crate, module, or type was used.
22

33
Erroneous code example:
44

55
```compile_fail,E0433
66
let map = HashMap::new();
7-
// error: failed to resolve: use of undeclared type or module `HashMap`
7+
// error: failed to resolve: use of undeclared type `HashMap`
88
```
99

1010
Please verify you didn't misspell the type/module's name or that you didn't
1111
forget to import it:
1212

13-
1413
```
1514
use std::collections::HashMap; // HashMap has been imported.
1615
let map: HashMap<u32, u32> = HashMap::new(); // So it can be used!
1716
```
17+
18+
If you've expected to use a crate name:
19+
20+
```compile_fail
21+
use ferris_wheel::BigO;
22+
// error: failed to resolve: use of undeclared crate or module `ferris_wheel`
23+
```
24+
25+
Make sure the crate has been added as a dependency in `Cargo.toml`.
26+
27+
To use a module from your current crate, add the `crate::` prefix to the path.

compiler/rustc_macros/src/session_diagnostic.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
#![deny(unused_must_use)]
2-
use quote::format_ident;
3-
use quote::quote;
4-
52
use proc_macro::Diagnostic;
3+
use quote::{format_ident, quote};
64
use syn::spanned::Spanned;
75

8-
use std::collections::{HashMap, HashSet};
6+
use std::collections::{BTreeSet, HashMap};
97

108
/// Implements #[derive(SessionDiagnostic)], which allows for errors to be specified as a struct, independent
119
/// from the actual diagnostics emitting code.
@@ -577,7 +575,10 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
577575
/// ```
578576
/// This function builds the entire call to format!.
579577
fn build_format(&self, input: &String, span: proc_macro2::Span) -> proc_macro2::TokenStream {
580-
let mut referenced_fields: HashSet<String> = HashSet::new();
578+
// This set is used later to generate the final format string. To keep builds reproducible,
579+
// the iteration order needs to be deterministic, hence why we use a BTreeSet here instead
580+
// of a HashSet.
581+
let mut referenced_fields: BTreeSet<String> = BTreeSet::new();
581582

582583
// At this point, we can start parsing the format string.
583584
let mut it = input.chars().peekable();

compiler/rustc_middle/src/mir/visit.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1150,8 +1150,6 @@ pub enum NonUseContext {
11501150
StorageDead,
11511151
/// User type annotation assertions for NLL.
11521152
AscribeUserTy,
1153-
/// Coverage code region and counter metadata.
1154-
Coverage,
11551153
/// The data of an user variable, for debug info.
11561154
VarDebugInfo,
11571155
}

compiler/rustc_mir/src/borrow_check/def_use.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ pub fn categorize(context: PlaceContext) -> Option<DefUse> {
7272
PlaceContext::MutatingUse(MutatingUseContext::Drop) =>
7373
Some(DefUse::Drop),
7474

75-
// Coverage and debug info are neither def nor use.
76-
PlaceContext::NonUse(NonUseContext::Coverage) |
75+
// Debug info is neither def nor use.
7776
PlaceContext::NonUse(NonUseContext::VarDebugInfo) => None,
7877
}
7978
}

compiler/rustc_mir/src/dataflow/impls/init_locals.rs

-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ where
9797
PlaceContext::NonUse(
9898
NonUseContext::StorageLive
9999
| NonUseContext::AscribeUserTy
100-
| NonUseContext::Coverage
101100
| NonUseContext::VarDebugInfo,
102101
)
103102
| PlaceContext::NonMutatingUse(

compiler/rustc_mir/src/transform/instrument_coverage.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
309309
for coverage_region in coverage_regions {
310310
span_viewables.push(SpanViewable {
311311
span: coverage_region.span,
312-
title: format!("{}", coverage_region.blocks[0].index()),
312+
id: format!("{}", coverage_region.blocks[0].index()),
313313
tooltip: self.make_tooltip_text(coverage_region),
314314
});
315315
}

0 commit comments

Comments
 (0)