Skip to content
Permalink
Browse files

Store type variable origins in InferenceFudger

  • Loading branch information...
varkor committed Mar 25, 2019
1 parent 58a04f0 commit 2d48ffa9c63255eafa25639142f3b5601d42ae05
Showing with 13 additions and 6 deletions.
  1. +4 −3 src/librustc/infer/fudge.rs
  2. +9 −3 src/librustc/infer/type_variable.rs
@@ -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
@@ -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`

0 comments on commit 2d48ffa

Please sign in to comment.
You can’t perform that action at this time.