Skip to content

Commit 86d5a69

Browse files
committed
Use Vec instead of FxHashMap
1 parent 688cbad commit 86d5a69

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

src/librustc/infer/fudge.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use super::RegionVariableOrigin;
66
use super::type_variable::TypeVariableOrigin;
77

88
use std::ops::Range;
9-
use rustc_data_structures::fx::FxHashMap;
109

1110
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1211
/// This rather funky routine is used while processing expected
@@ -102,10 +101,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
102101

103102
// Micro-optimization: if no variables have been created, then
104103
// `value` can't refer to any of them. =) So we can just return it.
105-
if fudger.type_vars.is_empty() &&
104+
if fudger.type_vars.0.is_empty() &&
106105
fudger.int_vars.is_empty() &&
107106
fudger.float_vars.is_empty() &&
108-
fudger.region_vars.is_empty() {
107+
fudger.region_vars.0.is_empty() {
109108
Ok(value)
110109
} else {
111110
Ok(value.fold_with(&mut fudger))
@@ -115,10 +114,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
115114

116115
pub struct InferenceFudger<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
117116
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
118-
type_vars: FxHashMap<TyVid, TypeVariableOrigin>,
117+
type_vars: (Range<TyVid>, Vec<TypeVariableOrigin>),
119118
int_vars: Range<IntVid>,
120119
float_vars: Range<FloatVid>,
121-
region_vars: FxHashMap<RegionVid, RegionVariableOrigin>,
120+
region_vars: (Range<RegionVid>, Vec<RegionVariableOrigin>),
122121
}
123122

124123
impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for InferenceFudger<'a, 'gcx, 'tcx> {
@@ -129,9 +128,11 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for InferenceFudger<'a, 'gcx, 'tcx>
129128
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
130129
match ty.sty {
131130
ty::Infer(ty::InferTy::TyVar(vid)) => {
132-
if let Some(&origin) = self.type_vars.get(&vid) {
131+
if self.type_vars.0.contains(&vid) {
133132
// This variable was created during the fudging.
134133
// Recreate it with a fresh variable here.
134+
let idx = (vid.index - self.type_vars.0.start.index) as usize;
135+
let origin = self.type_vars.1[idx];
135136
self.infcx.next_ty_var(origin)
136137
} else {
137138
// This variable was created before the
@@ -165,7 +166,9 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for InferenceFudger<'a, 'gcx, 'tcx>
165166

166167
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
167168
if let ty::ReVar(vid) = r {
168-
if let Some(&origin) = self.region_vars.get(&vid) {
169+
if self.region_vars.0.contains(&vid) {
170+
let idx = (vid.index() - self.region_vars.0.start.index()) as usize;
171+
let origin = self.region_vars.1[idx];
169172
return self.infcx.next_region_var(origin);
170173
}
171174
}

src/librustc/infer/region_constraints/mod.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::ty::{Region, RegionVid};
1616

1717
use std::collections::BTreeMap;
1818
use std::{cmp, fmt, mem, u32};
19+
use std::ops::Range;
1920

2021
mod leak_check;
2122

@@ -843,13 +844,11 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
843844
pub fn vars_since_snapshot(
844845
&self,
845846
mark: &RegionSnapshot,
846-
) -> FxHashMap<RegionVid, RegionVariableOrigin> {
847+
) -> (Range<RegionVid>, Vec<RegionVariableOrigin>) {
847848
let range = self.unification_table.vars_since_snapshot(&mark.region_snapshot);
848-
(range.start.index()..range.end.index()).map(|index| {
849-
let vid = ty::RegionVid::from(index);
850-
let origin = self.var_infos[vid].origin.clone();
851-
(vid, origin)
852-
}).collect()
849+
(range.clone(), (range.start.index()..range.end.index()).map(|index| {
850+
self.var_infos[ty::RegionVid::from(index)].origin.clone()
851+
}).collect())
853852
}
854853

855854
/// See [`RegionInference::region_constraints_added_in_snapshot`].

src/librustc/infer/type_variable.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::ty::{self, Ty, TyVid};
55
use std::cmp;
66
use std::marker::PhantomData;
77
use std::u32;
8-
use rustc_data_structures::fx::FxHashMap;
8+
use std::ops::Range;
99
use rustc_data_structures::snapshot_vec as sv;
1010
use rustc_data_structures::unify as ut;
1111

@@ -294,12 +294,11 @@ impl<'tcx> TypeVariableTable<'tcx> {
294294
pub fn vars_since_snapshot(
295295
&mut self,
296296
s: &Snapshot<'tcx>,
297-
) -> FxHashMap<TyVid, TypeVariableOrigin> {
297+
) -> (Range<TyVid>, Vec<TypeVariableOrigin>) {
298298
let range = self.eq_relations.vars_since_snapshot(&s.eq_snapshot);
299-
(range.start.vid.index..range.end.vid.index).map(|index| {
300-
let origin = self.values.get(index as usize).origin.clone();
301-
(TyVid { index }, origin)
302-
}).collect()
299+
(range.start.vid..range.end.vid, (range.start.vid.index..range.end.vid.index).map(|index| {
300+
self.values.get(index as usize).origin.clone()
301+
}).collect())
303302
}
304303

305304
/// Finds the set of type variables that existed *before* `s`

0 commit comments

Comments
 (0)