diff options
| author | varkor <github@varkor.com> | 2019-03-21 13:39:57 +0000 |
|---|---|---|
| committer | varkor <github@varkor.com> | 2019-03-27 09:44:55 +0000 |
| commit | ac94858e32bdf7a8d00126e8d901dfd44e2df508 (patch) | |
| tree | 0debd6f9ebd0f6970c671e936eedc7153d9d9d4b /src | |
| parent | 1f9a2326b58b1de43cb3d1bfae1e1403f5d059ef (diff) | |
| download | rust-ac94858e32bdf7a8d00126e8d901dfd44e2df508.tar.gz rust-ac94858e32bdf7a8d00126e8d901dfd44e2df508.zip | |
Add int variables and float variables to `InferenceFudger`
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/infer/fudge.rs | 43 | ||||
| -rw-r--r-- | src/librustc/infer/type_variable.rs | 1 |
2 files changed, 35 insertions, 9 deletions
diff --git a/src/librustc/infer/fudge.rs b/src/librustc/infer/fudge.rs index a335a21359b..198e0ce7381 100644 --- a/src/librustc/infer/fudge.rs +++ b/src/librustc/infer/fudge.rs @@ -1,4 +1,4 @@ -use crate::ty::{self, Ty, TyCtxt, TyVid, RegionVid}; +use crate::ty::{self, Ty, TyCtxt, TyVid, IntVid, FloatVid, RegionVid}; use crate::ty::fold::{TypeFoldable, TypeFolder}; use super::InferCtxt; @@ -56,7 +56,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { { debug!("fudge_inference_if_ok(origin={:?})", origin); - let (type_variables, region_vars, value) = self.probe(|snapshot| { + let (type_vars, int_vars, float_vars, region_vars, value) = self.probe(|snapshot| { match f() { Ok(value) => { let value = self.resolve_type_vars_if_possible(&value); @@ -67,14 +67,20 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { // going to be popped, so we will have to // eliminate any references to them. - let type_variables = self.type_variables.borrow_mut().vars_since_snapshot( + let type_vars = self.type_variables.borrow_mut().vars_since_snapshot( &snapshot.type_snapshot, ); + let int_vars = self.int_unification_table.borrow_mut().vars_since_snapshot( + &snapshot.int_snapshot, + ); + let float_vars = self.float_unification_table.borrow_mut().vars_since_snapshot( + &snapshot.float_snapshot, + ); let region_vars = self.borrow_region_constraints().vars_since_snapshot( &snapshot.region_constraints_snapshot, ); - Ok((type_variables, region_vars, value)) + Ok((type_vars, int_vars, float_vars, region_vars, value)) } Err(e) => Err(e), } @@ -87,13 +93,18 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { // Micro-optimization: if no variables have been created, then // `value` can't refer to any of them. =) So we can just return it. - if type_variables.is_empty() && region_vars.is_empty() { + if type_vars.is_empty() && + int_vars.is_empty() && + float_vars.is_empty() && + region_vars.is_empty() { return Ok(value); } let mut fudger = InferenceFudger { infcx: self, - type_variables: &type_variables, + type_vars: &type_vars, + int_vars: &int_vars, + float_vars: &float_vars, region_vars: ®ion_vars, origin, }; @@ -104,7 +115,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { pub struct InferenceFudger<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, - type_variables: &'a Range<TyVid>, + type_vars: &'a Range<TyVid>, + int_vars: &'a Range<IntVid>, + float_vars: &'a Range<FloatVid>, region_vars: &'a Range<RegionVid>, origin: &'a RegionVariableOrigin, } @@ -117,7 +130,7 @@ 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_variables.contains(&vid) { + if self.type_vars.contains(&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(); @@ -134,6 +147,20 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for InferenceFudger<'a, 'gcx, 'tcx> ty } } + ty::Infer(ty::InferTy::IntVar(vid)) => { + if self.int_vars.contains(&vid) { + self.infcx.tcx.mk_int_var(self.infcx.next_int_var_id()) + } else { + ty + } + } + ty::Infer(ty::InferTy::FloatVar(vid)) => { + if self.float_vars.contains(&vid) { + self.infcx.tcx.mk_float_var(self.infcx.next_float_var_id()) + } else { + ty + } + } _ => ty.super_fold_with(self), } } diff --git a/src/librustc/infer/type_variable.rs b/src/librustc/infer/type_variable.rs index 96a9f9520b4..a09c03c34ca 100644 --- a/src/librustc/infer/type_variable.rs +++ b/src/librustc/infer/type_variable.rs @@ -6,7 +6,6 @@ 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; use ut::UnifyKey; |
