Skip to content

Commit 2d48ffa

Browse files
committed
Store type variable origins in InferenceFudger
1 parent 58a04f0 commit 2d48ffa

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/librustc/infer/fudge.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ use crate::ty::fold::{TypeFoldable, TypeFolder};
33

44
use super::InferCtxt;
55
use super::RegionVariableOrigin;
6+
use super::type_variable::TypeVariableOrigin;
67

78
use std::ops::Range;
9+
use rustc_data_structures::fx::FxHashMap;
810

911
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1012
/// This rather funky routine is used while processing expected
@@ -115,7 +117,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
115117

116118
pub struct InferenceFudger<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
117119
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
118-
type_vars: Range<TyVid>,
120+
type_vars: FxHashMap<TyVid, TypeVariableOrigin>,
119121
int_vars: Range<IntVid>,
120122
float_vars: Range<FloatVid>,
121123
region_vars: Range<RegionVid>,
@@ -130,10 +132,9 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for InferenceFudger<'a, 'gcx, 'tcx>
130132
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
131133
match ty.sty {
132134
ty::Infer(ty::InferTy::TyVar(vid)) => {
133-
if self.type_vars.contains(&vid) {
135+
if let Some(&origin) = self.type_vars.get(&vid) {
134136
// This variable was created during the fudging.
135137
// Recreate it with a fresh variable here.
136-
let origin = self.infcx.type_variables.borrow().var_origin(vid).clone();
137138
self.infcx.next_ty_var(origin)
138139
} else {
139140
// This variable was created before the

src/librustc/infer/type_variable.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use crate::ty::{self, Ty, TyVid};
44

55
use std::cmp;
66
use std::marker::PhantomData;
7-
use std::ops::Range;
87
use std::u32;
8+
use rustc_data_structures::fx::FxHashMap;
99
use rustc_data_structures::snapshot_vec as sv;
1010
use rustc_data_structures::unify as ut;
1111

@@ -291,9 +291,15 @@ impl<'tcx> TypeVariableTable<'tcx> {
291291
}
292292

293293
/// Returns a range of the type variables created during the snapshot.
294-
pub fn vars_since_snapshot(&mut self, s: &Snapshot<'tcx>) -> Range<TyVid> {
294+
pub fn vars_since_snapshot(
295+
&mut self,
296+
s: &Snapshot<'tcx>,
297+
) -> FxHashMap<TyVid, TypeVariableOrigin> {
295298
let range = self.eq_relations.vars_since_snapshot(&s.eq_snapshot);
296-
range.start.vid..range.end.vid
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()
297303
}
298304

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

0 commit comments

Comments
 (0)