Fix remaining clippy warnings (#1340)
* clippy: allow complex encoding function * clippy: remove unnecessary main() function in doctest * clippy: remove redundant `Type` suffix on LaneType enum variants * clippy: ignore incorrect debug_assert_with_mut_call warning * clippy: fix FDE clippy warnings
This commit is contained in:
committed by
Yury Delendik
parent
435fc71d68
commit
e1d513ab4b
@@ -1346,7 +1346,7 @@ mod test {
|
|||||||
let type1 = TypeSetBuilder::new().ints(8..64).build();
|
let type1 = TypeSetBuilder::new().ints(8..64).build();
|
||||||
let in1 = OperandKindFields::TypeVar(TypeVar::new("a", "...", type1));
|
let in1 = OperandKindFields::TypeVar(TypeVar::new("a", "...", type1));
|
||||||
let inst = build_fake_instruction(vec![in1], vec![]);
|
let inst = build_fake_instruction(vec![in1], vec![]);
|
||||||
inst.bind(LaneType::IntType(I32));
|
inst.bind(LaneType::Int(I32));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -1360,7 +1360,7 @@ mod test {
|
|||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn ensure_instructions_fail_to_bind() {
|
fn ensure_instructions_fail_to_bind() {
|
||||||
let inst = build_fake_instruction(vec![], vec![]);
|
let inst = build_fake_instruction(vec![], vec![]);
|
||||||
inst.bind(BindParameter::Lane(LaneType::IntType(I32)));
|
inst.bind(BindParameter::Lane(LaneType::Int(I32)));
|
||||||
// Trying to bind to an instruction with no inputs should fail.
|
// Trying to bind to an instruction with no inputs should fail.
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1370,8 +1370,7 @@ mod test {
|
|||||||
let type1 = TypeSetBuilder::new().ints(8..64).build();
|
let type1 = TypeSetBuilder::new().ints(8..64).build();
|
||||||
let in1 = OperandKindFields::TypeVar(TypeVar::new("a", "...", type1));
|
let in1 = OperandKindFields::TypeVar(TypeVar::new("a", "...", type1));
|
||||||
let inst = build_fake_instruction(vec![in1], vec![]);
|
let inst = build_fake_instruction(vec![in1], vec![]);
|
||||||
inst.bind(LaneType::IntType(I32))
|
inst.bind(LaneType::Int(I32)).bind(LaneType::Int(I64));
|
||||||
.bind(LaneType::IntType(I64));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -140,42 +140,42 @@ impl From<VectorType> for ValueType {
|
|||||||
/// A concrete scalar type that can appear as a vector lane too.
|
/// A concrete scalar type that can appear as a vector lane too.
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub(crate) enum LaneType {
|
pub(crate) enum LaneType {
|
||||||
BoolType(shared_types::Bool),
|
Bool(shared_types::Bool),
|
||||||
FloatType(shared_types::Float),
|
Float(shared_types::Float),
|
||||||
IntType(shared_types::Int),
|
Int(shared_types::Int),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LaneType {
|
impl LaneType {
|
||||||
/// Return a string containing the documentation comment for this lane type.
|
/// Return a string containing the documentation comment for this lane type.
|
||||||
pub fn doc(self) -> String {
|
pub fn doc(self) -> String {
|
||||||
match self {
|
match self {
|
||||||
LaneType::BoolType(_) => format!("A boolean type with {} bits.", self.lane_bits()),
|
LaneType::Bool(_) => format!("A boolean type with {} bits.", self.lane_bits()),
|
||||||
LaneType::FloatType(shared_types::Float::F32) => String::from(
|
LaneType::Float(shared_types::Float::F32) => String::from(
|
||||||
"A 32-bit floating point type represented in the IEEE 754-2008
|
"A 32-bit floating point type represented in the IEEE 754-2008
|
||||||
*binary32* interchange format. This corresponds to the :c:type:`float`
|
*binary32* interchange format. This corresponds to the :c:type:`float`
|
||||||
type in most C implementations.",
|
type in most C implementations.",
|
||||||
),
|
),
|
||||||
LaneType::FloatType(shared_types::Float::F64) => String::from(
|
LaneType::Float(shared_types::Float::F64) => String::from(
|
||||||
"A 64-bit floating point type represented in the IEEE 754-2008
|
"A 64-bit floating point type represented in the IEEE 754-2008
|
||||||
*binary64* interchange format. This corresponds to the :c:type:`double`
|
*binary64* interchange format. This corresponds to the :c:type:`double`
|
||||||
type in most C implementations.",
|
type in most C implementations.",
|
||||||
),
|
),
|
||||||
LaneType::IntType(_) if self.lane_bits() < 32 => format!(
|
LaneType::Int(_) if self.lane_bits() < 32 => format!(
|
||||||
"An integer type with {} bits.
|
"An integer type with {} bits.
|
||||||
WARNING: arithmetic on {}bit integers is incomplete",
|
WARNING: arithmetic on {}bit integers is incomplete",
|
||||||
self.lane_bits(),
|
self.lane_bits(),
|
||||||
self.lane_bits()
|
self.lane_bits()
|
||||||
),
|
),
|
||||||
LaneType::IntType(_) => format!("An integer type with {} bits.", self.lane_bits()),
|
LaneType::Int(_) => format!("An integer type with {} bits.", self.lane_bits()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the number of bits in a lane.
|
/// Return the number of bits in a lane.
|
||||||
pub fn lane_bits(self) -> u64 {
|
pub fn lane_bits(self) -> u64 {
|
||||||
match self {
|
match self {
|
||||||
LaneType::BoolType(ref b) => *b as u64,
|
LaneType::Bool(ref b) => *b as u64,
|
||||||
LaneType::FloatType(ref f) => *f as u64,
|
LaneType::Float(ref f) => *f as u64,
|
||||||
LaneType::IntType(ref i) => *i as u64,
|
LaneType::Int(ref i) => *i as u64,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,24 +183,24 @@ impl LaneType {
|
|||||||
pub fn number(self) -> u8 {
|
pub fn number(self) -> u8 {
|
||||||
constants::LANE_BASE
|
constants::LANE_BASE
|
||||||
+ match self {
|
+ match self {
|
||||||
LaneType::BoolType(shared_types::Bool::B1) => 0,
|
LaneType::Bool(shared_types::Bool::B1) => 0,
|
||||||
LaneType::BoolType(shared_types::Bool::B8) => 1,
|
LaneType::Bool(shared_types::Bool::B8) => 1,
|
||||||
LaneType::BoolType(shared_types::Bool::B16) => 2,
|
LaneType::Bool(shared_types::Bool::B16) => 2,
|
||||||
LaneType::BoolType(shared_types::Bool::B32) => 3,
|
LaneType::Bool(shared_types::Bool::B32) => 3,
|
||||||
LaneType::BoolType(shared_types::Bool::B64) => 4,
|
LaneType::Bool(shared_types::Bool::B64) => 4,
|
||||||
LaneType::BoolType(shared_types::Bool::B128) => 5,
|
LaneType::Bool(shared_types::Bool::B128) => 5,
|
||||||
LaneType::IntType(shared_types::Int::I8) => 6,
|
LaneType::Int(shared_types::Int::I8) => 6,
|
||||||
LaneType::IntType(shared_types::Int::I16) => 7,
|
LaneType::Int(shared_types::Int::I16) => 7,
|
||||||
LaneType::IntType(shared_types::Int::I32) => 8,
|
LaneType::Int(shared_types::Int::I32) => 8,
|
||||||
LaneType::IntType(shared_types::Int::I64) => 9,
|
LaneType::Int(shared_types::Int::I64) => 9,
|
||||||
LaneType::IntType(shared_types::Int::I128) => 10,
|
LaneType::Int(shared_types::Int::I128) => 10,
|
||||||
LaneType::FloatType(shared_types::Float::F32) => 11,
|
LaneType::Float(shared_types::Float::F32) => 11,
|
||||||
LaneType::FloatType(shared_types::Float::F64) => 12,
|
LaneType::Float(shared_types::Float::F64) => 12,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bool_from_bits(num_bits: u16) -> LaneType {
|
pub fn bool_from_bits(num_bits: u16) -> LaneType {
|
||||||
LaneType::BoolType(match num_bits {
|
LaneType::Bool(match num_bits {
|
||||||
1 => shared_types::Bool::B1,
|
1 => shared_types::Bool::B1,
|
||||||
8 => shared_types::Bool::B8,
|
8 => shared_types::Bool::B8,
|
||||||
16 => shared_types::Bool::B16,
|
16 => shared_types::Bool::B16,
|
||||||
@@ -212,7 +212,7 @@ impl LaneType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn int_from_bits(num_bits: u16) -> LaneType {
|
pub fn int_from_bits(num_bits: u16) -> LaneType {
|
||||||
LaneType::IntType(match num_bits {
|
LaneType::Int(match num_bits {
|
||||||
8 => shared_types::Int::I8,
|
8 => shared_types::Int::I8,
|
||||||
16 => shared_types::Int::I16,
|
16 => shared_types::Int::I16,
|
||||||
32 => shared_types::Int::I32,
|
32 => shared_types::Int::I32,
|
||||||
@@ -223,7 +223,7 @@ impl LaneType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_from_bits(num_bits: u16) -> LaneType {
|
pub fn float_from_bits(num_bits: u16) -> LaneType {
|
||||||
LaneType::FloatType(match num_bits {
|
LaneType::Float(match num_bits {
|
||||||
32 => shared_types::Float::F32,
|
32 => shared_types::Float::F32,
|
||||||
64 => shared_types::Float::F64,
|
64 => shared_types::Float::F64,
|
||||||
_ => unreachable!("unxpected num bits for float"),
|
_ => unreachable!("unxpected num bits for float"),
|
||||||
@@ -240,14 +240,14 @@ impl LaneType {
|
|||||||
|
|
||||||
pub fn is_float(self) -> bool {
|
pub fn is_float(self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
LaneType::FloatType(_) => true,
|
LaneType::Float(_) => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_int(self) -> bool {
|
pub fn is_int(self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
LaneType::IntType(_) => true,
|
LaneType::Int(_) => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -256,9 +256,9 @@ impl LaneType {
|
|||||||
impl fmt::Display for LaneType {
|
impl fmt::Display for LaneType {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
LaneType::BoolType(_) => write!(f, "b{}", self.lane_bits()),
|
LaneType::Bool(_) => write!(f, "b{}", self.lane_bits()),
|
||||||
LaneType::FloatType(_) => write!(f, "f{}", self.lane_bits()),
|
LaneType::Float(_) => write!(f, "f{}", self.lane_bits()),
|
||||||
LaneType::IntType(_) => write!(f, "i{}", self.lane_bits()),
|
LaneType::Int(_) => write!(f, "i{}", self.lane_bits()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -270,9 +270,9 @@ impl fmt::Debug for LaneType {
|
|||||||
f,
|
f,
|
||||||
"{}",
|
"{}",
|
||||||
match *self {
|
match *self {
|
||||||
LaneType::BoolType(_) => format!("BoolType({})", inner_msg),
|
LaneType::Bool(_) => format!("BoolType({})", inner_msg),
|
||||||
LaneType::FloatType(_) => format!("FloatType({})", inner_msg),
|
LaneType::Float(_) => format!("FloatType({})", inner_msg),
|
||||||
LaneType::IntType(_) => format!("IntType({})", inner_msg),
|
LaneType::Int(_) => format!("IntType({})", inner_msg),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -281,21 +281,21 @@ impl fmt::Debug for LaneType {
|
|||||||
/// Create a LaneType from a given bool variant.
|
/// Create a LaneType from a given bool variant.
|
||||||
impl From<shared_types::Bool> for LaneType {
|
impl From<shared_types::Bool> for LaneType {
|
||||||
fn from(b: shared_types::Bool) -> Self {
|
fn from(b: shared_types::Bool) -> Self {
|
||||||
LaneType::BoolType(b)
|
LaneType::Bool(b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a LaneType from a given float variant.
|
/// Create a LaneType from a given float variant.
|
||||||
impl From<shared_types::Float> for LaneType {
|
impl From<shared_types::Float> for LaneType {
|
||||||
fn from(f: shared_types::Float) -> Self {
|
fn from(f: shared_types::Float) -> Self {
|
||||||
LaneType::FloatType(f)
|
LaneType::Float(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a LaneType from a given int variant.
|
/// Create a LaneType from a given int variant.
|
||||||
impl From<shared_types::Int> for LaneType {
|
impl From<shared_types::Int> for LaneType {
|
||||||
fn from(i: shared_types::Int) -> Self {
|
fn from(i: shared_types::Int) -> Self {
|
||||||
LaneType::IntType(i)
|
LaneType::Int(i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,15 +73,15 @@ impl TypeVar {
|
|||||||
builder = builder.simd_lanes(num_lanes..num_lanes);
|
builder = builder.simd_lanes(num_lanes..num_lanes);
|
||||||
|
|
||||||
let builder = match scalar_type {
|
let builder = match scalar_type {
|
||||||
LaneType::IntType(int_type) => {
|
LaneType::Int(int_type) => {
|
||||||
let bits = int_type as RangeBound;
|
let bits = int_type as RangeBound;
|
||||||
builder.ints(bits..bits)
|
builder.ints(bits..bits)
|
||||||
}
|
}
|
||||||
LaneType::FloatType(float_type) => {
|
LaneType::Float(float_type) => {
|
||||||
let bits = float_type as RangeBound;
|
let bits = float_type as RangeBound;
|
||||||
builder.floats(bits..bits)
|
builder.floats(bits..bits)
|
||||||
}
|
}
|
||||||
LaneType::BoolType(bool_type) => {
|
LaneType::Bool(bool_type) => {
|
||||||
let bits = bool_type as RangeBound;
|
let bits = bool_type as RangeBound;
|
||||||
builder.bools(bits..bits)
|
builder.bools(bits..bits)
|
||||||
}
|
}
|
||||||
@@ -1200,8 +1200,7 @@ fn test_typevar_singleton() {
|
|||||||
use crate::shared::types as shared_types;
|
use crate::shared::types as shared_types;
|
||||||
|
|
||||||
// Test i32.
|
// Test i32.
|
||||||
let typevar =
|
let typevar = TypeVar::new_singleton(ValueType::Lane(LaneType::Int(shared_types::Int::I32)));
|
||||||
TypeVar::new_singleton(ValueType::Lane(LaneType::IntType(shared_types::Int::I32)));
|
|
||||||
assert_eq!(typevar.name, "i32");
|
assert_eq!(typevar.name, "i32");
|
||||||
assert_eq!(typevar.type_set.ints, num_set![32]);
|
assert_eq!(typevar.type_set.ints, num_set![32]);
|
||||||
assert!(typevar.type_set.floats.is_empty());
|
assert!(typevar.type_set.floats.is_empty());
|
||||||
@@ -1211,7 +1210,7 @@ fn test_typevar_singleton() {
|
|||||||
|
|
||||||
// Test f32x4.
|
// Test f32x4.
|
||||||
let typevar = TypeVar::new_singleton(ValueType::Vector(VectorType::new(
|
let typevar = TypeVar::new_singleton(ValueType::Vector(VectorType::new(
|
||||||
LaneType::FloatType(shared_types::Float::F32),
|
LaneType::Float(shared_types::Float::F32),
|
||||||
4,
|
4,
|
||||||
)));
|
)));
|
||||||
assert_eq!(typevar.name, "f32x4");
|
assert_eq!(typevar.name, "f32x4");
|
||||||
|
|||||||
@@ -1530,6 +1530,7 @@ fn define_alu(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
|
#[allow(clippy::cognitive_complexity)]
|
||||||
fn define_simd(
|
fn define_simd(
|
||||||
e: &mut PerCpuModeEncodings,
|
e: &mut PerCpuModeEncodings,
|
||||||
shared_defs: &SharedDefinitions,
|
shared_defs: &SharedDefinitions,
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ use gimli::write::{
|
|||||||
FrameDescriptionEntry, FrameTable, Result, Writer,
|
FrameDescriptionEntry, FrameTable, Result, Writer,
|
||||||
};
|
};
|
||||||
use gimli::{Encoding, Format, LittleEndian, Register, X86_64};
|
use gimli::{Encoding, Format, LittleEndian, Register, X86_64};
|
||||||
use std::ptr;
|
|
||||||
|
|
||||||
pub type FDERelocEntry = (FrameUnwindOffset, Reloc);
|
pub type FDERelocEntry = (FrameUnwindOffset, Reloc);
|
||||||
|
|
||||||
@@ -196,7 +195,7 @@ pub fn emit_fde(func: &Function, isa: &dyn TargetIsa, sink: &mut dyn FrameUnwind
|
|||||||
assert!(last_offset <= address_offset);
|
assert!(last_offset <= address_offset);
|
||||||
if let Some(cmds) = frame_layout.instructions.get(&inst) {
|
if let Some(cmds) = frame_layout.instructions.get(&inst) {
|
||||||
for cmd in cmds.iter() {
|
for cmd in cmds.iter() {
|
||||||
changes.push((address_offset, cmd.clone()));
|
changes.push((address_offset, *cmd));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
last_offset = address_offset;
|
last_offset = address_offset;
|
||||||
@@ -252,7 +251,9 @@ pub fn emit_fde(func: &Function, isa: &dyn TargetIsa, sink: &mut dyn FrameUnwind
|
|||||||
for (off, r) in relocs {
|
for (off, r) in relocs {
|
||||||
sink.reloc(r, off + unwind_start);
|
sink.reloc(r, off + unwind_start);
|
||||||
}
|
}
|
||||||
let fde_offset = unsafe { ptr::read::<u32>(bytes.as_ptr() as *const u32) } as usize + 4;
|
|
||||||
|
let cie_len = u32::from_le_bytes(bytes.as_slice()[..4].try_into().unwrap());
|
||||||
|
let fde_offset = cie_len as usize + 4;
|
||||||
sink.set_entry_offset(unwind_start + fde_offset);
|
sink.set_entry_offset(unwind_start + fde_offset);
|
||||||
|
|
||||||
// Need 0 marker for GCC unwind to end FDE "list".
|
// Need 0 marker for GCC unwind to end FDE "list".
|
||||||
|
|||||||
@@ -124,8 +124,13 @@ pub fn do_simple_gvn(func: &mut Function, domtree: &mut DominatorTree) {
|
|||||||
use crate::scoped_hash_map::Entry::*;
|
use crate::scoped_hash_map::Entry::*;
|
||||||
match visible_values.entry(key) {
|
match visible_values.entry(key) {
|
||||||
Occupied(entry) => {
|
Occupied(entry) => {
|
||||||
let layout = &func.layout;
|
#[allow(clippy::debug_assert_with_mut_call)]
|
||||||
debug_assert!(domtree.dominates(*entry.get(), inst, layout));
|
{
|
||||||
|
// Clippy incorrectly believes `&func.layout` should not be used here:
|
||||||
|
// https://github.com/rust-lang/rust-clippy/issues/4737
|
||||||
|
debug_assert!(domtree.dominates(*entry.get(), inst, &func.layout));
|
||||||
|
}
|
||||||
|
|
||||||
// If the redundant instruction is representing the current
|
// If the redundant instruction is representing the current
|
||||||
// scope, pick a new representative.
|
// scope, pick a new representative.
|
||||||
let old = scope_stack.last_mut().unwrap();
|
let old = scope_stack.last_mut().unwrap();
|
||||||
|
|||||||
@@ -113,13 +113,13 @@ mod dwarfdump {
|
|||||||
|
|
||||||
impl From<gimli::Error> for Error {
|
impl From<gimli::Error> for Error {
|
||||||
fn from(err: gimli::Error) -> Self {
|
fn from(err: gimli::Error) -> Self {
|
||||||
Error::GimliError(err)
|
Self::GimliError(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<fmt::Error> for Error {
|
impl From<fmt::Error> for Error {
|
||||||
fn from(_: fmt::Error) -> Self {
|
fn from(_: fmt::Error) -> Self {
|
||||||
Error::IoError
|
Self::IoError
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,6 @@
|
|||||||
//! use cranelift_codegen::verifier::verify_function;
|
//! use cranelift_codegen::verifier::verify_function;
|
||||||
//! use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext, Variable};
|
//! use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext, Variable};
|
||||||
//!
|
//!
|
||||||
//! fn main() {
|
|
||||||
//! let mut sig = Signature::new(CallConv::SystemV);
|
//! let mut sig = Signature::new(CallConv::SystemV);
|
||||||
//! sig.returns.push(AbiParam::new(I32));
|
//! sig.returns.push(AbiParam::new(I32));
|
||||||
//! sig.params.push(AbiParam::new(I32));
|
//! sig.params.push(AbiParam::new(I32));
|
||||||
@@ -161,7 +160,6 @@
|
|||||||
//! if let Err(errors) = res {
|
//! if let Err(errors) = res {
|
||||||
//! panic!("{}", errors);
|
//! panic!("{}", errors);
|
||||||
//! }
|
//! }
|
||||||
//! }
|
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
#![deny(missing_docs, trivial_numeric_casts, unused_extern_crates)]
|
#![deny(missing_docs, trivial_numeric_casts, unused_extern_crates)]
|
||||||
|
|||||||
Reference in New Issue
Block a user