Skip to content

Commit 016673b

Browse files
committed
Fix rustc::internals lint warnings
1 parent 291c75d commit 016673b

File tree

10 files changed

+34
-33
lines changed

10 files changed

+34
-33
lines changed

src/backend.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use std::collections::HashMap;
21
use std::convert::TryFrom;
32

3+
use rustc_data_structures::fx::FxHashMap;
44
use rustc_session::Session;
55

66
use cranelift_module::{FuncId, Module};
@@ -44,7 +44,7 @@ pub(crate) trait WriteDebugInfo {
4444
fn add_debug_section(&mut self, name: SectionId, data: Vec<u8>) -> Self::SectionId;
4545
fn add_debug_reloc(
4646
&mut self,
47-
section_map: &HashMap<SectionId, Self::SectionId>,
47+
section_map: &FxHashMap<SectionId, Self::SectionId>,
4848
symbol_map: &indexmap::IndexMap<FuncId, String>,
4949
from: &Self::SectionId,
5050
reloc: &DebugReloc,
@@ -74,7 +74,7 @@ impl WriteDebugInfo for ObjectProduct {
7474

7575
fn add_debug_reloc(
7676
&mut self,
77-
section_map: &HashMap<SectionId, Self::SectionId>,
77+
section_map: &FxHashMap<SectionId, Self::SectionId>,
7878
symbol_map: &indexmap::IndexMap<FuncId, String>,
7979
from: &Self::SectionId,
8080
reloc: &DebugReloc,

src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub(crate) fn trans_fn<'clif, 'tcx, B: Backend + 'static>(
4747

4848
bcx,
4949
block_map,
50-
local_map: HashMap::new(),
50+
local_map: FxHashMap::default(),
5151
caller_location: None, // set by `codegen_fn_prelude`
5252
cold_blocks: EntitySet::new(),
5353

src/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ pub(crate) struct FunctionCx<'clif, 'tcx, B: Backend + 'static> {
265265

266266
pub(crate) bcx: FunctionBuilder<'clif>,
267267
pub(crate) block_map: IndexVec<BasicBlock, Block>,
268-
pub(crate) local_map: HashMap<Local, CPlace<'tcx>>,
268+
pub(crate) local_map: FxHashMap<Local, CPlace<'tcx>>,
269269

270270
/// When `#[track_caller]` is used, the implicit caller location is stored in this variable.
271271
pub(crate) caller_location: Option<CValue<'tcx>>,
@@ -275,7 +275,7 @@ pub(crate) struct FunctionCx<'clif, 'tcx, B: Backend + 'static> {
275275

276276
pub(crate) clif_comments: crate::pretty_clif::CommentWriter,
277277
pub(crate) constants_cx: &'clif mut crate::constant::ConstantCx,
278-
pub(crate) vtables: &'clif mut HashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), DataId>,
278+
pub(crate) vtables: &'clif mut FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), DataId>,
279279

280280
pub(crate) source_info_set: indexmap::IndexSet<SourceInfo>,
281281
}

src/debuginfo/emit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::HashMap;
1+
use rustc_data_structures::fx::FxHashMap;
22

33
use gimli::write::{Address, AttributeValue, EndianVec, Result, Sections, Writer};
44
use gimli::{RunTimeEndian, SectionId};
@@ -20,7 +20,7 @@ impl DebugContext<'_> {
2020
let mut sections = Sections::new(WriterRelocate::new(self));
2121
self.dwarf.write(&mut sections).unwrap();
2222

23-
let mut section_map = HashMap::new();
23+
let mut section_map = FxHashMap::default();
2424
let _: Result<()> = sections.for_each_mut(|id, section| {
2525
if !section.writer.slice().is_empty() {
2626
let section_id = product.add_debug_section(id, section.writer.take());

src/debuginfo/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub(crate) struct DebugContext<'tcx> {
3333
dwarf: DwarfUnit,
3434
unit_range_list: RangeList,
3535

36-
types: HashMap<Ty<'tcx>, UnitEntryId>,
36+
types: FxHashMap<Ty<'tcx>, UnitEntryId>,
3737
}
3838

3939
impl<'tcx> DebugContext<'tcx> {
@@ -97,7 +97,7 @@ impl<'tcx> DebugContext<'tcx> {
9797
dwarf,
9898
unit_range_list: RangeList(Vec::new()),
9999

100-
types: HashMap::new(),
100+
types: FxHashMap::default(),
101101
}
102102
}
103103

@@ -255,7 +255,7 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
255255
context: &Context,
256256
isa: &dyn TargetIsa,
257257
source_info_set: &indexmap::IndexSet<SourceInfo>,
258-
local_map: HashMap<mir::Local, CPlace<'tcx>>,
258+
local_map: FxHashMap<mir::Local, CPlace<'tcx>>,
259259
) {
260260
let end = self.create_debug_lines(context, isa, source_info_set);
261261

@@ -302,8 +302,9 @@ fn place_location<'a, 'tcx>(
302302
func_debug_ctx: &mut FunctionDebugContext<'a, 'tcx>,
303303
isa: &dyn TargetIsa,
304304
context: &Context,
305-
local_map: &HashMap<mir::Local, CPlace<'tcx>>,
306-
value_labels_ranges: &HashMap<ValueLabel, Vec<ValueLocRange>>,
305+
local_map: &FxHashMap<mir::Local, CPlace<'tcx>>,
306+
#[allow(rustc::default_hash_types)]
307+
value_labels_ranges: &std::collections::HashMap<ValueLabel, Vec<ValueLocRange>>,
307308
place: Place<'tcx>,
308309
) -> AttributeValue {
309310
assert!(place.projection.is_empty()); // FIXME implement them

src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ mod value_and_place;
6767
mod vtable;
6868

6969
mod prelude {
70-
pub(crate) use std::collections::HashMap;
7170
pub(crate) use std::convert::{TryFrom, TryInto};
7271

7372
pub(crate) use rustc_ast::ast::{FloatTy, IntTy, UintTy};
@@ -132,7 +131,7 @@ pub(crate) struct CodegenCx<'clif, 'tcx, B: Backend + 'static> {
132131
module: &'clif mut Module<B>,
133132
constants_cx: ConstantCx,
134133
cached_context: Context,
135-
vtables: HashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), DataId>,
134+
vtables: FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), DataId>,
136135
debug_context: Option<&'clif mut DebugContext<'tcx>>,
137136
}
138137

@@ -147,7 +146,7 @@ impl<'clif, 'tcx, B: Backend + 'static> CodegenCx<'clif, 'tcx, B> {
147146
module,
148147
constants_cx: ConstantCx::default(),
149148
cached_context: Context::new(),
150-
vtables: HashMap::new(),
149+
vtables: FxHashMap::default(),
151150
debug_context,
152151
}
153152
}

src/optimize/code_layout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub(super) fn optimize_function(ctx: &mut Context, cold_blocks: &EntitySet<Block
1414
// FIXME Move the block in place instead of remove and append once
1515
// bytecodealliance/cranelift#1339 is implemented.
1616

17-
let mut block_insts = HashMap::new();
17+
let mut block_insts = FxHashMap::default();
1818
for block in cold_blocks.keys().filter(|&block| cold_blocks.contains(block)) {
1919
let insts = ctx.func.layout.block_insts(block).collect::<Vec<_>>();
2020
for &inst in &insts {

src/optimize/stack2reg.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
//! `stack_store` instruction incorrectly, or incorrectly use a previously stored value as the value
1010
//! being loaded by a `stack_load`.
1111
12-
use std::collections::{BTreeMap, HashSet};
12+
use std::collections::BTreeMap;
1313
use std::fmt;
1414
use std::ops::Not;
1515

16+
use rustc_data_structures::fx::FxHashSet;
17+
1618
use cranelift_codegen::cursor::{Cursor, FuncCursor};
1719
use cranelift_codegen::ir::{InstructionData, Opcode, ValueDef};
1820
use cranelift_codegen::ir::immediates::Offset32;
@@ -43,9 +45,9 @@ impl Ord for OrdStackSlot {
4345

4446
#[derive(Debug, Default)]
4547
struct StackSlotUsage {
46-
stack_addr: HashSet<Inst>,
47-
stack_load: HashSet<Inst>,
48-
stack_store: HashSet<Inst>,
48+
stack_addr: FxHashSet<Inst>,
49+
stack_load: FxHashSet<Inst>,
50+
stack_store: FxHashSet<Inst>,
4951
}
5052

5153
impl StackSlotUsage {
@@ -284,7 +286,7 @@ fn combine_stack_addr_with_load_store(func: &mut Function) {
284286

285287
fn remove_unused_stack_addr_and_stack_load(opt_ctx: &mut OptimizeContext<'_>) {
286288
// FIXME incrementally rebuild on each call?
287-
let mut stack_addr_load_insts_users = HashMap::<Inst, HashSet<Inst>>::new();
289+
let mut stack_addr_load_insts_users = FxHashMap::<Inst, FxHashSet<Inst>>::default();
288290

289291
let mut cursor = FuncCursor::new(&mut opt_ctx.ctx.func);
290292
while let Some(_block) = cursor.next_block() {
@@ -293,7 +295,7 @@ fn remove_unused_stack_addr_and_stack_load(opt_ctx: &mut OptimizeContext<'_>) {
293295
if let ValueDef::Result(arg_origin, 0) = cursor.func.dfg.value_def(arg) {
294296
match cursor.func.dfg[arg_origin].opcode() {
295297
Opcode::StackAddr | Opcode::StackLoad => {
296-
stack_addr_load_insts_users.entry(arg_origin).or_insert_with(HashSet::new).insert(inst);
298+
stack_addr_load_insts_users.entry(arg_origin).or_insert_with(FxHashSet::default).insert(inst);
297299
}
298300
_ => {}
299301
}

src/pretty_clif.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::collections::HashMap;
21
use std::fmt;
32

43
use cranelift_codegen::{
@@ -66,7 +65,7 @@ use crate::prelude::*;
6665
#[derive(Debug)]
6766
pub(crate) struct CommentWriter {
6867
global_comments: Vec<String>,
69-
entity_comments: HashMap<AnyEntity, String>,
68+
entity_comments: FxHashMap<AnyEntity, String>,
7069
}
7170

7271
impl CommentWriter {
@@ -90,7 +89,7 @@ impl CommentWriter {
9089

9190
CommentWriter {
9291
global_comments,
93-
entity_comments: HashMap::new(),
92+
entity_comments: FxHashMap::default(),
9493
}
9594
}
9695
}

src/value_and_place.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,36 +202,36 @@ impl<'tcx> CValue<'tcx> {
202202
let clif_ty = fx.clif_type(layout.ty).unwrap();
203203

204204
match layout.ty.kind {
205-
ty::TyKind::Bool => {
205+
ty::Bool => {
206206
assert!(const_val == 0 || const_val == 1, "Invalid bool 0x{:032X}", const_val);
207207
}
208208
_ => {}
209209
}
210210

211211
let val = match layout.ty.kind {
212-
ty::TyKind::Uint(UintTy::U128) | ty::TyKind::Int(IntTy::I128) => {
212+
ty::Uint(UintTy::U128) | ty::Int(IntTy::I128) => {
213213
let lsb = fx.bcx.ins().iconst(types::I64, const_val as u64 as i64);
214214
let msb = fx
215215
.bcx
216216
.ins()
217217
.iconst(types::I64, (const_val >> 64) as u64 as i64);
218218
fx.bcx.ins().iconcat(lsb, msb)
219219
}
220-
ty::TyKind::Bool | ty::TyKind::Char | ty::TyKind::Uint(_) | ty::TyKind::Ref(..)
221-
| ty::TyKind::RawPtr(..) => {
220+
ty::Bool | ty::Char | ty::Uint(_) | ty::Ref(..)
221+
| ty::RawPtr(..) => {
222222
fx
223223
.bcx
224224
.ins()
225225
.iconst(clif_ty, u64::try_from(const_val).expect("uint") as i64)
226226
}
227-
ty::TyKind::Int(_) => {
227+
ty::Int(_) => {
228228
let const_val = rustc_middle::mir::interpret::sign_extend(const_val, layout.size);
229229
fx.bcx.ins().iconst(clif_ty, i64::try_from(const_val as i128).unwrap())
230230
}
231-
ty::TyKind::Float(FloatTy::F32) => {
231+
ty::Float(FloatTy::F32) => {
232232
fx.bcx.ins().f32const(Ieee32::with_bits(u32::try_from(const_val).unwrap()))
233233
}
234-
ty::TyKind::Float(FloatTy::F64) => {
234+
ty::Float(FloatTy::F64) => {
235235
fx.bcx.ins().f64const(Ieee64::with_bits(u64::try_from(const_val).unwrap()))
236236
}
237237
_ => panic!(

0 commit comments

Comments
 (0)