Store type variable origins in InferenceFudger

This commit is contained in:
varkor
2019-03-25 21:28:15 +00:00
parent 58a04f06cb
commit 2d48ffa9c6
2 changed files with 13 additions and 6 deletions

View File

@@ -3,8 +3,10 @@ use crate::ty::fold::{TypeFoldable, TypeFolder};
use super::InferCtxt;
use super::RegionVariableOrigin;
use super::type_variable::TypeVariableOrigin;
use std::ops::Range;
use rustc_data_structures::fx::FxHashMap;
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
/// This rather funky routine is used while processing expected
@@ -115,7 +117,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
pub struct InferenceFudger<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
type_vars: Range<TyVid>,
type_vars: FxHashMap<TyVid, TypeVariableOrigin>,
int_vars: Range<IntVid>,
float_vars: Range<FloatVid>,
region_vars: Range<RegionVid>,
@@ -130,10 +132,9 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for InferenceFudger<'a, 'gcx, 'tcx>
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
match ty.sty {
ty::Infer(ty::InferTy::TyVar(vid)) => {
if self.type_vars.contains(&vid) {
if let Some(&origin) = self.type_vars.get(&vid) {
// This variable was created during the fudging.
// Recreate it with a fresh variable here.
let origin = self.infcx.type_variables.borrow().var_origin(vid).clone();
self.infcx.next_ty_var(origin)
} else {
// This variable was created before the

View File

@@ -4,8 +4,8 @@ use crate::ty::{self, Ty, TyVid};
use std::cmp;
use std::marker::PhantomData;
use std::ops::Range;
use std::u32;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::snapshot_vec as sv;
use rustc_data_structures::unify as ut;
@@ -291,9 +291,15 @@ impl<'tcx> TypeVariableTable<'tcx> {
}
/// Returns a range of the type variables created during the snapshot.
pub fn vars_since_snapshot(&mut self, s: &Snapshot<'tcx>) -> Range<TyVid> {
pub fn vars_since_snapshot(
&mut self,
s: &Snapshot<'tcx>,
) -> FxHashMap<TyVid, TypeVariableOrigin> {
let range = self.eq_relations.vars_since_snapshot(&s.eq_snapshot);
range.start.vid..range.end.vid
(range.start.vid.index..range.end.vid.index).map(|index| {
let origin = self.values.get(index as usize).origin.clone();
(TyVid { index }, origin)
}).collect()
}
/// Finds the set of type variables that existed *before* `s`