add some cfgs back
This commit is contained in:
parent
aefc5ec110
commit
0725d0ceee
7 changed files with 134 additions and 124 deletions
|
@ -495,49 +495,59 @@ impl<'cx, 'tcx> BorrowckInferCtxt<'cx, 'tcx> {
|
|||
BorrowckInferCtxt { infcx, reg_var_to_origin: RefCell::new(Default::default()) }
|
||||
}
|
||||
|
||||
pub(crate) fn next_region_var(
|
||||
pub(crate) fn next_region_var<F>(
|
||||
&self,
|
||||
origin: RegionVariableOrigin,
|
||||
ctxt: RegionCtxt,
|
||||
) -> ty::Region<'tcx> {
|
||||
get_ctxt_fn: F,
|
||||
) -> ty::Region<'tcx>
|
||||
where
|
||||
F: Fn() -> RegionCtxt,
|
||||
{
|
||||
let next_region = self.infcx.next_region_var(origin);
|
||||
let vid = next_region
|
||||
.try_get_var()
|
||||
.unwrap_or_else(|| bug!("expected RegionKind::RegionVar on {:?}", next_region));
|
||||
|
||||
debug!("inserting vid {:?} with origin {:?} into var_to_origin", vid, origin);
|
||||
let mut var_to_origin = self.reg_var_to_origin.borrow_mut();
|
||||
let prev = var_to_origin.insert(vid, ctxt);
|
||||
debug!("var_to_origin after insertion: {:?}", var_to_origin);
|
||||
if cfg!(debug_assertions) {
|
||||
debug!("inserting vid {:?} with origin {:?} into var_to_origin", vid, origin);
|
||||
let ctxt = get_ctxt_fn();
|
||||
let mut var_to_origin = self.reg_var_to_origin.borrow_mut();
|
||||
let prev = var_to_origin.insert(vid, ctxt);
|
||||
|
||||
// This only makes sense if not called in a canonicalization context. If this
|
||||
// ever changes we either want to get rid of `BorrowckInferContext::reg_var_to_origin`
|
||||
// or modify how we track nll region vars for that map.
|
||||
assert!(matches!(prev, None));
|
||||
// This only makes sense if not called in a canonicalization context. If this
|
||||
// ever changes we either want to get rid of `BorrowckInferContext::reg_var_to_origin`
|
||||
// or modify how we track nll region vars for that map.
|
||||
assert!(matches!(prev, None));
|
||||
}
|
||||
|
||||
next_region
|
||||
}
|
||||
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
pub(crate) fn next_nll_region_var(
|
||||
#[instrument(skip(self, get_ctxt_fn), level = "debug")]
|
||||
pub(crate) fn next_nll_region_var<F>(
|
||||
&self,
|
||||
origin: NllRegionVariableOrigin,
|
||||
ctxt: RegionCtxt,
|
||||
) -> ty::Region<'tcx> {
|
||||
get_ctxt_fn: F,
|
||||
) -> ty::Region<'tcx>
|
||||
where
|
||||
F: Fn() -> RegionCtxt,
|
||||
{
|
||||
let next_region = self.infcx.next_nll_region_var(origin.clone());
|
||||
let vid = next_region
|
||||
.try_get_var()
|
||||
.unwrap_or_else(|| bug!("expected RegionKind::RegionVar on {:?}", next_region));
|
||||
|
||||
debug!("inserting vid {:?} with origin {:?} into var_to_origin", vid, origin);
|
||||
let mut var_to_origin = self.reg_var_to_origin.borrow_mut();
|
||||
let prev = var_to_origin.insert(vid, ctxt);
|
||||
debug!("var_to_origin after insertion: {:?}", var_to_origin);
|
||||
if cfg!(debug_assertions) {
|
||||
debug!("inserting vid {:?} with origin {:?} into var_to_origin", vid, origin);
|
||||
let ctxt = get_ctxt_fn();
|
||||
let mut var_to_origin = self.reg_var_to_origin.borrow_mut();
|
||||
let prev = var_to_origin.insert(vid, ctxt);
|
||||
|
||||
// This only makes sense if not called in a canonicalization context. If this
|
||||
// ever changes we either want to get rid of `BorrowckInferContext::reg_var_to_origin`
|
||||
// or modify how we track nll region vars for that map.
|
||||
assert!(matches!(prev, None));
|
||||
// This only makes sense if not called in a canonicalization context. If this
|
||||
// ever changes we either want to get rid of `BorrowckInferContext::reg_var_to_origin`
|
||||
// or modify how we track nll region vars for that map.
|
||||
assert!(matches!(prev, None));
|
||||
}
|
||||
|
||||
next_region
|
||||
}
|
||||
|
|
|
@ -244,6 +244,7 @@ pub enum ExtraConstraintInfo {
|
|||
PlaceholderFromPredicate(Span),
|
||||
}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
#[instrument(skip(infcx, sccs), level = "debug")]
|
||||
fn sccs_info<'cx, 'tcx>(
|
||||
infcx: &'cx BorrowckInferCtxt<'cx, 'tcx>,
|
||||
|
@ -252,31 +253,43 @@ fn sccs_info<'cx, 'tcx>(
|
|||
use crate::renumber::RegionCtxt;
|
||||
|
||||
let var_to_origin = infcx.reg_var_to_origin.borrow();
|
||||
|
||||
let mut var_to_origin_sorted = var_to_origin.clone().into_iter().collect::<Vec<_>>();
|
||||
var_to_origin_sorted.sort_by(|a, b| a.0.cmp(&b.0));
|
||||
let mut debug_str = "region variables to origins:\n".to_string();
|
||||
for (reg_var, origin) in var_to_origin_sorted.into_iter() {
|
||||
debug_str.push_str(&format!("{:?}: {:?}\n", reg_var, origin));
|
||||
}
|
||||
debug!(debug_str);
|
||||
|
||||
let num_components = sccs.scc_data.ranges.len();
|
||||
let mut components = vec![FxHashSet::default(); num_components];
|
||||
|
||||
for (reg_var_idx, scc_idx) in sccs.scc_indices.iter().enumerate() {
|
||||
let reg_var = ty::RegionVid::from_usize(reg_var_idx);
|
||||
let origin = var_to_origin.get(®_var).unwrap_or_else(|| &RegionCtxt::Unknown);
|
||||
components[scc_idx.as_usize()].insert(*origin);
|
||||
components[scc_idx.as_usize()].insert((reg_var, *origin));
|
||||
}
|
||||
|
||||
debug!(
|
||||
"strongly connected components: {:#?}",
|
||||
components
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(idx, origin)| { (ConstraintSccIndex::from_usize(idx), origin) })
|
||||
.collect::<Vec<_>>()
|
||||
);
|
||||
let mut components_str = "strongly connected components:";
|
||||
for (scc_idx, reg_vars_origins) in components.iter().enumerate() {
|
||||
let regions_info = reg_vars_origins.clone().into_iter().collect::<Vec<_>>();
|
||||
components_str.push(&format(
|
||||
"{:?}: {:?})",
|
||||
ConstraintSccIndex::from_usize(scc_idx),
|
||||
regions_info,
|
||||
))
|
||||
}
|
||||
debug!(components_str);
|
||||
|
||||
// Now let's calculate the best representative for each component
|
||||
// calculate the best representative for each component
|
||||
let components_representatives = components
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(scc_idx, region_ctxts)| {
|
||||
let repr = region_ctxts
|
||||
.into_iter()
|
||||
.map(|reg_var_origin| reg_var_origin.1)
|
||||
.max_by(|x, y| x.preference_value().cmp(&y.preference_value()))
|
||||
.unwrap();
|
||||
|
||||
|
@ -333,6 +346,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
let fr_static = universal_regions.fr_static;
|
||||
let constraint_sccs = Rc::new(constraints.compute_sccs(&constraint_graph, fr_static));
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
sccs_info(_infcx, constraint_sccs.clone());
|
||||
|
||||
let mut scc_values =
|
||||
|
|
|
@ -31,18 +31,19 @@ pub fn renumber_mir<'tcx>(
|
|||
|
||||
/// Replaces all regions appearing in `value` with fresh inference
|
||||
/// variables.
|
||||
#[instrument(skip(infcx), level = "debug")]
|
||||
pub(crate) fn renumber_regions<'tcx, T>(
|
||||
#[instrument(skip(infcx, get_ctxt_fn), level = "debug")]
|
||||
pub(crate) fn renumber_regions<'tcx, T, F>(
|
||||
infcx: &BorrowckInferCtxt<'_, 'tcx>,
|
||||
value: T,
|
||||
ctxt: RegionCtxt,
|
||||
get_ctxt_fn: F,
|
||||
) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
F: Fn() -> RegionCtxt,
|
||||
{
|
||||
infcx.tcx.fold_regions(value, |_region, _depth| {
|
||||
let origin = NllRegionVariableOrigin::Existential { from_forall: false };
|
||||
infcx.next_nll_region_var(origin, ctxt)
|
||||
infcx.next_nll_region_var(origin, || get_ctxt_fn())
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -61,13 +62,14 @@ pub(crate) enum RegionCtxt {
|
|||
LateBound(BoundRegionInfo),
|
||||
Existential(Option<Symbol>),
|
||||
Placeholder(BoundRegionInfo),
|
||||
#[cfg(debug_assertions)]
|
||||
Unknown,
|
||||
}
|
||||
|
||||
impl RegionCtxt {
|
||||
/// Used to determine the representative of a component in the strongly connected
|
||||
/// constraint graph
|
||||
/// FIXME: don't use underscore here. Got a 'not used' error for some reason
|
||||
#[cfg(debug_assertions)]
|
||||
pub(crate) fn preference_value(self) -> usize {
|
||||
let _anon = Symbol::intern("anon");
|
||||
|
||||
|
@ -87,11 +89,12 @@ struct NllVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> NllVisitor<'a, 'tcx> {
|
||||
fn renumber_regions<T>(&mut self, value: T, ctxt: RegionCtxt) -> T
|
||||
fn renumber_regions<T, F>(&mut self, value: T, region_ctxt_fn: F) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
F: Fn() -> RegionCtxt,
|
||||
{
|
||||
renumber_regions(self.infcx, value, ctxt)
|
||||
renumber_regions(self.infcx, value, region_ctxt_fn)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,15 +104,15 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NllVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
fn visit_ty(&mut self, ty: &mut Ty<'tcx>, _ty_context: TyContext) {
|
||||
*ty = self.renumber_regions(*ty, RegionCtxt::TyContext(_ty_context));
|
||||
fn visit_ty(&mut self, ty: &mut Ty<'tcx>, ty_context: TyContext) {
|
||||
*ty = self.renumber_regions(*ty, || RegionCtxt::TyContext(ty_context));
|
||||
|
||||
debug!(?ty);
|
||||
}
|
||||
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
fn visit_substs(&mut self, substs: &mut SubstsRef<'tcx>, location: Location) {
|
||||
*substs = self.renumber_regions(*substs, RegionCtxt::Location(location));
|
||||
*substs = self.renumber_regions(*substs, || RegionCtxt::Location(location));
|
||||
|
||||
debug!(?substs);
|
||||
}
|
||||
|
@ -117,7 +120,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NllVisitor<'a, 'tcx> {
|
|||
#[instrument(skip(self), level = "debug")]
|
||||
fn visit_region(&mut self, region: &mut ty::Region<'tcx>, location: Location) {
|
||||
let old_region = *region;
|
||||
*region = self.renumber_regions(old_region, RegionCtxt::Location(location));
|
||||
*region = self.renumber_regions(old_region, || RegionCtxt::Location(location));
|
||||
|
||||
debug!(?region);
|
||||
}
|
||||
|
@ -125,7 +128,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NllVisitor<'a, 'tcx> {
|
|||
#[instrument(skip(self), level = "debug")]
|
||||
fn visit_constant(&mut self, constant: &mut Constant<'tcx>, _location: Location) {
|
||||
let literal = constant.literal;
|
||||
constant.literal = self.renumber_regions(literal, RegionCtxt::Location(_location));
|
||||
constant.literal = self.renumber_regions(literal, || RegionCtxt::Location(_location));
|
||||
debug!("constant: {:#?}", constant);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1338,14 +1338,21 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
use crate::renumber::{BoundRegionInfo, RegionCtxt};
|
||||
use rustc_span::Symbol;
|
||||
|
||||
let reg_info = match br.kind {
|
||||
// FIXME Probably better to use the `Span` here
|
||||
ty::BoundRegionKind::BrAnon(_, Some(span)) => BoundRegionInfo::Span(span),
|
||||
ty::BoundRegionKind::BrAnon(..) => {
|
||||
BoundRegionInfo::Name(Symbol::intern("anon"))
|
||||
}
|
||||
ty::BoundRegionKind::BrNamed(_, name) => BoundRegionInfo::Name(name),
|
||||
ty::BoundRegionKind::BrEnv => BoundRegionInfo::Name(Symbol::intern("env")),
|
||||
let region_ctxt_fn = || {
|
||||
let reg_info = match br.kind {
|
||||
ty::BoundRegionKind::BrAnon(_, Some(span)) => {
|
||||
BoundRegionInfo::Span(span)
|
||||
}
|
||||
ty::BoundRegionKind::BrAnon(..) => {
|
||||
BoundRegionInfo::Name(Symbol::intern("anon"))
|
||||
}
|
||||
ty::BoundRegionKind::BrNamed(_, name) => BoundRegionInfo::Name(name),
|
||||
ty::BoundRegionKind::BrEnv => {
|
||||
BoundRegionInfo::Name(Symbol::intern("env"))
|
||||
}
|
||||
};
|
||||
|
||||
RegionCtxt::LateBound(reg_info)
|
||||
};
|
||||
|
||||
self.infcx.next_region_var(
|
||||
|
@ -1354,7 +1361,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
br.kind,
|
||||
LateBoundRegionConversionTime::FnCall,
|
||||
),
|
||||
RegionCtxt::LateBound(reg_info),
|
||||
region_ctxt_fn,
|
||||
)
|
||||
});
|
||||
debug!(?sig);
|
||||
|
|
|
@ -110,7 +110,7 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx>
|
|||
let origin = NllRegionVariableOrigin::Existential { from_forall };
|
||||
|
||||
let reg_var =
|
||||
self.type_checker.infcx.next_nll_region_var(origin, RegionCtxt::Existential(_name));
|
||||
self.type_checker.infcx.next_nll_region_var(origin, || RegionCtxt::Existential(_name));
|
||||
|
||||
reg_var
|
||||
}
|
||||
|
@ -150,9 +150,16 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx>
|
|||
let reg_var = reg
|
||||
.try_get_var()
|
||||
.unwrap_or_else(|| bug!("expected region {:?} to be of kind ReVar", reg));
|
||||
let mut var_to_origin = self.type_checker.infcx.reg_var_to_origin.borrow_mut();
|
||||
let prev = var_to_origin.insert(reg_var, RegionCtxt::Existential(None));
|
||||
assert!(matches!(prev, None));
|
||||
|
||||
if cfg!(debug_assertions) {
|
||||
let mut var_to_origin = self.type_checker.infcx.reg_var_to_origin.borrow_mut();
|
||||
let prev = var_to_origin.insert(reg_var, RegionCtxt::Existential(None));
|
||||
|
||||
// It only makes sense to track region vars in non-canonicalization contexts. If this
|
||||
// ever changes we either want to get rid of `BorrowckInferContext::reg_var_to_origin`
|
||||
// or modify how we track nll region vars for that map.
|
||||
assert!(matches!(prev, None));
|
||||
}
|
||||
|
||||
reg
|
||||
}
|
||||
|
|
|
@ -408,7 +408,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||
// Create the "global" region that is always free in all contexts: 'static.
|
||||
let fr_static = self
|
||||
.infcx
|
||||
.next_nll_region_var(FR, RegionCtxt::Free(Symbol::intern("static")))
|
||||
.next_nll_region_var(FR, || RegionCtxt::Free(Symbol::intern("static")))
|
||||
.to_region_vid();
|
||||
|
||||
// We've now added all the global regions. The next ones we
|
||||
|
@ -447,10 +447,9 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||
_ => Symbol::intern("anon"),
|
||||
};
|
||||
|
||||
self.infcx.next_nll_region_var(
|
||||
FR,
|
||||
RegionCtxt::LateBound(BoundRegionInfo::Name(name)),
|
||||
)
|
||||
self.infcx.next_nll_region_var(FR, || {
|
||||
RegionCtxt::LateBound(BoundRegionInfo::Name(name))
|
||||
})
|
||||
};
|
||||
|
||||
debug!(?region_vid);
|
||||
|
@ -486,8 +485,9 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||
_ => Symbol::intern("anon"),
|
||||
};
|
||||
|
||||
self.infcx
|
||||
.next_nll_region_var(FR, RegionCtxt::LateBound(BoundRegionInfo::Name(name)))
|
||||
self.infcx.next_nll_region_var(FR, || {
|
||||
RegionCtxt::LateBound(BoundRegionInfo::Name(name))
|
||||
})
|
||||
};
|
||||
|
||||
debug!(?region_vid);
|
||||
|
@ -506,9 +506,13 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||
LangItem::VaList,
|
||||
Some(self.infcx.tcx.def_span(self.mir_def.did)),
|
||||
);
|
||||
let reg_vid = self.infcx.next_nll_region_var(FR, RegionCtxt::Free(Symbol::intern("c-variadic")).to_region_vid();
|
||||
let region =
|
||||
self.infcx.tcx.mk_re_var(reg_vid);
|
||||
|
||||
let reg_vid = self
|
||||
.infcx
|
||||
.next_nll_region_var(FR, || RegionCtxt::Free(Symbol::intern("c-variadic")))
|
||||
.to_region_vid();
|
||||
|
||||
let region = self.infcx.tcx.mk_re_var(reg_vid);
|
||||
let va_list_ty =
|
||||
self.infcx.tcx.type_of(va_list_did).subst(self.infcx.tcx, &[region.into()]);
|
||||
|
||||
|
@ -520,7 +524,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||
|
||||
let fr_fn_body = self
|
||||
.infcx
|
||||
.next_nll_region_var(FR, RegionCtxt::Free(Symbol::intern("fn_body")))
|
||||
.next_nll_region_var(FR, || RegionCtxt::Free(Symbol::intern("fn_body")))
|
||||
.to_region_vid();
|
||||
|
||||
let num_universals = self.infcx.num_region_vars();
|
||||
|
@ -766,7 +770,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
|
|||
};
|
||||
debug!(?region, ?name);
|
||||
|
||||
let reg_var = self.next_nll_region_var(origin, RegionCtxt::Free(name));
|
||||
let reg_var = self.next_nll_region_var(origin, || RegionCtxt::Free(name));
|
||||
|
||||
reg_var
|
||||
})
|
||||
|
@ -786,7 +790,15 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
|
|||
let (value, _map) = self.tcx.replace_late_bound_regions(value, |br| {
|
||||
debug!(?br);
|
||||
let liberated_region = self.tcx.mk_re_free(all_outlive_scope.to_def_id(), br.kind);
|
||||
let region_vid = self.next_nll_region_var(origin, RegionCtxt::Bound(BoundRegionInfo::Name(name)));
|
||||
let region_vid = {
|
||||
let name = match br.kind.get_name() {
|
||||
Some(name) => name,
|
||||
_ => Symbol::intern("anon"),
|
||||
};
|
||||
|
||||
self.next_nll_region_var(origin, || RegionCtxt::Bound(BoundRegionInfo::Name(name)))
|
||||
};
|
||||
|
||||
indices.insert_late_bound_region(liberated_region, region_vid.to_region_vid());
|
||||
debug!(?liberated_region, ?region_vid);
|
||||
region_vid
|
||||
|
@ -818,7 +830,9 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
|
|||
_ => Symbol::intern("anon"),
|
||||
};
|
||||
|
||||
self.next_nll_region_var(FR, RegionCtxt::LateBound(BoundRegionInfo::Name(name)))
|
||||
self.next_nll_region_var(FR, || {
|
||||
RegionCtxt::LateBound(BoundRegionInfo::Name(name))
|
||||
})
|
||||
};
|
||||
|
||||
debug!(?region_vid);
|
||||
|
@ -842,7 +856,9 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
|
|||
_ => Symbol::intern("anon"),
|
||||
};
|
||||
|
||||
self.next_nll_region_var(FR, RegionCtxt::LateBound(BoundRegionInfo::Name(name)))
|
||||
self.next_nll_region_var(FR, || {
|
||||
RegionCtxt::LateBound(BoundRegionInfo::Name(name))
|
||||
})
|
||||
};
|
||||
|
||||
indices.insert_late_bound_region(r, region_vid.to_region_vid());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue