Skip to content

Commit

Permalink
Rollup merge of #78875 - petrochenkov:cleantarg, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
rustc_target: Further cleanup use of target options

Follow up to #77729.

Implements items 2 and 4 from the list in #77729 (comment).

The first commit collapses uses of `target.options.foo` into `target.foo`.

The second commit renames some target options to avoid tautology:
`target.target_endian` -> `target.endian`
`target.target_c_int_width` -> `target.c_int_width`
`target.target_os` -> `target.os`
`target.target_env` -> `target.env`
`target.target_vendor` -> `target.vendor`
`target.target_family` -> `target.os_family`
`target.target_mcount` -> `target.mcount`

r? `@Mark-Simulacrum`
  • Loading branch information
jonas-schievink committed Nov 10, 2020
2 parents e15fee9 + 7f91175 commit 105f4b8
Show file tree
Hide file tree
Showing 153 changed files with 453 additions and 503 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {

fn visit_expr(&mut self, expr: &'a Expr) {
match &expr.kind {
ExprKind::LlvmInlineAsm(..) if !self.session.target.options.allow_asm => {
ExprKind::LlvmInlineAsm(..) if !self.session.target.allow_asm => {
struct_span_err!(
self.session,
expr.span,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/test_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct TestCtxt<'a> {
pub fn inject(sess: &Session, resolver: &mut dyn ResolverExpand, krate: &mut ast::Crate) {
let span_diagnostic = sess.diagnostic();
let panic_strategy = sess.panic_strategy();
let platform_panic_strategy = sess.target.options.panic_strategy;
let platform_panic_strategy = sess.target.panic_strategy;

// Check for #![reexport_test_harness_main = "some_name"] which gives the
// main test function the name `some_name` without hygiene. This needs to be
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_cranelift/src/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
sess,
dst: output.to_path_buf(),
lib_search_paths: archive_search_paths(sess),
use_gnu_style_archive: sess.target.options.archive_format == "gnu",
use_gnu_style_archive: sess.target.archive_format == "gnu",
// FIXME fix builtin ranlib on macOS
no_builtin_ranlib: sess.target.options.is_like_osx,
no_builtin_ranlib: sess.target.is_like_osx,

src_archives,
entries,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl<'tcx> DebugContext<'tcx> {
// TODO: this should be configurable
// macOS doesn't seem to support DWARF > 3
// 5 version is required for md5 file hash
version: if tcx.sess.target.options.is_like_osx {
version: if tcx.sess.target.is_like_osx {
3
} else {
// FIXME change to version 5 once the gdb and lldb shipping with the latest debian
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_cranelift/src/driver/aot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ fn codegen_global_asm(tcx: TyCtxt<'_>, cgu_name: &str, global_asm: &str) {
}

if cfg!(not(feature = "inline_asm"))
|| tcx.sess.target.options.is_like_osx
|| tcx.sess.target.options.is_like_windows
|| tcx.sess.target.is_like_osx
|| tcx.sess.target.is_like_windows
{
if global_asm.contains("__rust_probestack") {
return;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub(crate) fn write_metadata<P: WriteMetadata>(
product.add_rustc_section(
rustc_middle::middle::exported_symbols::metadata_symbol_name(tcx),
compressed,
tcx.sess.target.options.is_like_osx,
tcx.sess.target.is_like_osx,
);

metadata
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_cranelift/src/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
} else if stem == "link" || stem == "lld-link" {
LinkerFlavor::Msvc
} else if stem == "lld" || stem == "rust-lld" {
LinkerFlavor::Lld(sess.target.options.lld_flavor)
LinkerFlavor::Lld(sess.target.lld_flavor)
} else {
// fall back to the value in the target spec
sess.target.linker_flavor
Expand All @@ -115,7 +115,7 @@ fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {

if let Some(ret) = infer_from(
sess,
sess.target.options.linker.clone().map(PathBuf::from),
sess.target.linker.clone().map(PathBuf::from),
Some(sess.target.linker_flavor),
) {
return ret;
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub(crate) unsafe fn codegen(
let name = format!("__rust_{}", method.name);
let llfn = llvm::LLVMRustGetOrInsertFunction(llmod, name.as_ptr().cast(), name.len(), ty);

if tcx.sess.target.options.default_hidden_visibility {
if tcx.sess.target.default_hidden_visibility {
llvm::LLVMRustSetVisibility(llfn, llvm::Visibility::Hidden);
}
if tcx.sess.must_emit_unwind_tables() {
Expand Down Expand Up @@ -98,7 +98,7 @@ pub(crate) unsafe fn codegen(
// -> ! DIFlagNoReturn
llvm::Attribute::NoReturn.apply_llfn(llvm::AttributePlace::Function, llfn);

if tcx.sess.target.options.default_hidden_visibility {
if tcx.sess.target.default_hidden_visibility {
llvm::LLVMRustSetVisibility(llfn, llvm::Visibility::Hidden);
}
if tcx.sess.must_emit_unwind_tables() {
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_codegen_llvm/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ fn set_instrument_function(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {

// The function name varies on platforms.
// See test/CodeGen/mcount.c in clang.
let mcount_name =
CString::new(cx.sess().target.options.target_mcount.as_str().as_bytes()).unwrap();
let mcount_name = CString::new(cx.sess().target.mcount.as_str().as_bytes()).unwrap();

llvm::AddFunctionAttrStringValue(
llfn,
Expand All @@ -105,7 +104,7 @@ fn set_instrument_function(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
fn set_probestack(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
// Only use stack probes if the target specification indicates that we
// should be using stack probes
if !cx.sess().target.options.stack_probes {
if !cx.sess().target.stack_probes {
return;
}

Expand Down Expand Up @@ -174,7 +173,6 @@ pub fn llvm_target_features(sess: &Session) -> impl Iterator<Item = &str> {
.split(',')
.filter(|f| !RUSTC_SPECIFIC_FEATURES.iter().any(|s| f.contains(s)));
sess.target
.options
.features
.split(',')
.chain(cmdline)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/back/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl<'a> LlvmArchiveBuilder<'a> {
}

fn llvm_archive_kind(&self) -> Result<ArchiveKind, &str> {
let kind = &*self.config.sess.target.options.archive_format;
let kind = &*self.config.sess.target.archive_format;
kind.parse().map_err(|_| kind)
}

Expand Down
24 changes: 9 additions & 15 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ pub fn target_machine_factory(
let use_softfp = sess.opts.cg.soft_float;

let ffunction_sections =
sess.opts.debugging_opts.function_sections.unwrap_or(sess.target.options.function_sections);
sess.opts.debugging_opts.function_sections.unwrap_or(sess.target.function_sections);
let fdata_sections = ffunction_sections;

let code_model = to_llvm_code_model(sess.code_model());

let features = attributes::llvm_target_features(sess).collect::<Vec<_>>();
let mut singlethread = sess.target.options.singlethread;
let mut singlethread = sess.target.singlethread;

// On the wasm target once the `atomics` feature is enabled that means that
// we're no longer single-threaded, or otherwise we don't want LLVM to
Expand All @@ -151,22 +151,16 @@ pub fn target_machine_factory(
let cpu = SmallCStr::new(llvm_util::target_cpu(sess));
let features = features.join(",");
let features = CString::new(features).unwrap();
let abi = SmallCStr::new(&sess.target.options.llvm_abiname);
let trap_unreachable = sess.target.options.trap_unreachable;
let abi = SmallCStr::new(&sess.target.llvm_abiname);
let trap_unreachable = sess.target.trap_unreachable;
let emit_stack_size_section = sess.opts.debugging_opts.emit_stack_sizes;

let asm_comments = sess.asm_comments();
let relax_elf_relocations = sess
.opts
.debugging_opts
.relax_elf_relocations
.unwrap_or(sess.target.options.relax_elf_relocations);

let use_init_array = !sess
.opts
.debugging_opts
.use_ctors_section
.unwrap_or(sess.target.options.use_ctors_section);
let relax_elf_relocations =
sess.opts.debugging_opts.relax_elf_relocations.unwrap_or(sess.target.relax_elf_relocations);

let use_init_array =
!sess.opts.debugging_opts.use_ctors_section.unwrap_or(sess.target.use_ctors_section);

Arc::new(move || {
let tm = unsafe {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ pub fn get_fn(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>) -> &'ll Value
// should use dllimport for functions.
if cx.use_dll_storage_attrs
&& tcx.is_dllimport_foreign_item(instance_def_id)
&& tcx.sess.target.target_env != "gnu"
&& tcx.sess.target.env != "gnu"
{
unsafe {
llvm::LLVMSetDLLStorageClass(llfn, llvm::DLLStorageClass::DllImport);
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_llvm/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn set_global_alignment(cx: &CodegenCx<'ll, '_>, gv: &'ll Value, mut align: Alig
// The target may require greater alignment for globals than the type does.
// Note: GCC and Clang also allow `__attribute__((aligned))` on variables,
// which can force it to be smaller. Rust doesn't support this yet.
if let Some(min) = cx.sess().target.options.min_global_align {
if let Some(min) = cx.sess().target.min_global_align {
match Align::from_bits(min) {
Ok(min) => align = align.max(min),
Err(err) => {
Expand Down Expand Up @@ -283,7 +283,7 @@ impl CodegenCx<'ll, 'tcx> {
// argument validation.
debug_assert!(
!(self.tcx.sess.opts.cg.linker_plugin_lto.enabled()
&& self.tcx.sess.target.options.is_like_windows
&& self.tcx.sess.target.is_like_windows
&& self.tcx.sess.opts.cg.prefer_dynamic)
);

Expand Down Expand Up @@ -435,7 +435,7 @@ impl StaticMethods for CodegenCx<'ll, 'tcx> {
// will use load-unaligned instructions instead, and thus avoiding the crash.
//
// We could remove this hack whenever we decide to drop macOS 10.10 support.
if self.tcx.sess.target.options.is_like_osx {
if self.tcx.sess.target.is_like_osx {
// The `inspect` method is okay here because we checked relocations, and
// because we are doing this access to inspect the final interpreter state
// (not as part of the interpreter execution).
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub unsafe fn create_module(
}

// Ensure the data-layout values hardcoded remain the defaults.
if sess.target.options.is_builtin {
if sess.target.is_builtin {
let tm = crate::back::write::create_informational_target_machine(tcx.sess);
llvm::LLVMRustSetDataLayoutFromTargetMachine(llmod, tm);
llvm::LLVMRustDisposeTargetMachine(tm);
Expand Down Expand Up @@ -190,7 +190,7 @@ pub unsafe fn create_module(
}

// Control Flow Guard is currently only supported by the MSVC linker on Windows.
if sess.target.options.is_like_msvc {
if sess.target.is_like_msvc {
match sess.opts.cg.control_flow_guard {
CFGuard::Disabled => {}
CFGuard::NoChecks => {
Expand Down Expand Up @@ -265,7 +265,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
// linker will take care of everything. Fixing this problem will likely
// require adding a few attributes to Rust itself (feature gated at the
// start) and then strongly recommending static linkage on Windows!
let use_dll_storage_attrs = tcx.sess.target.options.is_like_windows;
let use_dll_storage_attrs = tcx.sess.target.is_like_windows;

let check_overflow = tcx.sess.overflow_checks();

Expand Down Expand Up @@ -839,7 +839,7 @@ impl CodegenCx<'b, 'tcx> {
return eh_catch_typeinfo;
}
let tcx = self.tcx;
assert!(self.sess().target.options.is_like_emscripten);
assert!(self.sess().target.is_like_emscripten);
let eh_catch_typeinfo = match tcx.lang_items().eh_catch_typeinfo() {
Some(def_id) => self.get_static(def_id),
_ => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@ pub fn needs_gdb_debug_scripts_section(cx: &CodegenCx<'_, '_>) -> bool {

!omit_gdb_pretty_printer_section
&& cx.sess().opts.debuginfo != DebugInfo::None
&& cx.sess().target.options.emit_debug_gdb_scripts
&& cx.sess().target.emit_debug_gdb_scripts
}
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ fn basic_type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll DIType {

// When targeting MSVC, emit MSVC style type names for compatibility with
// .natvis visualizers (and perhaps other existing native debuggers?)
let msvc_like_names = cx.tcx.sess.target.options.is_like_msvc;
let msvc_like_names = cx.tcx.sess.target.is_like_msvc;

let (name, encoding) = match t.kind() {
ty::Never => ("!", DW_ATE_unsigned),
Expand Down Expand Up @@ -981,7 +981,7 @@ pub fn compile_unit_metadata(
// if multiple object files with the same `DW_AT_name` are linked together.
// As a workaround we generate unique names for each object file. Those do
// not correspond to an actual source file but that should be harmless.
if tcx.sess.target.options.is_like_osx {
if tcx.sess.target.is_like_osx {
name_in_debuginfo.push("@");
name_in_debuginfo.push(codegen_unit_name);
}
Expand Down Expand Up @@ -1397,7 +1397,7 @@ fn prepare_union_metadata(
/// on MSVC we have to use the fallback mode, because LLVM doesn't
/// lower variant parts to PDB.
fn use_enum_fallback(cx: &CodegenCx<'_, '_>) -> bool {
cx.sess().target.options.is_like_msvc
cx.sess().target.is_like_msvc
}

// FIXME(eddyb) maybe precompute this? Right now it's computed once
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_codegen_llvm/src/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ pub fn finalize(cx: &CodegenCx<'_, '_>) {
// for macOS to understand. For more info see #11352
// This can be overridden using --llvm-opts -dwarf-version,N.
// Android has the same issue (#22398)
if let Some(version) = cx.sess().target.options.dwarf_version {
if let Some(version) = cx.sess().target.dwarf_version {
llvm::LLVMRustAddModuleFlag(cx.llmod, "Dwarf Version\0".as_ptr().cast(), version)
}

// Indicate that we want CodeView debug information on MSVC
if cx.sess().target.options.is_like_msvc {
if cx.sess().target.is_like_msvc {
llvm::LLVMRustAddModuleFlag(cx.llmod, "CodeView\0".as_ptr().cast(), 1)
}

Expand Down Expand Up @@ -251,7 +251,7 @@ impl CodegenCx<'ll, '_> {
// For MSVC, omit the column number.
// Otherwise, emit it. This mimics clang behaviour.
// See discussion in https://github.com/rust-lang/rust/issues/42921
if self.sess().target.options.is_like_msvc {
if self.sess().target.is_like_msvc {
DebugLoc { file, line, col: None }
} else {
DebugLoc { file, line, col }
Expand Down Expand Up @@ -387,7 +387,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
});

// Arguments types
if cx.sess().target.options.is_like_msvc {
if cx.sess().target.is_like_msvc {
// FIXME(#42800):
// There is a bug in MSDIA that leads to a crash when it encounters
// a fixed-size array of `u8` or something zero-sized in a
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn declare_raw_fn(
// be merged.
llvm::SetUnnamedAddress(llfn, llvm::UnnamedAddr::Global);

if cx.tcx.sess.opts.cg.no_redzone.unwrap_or(cx.tcx.sess.target.options.disable_redzone) {
if cx.tcx.sess.opts.cg.no_redzone.unwrap_or(cx.tcx.sess.target.disable_redzone) {
llvm::Attribute::NoRedZone.apply_llfn(Function, llfn);
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ fn try_intrinsic(
bx.store(bx.const_i32(0), dest, ret_align);
} else if wants_msvc_seh(bx.sess()) {
codegen_msvc_try(bx, try_func, data, catch_func, dest);
} else if bx.sess().target.options.is_like_emscripten {
} else if bx.sess().target.is_like_emscripten {
codegen_emcc_try(bx, try_func, data, catch_func, dest);
} else {
codegen_gnu_try(bx, try_func, data, catch_func, dest);
Expand Down
15 changes: 5 additions & 10 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn require_inited() {
}

unsafe fn configure_llvm(sess: &Session) {
let n_args = sess.opts.cg.llvm_args.len() + sess.target.options.llvm_args.len();
let n_args = sess.opts.cg.llvm_args.len() + sess.target.llvm_args.len();
let mut llvm_c_strs = Vec::with_capacity(n_args + 1);
let mut llvm_args = Vec::with_capacity(n_args + 1);

Expand All @@ -57,7 +57,7 @@ unsafe fn configure_llvm(sess: &Session) {
}

let cg_opts = sess.opts.cg.llvm_args.iter();
let tg_opts = sess.target.options.llvm_args.iter();
let tg_opts = sess.target.llvm_args.iter();
let sess_args = cg_opts.chain(tg_opts);

let user_specified_args: FxHashSet<_> =
Expand All @@ -84,19 +84,14 @@ unsafe fn configure_llvm(sess: &Session) {
if !sess.opts.debugging_opts.no_generate_arange_section {
add("-generate-arange-section", false);
}
match sess
.opts
.debugging_opts
.merge_functions
.unwrap_or(sess.target.options.merge_functions)
{
match sess.opts.debugging_opts.merge_functions.unwrap_or(sess.target.merge_functions) {
MergeFunctions::Disabled | MergeFunctions::Trampolines => {}
MergeFunctions::Aliases => {
add("-mergefunc-use-aliases", false);
}
}

if sess.target.target_os == "emscripten" && sess.panic_strategy() == PanicStrategy::Unwind {
if sess.target.os == "emscripten" && sess.panic_strategy() == PanicStrategy::Unwind {
add("-enable-emscripten-cxx-exceptions", false);
}

Expand Down Expand Up @@ -215,7 +210,7 @@ fn handle_native(name: &str) -> &str {
pub fn target_cpu(sess: &Session) -> &str {
let name = match sess.opts.cg.target_cpu {
Some(ref s) => &**s,
None => &*sess.target.options.cpu,
None => &*sess.target.cpu,
};

handle_native(name)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub fn metadata_section_name(target: &Target) -> &'static str {
// As a result, we choose a slightly shorter name! As to why
// `.note.rustc` works on MinGW, that's another good question...

if target.options.is_like_osx { "__DATA,.rustc" } else { ".rustc" }
if target.is_like_osx { "__DATA,.rustc" } else { ".rustc" }
}

fn read_metadata_section_name(_target: &Target) -> &'static str {
Expand Down
Loading

0 comments on commit 105f4b8

Please sign in to comment.