Skip to content

Commit

Permalink
Auto merge of rust-lang#81493 - JohnTitor:rollup-sa4m4zh, r=JohnTitor
Browse files Browse the repository at this point in the history
Rollup of 10 pull requests

Successful merges:

 - rust-lang#79570 (rustc: Stabilize `-Zrun-dsymutil` as `-Csplit-debuginfo`)
 - rust-lang#79819 (Add `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` lint)
 - rust-lang#79991 (rustdoc: Render HRTB correctly for bare functions)
 - rust-lang#80215 (Use -target when linking binaries for Mac Catalyst)
 - rust-lang#81158 (Point to span of upvar making closure FnMut)
 - rust-lang#81176 (Improve safety of `LateContext::qpath_res`)
 - rust-lang#81287 (Split rustdoc JSON types into separately versioned crate)
 - rust-lang#81306 (Fuse inner iterator in FlattenCompat and improve related tests)
 - rust-lang#81333 (clean up some const error reporting around promoteds)
 - rust-lang#81459 (Fix rustdoc text selection for page titles)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jan 29, 2021
2 parents b05fd2a + 2b4fa3d commit 74500b9
Show file tree
Hide file tree
Showing 90 changed files with 979 additions and 442 deletions.
9 changes: 9 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3746,6 +3746,7 @@ dependencies = [
"rustc_errors",
"rustc_feature",
"rustc_lexer",
"rustc_lint_defs",
"rustc_macros",
"rustc_parse",
"rustc_serialize",
Expand Down Expand Up @@ -4391,12 +4392,20 @@ dependencies = [
"pulldown-cmark 0.8.0",
"regex",
"rustc-rayon",
"rustdoc-json-types",
"serde",
"serde_json",
"smallvec 1.4.2",
"tempfile",
]

[[package]]
name = "rustdoc-json-types"
version = "0.1.0"
dependencies = [
"serde",
]

[[package]]
name = "rustdoc-themes"
version = "0.1.0"
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"compiler/rustc",
"library/std",
"library/test",
"src/rustdoc-json-types",
"src/tools/cargotest",
"src/tools/clippy",
"src/tools/compiletest",
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_codegen_cranelift/src/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,9 @@ pub(crate) fn codegen_constant<'tcx>(
{
Ok(const_val) => const_val,
Err(_) => {
if promoted.is_none() {
fx.tcx
.sess
.span_err(constant.span, "erroneous constant encountered");
}
fx.tcx
.sess
.span_err(constant.span, "erroneous constant encountered");
return crate::trap::trap_unreachable_ret_value(
fx,
fx.layout_of(const_.ty),
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_codegen_llvm/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,10 +732,7 @@ pub unsafe fn optimize_thin_module(
let diag_handler = cgcx.create_diag_handler();

let module_name = &thin_module.shared.module_names[thin_module.idx];
let split_dwarf_file = cgcx
.output_filenames
.split_dwarf_filename(cgcx.split_dwarf_kind, Some(module_name.to_str().unwrap()));
let tm_factory_config = TargetMachineFactoryConfig { split_dwarf_file };
let tm_factory_config = TargetMachineFactoryConfig::new(cgcx, module_name.to_str().unwrap());
let tm =
(cgcx.tm_factory)(tm_factory_config).map_err(|e| write::llvm_err(&diag_handler, &e))?;

Expand Down
29 changes: 18 additions & 11 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ use rustc_fs_util::{link_or_copy, path_to_c_string};
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_middle::bug;
use rustc_middle::ty::TyCtxt;
use rustc_session::config::{
self, Lto, OutputType, Passes, SanitizerSet, SplitDwarfKind, SwitchWithOptPath,
};
use rustc_session::config::{self, Lto, OutputType, Passes, SanitizerSet, SwitchWithOptPath};
use rustc_session::Session;
use rustc_span::symbol::sym;
use rustc_span::InnerSpan;
use rustc_target::spec::{CodeModel, RelocModel};
use rustc_target::spec::{CodeModel, RelocModel, SplitDebuginfo};
use tracing::debug;

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

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

let dwo_out = cgcx.output_filenames.temp_path_dwo(module_name);
let dwo_out = match cgcx.split_dwarf_kind {
let dwo_out = match cgcx.split_debuginfo {
// Don't change how DWARF is emitted in single mode (or when disabled).
SplitDwarfKind::None | SplitDwarfKind::Single => None,
SplitDebuginfo::Off | SplitDebuginfo::Packed => None,
// Emit (a subset of the) DWARF into a separate file in split mode.
SplitDwarfKind::Split => Some(dwo_out.as_path()),
SplitDebuginfo::Unpacked => {
if cgcx.target_can_use_split_dwarf {
Some(dwo_out.as_path())
} else {
None
}
}
};

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

Ok(module.into_compiled_module(
config.emit_obj != EmitObj::None,
cgcx.split_dwarf_kind == SplitDwarfKind::Split,
cgcx.target_can_use_split_dwarf && cgcx.split_debuginfo == SplitDebuginfo::Unpacked,
config.emit_bc,
&cgcx.output_filenames,
))
Expand Down
11 changes: 7 additions & 4 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -995,10 +995,13 @@ pub fn compile_unit_metadata(
let flags = "\0";

let out_dir = &tcx.output_filenames(LOCAL_CRATE).out_directory;
let split_name = tcx
.output_filenames(LOCAL_CRATE)
.split_dwarf_filename(tcx.sess.opts.debugging_opts.split_dwarf, Some(codegen_unit_name))
.unwrap_or_default();
let split_name = if tcx.sess.target_can_use_split_dwarf() {
tcx.output_filenames(LOCAL_CRATE)
.split_dwarf_filename(tcx.sess.split_debuginfo(), Some(codegen_unit_name))
} else {
None
}
.unwrap_or_default();
let out_dir = out_dir.to_str().unwrap();
let split_name = split_name.to_str().unwrap();

Expand Down
7 changes: 1 addition & 6 deletions compiler/rustc_codegen_llvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,7 @@ impl ModuleLlvm {
unsafe {
let llcx = llvm::LLVMRustContextCreate(cgcx.fewer_names);
let llmod_raw = back::lto::parse_module(llcx, name, buffer, handler)?;

let split_dwarf_file = cgcx
.output_filenames
.split_dwarf_filename(cgcx.split_dwarf_kind, Some(name.to_str().unwrap()));
let tm_factory_config = TargetMachineFactoryConfig { split_dwarf_file };

let tm_factory_config = TargetMachineFactoryConfig::new(&cgcx, name.to_str().unwrap());
let tm = match (cgcx.tm_factory)(tm_factory_config) {
Ok(m) => m,
Err(e) => {
Expand Down
93 changes: 45 additions & 48 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rustc_session::utils::NativeLibKind;
use rustc_session::{filesearch, Session};
use rustc_span::symbol::Symbol;
use rustc_target::spec::crt_objects::{CrtObjects, CrtObjectsFallback};
use rustc_target::spec::{LinkOutputKind, LinkerFlavor, LldFlavor};
use rustc_target::spec::{LinkOutputKind, LinkerFlavor, LldFlavor, SplitDebuginfo};
use rustc_target::spec::{PanicStrategy, RelocModel, RelroLevel, Target};

use super::archive::ArchiveBuilder;
Expand Down Expand Up @@ -99,9 +99,6 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(
path.as_ref(),
target_cpu,
);
if sess.opts.debugging_opts.split_dwarf == config::SplitDwarfKind::Split {
link_dwarf_object(sess, &out_filename);
}
}
}
if sess.opts.json_artifact_notifications {
Expand Down Expand Up @@ -828,29 +825,43 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
}
}

// On macOS, debuggers need this utility to get run to do some munging of
// the symbols. Note, though, that if the object files are being preserved
// for their debug information there's no need for us to run dsymutil.
if sess.target.is_like_osx
&& sess.opts.debuginfo != DebugInfo::None
&& !preserve_objects_for_their_debuginfo(sess)
{
let prog = Command::new("dsymutil").arg(out_filename).output();
match prog {
Ok(prog) => {
if !prog.status.success() {
let mut output = prog.stderr.clone();
output.extend_from_slice(&prog.stdout);
sess.struct_warn(&format!(
"processing debug info with `dsymutil` failed: {}",
prog.status
))
.note(&escape_string(&output))
.emit();
match sess.split_debuginfo() {
// If split debug information is disabled or located in individual files
// there's nothing to do here.
SplitDebuginfo::Off | SplitDebuginfo::Unpacked => {}

// If packed split-debuginfo is requested, but the final compilation
// doesn't actually have any debug information, then we skip this step.
SplitDebuginfo::Packed if sess.opts.debuginfo == DebugInfo::None => {}

// On macOS the external `dsymutil` tool is used to create the packed
// debug information. Note that this will read debug information from
// the objects on the filesystem which we'll clean up later.
SplitDebuginfo::Packed if sess.target.is_like_osx => {
let prog = Command::new("dsymutil").arg(out_filename).output();
match prog {
Ok(prog) => {
if !prog.status.success() {
let mut output = prog.stderr.clone();
output.extend_from_slice(&prog.stdout);
sess.struct_warn(&format!(
"processing debug info with `dsymutil` failed: {}",
prog.status
))
.note(&escape_string(&output))
.emit();
}
}
Err(e) => sess.fatal(&format!("unable to run `dsymutil`: {}", e)),
}
Err(e) => sess.fatal(&format!("unable to run `dsymutil`: {}", e)),
}

// On MSVC packed debug information is produced by the linker itself so
// there's no need to do anything else here.
SplitDebuginfo::Packed if sess.target.is_like_msvc => {}

// ... and otherwise we're processing a `*.dwp` packed dwarf file.
SplitDebuginfo::Packed => link_dwarf_object(sess, &out_filename),
}
}

Expand Down Expand Up @@ -1050,28 +1061,9 @@ fn preserve_objects_for_their_debuginfo(sess: &Session) -> bool {
return false;
}

// Single mode keeps debuginfo in the same object file, but in such a way that it it skipped
// by the linker - so it's expected that when codegen units are linked together that this
// debuginfo would be lost without keeping around the temps.
if sess.opts.debugging_opts.split_dwarf == config::SplitDwarfKind::Single {
return true;
}

// If we're on OSX then the equivalent of split dwarf is turned on by
// default. The final executable won't actually have any debug information
// except it'll have pointers to elsewhere. Historically we've always run
// `dsymutil` to "link all the dwarf together" but this is actually sort of
// a bummer for incremental compilation! (the whole point of split dwarf is
// that you don't do this sort of dwarf link).
//
// Basically as a result this just means that if we're on OSX and we're
// *not* running dsymutil then the object files are the only source of truth
// for debug information, so we must preserve them.
if sess.target.is_like_osx {
return !sess.opts.debugging_opts.run_dsymutil;
}

false
// "unpacked" split debuginfo means that we leave object files as the
// debuginfo is found in the original object files themselves
sess.split_debuginfo() == SplitDebuginfo::Unpacked
}

pub fn archive_search_paths(sess: &Session) -> Vec<PathBuf> {
Expand Down Expand Up @@ -2211,8 +2203,13 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
return;
}
};
let arch_name = llvm_target.split('-').next().expect("LLVM target must have a hyphen");
cmd.args(&["-arch", arch_name, "-isysroot", &sdk_root, "-Wl,-syslibroot", &sdk_root]);
if llvm_target.contains("macabi") {
cmd.args(&["-target", llvm_target])
} else {
let arch_name = llvm_target.split('-').next().expect("LLVM target must have a hyphen");
cmd.args(&["-arch", arch_name])
}
cmd.args(&["-isysroot", &sdk_root, "-Wl,-syslibroot", &sdk_root]);
}

fn get_apple_sdk_root(sdk_name: &str) -> Result<String, String> {
Expand Down
20 changes: 18 additions & 2 deletions compiler/rustc_codegen_ssa/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,20 @@ pub struct TargetMachineFactoryConfig {
pub split_dwarf_file: Option<PathBuf>,
}

impl TargetMachineFactoryConfig {
pub fn new(
cgcx: &CodegenContext<impl WriteBackendMethods>,
module_name: &str,
) -> TargetMachineFactoryConfig {
let split_dwarf_file = if cgcx.target_can_use_split_dwarf {
cgcx.output_filenames.split_dwarf_filename(cgcx.split_debuginfo, Some(module_name))
} else {
None
};
TargetMachineFactoryConfig { split_dwarf_file }
}
}

pub type TargetMachineFactoryFn<B> = Arc<
dyn Fn(TargetMachineFactoryConfig) -> Result<<B as WriteBackendMethods>::TargetMachine, String>
+ Send
Expand Down Expand Up @@ -311,10 +325,11 @@ pub struct CodegenContext<B: WriteBackendMethods> {
pub tm_factory: TargetMachineFactoryFn<B>,
pub msvc_imps_needed: bool,
pub is_pe_coff: bool,
pub target_can_use_split_dwarf: bool,
pub target_pointer_width: u32,
pub target_arch: String,
pub debuginfo: config::DebugInfo,
pub split_dwarf_kind: config::SplitDwarfKind,
pub split_debuginfo: rustc_target::spec::SplitDebuginfo,

// Number of cgus excluding the allocator/metadata modules
pub total_cgus: usize,
Expand Down Expand Up @@ -1035,10 +1050,11 @@ fn start_executing_work<B: ExtraBackendMethods>(
total_cgus,
msvc_imps_needed: msvc_imps_needed(tcx),
is_pe_coff: tcx.sess.target.is_like_windows,
target_can_use_split_dwarf: tcx.sess.target_can_use_split_dwarf(),
target_pointer_width: tcx.sess.target.pointer_width,
target_arch: tcx.sess.target.arch.clone(),
debuginfo: tcx.sess.opts.debuginfo,
split_dwarf_kind: tcx.sess.opts.debugging_opts.split_dwarf,
split_debuginfo: tcx.sess.split_debuginfo(),
};

// This is the "main loop" of parallel work happening for parallel codegen.
Expand Down
7 changes: 1 addition & 6 deletions compiler/rustc_codegen_ssa/src/mir/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
.tcx()
.const_eval_resolve(ty::ParamEnv::reveal_all(), def, substs, promoted, None)
.map_err(|err| {
if promoted.is_none() {
self.cx
.tcx()
.sess
.span_err(constant.span, "erroneous constant encountered");
}
self.cx.tcx().sess.span_err(constant.span, "erroneous constant encountered");
err
}),
ty::ConstKind::Value(value) => Ok(value),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_expand/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ rustc_attr = { path = "../rustc_attr" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" }
rustc_feature = { path = "../rustc_feature" }
rustc_lint_defs = { path = "../rustc_lint_defs" }
rustc_macros = { path = "../rustc_macros" }
rustc_lexer = { path = "../rustc_lexer" }
rustc_parse = { path = "../rustc_parse" }
Expand Down
Loading

0 comments on commit 74500b9

Please sign in to comment.