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 rustc_data_structures::fx::FxHashMap;
use rustc_session::Session;
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_reloc(
&mut self,
section_map: &HashMap<SectionId, Self::SectionId>,
section_map: &FxHashMap<SectionId, Self::SectionId>,
symbol_map: &indexmap::IndexMap<FuncId, String>,
from: &Self::SectionId,
reloc: &DebugReloc,
@ -74,7 +74,7 @@ impl WriteDebugInfo for ObjectProduct {
fn add_debug_reloc(
&mut self,
section_map: &HashMap<SectionId, Self::SectionId>,
section_map: &FxHashMap<SectionId, Self::SectionId>,
symbol_map: &indexmap::IndexMap<FuncId, String>,
from: &Self::SectionId,
reloc: &DebugReloc,

View File

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

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::{RunTimeEndian, SectionId};
@ -20,7 +20,7 @@ impl DebugContext<'_> {
let mut sections = Sections::new(WriterRelocate::new(self));
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| {
if !section.writer.slice().is_empty() {
let section_id = product.add_debug_section(id, section.writer.take());

View File

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

View File

@ -67,7 +67,6 @@ mod value_and_place;
mod vtable;
mod prelude {
pub(crate) use std::collections::HashMap;
pub(crate) use std::convert::{TryFrom, TryInto};
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>,
constants_cx: ConstantCx,
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>>,
}
@ -147,7 +146,7 @@ impl<'clif, 'tcx, B: Backend + 'static> CodegenCx<'clif, 'tcx, B> {
module,
constants_cx: ConstantCx::default(),
cached_context: Context::new(),
vtables: HashMap::new(),
vtables: FxHashMap::default(),
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
// 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)) {
let insts = ctx.func.layout.block_insts(block).collect::<Vec<_>>();
for &inst in &insts {

View File

@ -9,10 +9,12 @@
//! `stack_store` instruction incorrectly, or incorrectly use a previously stored value as the value
//! being loaded by a `stack_load`.
use std::collections::{BTreeMap, HashSet};
use std::collections::BTreeMap;
use std::fmt;
use std::ops::Not;
use rustc_data_structures::fx::FxHashSet;
use cranelift_codegen::cursor::{Cursor, FuncCursor};
use cranelift_codegen::ir::{InstructionData, Opcode, ValueDef};
use cranelift_codegen::ir::immediates::Offset32;
@ -43,9 +45,9 @@ impl Ord for OrdStackSlot {
#[derive(Debug, Default)]
struct StackSlotUsage {
stack_addr: HashSet<Inst>,
stack_load: HashSet<Inst>,
stack_store: HashSet<Inst>,
stack_addr: FxHashSet<Inst>,
stack_load: FxHashSet<Inst>,
stack_store: FxHashSet<Inst>,
}
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<'_>) {
// 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);
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) {
match cursor.func.dfg[arg_origin].opcode() {
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 cranelift_codegen::{
@ -66,7 +65,7 @@ use crate::prelude::*;
#[derive(Debug)]
pub(crate) struct CommentWriter {
global_comments: Vec<String>,
entity_comments: HashMap<AnyEntity, String>,
entity_comments: FxHashMap<AnyEntity, String>,
}
impl CommentWriter {
@ -90,7 +89,7 @@ impl CommentWriter {
CommentWriter {
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();
match layout.ty.kind {
ty::TyKind::Bool => {
ty::Bool => {
assert!(const_val == 0 || const_val == 1, "Invalid bool 0x{:032X}", const_val);
}
_ => {}
}
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 msb = fx
.bcx
@ -217,21 +217,21 @@ impl<'tcx> CValue<'tcx> {
.iconst(types::I64, (const_val >> 64) as u64 as i64);
fx.bcx.ins().iconcat(lsb, msb)
}
ty::TyKind::Bool | ty::TyKind::Char | ty::TyKind::Uint(_) | ty::TyKind::Ref(..)
| ty::TyKind::RawPtr(..) => {
ty::Bool | ty::Char | ty::Uint(_) | ty::Ref(..)
| ty::RawPtr(..) => {
fx
.bcx
.ins()
.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);
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()))
}
ty::TyKind::Float(FloatTy::F64) => {
ty::Float(FloatTy::F64) => {
fx.bcx.ins().f64const(Ieee64::with_bits(u64::try_from(const_val).unwrap()))
}
_ => panic!(