Skip to content

Commit 74500b9

Browse files
committed
Auto merge of #81493 - JohnTitor:rollup-sa4m4zh, r=JohnTitor
Rollup of 10 pull requests Successful merges: - #79570 (rustc: Stabilize `-Zrun-dsymutil` as `-Csplit-debuginfo`) - #79819 (Add `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` lint) - #79991 (rustdoc: Render HRTB correctly for bare functions) - #80215 (Use -target when linking binaries for Mac Catalyst) - #81158 (Point to span of upvar making closure FnMut) - #81176 (Improve safety of `LateContext::qpath_res`) - #81287 (Split rustdoc JSON types into separately versioned crate) - #81306 (Fuse inner iterator in FlattenCompat and improve related tests) - #81333 (clean up some const error reporting around promoteds) - #81459 (Fix rustdoc text selection for page titles) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents b05fd2a + 2b4fa3d commit 74500b9

File tree

90 files changed

+979
-442
lines changed

Some content is hidden

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

90 files changed

+979
-442
lines changed

Cargo.lock

+9
Original file line numberDiff line numberDiff line change
@@ -3746,6 +3746,7 @@ dependencies = [
37463746
"rustc_errors",
37473747
"rustc_feature",
37483748
"rustc_lexer",
3749+
"rustc_lint_defs",
37493750
"rustc_macros",
37503751
"rustc_parse",
37513752
"rustc_serialize",
@@ -4391,12 +4392,20 @@ dependencies = [
43914392
"pulldown-cmark 0.8.0",
43924393
"regex",
43934394
"rustc-rayon",
4395+
"rustdoc-json-types",
43944396
"serde",
43954397
"serde_json",
43964398
"smallvec 1.4.2",
43974399
"tempfile",
43984400
]
43994401

4402+
[[package]]
4403+
name = "rustdoc-json-types"
4404+
version = "0.1.0"
4405+
dependencies = [
4406+
"serde",
4407+
]
4408+
44004409
[[package]]
44014410
name = "rustdoc-themes"
44024411
version = "0.1.0"

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ members = [
44
"compiler/rustc",
55
"library/std",
66
"library/test",
7+
"src/rustdoc-json-types",
78
"src/tools/cargotest",
89
"src/tools/clippy",
910
"src/tools/compiletest",

compiler/rustc_codegen_cranelift/src/constant.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,9 @@ pub(crate) fn codegen_constant<'tcx>(
134134
{
135135
Ok(const_val) => const_val,
136136
Err(_) => {
137-
if promoted.is_none() {
138-
fx.tcx
139-
.sess
140-
.span_err(constant.span, "erroneous constant encountered");
141-
}
137+
fx.tcx
138+
.sess
139+
.span_err(constant.span, "erroneous constant encountered");
142140
return crate::trap::trap_unreachable_ret_value(
143141
fx,
144142
fx.layout_of(const_.ty),

compiler/rustc_codegen_llvm/src/back/lto.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -732,10 +732,7 @@ pub unsafe fn optimize_thin_module(
732732
let diag_handler = cgcx.create_diag_handler();
733733

734734
let module_name = &thin_module.shared.module_names[thin_module.idx];
735-
let split_dwarf_file = cgcx
736-
.output_filenames
737-
.split_dwarf_filename(cgcx.split_dwarf_kind, Some(module_name.to_str().unwrap()));
738-
let tm_factory_config = TargetMachineFactoryConfig { split_dwarf_file };
735+
let tm_factory_config = TargetMachineFactoryConfig::new(cgcx, module_name.to_str().unwrap());
739736
let tm =
740737
(cgcx.tm_factory)(tm_factory_config).map_err(|e| write::llvm_err(&diag_handler, &e))?;
741738

compiler/rustc_codegen_llvm/src/back/write.rs

+18-11
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@ use rustc_fs_util::{link_or_copy, path_to_c_string};
2323
use rustc_hir::def_id::LOCAL_CRATE;
2424
use rustc_middle::bug;
2525
use rustc_middle::ty::TyCtxt;
26-
use rustc_session::config::{
27-
self, Lto, OutputType, Passes, SanitizerSet, SplitDwarfKind, SwitchWithOptPath,
28-
};
26+
use rustc_session::config::{self, Lto, OutputType, Passes, SanitizerSet, SwitchWithOptPath};
2927
use rustc_session::Session;
3028
use rustc_span::symbol::sym;
3129
use rustc_span::InnerSpan;
32-
use rustc_target::spec::{CodeModel, RelocModel};
30+
use rustc_target::spec::{CodeModel, RelocModel, SplitDebuginfo};
3331
use tracing::debug;
3432

3533
use libc::{c_char, c_int, c_uint, c_void, size_t};
@@ -93,9 +91,12 @@ pub fn create_informational_target_machine(sess: &Session) -> &'static mut llvm:
9391
}
9492

9593
pub fn create_target_machine(tcx: TyCtxt<'_>, mod_name: &str) -> &'static mut llvm::TargetMachine {
96-
let split_dwarf_file = tcx
97-
.output_filenames(LOCAL_CRATE)
98-
.split_dwarf_filename(tcx.sess.opts.debugging_opts.split_dwarf, Some(mod_name));
94+
let split_dwarf_file = if tcx.sess.target_can_use_split_dwarf() {
95+
tcx.output_filenames(LOCAL_CRATE)
96+
.split_dwarf_filename(tcx.sess.split_debuginfo(), Some(mod_name))
97+
} else {
98+
None
99+
};
99100
let config = TargetMachineFactoryConfig { split_dwarf_file };
100101
target_machine_factory(&tcx.sess, tcx.backend_optimization_level(LOCAL_CRATE))(config)
101102
.unwrap_or_else(|err| llvm_err(tcx.sess.diagnostic(), &err).raise())
@@ -838,11 +839,17 @@ pub(crate) unsafe fn codegen(
838839
.generic_activity_with_arg("LLVM_module_codegen_emit_obj", &module.name[..]);
839840

840841
let dwo_out = cgcx.output_filenames.temp_path_dwo(module_name);
841-
let dwo_out = match cgcx.split_dwarf_kind {
842+
let dwo_out = match cgcx.split_debuginfo {
842843
// Don't change how DWARF is emitted in single mode (or when disabled).
843-
SplitDwarfKind::None | SplitDwarfKind::Single => None,
844+
SplitDebuginfo::Off | SplitDebuginfo::Packed => None,
844845
// Emit (a subset of the) DWARF into a separate file in split mode.
845-
SplitDwarfKind::Split => Some(dwo_out.as_path()),
846+
SplitDebuginfo::Unpacked => {
847+
if cgcx.target_can_use_split_dwarf {
848+
Some(dwo_out.as_path())
849+
} else {
850+
None
851+
}
852+
}
846853
};
847854

848855
with_codegen(tm, llmod, config.no_builtins, |cpm| {
@@ -880,7 +887,7 @@ pub(crate) unsafe fn codegen(
880887

881888
Ok(module.into_compiled_module(
882889
config.emit_obj != EmitObj::None,
883-
cgcx.split_dwarf_kind == SplitDwarfKind::Split,
890+
cgcx.target_can_use_split_dwarf && cgcx.split_debuginfo == SplitDebuginfo::Unpacked,
884891
config.emit_bc,
885892
&cgcx.output_filenames,
886893
))

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -995,10 +995,13 @@ pub fn compile_unit_metadata(
995995
let flags = "\0";
996996

997997
let out_dir = &tcx.output_filenames(LOCAL_CRATE).out_directory;
998-
let split_name = tcx
999-
.output_filenames(LOCAL_CRATE)
1000-
.split_dwarf_filename(tcx.sess.opts.debugging_opts.split_dwarf, Some(codegen_unit_name))
1001-
.unwrap_or_default();
998+
let split_name = if tcx.sess.target_can_use_split_dwarf() {
999+
tcx.output_filenames(LOCAL_CRATE)
1000+
.split_dwarf_filename(tcx.sess.split_debuginfo(), Some(codegen_unit_name))
1001+
} else {
1002+
None
1003+
}
1004+
.unwrap_or_default();
10021005
let out_dir = out_dir.to_str().unwrap();
10031006
let split_name = split_name.to_str().unwrap();
10041007

compiler/rustc_codegen_llvm/src/lib.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -351,12 +351,7 @@ impl ModuleLlvm {
351351
unsafe {
352352
let llcx = llvm::LLVMRustContextCreate(cgcx.fewer_names);
353353
let llmod_raw = back::lto::parse_module(llcx, name, buffer, handler)?;
354-
355-
let split_dwarf_file = cgcx
356-
.output_filenames
357-
.split_dwarf_filename(cgcx.split_dwarf_kind, Some(name.to_str().unwrap()));
358-
let tm_factory_config = TargetMachineFactoryConfig { split_dwarf_file };
359-
354+
let tm_factory_config = TargetMachineFactoryConfig::new(&cgcx, name.to_str().unwrap());
360355
let tm = match (cgcx.tm_factory)(tm_factory_config) {
361356
Ok(m) => m,
362357
Err(e) => {

compiler/rustc_codegen_ssa/src/back/link.rs

+45-48
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_session::utils::NativeLibKind;
1414
use rustc_session::{filesearch, Session};
1515
use rustc_span::symbol::Symbol;
1616
use rustc_target::spec::crt_objects::{CrtObjects, CrtObjectsFallback};
17-
use rustc_target::spec::{LinkOutputKind, LinkerFlavor, LldFlavor};
17+
use rustc_target::spec::{LinkOutputKind, LinkerFlavor, LldFlavor, SplitDebuginfo};
1818
use rustc_target::spec::{PanicStrategy, RelocModel, RelroLevel, Target};
1919

2020
use super::archive::ArchiveBuilder;
@@ -99,9 +99,6 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(
9999
path.as_ref(),
100100
target_cpu,
101101
);
102-
if sess.opts.debugging_opts.split_dwarf == config::SplitDwarfKind::Split {
103-
link_dwarf_object(sess, &out_filename);
104-
}
105102
}
106103
}
107104
if sess.opts.json_artifact_notifications {
@@ -828,29 +825,43 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
828825
}
829826
}
830827

831-
// On macOS, debuggers need this utility to get run to do some munging of
832-
// the symbols. Note, though, that if the object files are being preserved
833-
// for their debug information there's no need for us to run dsymutil.
834-
if sess.target.is_like_osx
835-
&& sess.opts.debuginfo != DebugInfo::None
836-
&& !preserve_objects_for_their_debuginfo(sess)
837-
{
838-
let prog = Command::new("dsymutil").arg(out_filename).output();
839-
match prog {
840-
Ok(prog) => {
841-
if !prog.status.success() {
842-
let mut output = prog.stderr.clone();
843-
output.extend_from_slice(&prog.stdout);
844-
sess.struct_warn(&format!(
845-
"processing debug info with `dsymutil` failed: {}",
846-
prog.status
847-
))
848-
.note(&escape_string(&output))
849-
.emit();
828+
match sess.split_debuginfo() {
829+
// If split debug information is disabled or located in individual files
830+
// there's nothing to do here.
831+
SplitDebuginfo::Off | SplitDebuginfo::Unpacked => {}
832+
833+
// If packed split-debuginfo is requested, but the final compilation
834+
// doesn't actually have any debug information, then we skip this step.
835+
SplitDebuginfo::Packed if sess.opts.debuginfo == DebugInfo::None => {}
836+
837+
// On macOS the external `dsymutil` tool is used to create the packed
838+
// debug information. Note that this will read debug information from
839+
// the objects on the filesystem which we'll clean up later.
840+
SplitDebuginfo::Packed if sess.target.is_like_osx => {
841+
let prog = Command::new("dsymutil").arg(out_filename).output();
842+
match prog {
843+
Ok(prog) => {
844+
if !prog.status.success() {
845+
let mut output = prog.stderr.clone();
846+
output.extend_from_slice(&prog.stdout);
847+
sess.struct_warn(&format!(
848+
"processing debug info with `dsymutil` failed: {}",
849+
prog.status
850+
))
851+
.note(&escape_string(&output))
852+
.emit();
853+
}
850854
}
855+
Err(e) => sess.fatal(&format!("unable to run `dsymutil`: {}", e)),
851856
}
852-
Err(e) => sess.fatal(&format!("unable to run `dsymutil`: {}", e)),
853857
}
858+
859+
// On MSVC packed debug information is produced by the linker itself so
860+
// there's no need to do anything else here.
861+
SplitDebuginfo::Packed if sess.target.is_like_msvc => {}
862+
863+
// ... and otherwise we're processing a `*.dwp` packed dwarf file.
864+
SplitDebuginfo::Packed => link_dwarf_object(sess, &out_filename),
854865
}
855866
}
856867

@@ -1050,28 +1061,9 @@ fn preserve_objects_for_their_debuginfo(sess: &Session) -> bool {
10501061
return false;
10511062
}
10521063

1053-
// Single mode keeps debuginfo in the same object file, but in such a way that it it skipped
1054-
// by the linker - so it's expected that when codegen units are linked together that this
1055-
// debuginfo would be lost without keeping around the temps.
1056-
if sess.opts.debugging_opts.split_dwarf == config::SplitDwarfKind::Single {
1057-
return true;
1058-
}
1059-
1060-
// If we're on OSX then the equivalent of split dwarf is turned on by
1061-
// default. The final executable won't actually have any debug information
1062-
// except it'll have pointers to elsewhere. Historically we've always run
1063-
// `dsymutil` to "link all the dwarf together" but this is actually sort of
1064-
// a bummer for incremental compilation! (the whole point of split dwarf is
1065-
// that you don't do this sort of dwarf link).
1066-
//
1067-
// Basically as a result this just means that if we're on OSX and we're
1068-
// *not* running dsymutil then the object files are the only source of truth
1069-
// for debug information, so we must preserve them.
1070-
if sess.target.is_like_osx {
1071-
return !sess.opts.debugging_opts.run_dsymutil;
1072-
}
1073-
1074-
false
1064+
// "unpacked" split debuginfo means that we leave object files as the
1065+
// debuginfo is found in the original object files themselves
1066+
sess.split_debuginfo() == SplitDebuginfo::Unpacked
10751067
}
10761068

10771069
pub fn archive_search_paths(sess: &Session) -> Vec<PathBuf> {
@@ -2211,8 +2203,13 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
22112203
return;
22122204
}
22132205
};
2214-
let arch_name = llvm_target.split('-').next().expect("LLVM target must have a hyphen");
2215-
cmd.args(&["-arch", arch_name, "-isysroot", &sdk_root, "-Wl,-syslibroot", &sdk_root]);
2206+
if llvm_target.contains("macabi") {
2207+
cmd.args(&["-target", llvm_target])
2208+
} else {
2209+
let arch_name = llvm_target.split('-').next().expect("LLVM target must have a hyphen");
2210+
cmd.args(&["-arch", arch_name])
2211+
}
2212+
cmd.args(&["-isysroot", &sdk_root, "-Wl,-syslibroot", &sdk_root]);
22162213
}
22172214

22182215
fn get_apple_sdk_root(sdk_name: &str) -> Result<String, String> {

compiler/rustc_codegen_ssa/src/back/write.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,20 @@ pub struct TargetMachineFactoryConfig {
282282
pub split_dwarf_file: Option<PathBuf>,
283283
}
284284

285+
impl TargetMachineFactoryConfig {
286+
pub fn new(
287+
cgcx: &CodegenContext<impl WriteBackendMethods>,
288+
module_name: &str,
289+
) -> TargetMachineFactoryConfig {
290+
let split_dwarf_file = if cgcx.target_can_use_split_dwarf {
291+
cgcx.output_filenames.split_dwarf_filename(cgcx.split_debuginfo, Some(module_name))
292+
} else {
293+
None
294+
};
295+
TargetMachineFactoryConfig { split_dwarf_file }
296+
}
297+
}
298+
285299
pub type TargetMachineFactoryFn<B> = Arc<
286300
dyn Fn(TargetMachineFactoryConfig) -> Result<<B as WriteBackendMethods>::TargetMachine, String>
287301
+ Send
@@ -311,10 +325,11 @@ pub struct CodegenContext<B: WriteBackendMethods> {
311325
pub tm_factory: TargetMachineFactoryFn<B>,
312326
pub msvc_imps_needed: bool,
313327
pub is_pe_coff: bool,
328+
pub target_can_use_split_dwarf: bool,
314329
pub target_pointer_width: u32,
315330
pub target_arch: String,
316331
pub debuginfo: config::DebugInfo,
317-
pub split_dwarf_kind: config::SplitDwarfKind,
332+
pub split_debuginfo: rustc_target::spec::SplitDebuginfo,
318333

319334
// Number of cgus excluding the allocator/metadata modules
320335
pub total_cgus: usize,
@@ -1035,10 +1050,11 @@ fn start_executing_work<B: ExtraBackendMethods>(
10351050
total_cgus,
10361051
msvc_imps_needed: msvc_imps_needed(tcx),
10371052
is_pe_coff: tcx.sess.target.is_like_windows,
1053+
target_can_use_split_dwarf: tcx.sess.target_can_use_split_dwarf(),
10381054
target_pointer_width: tcx.sess.target.pointer_width,
10391055
target_arch: tcx.sess.target.arch.clone(),
10401056
debuginfo: tcx.sess.opts.debuginfo,
1041-
split_dwarf_kind: tcx.sess.opts.debugging_opts.split_dwarf,
1057+
split_debuginfo: tcx.sess.split_debuginfo(),
10421058
};
10431059

10441060
// This is the "main loop" of parallel work happening for parallel codegen.

compiler/rustc_codegen_ssa/src/mir/constant.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
3030
.tcx()
3131
.const_eval_resolve(ty::ParamEnv::reveal_all(), def, substs, promoted, None)
3232
.map_err(|err| {
33-
if promoted.is_none() {
34-
self.cx
35-
.tcx()
36-
.sess
37-
.span_err(constant.span, "erroneous constant encountered");
38-
}
33+
self.cx.tcx().sess.span_err(constant.span, "erroneous constant encountered");
3934
err
4035
}),
4136
ty::ConstKind::Value(value) => Ok(value),

compiler/rustc_expand/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ rustc_attr = { path = "../rustc_attr" }
1818
rustc_data_structures = { path = "../rustc_data_structures" }
1919
rustc_errors = { path = "../rustc_errors" }
2020
rustc_feature = { path = "../rustc_feature" }
21+
rustc_lint_defs = { path = "../rustc_lint_defs" }
2122
rustc_macros = { path = "../rustc_macros" }
2223
rustc_lexer = { path = "../rustc_lexer" }
2324
rustc_parse = { path = "../rustc_parse" }

0 commit comments

Comments
 (0)