Skip to content

Commit f8f6997

Browse files
committed
Auto merge of rust-lang#144044 - fmease:rollup-kg413pt, r=fmease
Rollup of 15 pull requests Successful merges: - rust-lang#142304 (tests: Add `RUST_BACKTRACE` and `-Cpanic` revisions to `panic-main.rs` test) - rust-lang#143388 (Various refactors to the LTO handling code) - rust-lang#143409 (Enable xgot feature for mips64 musl targets) - rust-lang#143592 (UWP: link ntdll functions using raw-dylib) - rust-lang#143595 (add `const_make_global`; err for `const_allocate` ptrs if didn't call) - rust-lang#143678 (Added error for invalid char cast) - rust-lang#143820 (Fixed a core crate compilation failure when enabling the `optimize_for_size` feature on some targets) - rust-lang#143829 (Trim `BorrowedCursor` API) - rust-lang#143851 (ci cleanup: rustdoc-gui-test now installs browser-ui-test) - rust-lang#143856 (Linting public reexport of private dependencies) - rust-lang#143895 (Dont collect assoc ty item bounds from trait where clause for host effect predicates) - rust-lang#143922 (Improve path segment joining) - rust-lang#143964 (Fix handling of SCRIPT_ARG in docker images) - rust-lang#144002 (Update poison.rs) - rust-lang#144016 (trait_sel: `MetaSized` always holds temporarily) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 014bd82 + d5a471c commit f8f6997

File tree

138 files changed

+1325
-1064
lines changed

Some content is hidden

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

138 files changed

+1325
-1064
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//! - [`Attribute`]: Metadata associated with item.
1919
//! - [`UnOp`], [`BinOp`], and [`BinOpKind`]: Unary and binary operators.
2020
21-
use std::borrow::Cow;
21+
use std::borrow::{Borrow, Cow};
2222
use std::{cmp, fmt};
2323

2424
pub use GenericArgs::*;
@@ -155,6 +155,59 @@ impl Path {
155155
}
156156
}
157157

158+
/// Joins multiple symbols with "::" into a path, e.g. "a::b::c". If the first
159+
/// segment is `kw::PathRoot` it will be printed as empty, e.g. "::b::c".
160+
///
161+
/// The generics on the `path` argument mean it can accept many forms, such as:
162+
/// - `&[Symbol]`
163+
/// - `Vec<Symbol>`
164+
/// - `Vec<&Symbol>`
165+
/// - `impl Iterator<Item = Symbol>`
166+
/// - `impl Iterator<Item = &Symbol>`
167+
///
168+
/// Panics if `path` is empty or a segment after the first is `kw::PathRoot`.
169+
pub fn join_path_syms(path: impl IntoIterator<Item = impl Borrow<Symbol>>) -> String {
170+
// This is a guess at the needed capacity that works well in practice. It is slightly faster
171+
// than (a) starting with an empty string, or (b) computing the exact capacity required.
172+
// `8` works well because it's about the right size and jemalloc's size classes are all
173+
// multiples of 8.
174+
let mut iter = path.into_iter();
175+
let len_hint = iter.size_hint().1.unwrap_or(1);
176+
let mut s = String::with_capacity(len_hint * 8);
177+
178+
let first_sym = *iter.next().unwrap().borrow();
179+
if first_sym != kw::PathRoot {
180+
s.push_str(first_sym.as_str());
181+
}
182+
for sym in iter {
183+
let sym = *sym.borrow();
184+
debug_assert_ne!(sym, kw::PathRoot);
185+
s.push_str("::");
186+
s.push_str(sym.as_str());
187+
}
188+
s
189+
}
190+
191+
/// Like `join_path_syms`, but for `Ident`s. This function is necessary because
192+
/// `Ident::to_string` does more than just print the symbol in the `name` field.
193+
pub fn join_path_idents(path: impl IntoIterator<Item = impl Borrow<Ident>>) -> String {
194+
let mut iter = path.into_iter();
195+
let len_hint = iter.size_hint().1.unwrap_or(1);
196+
let mut s = String::with_capacity(len_hint * 8);
197+
198+
let first_ident = *iter.next().unwrap().borrow();
199+
if first_ident.name != kw::PathRoot {
200+
s.push_str(&first_ident.to_string());
201+
}
202+
for ident in iter {
203+
let ident = *ident.borrow();
204+
debug_assert_ne!(ident.name, kw::PathRoot);
205+
s.push_str("::");
206+
s.push_str(&ident.to_string());
207+
}
208+
s
209+
}
210+
158211
/// A segment of a path: an identifier, an optional lifetime, and a set of types.
159212
///
160213
/// E.g., `std`, `String` or `Box<T>`.

compiler/rustc_builtin_macros/src/source_util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use std::sync::Arc;
44

55
use rustc_ast as ast;
66
use rustc_ast::ptr::P;
7-
use rustc_ast::token;
87
use rustc_ast::tokenstream::TokenStream;
8+
use rustc_ast::{join_path_idents, token};
99
use rustc_ast_pretty::pprust;
1010
use rustc_expand::base::{
1111
DummyResult, ExpandResult, ExtCtxt, MacEager, MacResult, MacroExpanderResult, resolve_path,
@@ -100,7 +100,7 @@ pub(crate) fn expand_mod(
100100
let sp = cx.with_def_site_ctxt(sp);
101101
check_zero_tts(cx, sp, tts, "module_path!");
102102
let mod_path = &cx.current_expansion.module.mod_path;
103-
let string = mod_path.iter().map(|x| x.to_string()).collect::<Vec<String>>().join("::");
103+
let string = join_path_idents(mod_path);
104104

105105
ExpandResult::Ready(MacEager::expr(cx.expr_str(sp, Symbol::intern(&string))))
106106
}

compiler/rustc_builtin_macros/src/test.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::assert_matches::assert_matches;
55
use std::iter;
66

77
use rustc_ast::ptr::P;
8-
use rustc_ast::{self as ast, GenericParamKind, attr};
8+
use rustc_ast::{self as ast, GenericParamKind, attr, join_path_idents};
99
use rustc_ast_pretty::pprust;
1010
use rustc_errors::{Applicability, Diag, Level};
1111
use rustc_expand::base::*;
@@ -446,12 +446,7 @@ fn get_location_info(cx: &ExtCtxt<'_>, fn_: &ast::Fn) -> (Symbol, usize, usize,
446446
}
447447

448448
fn item_path(mod_path: &[Ident], item_ident: &Ident) -> String {
449-
mod_path
450-
.iter()
451-
.chain(iter::once(item_ident))
452-
.map(|x| x.to_string())
453-
.collect::<Vec<String>>()
454-
.join("::")
449+
join_path_idents(mod_path.iter().chain(iter::once(item_ident)))
455450
}
456451

457452
enum ShouldPanic {

compiler/rustc_codegen_gcc/src/back/lto.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use std::sync::Arc;
2424

2525
use gccjit::{Context, OutputKind};
2626
use object::read::archive::ArchiveFile;
27-
use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule, ThinShared};
27+
use rustc_codegen_ssa::back::lto::{SerializedModule, ThinModule, ThinShared};
2828
use rustc_codegen_ssa::back::symbol_export;
2929
use rustc_codegen_ssa::back::write::{CodegenContext, FatLtoInput};
3030
use rustc_codegen_ssa::traits::*;
@@ -176,7 +176,7 @@ pub(crate) fn run_fat(
176176
cgcx: &CodegenContext<GccCodegenBackend>,
177177
modules: Vec<FatLtoInput<GccCodegenBackend>>,
178178
cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
179-
) -> Result<LtoModuleCodegen<GccCodegenBackend>, FatalError> {
179+
) -> Result<ModuleCodegen<GccContext>, FatalError> {
180180
let dcx = cgcx.create_dcx();
181181
let dcx = dcx.handle();
182182
let lto_data = prepare_lto(cgcx, dcx)?;
@@ -201,7 +201,7 @@ fn fat_lto(
201201
mut serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>,
202202
tmp_path: TempDir,
203203
//symbols_below_threshold: &[String],
204-
) -> Result<LtoModuleCodegen<GccCodegenBackend>, FatalError> {
204+
) -> Result<ModuleCodegen<GccContext>, FatalError> {
205205
let _timer = cgcx.prof.generic_activity("GCC_fat_lto_build_monolithic_module");
206206
info!("going for a fat lto");
207207

@@ -334,7 +334,7 @@ fn fat_lto(
334334
// of now.
335335
module.module_llvm.temp_dir = Some(tmp_path);
336336

337-
Ok(LtoModuleCodegen::Fat(module))
337+
Ok(module)
338338
}
339339

340340
pub struct ModuleBuffer(PathBuf);
@@ -358,7 +358,7 @@ pub(crate) fn run_thin(
358358
cgcx: &CodegenContext<GccCodegenBackend>,
359359
modules: Vec<(String, ThinBuffer)>,
360360
cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
361-
) -> Result<(Vec<LtoModuleCodegen<GccCodegenBackend>>, Vec<WorkProduct>), FatalError> {
361+
) -> Result<(Vec<ThinModule<GccCodegenBackend>>, Vec<WorkProduct>), FatalError> {
362362
let dcx = cgcx.create_dcx();
363363
let dcx = dcx.handle();
364364
let lto_data = prepare_lto(cgcx, dcx)?;
@@ -427,7 +427,7 @@ fn thin_lto(
427427
tmp_path: TempDir,
428428
cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
429429
//_symbols_below_threshold: &[String],
430-
) -> Result<(Vec<LtoModuleCodegen<GccCodegenBackend>>, Vec<WorkProduct>), FatalError> {
430+
) -> Result<(Vec<ThinModule<GccCodegenBackend>>, Vec<WorkProduct>), FatalError> {
431431
let _timer = cgcx.prof.generic_activity("LLVM_thin_lto_global_analysis");
432432
info!("going for that thin, thin LTO");
433433

@@ -573,8 +573,7 @@ fn thin_lto(
573573
}*/
574574

575575
info!(" - {}: re-compiled", module_name);
576-
opt_jobs
577-
.push(LtoModuleCodegen::Thin(ThinModule { shared: shared.clone(), idx: module_index }));
576+
opt_jobs.push(ThinModule { shared: shared.clone(), idx: module_index });
578577
}
579578

580579
// Save the current ThinLTO import information for the next compilation

compiler/rustc_codegen_gcc/src/back/write.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ use crate::{GccCodegenBackend, GccContext};
1616

1717
pub(crate) fn codegen(
1818
cgcx: &CodegenContext<GccCodegenBackend>,
19-
dcx: DiagCtxtHandle<'_>,
2019
module: ModuleCodegen<GccContext>,
2120
config: &ModuleConfig,
2221
) -> Result<CompiledModule, FatalError> {
22+
let dcx = cgcx.create_dcx();
23+
let dcx = dcx.handle();
24+
2325
let _timer = cgcx.prof.generic_activity_with_arg("GCC_module_codegen", &*module.name);
2426
{
2527
let context = &module.module_llvm.context;

compiler/rustc_codegen_gcc/src/lib.rs

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ use gccjit::{CType, Context, OptimizationLevel};
9393
use gccjit::{TargetInfo, Version};
9494
use rustc_ast::expand::allocator::AllocatorKind;
9595
use rustc_ast::expand::autodiff_attrs::AutoDiffItem;
96-
use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule};
96+
use rustc_codegen_ssa::back::lto::{SerializedModule, ThinModule};
9797
use rustc_codegen_ssa::back::write::{
9898
CodegenContext, FatLtoInput, ModuleConfig, TargetMachineFactoryFn,
9999
};
@@ -353,19 +353,24 @@ impl WriteBackendMethods for GccCodegenBackend {
353353
type ThinData = ThinData;
354354
type ThinBuffer = ThinBuffer;
355355

356-
fn run_fat_lto(
356+
fn run_and_optimize_fat_lto(
357357
cgcx: &CodegenContext<Self>,
358358
modules: Vec<FatLtoInput<Self>>,
359359
cached_modules: Vec<(SerializedModule<Self::ModuleBuffer>, WorkProduct)>,
360-
) -> Result<LtoModuleCodegen<Self>, FatalError> {
360+
diff_fncs: Vec<AutoDiffItem>,
361+
) -> Result<ModuleCodegen<Self::Module>, FatalError> {
362+
if !diff_fncs.is_empty() {
363+
unimplemented!();
364+
}
365+
361366
back::lto::run_fat(cgcx, modules, cached_modules)
362367
}
363368

364369
fn run_thin_lto(
365370
cgcx: &CodegenContext<Self>,
366371
modules: Vec<(String, Self::ThinBuffer)>,
367372
cached_modules: Vec<(SerializedModule<Self::ModuleBuffer>, WorkProduct)>,
368-
) -> Result<(Vec<LtoModuleCodegen<Self>>, Vec<WorkProduct>), FatalError> {
373+
) -> Result<(Vec<ThinModule<Self>>, Vec<WorkProduct>), FatalError> {
369374
back::lto::run_thin(cgcx, modules, cached_modules)
370375
}
371376

@@ -387,14 +392,6 @@ impl WriteBackendMethods for GccCodegenBackend {
387392
Ok(())
388393
}
389394

390-
fn optimize_fat(
391-
_cgcx: &CodegenContext<Self>,
392-
_module: &mut ModuleCodegen<Self::Module>,
393-
) -> Result<(), FatalError> {
394-
// TODO(antoyo)
395-
Ok(())
396-
}
397-
398395
fn optimize_thin(
399396
cgcx: &CodegenContext<Self>,
400397
thin: ThinModule<Self>,
@@ -404,11 +401,10 @@ impl WriteBackendMethods for GccCodegenBackend {
404401

405402
fn codegen(
406403
cgcx: &CodegenContext<Self>,
407-
dcx: DiagCtxtHandle<'_>,
408404
module: ModuleCodegen<Self::Module>,
409405
config: &ModuleConfig,
410406
) -> Result<CompiledModule, FatalError> {
411-
back::write::codegen(cgcx, dcx, module, config)
407+
back::write::codegen(cgcx, module, config)
412408
}
413409

414410
fn prepare_thin(
@@ -429,15 +425,6 @@ impl WriteBackendMethods for GccCodegenBackend {
429425
) -> Result<ModuleCodegen<Self::Module>, FatalError> {
430426
back::write::link(cgcx, dcx, modules)
431427
}
432-
433-
fn autodiff(
434-
_cgcx: &CodegenContext<Self>,
435-
_module: &ModuleCodegen<Self::Module>,
436-
_diff_functions: Vec<AutoDiffItem>,
437-
_config: &ModuleConfig,
438-
) -> Result<(), FatalError> {
439-
unimplemented!()
440-
}
441428
}
442429

443430
/// This is the entrypoint for a hot plugged rustc_codegen_gccjit

compiler/rustc_codegen_llvm/messages.ftl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
codegen_llvm_autodiff_without_enable = using the autodiff feature requires -Z autodiff=Enable
2-
codegen_llvm_autodiff_without_lto = using the autodiff feature requires using fat-lto
32
43
codegen_llvm_copy_bitcode = failed to copy bitcode to object file: {$err}
54

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::sync::Arc;
77
use std::{io, iter, slice};
88

99
use object::read::archive::ArchiveFile;
10-
use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule, ThinShared};
10+
use rustc_codegen_ssa::back::lto::{SerializedModule, ThinModule, ThinShared};
1111
use rustc_codegen_ssa::back::symbol_export;
1212
use rustc_codegen_ssa::back::write::{CodegenContext, FatLtoInput};
1313
use rustc_codegen_ssa::traits::*;
@@ -201,7 +201,7 @@ pub(crate) fn run_fat(
201201
cgcx: &CodegenContext<LlvmCodegenBackend>,
202202
modules: Vec<FatLtoInput<LlvmCodegenBackend>>,
203203
cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
204-
) -> Result<LtoModuleCodegen<LlvmCodegenBackend>, FatalError> {
204+
) -> Result<ModuleCodegen<ModuleLlvm>, FatalError> {
205205
let dcx = cgcx.create_dcx();
206206
let dcx = dcx.handle();
207207
let (symbols_below_threshold, upstream_modules) = prepare_lto(cgcx, dcx)?;
@@ -217,7 +217,7 @@ pub(crate) fn run_thin(
217217
cgcx: &CodegenContext<LlvmCodegenBackend>,
218218
modules: Vec<(String, ThinBuffer)>,
219219
cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
220-
) -> Result<(Vec<LtoModuleCodegen<LlvmCodegenBackend>>, Vec<WorkProduct>), FatalError> {
220+
) -> Result<(Vec<ThinModule<LlvmCodegenBackend>>, Vec<WorkProduct>), FatalError> {
221221
let dcx = cgcx.create_dcx();
222222
let dcx = dcx.handle();
223223
let (symbols_below_threshold, upstream_modules) = prepare_lto(cgcx, dcx)?;
@@ -248,7 +248,7 @@ fn fat_lto(
248248
cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
249249
mut serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>,
250250
symbols_below_threshold: &[*const libc::c_char],
251-
) -> Result<LtoModuleCodegen<LlvmCodegenBackend>, FatalError> {
251+
) -> Result<ModuleCodegen<ModuleLlvm>, FatalError> {
252252
let _timer = cgcx.prof.generic_activity("LLVM_fat_lto_build_monolithic_module");
253253
info!("going for a fat lto");
254254

@@ -366,7 +366,7 @@ fn fat_lto(
366366
save_temp_bitcode(cgcx, &module, "lto.after-restriction");
367367
}
368368

369-
Ok(LtoModuleCodegen::Fat(module))
369+
Ok(module)
370370
}
371371

372372
pub(crate) struct Linker<'a>(&'a mut llvm::Linker<'a>);
@@ -436,7 +436,7 @@ fn thin_lto(
436436
serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>,
437437
cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
438438
symbols_below_threshold: &[*const libc::c_char],
439-
) -> Result<(Vec<LtoModuleCodegen<LlvmCodegenBackend>>, Vec<WorkProduct>), FatalError> {
439+
) -> Result<(Vec<ThinModule<LlvmCodegenBackend>>, Vec<WorkProduct>), FatalError> {
440440
let _timer = cgcx.prof.generic_activity("LLVM_thin_lto_global_analysis");
441441
unsafe {
442442
info!("going for that thin, thin LTO");
@@ -568,10 +568,7 @@ fn thin_lto(
568568
}
569569

570570
info!(" - {}: re-compiled", module_name);
571-
opt_jobs.push(LtoModuleCodegen::Thin(ThinModule {
572-
shared: Arc::clone(&shared),
573-
idx: module_index,
574-
}));
571+
opt_jobs.push(ThinModule { shared: Arc::clone(&shared), idx: module_index });
575572
}
576573

577574
// Save the current ThinLTO import information for the next compilation

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,10 +817,12 @@ pub(crate) fn link(
817817

818818
pub(crate) fn codegen(
819819
cgcx: &CodegenContext<LlvmCodegenBackend>,
820-
dcx: DiagCtxtHandle<'_>,
821820
module: ModuleCodegen<ModuleLlvm>,
822821
config: &ModuleConfig,
823822
) -> Result<CompiledModule, FatalError> {
823+
let dcx = cgcx.create_dcx();
824+
let dcx = dcx.handle();
825+
824826
let _timer = cgcx.prof.generic_activity_with_arg("LLVM_module_codegen", &*module.name);
825827
{
826828
let llmod = module.module_llvm.llmod();

compiler/rustc_codegen_llvm/src/builder/autodiff.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::ptr;
22

33
use rustc_ast::expand::autodiff_attrs::{AutoDiffAttrs, AutoDiffItem, DiffActivity, DiffMode};
44
use rustc_codegen_ssa::ModuleCodegen;
5-
use rustc_codegen_ssa::back::write::ModuleConfig;
65
use rustc_codegen_ssa::common::TypeKind;
76
use rustc_codegen_ssa::traits::BaseTypeCodegenMethods;
87
use rustc_errors::FatalError;
@@ -461,7 +460,6 @@ pub(crate) fn differentiate<'ll>(
461460
module: &'ll ModuleCodegen<ModuleLlvm>,
462461
cgcx: &CodegenContext<LlvmCodegenBackend>,
463462
diff_items: Vec<AutoDiffItem>,
464-
_config: &ModuleConfig,
465463
) -> Result<(), FatalError> {
466464
for item in &diff_items {
467465
trace!("{}", item);

0 commit comments

Comments
 (0)