Skip to content

Commit b5c9e24

Browse files
committed
Auto merge of #77943 - est31:target_refactor, r=petrochenkov
No more target.target Two main changes of this PR: * Turn `target_pointer_width` into an integer and rename to `pointer_width`. The compiler only allowed three valid values for the width anyways. An integer is more natural for this value, and saves a few allocations and copies. * Remove the `rustc_session::config::Config` wrapper and replace it with its inner member `Target`. Aka. no more `target.target`. This makes life so much easier, but it also causes a ton of downstream breakage. Some changes of this PR were done using tooling. These tooling-made changes were isolated to their own commits to make review easier. It's best to review the PR commit-by-commit. Miri PR: rust-lang/miri#1583 I request p=10 bors priority because of the breakage.
2 parents 7f58716 + d683e3a commit b5c9e24

File tree

203 files changed

+406
-430
lines changed

Some content is hidden

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

203 files changed

+406
-430
lines changed

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
985985
asm::InlineAsmReg::parse(
986986
sess.asm_arch?,
987987
|feature| sess.target_features.contains(&Symbol::intern(feature)),
988-
&sess.target.target,
988+
&sess.target,
989989
s,
990990
)
991991
.map_err(|e| {

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
796796

797797
fn visit_expr(&mut self, expr: &'a Expr) {
798798
match &expr.kind {
799-
ExprKind::LlvmInlineAsm(..) if !self.session.target.target.options.allow_asm => {
799+
ExprKind::LlvmInlineAsm(..) if !self.session.target.options.allow_asm => {
800800
struct_span_err!(
801801
self.session,
802802
expr.span,

compiler/rustc_builtin_macros/src/test_harness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct TestCtxt<'a> {
3737
pub fn inject(sess: &Session, resolver: &mut dyn ResolverExpand, krate: &mut ast::Crate) {
3838
let span_diagnostic = sess.diagnostic();
3939
let panic_strategy = sess.panic_strategy();
40-
let platform_panic_strategy = sess.target.target.options.panic_strategy;
40+
let platform_panic_strategy = sess.target.options.panic_strategy;
4141

4242
// Check for #![reexport_test_harness_main = "some_name"] which gives the
4343
// main test function the name `some_name` without hygiene. This needs to be

compiler/rustc_codegen_llvm/src/allocator.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ pub(crate) unsafe fn codegen(
1616
) {
1717
let llcx = &*mods.llcx;
1818
let llmod = mods.llmod();
19-
let usize = match &tcx.sess.target.target.target_pointer_width[..] {
20-
"16" => llvm::LLVMInt16TypeInContext(llcx),
21-
"32" => llvm::LLVMInt32TypeInContext(llcx),
22-
"64" => llvm::LLVMInt64TypeInContext(llcx),
19+
let usize = match tcx.sess.target.pointer_width {
20+
16 => llvm::LLVMInt16TypeInContext(llcx),
21+
32 => llvm::LLVMInt32TypeInContext(llcx),
22+
64 => llvm::LLVMInt64TypeInContext(llcx),
2323
tws => bug!("Unsupported target word size for int: {}", tws),
2424
};
2525
let i8 = llvm::LLVMInt8TypeInContext(llcx);
@@ -57,7 +57,7 @@ pub(crate) unsafe fn codegen(
5757
let name = format!("__rust_{}", method.name);
5858
let llfn = llvm::LLVMRustGetOrInsertFunction(llmod, name.as_ptr().cast(), name.len(), ty);
5959

60-
if tcx.sess.target.target.options.default_hidden_visibility {
60+
if tcx.sess.target.options.default_hidden_visibility {
6161
llvm::LLVMRustSetVisibility(llfn, llvm::Visibility::Hidden);
6262
}
6363
if tcx.sess.must_emit_unwind_tables() {
@@ -98,7 +98,7 @@ pub(crate) unsafe fn codegen(
9898
// -> ! DIFlagNoReturn
9999
llvm::Attribute::NoReturn.apply_llfn(llvm::AttributePlace::Function, llfn);
100100

101-
if tcx.sess.target.target.options.default_hidden_visibility {
101+
if tcx.sess.target.options.default_hidden_visibility {
102102
llvm::LLVMRustSetVisibility(llfn, llvm::Visibility::Hidden);
103103
}
104104
if tcx.sess.must_emit_unwind_tables() {

compiler/rustc_codegen_llvm/src/asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
6060

6161
// Default per-arch clobbers
6262
// Basically what clang does
63-
let arch_clobbers = match &self.sess().target.target.arch[..] {
63+
let arch_clobbers = match &self.sess().target.arch[..] {
6464
"x86" | "x86_64" => vec!["~{dirflag}", "~{fpsr}", "~{flags}"],
6565
"mips" | "mips64" => vec!["~{$1}"],
6666
_ => Vec::new(),

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn inline(cx: &CodegenCx<'ll, '_>, val: &'ll Value, inline: InlineAttr) {
3131
Hint => Attribute::InlineHint.apply_llfn(Function, val),
3232
Always => Attribute::AlwaysInline.apply_llfn(Function, val),
3333
Never => {
34-
if cx.tcx().sess.target.target.arch != "amdgpu" {
34+
if cx.tcx().sess.target.arch != "amdgpu" {
3535
Attribute::NoInline.apply_llfn(Function, val);
3636
}
3737
}
@@ -91,8 +91,7 @@ fn set_instrument_function(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
9191
// The function name varies on platforms.
9292
// See test/CodeGen/mcount.c in clang.
9393
let mcount_name =
94-
CString::new(cx.sess().target.target.options.target_mcount.as_str().as_bytes())
95-
.unwrap();
94+
CString::new(cx.sess().target.options.target_mcount.as_str().as_bytes()).unwrap();
9695

9796
llvm::AddFunctionAttrStringValue(
9897
llfn,
@@ -106,7 +105,7 @@ fn set_instrument_function(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
106105
fn set_probestack(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
107106
// Only use stack probes if the target specification indicates that we
108107
// should be using stack probes
109-
if !cx.sess().target.target.options.stack_probes {
108+
if !cx.sess().target.options.stack_probes {
110109
return;
111110
}
112111

@@ -175,7 +174,6 @@ pub fn llvm_target_features(sess: &Session) -> impl Iterator<Item = &str> {
175174
.split(',')
176175
.filter(|f| !RUSTC_SPECIFIC_FEATURES.iter().any(|s| f.contains(s)));
177176
sess.target
178-
.target
179177
.options
180178
.features
181179
.split(',')
@@ -345,7 +343,7 @@ pub fn from_fn_attrs(cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value, instance: ty::
345343
// Note that currently the `wasm-import-module` doesn't do anything, but
346344
// eventually LLVM 7 should read this and ferry the appropriate import
347345
// module to the output file.
348-
if cx.tcx.sess.target.target.arch == "wasm32" {
346+
if cx.tcx.sess.target.arch == "wasm32" {
349347
if let Some(module) = wasm_import_module(cx.tcx, instance.def_id()) {
350348
llvm::AddFunctionAttrStringValue(
351349
llfn,

compiler/rustc_codegen_llvm/src/back/archive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl<'a> LlvmArchiveBuilder<'a> {
206206
}
207207

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

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,40 +128,40 @@ pub fn target_machine_factory(
128128
let (opt_level, _) = to_llvm_opt_settings(optlvl);
129129
let use_softfp = sess.opts.cg.soft_float;
130130

131-
let ffunction_sections = sess.target.target.options.function_sections;
131+
let ffunction_sections = sess.target.options.function_sections;
132132
let fdata_sections = ffunction_sections;
133133

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

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

139139
// On the wasm target once the `atomics` feature is enabled that means that
140140
// we're no longer single-threaded, or otherwise we don't want LLVM to
141141
// lower atomic operations to single-threaded operations.
142142
if singlethread
143-
&& sess.target.target.llvm_target.contains("wasm32")
143+
&& sess.target.llvm_target.contains("wasm32")
144144
&& sess.target_features.contains(&sym::atomics)
145145
{
146146
singlethread = false;
147147
}
148148

149-
let triple = SmallCStr::new(&sess.target.target.llvm_target);
149+
let triple = SmallCStr::new(&sess.target.llvm_target);
150150
let cpu = SmallCStr::new(llvm_util::target_cpu(sess));
151151
let features = features.join(",");
152152
let features = CString::new(features).unwrap();
153-
let abi = SmallCStr::new(&sess.target.target.options.llvm_abiname);
154-
let trap_unreachable = sess.target.target.options.trap_unreachable;
153+
let abi = SmallCStr::new(&sess.target.options.llvm_abiname);
154+
let trap_unreachable = sess.target.options.trap_unreachable;
155155
let emit_stack_size_section = sess.opts.debugging_opts.emit_stack_sizes;
156156

157157
let asm_comments = sess.asm_comments();
158-
let relax_elf_relocations = sess.target.target.options.relax_elf_relocations;
158+
let relax_elf_relocations = sess.target.options.relax_elf_relocations;
159159

160160
let use_init_array = !sess
161161
.opts
162162
.debugging_opts
163163
.use_ctors_section
164-
.unwrap_or(sess.target.target.options.use_ctors_section);
164+
.unwrap_or(sess.target.options.use_ctors_section);
165165

166166
Arc::new(move || {
167167
let tm = unsafe {

compiler/rustc_codegen_llvm/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub fn write_compressed_metadata<'tcx>(
6060
unsafe { llvm::LLVMAddGlobal(metadata_llmod, common::val_ty(llconst), buf.as_ptr()) };
6161
unsafe {
6262
llvm::LLVMSetInitializer(llglobal, llconst);
63-
let section_name = metadata::metadata_section_name(&tcx.sess.target.target);
63+
let section_name = metadata::metadata_section_name(&tcx.sess.target);
6464
let name = SmallCStr::new(section_name);
6565
llvm::LLVMSetSection(llglobal, name.as_ptr());
6666

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
308308
use rustc_middle::ty::{Int, Uint};
309309

310310
let new_kind = match ty.kind() {
311-
Int(t @ Isize) => Int(t.normalize(self.tcx.sess.target.ptr_width)),
312-
Uint(t @ Usize) => Uint(t.normalize(self.tcx.sess.target.ptr_width)),
311+
Int(t @ Isize) => Int(t.normalize(self.tcx.sess.target.pointer_width)),
312+
Uint(t @ Usize) => Uint(t.normalize(self.tcx.sess.target.pointer_width)),
313313
t @ (Uint(_) | Int(_)) => t.clone(),
314314
_ => panic!("tried to get overflow intrinsic for op applied to non-int type"),
315315
};
@@ -541,7 +541,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
541541
}
542542

543543
fn range_metadata(&mut self, load: &'ll Value, range: Range<u128>) {
544-
if self.sess().target.target.arch == "amdgpu" {
544+
if self.sess().target.arch == "amdgpu" {
545545
// amdgpu/LLVM does something weird and thinks a i64 value is
546546
// split into a v2i32, halving the bitwidth LLVM expects,
547547
// tripping an assertion. So, for now, just disable this
@@ -671,7 +671,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
671671
// WebAssembly has saturating floating point to integer casts if the
672672
// `nontrapping-fptoint` target feature is activated. We'll use those if
673673
// they are available.
674-
if self.sess().target.target.arch == "wasm32"
674+
if self.sess().target.arch == "wasm32"
675675
&& self.sess().target_features.contains(&sym::nontrapping_dash_fptoint)
676676
{
677677
let src_ty = self.cx.val_ty(val);
@@ -696,7 +696,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
696696
// WebAssembly has saturating floating point to integer casts if the
697697
// `nontrapping-fptoint` target feature is activated. We'll use those if
698698
// they are available.
699-
if self.sess().target.target.arch == "wasm32"
699+
if self.sess().target.arch == "wasm32"
700700
&& self.sess().target_features.contains(&sym::nontrapping_dash_fptoint)
701701
{
702702
let src_ty = self.cx.val_ty(val);
@@ -1427,7 +1427,7 @@ impl Builder<'a, 'll, 'tcx> {
14271427
}
14281428

14291429
fn wasm_and_missing_nontrapping_fptoint(&self) -> bool {
1430-
self.sess().target.target.arch == "wasm32"
1430+
self.sess().target.arch == "wasm32"
14311431
&& !self.sess().target_features.contains(&sym::nontrapping_dash_fptoint)
14321432
}
14331433
}

0 commit comments

Comments
 (0)