Skip to content

Commit

Permalink
Lookup region variable origin instead of choosing one
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Mar 27, 2019
1 parent 2d48ffa commit 688cbad
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
15 changes: 6 additions & 9 deletions src/librustc/infer/fudge.rs
Expand Up @@ -50,13 +50,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
/// unified. /// unified.
pub fn fudge_inference_if_ok<T, E, F>( pub fn fudge_inference_if_ok<T, E, F>(
&self, &self,
origin: &RegionVariableOrigin,
f: F, f: F,
) -> Result<T, E> where ) -> Result<T, E> where
F: FnOnce() -> Result<T, E>, F: FnOnce() -> Result<T, E>,
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
{ {
debug!("fudge_inference_if_ok(origin={:?})", origin); debug!("fudge_inference_if_ok()");


let (mut fudger, value) = self.probe(|snapshot| { let (mut fudger, value) = self.probe(|snapshot| {
match f() { match f() {
Expand Down Expand Up @@ -88,7 +87,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
int_vars, int_vars,
float_vars, float_vars,
region_vars, region_vars,
origin,
}; };


Ok((fudger, value)) Ok((fudger, value))
Expand Down Expand Up @@ -120,8 +118,7 @@ pub struct InferenceFudger<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
type_vars: FxHashMap<TyVid, TypeVariableOrigin>, type_vars: FxHashMap<TyVid, TypeVariableOrigin>,
int_vars: Range<IntVid>, int_vars: Range<IntVid>,
float_vars: Range<FloatVid>, float_vars: Range<FloatVid>,
region_vars: Range<RegionVid>, region_vars: FxHashMap<RegionVid, RegionVariableOrigin>,
origin: &'a RegionVariableOrigin,
} }


impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for InferenceFudger<'a, 'gcx, 'tcx> { impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for InferenceFudger<'a, 'gcx, 'tcx> {
Expand Down Expand Up @@ -167,11 +164,11 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for InferenceFudger<'a, 'gcx, 'tcx>
} }


fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> { fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
match *r { if let ty::ReVar(vid) = r {
ty::ReVar(vid) if self.region_vars.contains(&vid) => { if let Some(&origin) = self.region_vars.get(&vid) {
self.infcx.next_region_var(self.origin.clone()) return self.infcx.next_region_var(origin);
} }
_ => r,
} }
r
} }
} }
13 changes: 10 additions & 3 deletions src/librustc/infer/region_constraints/mod.rs
Expand Up @@ -16,7 +16,6 @@ use crate::ty::{Region, RegionVid};


use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::{cmp, fmt, mem, u32}; use std::{cmp, fmt, mem, u32};
use std::ops::Range;


mod leak_check; mod leak_check;


Expand Down Expand Up @@ -841,8 +840,16 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
} }
} }


pub fn vars_since_snapshot(&self, mark: &RegionSnapshot) -> Range<RegionVid> { pub fn vars_since_snapshot(
self.unification_table.vars_since_snapshot(&mark.region_snapshot) &self,
mark: &RegionSnapshot,
) -> FxHashMap<RegionVid, RegionVariableOrigin> {
let range = self.unification_table.vars_since_snapshot(&mark.region_snapshot);
(range.start.index()..range.end.index()).map(|index| {
let vid = ty::RegionVid::from(index);
let origin = self.var_infos[vid].origin.clone();
(vid, origin)
}).collect()
} }


/// See [`RegionInference::region_constraints_added_in_snapshot`]. /// See [`RegionInference::region_constraints_added_in_snapshot`].
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_typeck/check/mod.rs
Expand Up @@ -92,7 +92,7 @@ use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::hir::itemlikevisit::ItemLikeVisitor;
use crate::middle::lang_items; use crate::middle::lang_items;
use crate::namespace::Namespace; use crate::namespace::Namespace;
use rustc::infer::{self, InferCtxt, InferOk, InferResult, RegionVariableOrigin}; use rustc::infer::{self, InferCtxt, InferOk, InferResult};
use rustc::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse}; use rustc::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse};
use rustc_data_structures::indexed_vec::Idx; use rustc_data_structures::indexed_vec::Idx;
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::Lrc;
Expand Down Expand Up @@ -3229,8 +3229,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
Some(ret) => ret, Some(ret) => ret,
None => return Vec::new() None => return Vec::new()
}; };
let origin = RegionVariableOrigin::Coercion(call_span); let expect_args = self.fudge_inference_if_ok(|| {
let expect_args = self.fudge_inference_if_ok(&origin, || {
// Attempt to apply a subtyping relationship between the formal // Attempt to apply a subtyping relationship between the formal
// return type (likely containing type variables if the function // return type (likely containing type variables if the function
// is polymorphic) and the expected return type. // is polymorphic) and the expected return type.
Expand Down

0 comments on commit 688cbad

Please sign in to comment.