Fix rustc::internals lint warnings

This commit is contained in:
bjorn3 2020-04-05 14:01:02 +02:00
parent 291c75d10b
commit 016673b0c3
10 changed files with 34 additions and 33 deletions

View file

@ -1,6 +1,6 @@
use std::collections::HashMap;
use std::convert::TryFrom; use std::convert::TryFrom;
use rustc_data_structures::fx::FxHashMap;
use rustc_session::Session; use rustc_session::Session;
use cranelift_module::{FuncId, Module}; use cranelift_module::{FuncId, Module};
@ -44,7 +44,7 @@ pub(crate) trait WriteDebugInfo {
fn add_debug_section(&mut self, name: SectionId, data: Vec<u8>) -> Self::SectionId; fn add_debug_section(&mut self, name: SectionId, data: Vec<u8>) -> Self::SectionId;
fn add_debug_reloc( fn add_debug_reloc(
&mut self, &mut self,
section_map: &HashMap<SectionId, Self::SectionId>, section_map: &FxHashMap<SectionId, Self::SectionId>,
symbol_map: &indexmap::IndexMap<FuncId, String>, symbol_map: &indexmap::IndexMap<FuncId, String>,
from: &Self::SectionId, from: &Self::SectionId,
reloc: &DebugReloc, reloc: &DebugReloc,
@ -74,7 +74,7 @@ impl WriteDebugInfo for ObjectProduct {
fn add_debug_reloc( fn add_debug_reloc(
&mut self, &mut self,
section_map: &HashMap<SectionId, Self::SectionId>, section_map: &FxHashMap<SectionId, Self::SectionId>,
symbol_map: &indexmap::IndexMap<FuncId, String>, symbol_map: &indexmap::IndexMap<FuncId, String>,
from: &Self::SectionId, from: &Self::SectionId,
reloc: &DebugReloc, reloc: &DebugReloc,

View file

@ -47,7 +47,7 @@ pub(crate) fn trans_fn<'clif, 'tcx, B: Backend + 'static>(
bcx, bcx,
block_map, block_map,
local_map: HashMap::new(), local_map: FxHashMap::default(),
caller_location: None, // set by `codegen_fn_prelude` caller_location: None, // set by `codegen_fn_prelude`
cold_blocks: EntitySet::new(), cold_blocks: EntitySet::new(),

View file

@ -265,7 +265,7 @@ pub(crate) struct FunctionCx<'clif, 'tcx, B: Backend + 'static> {
pub(crate) bcx: FunctionBuilder<'clif>, pub(crate) bcx: FunctionBuilder<'clif>,
pub(crate) block_map: IndexVec<BasicBlock, Block>, pub(crate) block_map: IndexVec<BasicBlock, Block>,
pub(crate) local_map: HashMap<Local, CPlace<'tcx>>, pub(crate) local_map: FxHashMap<Local, CPlace<'tcx>>,
/// When `#[track_caller]` is used, the implicit caller location is stored in this variable. /// When `#[track_caller]` is used, the implicit caller location is stored in this variable.
pub(crate) caller_location: Option<CValue<'tcx>>, pub(crate) caller_location: Option<CValue<'tcx>>,
@ -275,7 +275,7 @@ pub(crate) struct FunctionCx<'clif, 'tcx, B: Backend + 'static> {
pub(crate) clif_comments: crate::pretty_clif::CommentWriter, pub(crate) clif_comments: crate::pretty_clif::CommentWriter,
pub(crate) constants_cx: &'clif mut crate::constant::ConstantCx, pub(crate) constants_cx: &'clif mut crate::constant::ConstantCx,
pub(crate) vtables: &'clif mut HashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), DataId>, pub(crate) vtables: &'clif mut FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), DataId>,
pub(crate) source_info_set: indexmap::IndexSet<SourceInfo>, pub(crate) source_info_set: indexmap::IndexSet<SourceInfo>,
} }

View file

@ -1,4 +1,4 @@
use std::collections::HashMap; use rustc_data_structures::fx::FxHashMap;
use gimli::write::{Address, AttributeValue, EndianVec, Result, Sections, Writer}; use gimli::write::{Address, AttributeValue, EndianVec, Result, Sections, Writer};
use gimli::{RunTimeEndian, SectionId}; use gimli::{RunTimeEndian, SectionId};
@ -20,7 +20,7 @@ impl DebugContext<'_> {
let mut sections = Sections::new(WriterRelocate::new(self)); let mut sections = Sections::new(WriterRelocate::new(self));
self.dwarf.write(&mut sections).unwrap(); self.dwarf.write(&mut sections).unwrap();
let mut section_map = HashMap::new(); let mut section_map = FxHashMap::default();
let _: Result<()> = sections.for_each_mut(|id, section| { let _: Result<()> = sections.for_each_mut(|id, section| {
if !section.writer.slice().is_empty() { if !section.writer.slice().is_empty() {
let section_id = product.add_debug_section(id, section.writer.take()); let section_id = product.add_debug_section(id, section.writer.take());

View file

@ -33,7 +33,7 @@ pub(crate) struct DebugContext<'tcx> {
dwarf: DwarfUnit, dwarf: DwarfUnit,
unit_range_list: RangeList, unit_range_list: RangeList,
types: HashMap<Ty<'tcx>, UnitEntryId>, types: FxHashMap<Ty<'tcx>, UnitEntryId>,
} }
impl<'tcx> DebugContext<'tcx> { impl<'tcx> DebugContext<'tcx> {
@ -97,7 +97,7 @@ impl<'tcx> DebugContext<'tcx> {
dwarf, dwarf,
unit_range_list: RangeList(Vec::new()), unit_range_list: RangeList(Vec::new()),
types: HashMap::new(), types: FxHashMap::default(),
} }
} }
@ -255,7 +255,7 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
context: &Context, context: &Context,
isa: &dyn TargetIsa, isa: &dyn TargetIsa,
source_info_set: &indexmap::IndexSet<SourceInfo>, source_info_set: &indexmap::IndexSet<SourceInfo>,
local_map: HashMap<mir::Local, CPlace<'tcx>>, local_map: FxHashMap<mir::Local, CPlace<'tcx>>,
) { ) {
let end = self.create_debug_lines(context, isa, source_info_set); let end = self.create_debug_lines(context, isa, source_info_set);
@ -302,8 +302,9 @@ fn place_location<'a, 'tcx>(
func_debug_ctx: &mut FunctionDebugContext<'a, 'tcx>, func_debug_ctx: &mut FunctionDebugContext<'a, 'tcx>,
isa: &dyn TargetIsa, isa: &dyn TargetIsa,
context: &Context, context: &Context,
local_map: &HashMap<mir::Local, CPlace<'tcx>>, local_map: &FxHashMap<mir::Local, CPlace<'tcx>>,
value_labels_ranges: &HashMap<ValueLabel, Vec<ValueLocRange>>, #[allow(rustc::default_hash_types)]
value_labels_ranges: &std::collections::HashMap<ValueLabel, Vec<ValueLocRange>>,
place: Place<'tcx>, place: Place<'tcx>,
) -> AttributeValue { ) -> AttributeValue {
assert!(place.projection.is_empty()); // FIXME implement them assert!(place.projection.is_empty()); // FIXME implement them

View file

@ -67,7 +67,6 @@ mod value_and_place;
mod vtable; mod vtable;
mod prelude { mod prelude {
pub(crate) use std::collections::HashMap;
pub(crate) use std::convert::{TryFrom, TryInto}; pub(crate) use std::convert::{TryFrom, TryInto};
pub(crate) use rustc_ast::ast::{FloatTy, IntTy, UintTy}; pub(crate) use rustc_ast::ast::{FloatTy, IntTy, UintTy};
@ -132,7 +131,7 @@ pub(crate) struct CodegenCx<'clif, 'tcx, B: Backend + 'static> {
module: &'clif mut Module<B>, module: &'clif mut Module<B>,
constants_cx: ConstantCx, constants_cx: ConstantCx,
cached_context: Context, cached_context: Context,
vtables: HashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), DataId>, vtables: FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), DataId>,
debug_context: Option<&'clif mut DebugContext<'tcx>>, debug_context: Option<&'clif mut DebugContext<'tcx>>,
} }
@ -147,7 +146,7 @@ impl<'clif, 'tcx, B: Backend + 'static> CodegenCx<'clif, 'tcx, B> {
module, module,
constants_cx: ConstantCx::default(), constants_cx: ConstantCx::default(),
cached_context: Context::new(), cached_context: Context::new(),
vtables: HashMap::new(), vtables: FxHashMap::default(),
debug_context, debug_context,
} }
} }

View file

@ -14,7 +14,7 @@ pub(super) fn optimize_function(ctx: &mut Context, cold_blocks: &EntitySet<Block
// FIXME Move the block in place instead of remove and append once // FIXME Move the block in place instead of remove and append once
// bytecodealliance/cranelift#1339 is implemented. // bytecodealliance/cranelift#1339 is implemented.
let mut block_insts = HashMap::new(); let mut block_insts = FxHashMap::default();
for block in cold_blocks.keys().filter(|&block| cold_blocks.contains(block)) { for block in cold_blocks.keys().filter(|&block| cold_blocks.contains(block)) {
let insts = ctx.func.layout.block_insts(block).collect::<Vec<_>>(); let insts = ctx.func.layout.block_insts(block).collect::<Vec<_>>();
for &inst in &insts { for &inst in &insts {

View file

@ -9,10 +9,12 @@
//! `stack_store` instruction incorrectly, or incorrectly use a previously stored value as the value //! `stack_store` instruction incorrectly, or incorrectly use a previously stored value as the value
//! being loaded by a `stack_load`. //! being loaded by a `stack_load`.
use std::collections::{BTreeMap, HashSet}; use std::collections::BTreeMap;
use std::fmt; use std::fmt;
use std::ops::Not; use std::ops::Not;
use rustc_data_structures::fx::FxHashSet;
use cranelift_codegen::cursor::{Cursor, FuncCursor}; use cranelift_codegen::cursor::{Cursor, FuncCursor};
use cranelift_codegen::ir::{InstructionData, Opcode, ValueDef}; use cranelift_codegen::ir::{InstructionData, Opcode, ValueDef};
use cranelift_codegen::ir::immediates::Offset32; use cranelift_codegen::ir::immediates::Offset32;
@ -43,9 +45,9 @@ impl Ord for OrdStackSlot {
#[derive(Debug, Default)] #[derive(Debug, Default)]
struct StackSlotUsage { struct StackSlotUsage {
stack_addr: HashSet<Inst>, stack_addr: FxHashSet<Inst>,
stack_load: HashSet<Inst>, stack_load: FxHashSet<Inst>,
stack_store: HashSet<Inst>, stack_store: FxHashSet<Inst>,
} }
impl StackSlotUsage { impl StackSlotUsage {
@ -284,7 +286,7 @@ fn combine_stack_addr_with_load_store(func: &mut Function) {
fn remove_unused_stack_addr_and_stack_load(opt_ctx: &mut OptimizeContext<'_>) { fn remove_unused_stack_addr_and_stack_load(opt_ctx: &mut OptimizeContext<'_>) {
// FIXME incrementally rebuild on each call? // FIXME incrementally rebuild on each call?
let mut stack_addr_load_insts_users = HashMap::<Inst, HashSet<Inst>>::new(); let mut stack_addr_load_insts_users = FxHashMap::<Inst, FxHashSet<Inst>>::default();
let mut cursor = FuncCursor::new(&mut opt_ctx.ctx.func); let mut cursor = FuncCursor::new(&mut opt_ctx.ctx.func);
while let Some(_block) = cursor.next_block() { while let Some(_block) = cursor.next_block() {
@ -293,7 +295,7 @@ fn remove_unused_stack_addr_and_stack_load(opt_ctx: &mut OptimizeContext<'_>) {
if let ValueDef::Result(arg_origin, 0) = cursor.func.dfg.value_def(arg) { if let ValueDef::Result(arg_origin, 0) = cursor.func.dfg.value_def(arg) {
match cursor.func.dfg[arg_origin].opcode() { match cursor.func.dfg[arg_origin].opcode() {
Opcode::StackAddr | Opcode::StackLoad => { Opcode::StackAddr | Opcode::StackLoad => {
stack_addr_load_insts_users.entry(arg_origin).or_insert_with(HashSet::new).insert(inst); stack_addr_load_insts_users.entry(arg_origin).or_insert_with(FxHashSet::default).insert(inst);
} }
_ => {} _ => {}
} }

View file

@ -1,4 +1,3 @@
use std::collections::HashMap;
use std::fmt; use std::fmt;
use cranelift_codegen::{ use cranelift_codegen::{
@ -66,7 +65,7 @@ use crate::prelude::*;
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct CommentWriter { pub(crate) struct CommentWriter {
global_comments: Vec<String>, global_comments: Vec<String>,
entity_comments: HashMap<AnyEntity, String>, entity_comments: FxHashMap<AnyEntity, String>,
} }
impl CommentWriter { impl CommentWriter {
@ -90,7 +89,7 @@ impl CommentWriter {
CommentWriter { CommentWriter {
global_comments, global_comments,
entity_comments: HashMap::new(), entity_comments: FxHashMap::default(),
} }
} }
} }

View file

@ -202,14 +202,14 @@ impl<'tcx> CValue<'tcx> {
let clif_ty = fx.clif_type(layout.ty).unwrap(); let clif_ty = fx.clif_type(layout.ty).unwrap();
match layout.ty.kind { match layout.ty.kind {
ty::TyKind::Bool => { ty::Bool => {
assert!(const_val == 0 || const_val == 1, "Invalid bool 0x{:032X}", const_val); assert!(const_val == 0 || const_val == 1, "Invalid bool 0x{:032X}", const_val);
} }
_ => {} _ => {}
} }
let val = match layout.ty.kind { let val = match layout.ty.kind {
ty::TyKind::Uint(UintTy::U128) | ty::TyKind::Int(IntTy::I128) => { ty::Uint(UintTy::U128) | ty::Int(IntTy::I128) => {
let lsb = fx.bcx.ins().iconst(types::I64, const_val as u64 as i64); let lsb = fx.bcx.ins().iconst(types::I64, const_val as u64 as i64);
let msb = fx let msb = fx
.bcx .bcx
@ -217,21 +217,21 @@ impl<'tcx> CValue<'tcx> {
.iconst(types::I64, (const_val >> 64) as u64 as i64); .iconst(types::I64, (const_val >> 64) as u64 as i64);
fx.bcx.ins().iconcat(lsb, msb) fx.bcx.ins().iconcat(lsb, msb)
} }
ty::TyKind::Bool | ty::TyKind::Char | ty::TyKind::Uint(_) | ty::TyKind::Ref(..) ty::Bool | ty::Char | ty::Uint(_) | ty::Ref(..)
| ty::TyKind::RawPtr(..) => { | ty::RawPtr(..) => {
fx fx
.bcx .bcx
.ins() .ins()
.iconst(clif_ty, u64::try_from(const_val).expect("uint") as i64) .iconst(clif_ty, u64::try_from(const_val).expect("uint") as i64)
} }
ty::TyKind::Int(_) => { ty::Int(_) => {
let const_val = rustc_middle::mir::interpret::sign_extend(const_val, layout.size); let const_val = rustc_middle::mir::interpret::sign_extend(const_val, layout.size);
fx.bcx.ins().iconst(clif_ty, i64::try_from(const_val as i128).unwrap()) fx.bcx.ins().iconst(clif_ty, i64::try_from(const_val as i128).unwrap())
} }
ty::TyKind::Float(FloatTy::F32) => { ty::Float(FloatTy::F32) => {
fx.bcx.ins().f32const(Ieee32::with_bits(u32::try_from(const_val).unwrap())) fx.bcx.ins().f32const(Ieee32::with_bits(u32::try_from(const_val).unwrap()))
} }
ty::TyKind::Float(FloatTy::F64) => { ty::Float(FloatTy::F64) => {
fx.bcx.ins().f64const(Ieee64::with_bits(u64::try_from(const_val).unwrap())) fx.bcx.ins().f64const(Ieee64::with_bits(u64::try_from(const_val).unwrap()))
} }
_ => panic!( _ => panic!(