Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few cleanups for rustc_target #53222

Merged
merged 1 commit into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc_target/abi/call/mips64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ fn classify_arg_ty<'a, Ty, C>(cx: C, arg: &mut ArgType<'a, Ty>)
// Extract first 8 chunks as the prefix
let rest_size = size - Size::from_bytes(8) * prefix_index as u64;
arg.cast_to(CastTarget {
prefix: prefix,
prefix,
prefix_chunk: Size::from_bytes(8),
rest: Uniform { unit: Reg::i64(), total: rest_size }
});
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_target/abi/call/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl ArgAttributes {
}

pub fn set(&mut self, attr: ArgAttribute) -> &mut Self {
self.regular = self.regular | attr;
self.regular |= attr;
self
}

Expand Down Expand Up @@ -229,7 +229,7 @@ impl CastTarget {

pub fn align<C: HasDataLayout>(&self, cx: C) -> Align {
self.prefix.iter()
.filter_map(|x| x.map(|kind| Reg { kind: kind, size: self.prefix_chunk }.align(cx)))
.filter_map(|x| x.map(|kind| Reg { kind, size: self.prefix_chunk }.align(cx)))
.fold(cx.data_layout().aggregate_align.max(self.rest.align(cx)),
|acc, align| acc.max(align))
}
Expand Down
6 changes: 2 additions & 4 deletions src/librustc_target/abi/call/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,8 @@ pub fn compute_abi_info<'a, Ty, C>(cx: C, fty: &mut FnType<'a, Ty>)
_ => {}
}
}
if arg.layout.is_aggregate() {
if int_regs < needed_int || sse_regs < needed_sse {
cls_or_mem = Err(Memory);
}
if arg.layout.is_aggregate() && (int_regs < needed_int || sse_regs < needed_sse) {
cls_or_mem = Err(Memory);
}
}
}
Expand Down
34 changes: 17 additions & 17 deletions src/librustc_target/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,17 @@ impl TargetDataLayout {
let mut dl = TargetDataLayout::default();
let mut i128_align_src = 64;
for spec in target.data_layout.split('-') {
match &spec.split(':').collect::<Vec<_>>()[..] {
&["e"] => dl.endian = Endian::Little,
&["E"] => dl.endian = Endian::Big,
&["a", ref a..] => dl.aggregate_align = align(a, "a")?,
&["f32", ref a..] => dl.f32_align = align(a, "f32")?,
&["f64", ref a..] => dl.f64_align = align(a, "f64")?,
&[p @ "p", s, ref a..] | &[p @ "p0", s, ref a..] => {
match spec.split(':').collect::<Vec<_>>()[..] {
["e"] => dl.endian = Endian::Little,
["E"] => dl.endian = Endian::Big,
["a", ref a..] => dl.aggregate_align = align(a, "a")?,
["f32", ref a..] => dl.f32_align = align(a, "f32")?,
["f64", ref a..] => dl.f64_align = align(a, "f64")?,
[p @ "p", s, ref a..] | [p @ "p0", s, ref a..] => {
dl.pointer_size = size(s, p)?;
dl.pointer_align = align(a, p)?;
}
&[s, ref a..] if s.starts_with("i") => {
[s, ref a..] if s.starts_with("i") => {
let bits = match s[1..].parse::<u64>() {
Ok(bits) => bits,
Err(_) => {
Expand All @@ -127,7 +127,7 @@ impl TargetDataLayout {
dl.i128_align = a;
}
}
&[s, ref a..] if s.starts_with("v") => {
[s, ref a..] if s.starts_with("v") => {
let v_size = size(&s[1..], "v")?;
let a = align(a, s)?;
if let Some(v) = dl.vector_align.iter_mut().find(|v| v.0 == v_size) {
Expand Down Expand Up @@ -429,8 +429,8 @@ pub enum Integer {
}

impl Integer {
pub fn size(&self) -> Size {
match *self {
pub fn size(self) -> Size {
match self {
I8 => Size::from_bytes(1),
I16 => Size::from_bytes(2),
I32 => Size::from_bytes(4),
Expand All @@ -439,10 +439,10 @@ impl Integer {
}
}

pub fn align<C: HasDataLayout>(&self, cx: C) -> Align {
pub fn align<C: HasDataLayout>(self, cx: C) -> Align {
let dl = cx.data_layout();

match *self {
match self {
I8 => dl.i8_align,
I16 => dl.i16_align,
I32 => dl.i32_align,
Expand Down Expand Up @@ -522,15 +522,15 @@ impl fmt::Display for FloatTy {
}

impl FloatTy {
pub fn ty_to_string(&self) -> &'static str {
match *self {
pub fn ty_to_string(self) -> &'static str {
match self {
FloatTy::F32 => "f32",
FloatTy::F64 => "f64",
}
}

pub fn bit_width(&self) -> usize {
match *self {
pub fn bit_width(self) -> usize {
match self {
FloatTy::F32 => 32,
FloatTy::F64 => 64,
}
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_target/spec/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub struct AbiData {
}

#[allow(non_upper_case_globals)]
const AbiDatas: &'static [AbiData] = &[
const AbiDatas: &[AbiData] = &[
// Platform-specific ABIs
AbiData {abi: Abi::Cdecl, name: "cdecl", generic: false },
AbiData {abi: Abi::Stdcall, name: "stdcall", generic: false },
Expand Down Expand Up @@ -87,20 +87,20 @@ pub fn all_names() -> Vec<&'static str> {

impl Abi {
#[inline]
pub fn index(&self) -> usize {
*self as usize
pub fn index(self) -> usize {
self as usize
}

#[inline]
pub fn data(&self) -> &'static AbiData {
pub fn data(self) -> &'static AbiData {
&AbiDatas[self.index()]
}

pub fn name(&self) -> &'static str {
pub fn name(self) -> &'static str {
self.data().name
}

pub fn generic(&self) -> bool {
pub fn generic(self) -> bool {
self.data().generic
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_target/spec/apple_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn opts() -> TargetOptions {
// TLS is flagged as enabled if it looks to be supported.
let deployment_target = env::var("MACOSX_DEPLOYMENT_TARGET").ok();
let version = deployment_target.as_ref().and_then(|s| {
let mut i = s.splitn(2, ".");
let mut i = s.splitn(2, '.');
i.next().and_then(|a| i.next().map(|b| (a, b)))
}).and_then(|(a, b)| {
a.parse::<u32>().and_then(|a| b.parse::<u32>().map(|b| (a, b))).ok()
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_target/spec/apple_ios_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ pub enum Arch {
}

impl Arch {
pub fn to_string(&self) -> &'static str {
pub fn to_string(self) -> &'static str {
match self {
&Armv7 => "armv7",
&Armv7s => "armv7s",
&Arm64 => "arm64",
&I386 => "i386",
&X86_64 => "x86_64"
Armv7 => "armv7",
Armv7s => "armv7s",
Arm64 => "arm64",
I386 => "i386",
X86_64 => "x86_64"
}
}
}
Expand Down
24 changes: 11 additions & 13 deletions src/librustc_target/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ impl Target {
/// Maximum integer size in bits that this target can perform atomic
/// operations on.
pub fn max_atomic_width(&self) -> u64 {
self.options.max_atomic_width.unwrap_or(self.target_pointer_width.parse().unwrap())
self.options.max_atomic_width.unwrap_or_else(|| self.target_pointer_width.parse().unwrap())
}

pub fn is_abi_supported(&self, abi: Abi) -> bool {
Expand Down Expand Up @@ -777,7 +777,7 @@ impl Target {
let get_opt_field = |name: &str, default: &str| {
obj.find(name).and_then(|s| s.as_string())
.map(|s| s.to_string())
.unwrap_or(default.to_string())
.unwrap_or_else(|| default.to_string())
};

let mut base = Target {
Expand Down Expand Up @@ -1007,7 +1007,6 @@ impl Target {
/// filesystem access and JSON decoding.
pub fn search(target_triple: &TargetTriple) -> Result<Target, String> {
use std::env;
use std::ffi::OsString;
use std::fs;
use serialize::json;

Expand All @@ -1018,8 +1017,8 @@ impl Target {
Target::from_json(obj)
}

match target_triple {
&TargetTriple::TargetTriple(ref target_triple) => {
match *target_triple {
TargetTriple::TargetTriple(ref target_triple) => {
// check if triple is in list of supported targets
if let Ok(t) = load_specific(target_triple) {
return Ok(t)
Expand All @@ -1032,8 +1031,7 @@ impl Target {
PathBuf::from(target)
};

let target_path = env::var_os("RUST_TARGET_PATH")
.unwrap_or(OsString::new());
let target_path = env::var_os("RUST_TARGET_PATH").unwrap_or_default();

// FIXME 16351: add a sane default search path?

Expand All @@ -1045,7 +1043,7 @@ impl Target {
}
Err(format!("Could not find specification for target {:?}", target_triple))
}
&TargetTriple::TargetPath(ref target_path) => {
TargetTriple::TargetPath(ref target_path) => {
if target_path.is_file() {
return load_file(&target_path);
}
Expand Down Expand Up @@ -1190,7 +1188,7 @@ impl ToJson for Target {

if default.abi_blacklist != self.options.abi_blacklist {
d.insert("abi-blacklist".to_string(), self.options.abi_blacklist.iter()
.map(Abi::name).map(|name| name.to_json())
.map(|&name| Abi::name(name).to_json())
.collect::<Vec<_>>().to_json());
}

Expand Down Expand Up @@ -1229,9 +1227,9 @@ impl TargetTriple {
///
/// If this target is a path, the file name (without extension) is returned.
pub fn triple(&self) -> &str {
match self {
&TargetTriple::TargetTriple(ref triple) => triple,
&TargetTriple::TargetPath(ref path) => {
match *self {
TargetTriple::TargetTriple(ref triple) => triple,
TargetTriple::TargetPath(ref path) => {
path.file_stem().expect("target path must not be empty").to_str()
.expect("target path must be valid unicode")
}
Expand All @@ -1247,7 +1245,7 @@ impl TargetTriple {
use std::collections::hash_map::DefaultHasher;

let triple = self.triple();
if let &TargetTriple::TargetPath(ref path) = self {
if let TargetTriple::TargetPath(ref path) = *self {
let mut hasher = DefaultHasher::new();
path.hash(&mut hasher);
let hash = hasher.finish();
Expand Down