a95fb8b150
Specifically, rename the `Const` struct as `ConstS` and re-introduce `Const` as this: ``` pub struct Const<'tcx>(&'tcx Interned<ConstS>); ``` This now matches `Ty` and `Predicate` more closely, including using pointer-based `eq` and `hash`. Notable changes: - `mk_const` now takes a `ConstS`. - `Const` was copy, despite being 48 bytes. Now `ConstS` is not, so need a we need separate arena for it, because we can't use the `Dropless` one any more. - Many `&'tcx Const<'tcx>`/`&Const<'tcx>` to `Const<'tcx>` changes - Many `ct.ty` to `ct.ty()` and `ct.val` to `ct.val()` changes. - Lots of tedious sigil fiddling.
84 lines
2.4 KiB
Rust
84 lines
2.4 KiB
Rust
use rustc_index::vec::IndexVec;
|
|
use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin};
|
|
use rustc_middle::mir::visit::{MutVisitor, TyContext};
|
|
use rustc_middle::mir::{Body, Location, Promoted};
|
|
use rustc_middle::ty::subst::SubstsRef;
|
|
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
|
|
|
|
/// Replaces all free regions appearing in the MIR with fresh
|
|
/// inference variables, returning the number of variables created.
|
|
#[instrument(skip(infcx, body, promoted), level = "debug")]
|
|
pub fn renumber_mir<'tcx>(
|
|
infcx: &InferCtxt<'_, 'tcx>,
|
|
body: &mut Body<'tcx>,
|
|
promoted: &mut IndexVec<Promoted, Body<'tcx>>,
|
|
) {
|
|
debug!(?body.arg_count);
|
|
|
|
let mut visitor = NllVisitor { infcx };
|
|
|
|
for body in promoted.iter_mut() {
|
|
visitor.visit_body(body);
|
|
}
|
|
|
|
visitor.visit_body(body);
|
|
}
|
|
|
|
/// Replaces all regions appearing in `value` with fresh inference
|
|
/// variables.
|
|
#[instrument(skip(infcx), level = "debug")]
|
|
pub fn renumber_regions<'tcx, T>(infcx: &InferCtxt<'_, 'tcx>, value: T) -> T
|
|
where
|
|
T: TypeFoldable<'tcx>,
|
|
{
|
|
infcx.tcx.fold_regions(value, &mut false, |_region, _depth| {
|
|
let origin = NllRegionVariableOrigin::Existential { from_forall: false };
|
|
infcx.next_nll_region_var(origin)
|
|
})
|
|
}
|
|
|
|
struct NllVisitor<'a, 'tcx> {
|
|
infcx: &'a InferCtxt<'a, 'tcx>,
|
|
}
|
|
|
|
impl<'a, 'tcx> NllVisitor<'a, 'tcx> {
|
|
fn renumber_regions<T>(&mut self, value: T) -> T
|
|
where
|
|
T: TypeFoldable<'tcx>,
|
|
{
|
|
renumber_regions(self.infcx, value)
|
|
}
|
|
}
|
|
|
|
impl<'a, 'tcx> MutVisitor<'tcx> for NllVisitor<'a, 'tcx> {
|
|
fn tcx(&self) -> TyCtxt<'tcx> {
|
|
self.infcx.tcx
|
|
}
|
|
|
|
#[instrument(skip(self), level = "debug")]
|
|
fn visit_ty(&mut self, ty: &mut Ty<'tcx>, ty_context: TyContext) {
|
|
*ty = self.renumber_regions(*ty);
|
|
|
|
debug!(?ty);
|
|
}
|
|
|
|
#[instrument(skip(self), level = "debug")]
|
|
fn visit_substs(&mut self, substs: &mut SubstsRef<'tcx>, location: Location) {
|
|
*substs = self.renumber_regions(*substs);
|
|
|
|
debug!(?substs);
|
|
}
|
|
|
|
#[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);
|
|
|
|
debug!(?region);
|
|
}
|
|
|
|
fn visit_const(&mut self, constant: &mut ty::Const<'tcx>, _location: Location) {
|
|
*constant = self.renumber_regions(*constant);
|
|
}
|
|
}
|