Skip to content

Commit 1a1f5b8

Browse files
committed
Cleanup after some refactoring in rustc_target
1 parent c16a558 commit 1a1f5b8

25 files changed

+79
-112
lines changed

compiler/rustc_codegen_cranelift/src/driver/aot.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,12 @@ pub(crate) fn run_aot(
304304
};
305305

306306
// FIXME handle `-Ctarget-cpu=native`
307-
let target_cpu =
308-
tcx.sess.opts.cg.target_cpu.as_ref().unwrap_or(&tcx.sess.target.cpu).to_owned();
307+
let target_cpu = match tcx.sess.opts.cg.target_cpu {
308+
Some(ref name) => name,
309+
None => tcx.sess.target.cpu.as_ref(),
310+
}
311+
.to_owned();
312+
309313
Box::new((
310314
CodegenResults {
311315
modules,

compiler/rustc_codegen_gcc/src/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,10 @@ fn handle_native(name: &str) -> &str {
287287
}
288288

289289
pub fn target_cpu(sess: &Session) -> &str {
290-
let name = sess.opts.cg.target_cpu.as_ref().unwrap_or(&sess.target.cpu);
291-
handle_native(name)
290+
match sess.opts.cg.target_cpu {
291+
Some(ref name) => handle_native(name),
292+
None => handle_native(sess.target.cpu.as_ref()),
293+
}
292294
}
293295

294296
pub fn target_features(sess: &Session) -> Vec<Symbol> {

compiler/rustc_codegen_ssa/src/back/link.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -675,10 +675,10 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
675675

676676
linker::disable_localization(&mut cmd);
677677

678-
for &(ref k, ref v) in sess.target.link_env.iter() {
678+
for &(ref k, ref v) in sess.target.link_env.as_ref() {
679679
cmd.env(k.as_ref(), v.as_ref());
680680
}
681-
for k in sess.target.link_env_remove.iter() {
681+
for k in sess.target.link_env_remove.as_ref() {
682682
cmd.env_remove(k.as_ref());
683683
}
684684

@@ -1217,7 +1217,7 @@ pub fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
12171217

12181218
if let Some(ret) = infer_from(
12191219
sess,
1220-
sess.target.linker.as_ref().map(|l| PathBuf::from(l.as_ref())),
1220+
sess.target.linker.as_deref().map(PathBuf::from),
12211221
Some(sess.target.linker_flavor),
12221222
) {
12231223
return ret;

compiler/rustc_session/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ fn default_configuration(sess: &Session) -> CrateConfig {
956956
ret.reserve(7); // the minimum number of insertions
957957
// Target bindings.
958958
ret.insert((sym::target_os, Some(Symbol::intern(os))));
959-
for fam in sess.target.families.iter() {
959+
for fam in sess.target.families.as_ref() {
960960
ret.insert((sym::target_family, Some(Symbol::intern(fam))));
961961
if fam == "windows" {
962962
ret.insert((sym::windows, None));

compiler/rustc_target/src/spec/apple_base.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use std::{borrow::Cow, env};
22

3-
use crate::spec::{FramePointer, LldFlavor, SplitDebuginfo, TargetOptions};
4-
5-
use super::cvs;
3+
use crate::spec::{cvs, FramePointer, LldFlavor, SplitDebuginfo, TargetOptions};
64

75
pub fn opts(os: &'static str) -> TargetOptions {
86
// ELF TLS is only available in macOS 10.7+. If you try to compile for 10.6

compiler/rustc_target/src/spec/armv6k_nintendo_3ds.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use crate::spec::{LinkArgs, LinkerFlavor, RelocModel, Target, TargetOptions};
2-
3-
use super::cvs;
1+
use crate::spec::{cvs, LinkArgs, LinkerFlavor, RelocModel, Target, TargetOptions};
42

53
/// A base target for Nintendo 3DS devices using the devkitARM toolchain.
64
///

compiler/rustc_target/src/spec/dragonfly_base.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use crate::spec::{RelroLevel, TargetOptions};
2-
3-
use super::cvs;
1+
use crate::spec::{cvs, RelroLevel, TargetOptions};
42

53
pub fn opts() -> TargetOptions {
64
TargetOptions {

compiler/rustc_target/src/spec/freebsd_base.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use crate::spec::{RelroLevel, TargetOptions};
2-
3-
use super::cvs;
1+
use crate::spec::{cvs, RelroLevel, TargetOptions};
42

53
pub fn opts() -> TargetOptions {
64
TargetOptions {

compiler/rustc_target/src/spec/fuchsia_base.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use crate::spec::{crt_objects, LinkArgs, LinkOutputKind, LinkerFlavor, LldFlavor, TargetOptions};
2-
3-
use super::cvs;
1+
use crate::spec::{
2+
crt_objects, cvs, LinkArgs, LinkOutputKind, LinkerFlavor, LldFlavor, TargetOptions,
3+
};
44

55
pub fn opts() -> TargetOptions {
66
let mut pre_link_args = LinkArgs::new();

compiler/rustc_target/src/spec/haiku_base.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use crate::spec::{RelroLevel, TargetOptions};
2-
3-
use super::cvs;
1+
use crate::spec::{cvs, RelroLevel, TargetOptions};
42

53
pub fn opts() -> TargetOptions {
64
TargetOptions {

compiler/rustc_target/src/spec/illumos_base.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use crate::spec::{FramePointer, LinkArgs, LinkerFlavor, TargetOptions};
2-
use std::default::Default;
3-
4-
use super::cvs;
1+
use crate::spec::{cvs, FramePointer, LinkArgs, LinkerFlavor, TargetOptions};
52

63
pub fn opts() -> TargetOptions {
74
let mut late_link_args = LinkArgs::new();

compiler/rustc_target/src/spec/l4re_base.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use crate::spec::{LinkerFlavor, PanicStrategy, TargetOptions};
2-
use std::default::Default;
3-
4-
use super::cvs;
1+
use crate::spec::{cvs, LinkerFlavor, PanicStrategy, TargetOptions};
52

63
pub fn opts() -> TargetOptions {
74
TargetOptions {

compiler/rustc_target/src/spec/linux_base.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use crate::spec::{RelroLevel, TargetOptions};
2-
3-
use super::cvs;
1+
use crate::spec::{cvs, RelroLevel, TargetOptions};
42

53
pub fn opts() -> TargetOptions {
64
TargetOptions {

compiler/rustc_target/src/spec/mipsel_sony_psp.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1+
use crate::spec::{cvs, Target, TargetOptions};
12
use crate::spec::{LinkArgs, LinkerFlavor, LldFlavor, RelocModel};
2-
use crate::spec::{Target, TargetOptions};
3-
4-
use super::cvs;
53

64
// The PSP has custom linker requirements.
75
const LINKER_SCRIPT: &str = include_str!("./mipsel_sony_psp_linker_script.ld");

compiler/rustc_target/src/spec/mod.rs

+43-44
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ impl fmt::Display for LinkOutputKind {
459459
}
460460
}
461461

462-
pub type LinkArgs = BTreeMap<LinkerFlavor, Vec<Cow<'static, str>>>;
462+
pub type LinkArgs = BTreeMap<LinkerFlavor, Vec<StaticCow<str>>>;
463463

464464
#[derive(Clone, Copy, Hash, Debug, PartialEq, Eq)]
465465
pub enum SplitDebuginfo {
@@ -1028,19 +1028,16 @@ supported_targets! {
10281028
}
10291029

10301030
/// Cow-Vec-Str: Cow<'static, [Cow<'static, str>]>
1031-
// FIXME(Urgau): Figure out why the obvious form `["".into()].into()` doesn't work.
10321031
macro_rules! cvs {
10331032
() => {
10341033
::std::borrow::Cow::Borrowed(&[])
10351034
};
10361035
($($x:expr),+ $(,)?) => {
1037-
{
1038-
::std::borrow::Cow::Borrowed(&[
1039-
$(
1040-
::std::borrow::Cow::Borrowed($x),
1041-
)*
1042-
])
1043-
}
1036+
::std::borrow::Cow::Borrowed(&[
1037+
$(
1038+
::std::borrow::Cow::Borrowed($x),
1039+
)*
1040+
])
10441041
};
10451042
}
10461043

@@ -1084,14 +1081,14 @@ impl TargetWarnings {
10841081
#[derive(PartialEq, Clone, Debug)]
10851082
pub struct Target {
10861083
/// Target triple to pass to LLVM.
1087-
pub llvm_target: Cow<'static, str>,
1084+
pub llvm_target: StaticCow<str>,
10881085
/// Number of bits in a pointer. Influences the `target_pointer_width` `cfg` variable.
10891086
pub pointer_width: u32,
10901087
/// Architecture to use for ABI considerations. Valid options include: "x86",
10911088
/// "x86_64", "arm", "aarch64", "mips", "powerpc", "powerpc64", and others.
1092-
pub arch: Cow<'static, str>,
1089+
pub arch: StaticCow<str>,
10931090
/// [Data layout](https://llvm.org/docs/LangRef.html#data-layout) to pass to LLVM.
1094-
pub data_layout: Cow<'static, str>,
1091+
pub data_layout: StaticCow<str>,
10951092
/// Optional settings with defaults.
10961093
pub options: TargetOptions,
10971094
}
@@ -1107,6 +1104,8 @@ impl HasTargetSpec for Target {
11071104
}
11081105
}
11091106

1107+
type StaticCow<T> = Cow<'static, T>;
1108+
11101109
/// Optional aspects of a target specification.
11111110
///
11121111
/// This has an implementation of `Default`, see each field for what the default is. In general,
@@ -1123,25 +1122,25 @@ pub struct TargetOptions {
11231122
/// Used as the `target_endian` `cfg` variable. Defaults to little endian.
11241123
pub endian: Endian,
11251124
/// Width of c_int type. Defaults to "32".
1126-
pub c_int_width: Cow<'static, str>,
1125+
pub c_int_width: StaticCow<str>,
11271126
/// OS name to use for conditional compilation (`target_os`). Defaults to "none".
11281127
/// "none" implies a bare metal target without `std` library.
11291128
/// A couple of targets having `std` also use "unknown" as an `os` value,
11301129
/// but they are exceptions.
1131-
pub os: Cow<'static, str>,
1130+
pub os: StaticCow<str>,
11321131
/// Environment name to use for conditional compilation (`target_env`). Defaults to "".
1133-
pub env: Cow<'static, str>,
1132+
pub env: StaticCow<str>,
11341133
/// ABI name to distinguish multiple ABIs on the same OS and architecture. For instance, `"eabi"`
11351134
/// or `"eabihf"`. Defaults to "".
1136-
pub abi: Cow<'static, str>,
1135+
pub abi: StaticCow<str>,
11371136
/// Vendor name to use for conditional compilation (`target_vendor`). Defaults to "unknown".
1138-
pub vendor: Cow<'static, str>,
1137+
pub vendor: StaticCow<str>,
11391138
/// Default linker flavor used if `-C linker-flavor` or `-C linker` are not passed
11401139
/// on the command line. Defaults to `LinkerFlavor::Gcc`.
11411140
pub linker_flavor: LinkerFlavor,
11421141

11431142
/// Linker to invoke
1144-
pub linker: Option<Cow<'static, str>>,
1143+
pub linker: Option<StaticCow<str>>,
11451144

11461145
/// LLD flavor used if `lld` (or `rust-lld`) is specified as a linker
11471146
/// without clarifying its flavor in any way.
@@ -1176,23 +1175,23 @@ pub struct TargetOptions {
11761175
/// Optional link script applied to `dylib` and `executable` crate types.
11771176
/// This is a string containing the script, not a path. Can only be applied
11781177
/// to linkers where `linker_is_gnu` is true.
1179-
pub link_script: Option<Cow<'static, str>>,
1178+
pub link_script: Option<StaticCow<str>>,
11801179

11811180
/// Environment variables to be set for the linker invocation.
1182-
pub link_env: Cow<'static, [(Cow<'static, str>, Cow<'static, str>)]>,
1181+
pub link_env: StaticCow<[(StaticCow<str>, StaticCow<str>)]>,
11831182
/// Environment variables to be removed for the linker invocation.
1184-
pub link_env_remove: Cow<'static, [Cow<'static, str>]>,
1183+
pub link_env_remove: StaticCow<[StaticCow<str>]>,
11851184

11861185
/// Extra arguments to pass to the external assembler (when used)
1187-
pub asm_args: Cow<'static, [Cow<'static, str>]>,
1186+
pub asm_args: StaticCow<[StaticCow<str>]>,
11881187

11891188
/// Default CPU to pass to LLVM. Corresponds to `llc -mcpu=$cpu`. Defaults
11901189
/// to "generic".
1191-
pub cpu: Cow<'static, str>,
1190+
pub cpu: StaticCow<str>,
11921191
/// Default target features to pass to LLVM. These features will *always* be
11931192
/// passed, and cannot be disabled even via `-C`. Corresponds to `llc
11941193
/// -mattr=$features`.
1195-
pub features: Cow<'static, str>,
1194+
pub features: StaticCow<str>,
11961195
/// Whether dynamic linking is available on this target. Defaults to false.
11971196
pub dynamic_linking: bool,
11981197
/// If dynamic linking is available, whether only cdylibs are supported.
@@ -1216,21 +1215,21 @@ pub struct TargetOptions {
12161215
/// Emit each function in its own section. Defaults to true.
12171216
pub function_sections: bool,
12181217
/// String to prepend to the name of every dynamic library. Defaults to "lib".
1219-
pub dll_prefix: Cow<'static, str>,
1218+
pub dll_prefix: StaticCow<str>,
12201219
/// String to append to the name of every dynamic library. Defaults to ".so".
1221-
pub dll_suffix: Cow<'static, str>,
1220+
pub dll_suffix: StaticCow<str>,
12221221
/// String to append to the name of every executable.
1223-
pub exe_suffix: Cow<'static, str>,
1222+
pub exe_suffix: StaticCow<str>,
12241223
/// String to prepend to the name of every static library. Defaults to "lib".
1225-
pub staticlib_prefix: Cow<'static, str>,
1224+
pub staticlib_prefix: StaticCow<str>,
12261225
/// String to append to the name of every static library. Defaults to ".a".
1227-
pub staticlib_suffix: Cow<'static, str>,
1226+
pub staticlib_suffix: StaticCow<str>,
12281227
/// Values of the `target_family` cfg set for this target.
12291228
///
12301229
/// Common options are: "unix", "windows". Defaults to no families.
12311230
///
12321231
/// See <https://doc.rust-lang.org/reference/conditional-compilation.html#target_family>.
1233-
pub families: Cow<'static, [Cow<'static, str>]>,
1232+
pub families: StaticCow<[StaticCow<str>]>,
12341233
/// Whether the target toolchain's ABI supports returning small structs as an integer.
12351234
pub abi_return_struct_as_int: bool,
12361235
/// Whether the target toolchain is like macOS's. Only useful for compiling against iOS/macOS,
@@ -1302,7 +1301,7 @@ pub struct TargetOptions {
13021301
/// LLVM to assemble an archive or fall back to the system linker, and
13031302
/// currently only "gnu" is used to fall into LLVM. Unknown strings cause
13041303
/// the system linker to be used.
1305-
pub archive_format: Cow<'static, str>,
1304+
pub archive_format: StaticCow<str>,
13061305
/// Is asm!() allowed? Defaults to true.
13071306
pub allow_asm: bool,
13081307
/// Whether the runtime startup code requires the `main` function be passed
@@ -1318,7 +1317,7 @@ pub struct TargetOptions {
13181317
/// Whether the target requires that emitted object code includes bitcode.
13191318
pub forces_embed_bitcode: bool,
13201319
/// Content of the LLVM cmdline section associated with embedded bitcode.
1321-
pub bitcode_llvm_cmdline: Cow<'static, str>,
1320+
pub bitcode_llvm_cmdline: StaticCow<str>,
13221321

13231322
/// Don't use this field; instead use the `.min_atomic_width()` method.
13241323
pub min_atomic_width: Option<u64>,
@@ -1390,7 +1389,7 @@ pub struct TargetOptions {
13901389

13911390
/// If set, have the linker export exactly these symbols, instead of using
13921391
/// the usual logic to figure this out from the crate itself.
1393-
pub override_export_symbols: Option<Cow<'static, [Cow<'static, str>]>>,
1392+
pub override_export_symbols: Option<StaticCow<[StaticCow<str>]>>,
13941393

13951394
/// Determines how or whether the MergeFunctions LLVM pass should run for
13961395
/// this target. Either "disabled", "trampolines", or "aliases".
@@ -1401,16 +1400,16 @@ pub struct TargetOptions {
14011400
pub merge_functions: MergeFunctions,
14021401

14031402
/// Use platform dependent mcount function
1404-
pub mcount: Cow<'static, str>,
1403+
pub mcount: StaticCow<str>,
14051404

14061405
/// LLVM ABI name, corresponds to the '-mabi' parameter available in multilib C compilers
1407-
pub llvm_abiname: Cow<'static, str>,
1406+
pub llvm_abiname: StaticCow<str>,
14081407

14091408
/// Whether or not RelaxElfRelocation flag will be passed to the linker
14101409
pub relax_elf_relocations: bool,
14111410

14121411
/// Additional arguments to pass to LLVM, similar to the `-C llvm-args` codegen option.
1413-
pub llvm_args: Cow<'static, [Cow<'static, str>]>,
1412+
pub llvm_args: StaticCow<[StaticCow<str>]>,
14141413

14151414
/// Whether to use legacy .ctors initialization hooks rather than .init_array. Defaults
14161415
/// to false (uses .init_array).
@@ -1459,18 +1458,18 @@ impl Default for TargetOptions {
14591458
endian: Endian::Little,
14601459
c_int_width: "32".into(),
14611460
os: "none".into(),
1462-
env: Cow::from(""),
1463-
abi: Cow::from(""),
1461+
env: "".into(),
1462+
abi: "".into(),
14641463
vendor: "unknown".into(),
14651464
linker_flavor: LinkerFlavor::Gcc,
14661465
linker: option_env!("CFG_DEFAULT_LINKER").map(|s| s.into()),
14671466
lld_flavor: LldFlavor::Ld,
14681467
pre_link_args: LinkArgs::new(),
14691468
post_link_args: LinkArgs::new(),
14701469
link_script: None,
1471-
asm_args: Cow::Borrowed(&[]),
1470+
asm_args: cvs![],
14721471
cpu: "generic".into(),
1473-
features: Cow::from(""),
1472+
features: "".into(),
14741473
dynamic_linking: false,
14751474
only_cdylib: false,
14761475
executables: false,
@@ -1482,7 +1481,7 @@ impl Default for TargetOptions {
14821481
function_sections: true,
14831482
dll_prefix: "lib".into(),
14841483
dll_suffix: ".so".into(),
1485-
exe_suffix: Cow::from(""),
1484+
exe_suffix: "".into(),
14861485
staticlib_prefix: "lib".into(),
14871486
staticlib_suffix: ".a".into(),
14881487
families: cvs![],
@@ -1511,15 +1510,15 @@ impl Default for TargetOptions {
15111510
late_link_args: LinkArgs::new(),
15121511
late_link_args_dynamic: LinkArgs::new(),
15131512
late_link_args_static: LinkArgs::new(),
1514-
link_env: Cow::Borrowed(&[]),
1515-
link_env_remove: Cow::Borrowed(&[]),
1513+
link_env: cvs![],
1514+
link_env_remove: cvs![],
15161515
archive_format: "gnu".into(),
15171516
main_needs_argc_argv: true,
15181517
allow_asm: true,
15191518
has_thread_local: false,
15201519
obj_is_bitcode: false,
15211520
forces_embed_bitcode: false,
1522-
bitcode_llvm_cmdline: Cow::from(""),
1521+
bitcode_llvm_cmdline: "".into(),
15231522
min_atomic_width: None,
15241523
max_atomic_width: None,
15251524
atomic_cas: true,

0 commit comments

Comments
 (0)