Auto merge of #102355 - lcnr:bye-bye-type-traversal, r=oli-obk
remove type traversal for mir constants r? `@oli-obk` cc `@b-naber`
This commit is contained in:
commit
a9d1cafa87
15 changed files with 37 additions and 251 deletions
|
@ -1,8 +1,8 @@
|
||||||
use rustc_index::vec::IndexVec;
|
use rustc_index::vec::IndexVec;
|
||||||
use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin};
|
use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin};
|
||||||
use rustc_middle::mir::visit::{MutVisitor, TyContext};
|
use rustc_middle::mir::visit::{MutVisitor, TyContext};
|
||||||
|
use rustc_middle::mir::Constant;
|
||||||
use rustc_middle::mir::{Body, Location, Promoted};
|
use rustc_middle::mir::{Body, Location, Promoted};
|
||||||
use rustc_middle::mir::{Constant, ConstantKind};
|
|
||||||
use rustc_middle::ty::subst::SubstsRef;
|
use rustc_middle::ty::subst::SubstsRef;
|
||||||
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
|
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
|
||||||
|
|
||||||
|
@ -38,21 +38,6 @@ where
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(valtrees): This function is necessary because `fold_regions`
|
|
||||||
// panics for mir constants in the visitor.
|
|
||||||
//
|
|
||||||
// Once `visit_mir_constant` is removed we can also remove this function
|
|
||||||
// and just use `renumber_regions`.
|
|
||||||
fn renumber_regions_in_mir_constant<'tcx>(
|
|
||||||
infcx: &InferCtxt<'tcx>,
|
|
||||||
value: ConstantKind<'tcx>,
|
|
||||||
) -> ConstantKind<'tcx> {
|
|
||||||
infcx.tcx.super_fold_regions(value, |_region, _depth| {
|
|
||||||
let origin = NllRegionVariableOrigin::Existential { from_forall: false };
|
|
||||||
infcx.next_nll_region_var(origin)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
struct NllVisitor<'a, 'tcx> {
|
struct NllVisitor<'a, 'tcx> {
|
||||||
infcx: &'a InferCtxt<'tcx>,
|
infcx: &'a InferCtxt<'tcx>,
|
||||||
}
|
}
|
||||||
|
@ -64,13 +49,6 @@ impl<'a, 'tcx> NllVisitor<'a, 'tcx> {
|
||||||
{
|
{
|
||||||
renumber_regions(self.infcx, value)
|
renumber_regions(self.infcx, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn renumber_regions_in_mir_constant(
|
|
||||||
&mut self,
|
|
||||||
value: ConstantKind<'tcx>,
|
|
||||||
) -> ConstantKind<'tcx> {
|
|
||||||
renumber_regions_in_mir_constant(self.infcx, value)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> MutVisitor<'tcx> for NllVisitor<'a, 'tcx> {
|
impl<'a, 'tcx> MutVisitor<'tcx> for NllVisitor<'a, 'tcx> {
|
||||||
|
@ -103,7 +81,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NllVisitor<'a, 'tcx> {
|
||||||
#[instrument(skip(self), level = "debug")]
|
#[instrument(skip(self), level = "debug")]
|
||||||
fn visit_constant(&mut self, constant: &mut Constant<'tcx>, _location: Location) {
|
fn visit_constant(&mut self, constant: &mut Constant<'tcx>, _location: Location) {
|
||||||
let literal = constant.literal;
|
let literal = constant.literal;
|
||||||
constant.literal = self.renumber_regions_in_mir_constant(literal);
|
constant.literal = self.renumber_regions(literal);
|
||||||
debug!("constant: {:#?}", constant);
|
debug!("constant: {:#?}", constant);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use super::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
use super::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||||
use super::{FixupError, FixupResult, InferCtxt, Span};
|
use super::{FixupError, FixupResult, InferCtxt, Span};
|
||||||
use rustc_middle::mir;
|
|
||||||
use rustc_middle::ty::fold::{FallibleTypeFolder, TypeFolder, TypeSuperFoldable};
|
use rustc_middle::ty::fold::{FallibleTypeFolder, TypeFolder, TypeSuperFoldable};
|
||||||
use rustc_middle::ty::visit::{TypeSuperVisitable, TypeVisitor};
|
use rustc_middle::ty::visit::{TypeSuperVisitable, TypeVisitor};
|
||||||
use rustc_middle::ty::{self, Const, InferConst, Ty, TyCtxt, TypeFoldable, TypeVisitable};
|
use rustc_middle::ty::{self, Const, InferConst, Ty, TyCtxt, TypeFoldable, TypeVisitable};
|
||||||
|
@ -48,10 +47,6 @@ impl<'a, 'tcx> TypeFolder<'tcx> for OpportunisticVarResolver<'a, 'tcx> {
|
||||||
ct.super_fold_with(self)
|
ct.super_fold_with(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold_mir_const(&mut self, constant: mir::ConstantKind<'tcx>) -> mir::ConstantKind<'tcx> {
|
|
||||||
constant.super_fold_with(self)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The opportunistic region resolver opportunistically resolves regions
|
/// The opportunistic region resolver opportunistically resolves regions
|
||||||
|
|
|
@ -54,13 +54,22 @@ macro_rules! TrivialTypeTraversalImpls {
|
||||||
impl<$tcx> $crate::ty::fold::TypeFoldable<$tcx> for $ty {
|
impl<$tcx> $crate::ty::fold::TypeFoldable<$tcx> for $ty {
|
||||||
fn try_fold_with<F: $crate::ty::fold::FallibleTypeFolder<$tcx>>(
|
fn try_fold_with<F: $crate::ty::fold::FallibleTypeFolder<$tcx>>(
|
||||||
self,
|
self,
|
||||||
_: &mut F
|
_: &mut F,
|
||||||
) -> ::std::result::Result<$ty, F::Error> {
|
) -> ::std::result::Result<Self, F::Error> {
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn fold_with<F: $crate::ty::fold::TypeFolder<$tcx>>(
|
||||||
|
self,
|
||||||
|
_: &mut F,
|
||||||
|
) -> Self {
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<$tcx> $crate::ty::visit::TypeVisitable<$tcx> for $ty {
|
impl<$tcx> $crate::ty::visit::TypeVisitable<$tcx> for $ty {
|
||||||
|
#[inline]
|
||||||
fn visit_with<F: $crate::ty::visit::TypeVisitor<$tcx>>(
|
fn visit_with<F: $crate::ty::visit::TypeVisitor<$tcx>>(
|
||||||
&self,
|
&self,
|
||||||
_: &mut F)
|
_: &mut F)
|
||||||
|
|
|
@ -7,9 +7,9 @@ use crate::mir::interpret::{
|
||||||
};
|
};
|
||||||
use crate::mir::visit::MirVisitable;
|
use crate::mir::visit::MirVisitable;
|
||||||
use crate::ty::codec::{TyDecoder, TyEncoder};
|
use crate::ty::codec::{TyDecoder, TyEncoder};
|
||||||
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeSuperFoldable};
|
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable};
|
||||||
use crate::ty::print::{FmtPrinter, Printer};
|
use crate::ty::print::{FmtPrinter, Printer};
|
||||||
use crate::ty::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor};
|
use crate::ty::visit::{TypeVisitable, TypeVisitor};
|
||||||
use crate::ty::{self, List, Ty, TyCtxt};
|
use crate::ty::{self, List, Ty, TyCtxt};
|
||||||
use crate::ty::{AdtDef, InstanceDef, ScalarInt, UserTypeAnnotationIndex};
|
use crate::ty::{AdtDef, InstanceDef, ScalarInt, UserTypeAnnotationIndex};
|
||||||
use crate::ty::{GenericArg, InternalSubsts, SubstsRef};
|
use crate::ty::{GenericArg, InternalSubsts, SubstsRef};
|
||||||
|
@ -2056,7 +2056,7 @@ pub struct Constant<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable, Debug)]
|
#[derive(Clone, Copy, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable, Debug)]
|
||||||
#[derive(Lift)]
|
#[derive(Lift, TypeFoldable, TypeVisitable)]
|
||||||
pub enum ConstantKind<'tcx> {
|
pub enum ConstantKind<'tcx> {
|
||||||
/// This constant came from the type system
|
/// This constant came from the type system
|
||||||
Ty(ty::Const<'tcx>),
|
Ty(ty::Const<'tcx>),
|
||||||
|
@ -2448,7 +2448,7 @@ impl<'tcx> ConstantKind<'tcx> {
|
||||||
|
|
||||||
/// An unevaluated (potentially generic) constant used in MIR.
|
/// An unevaluated (potentially generic) constant used in MIR.
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable, Lift)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable, Lift)]
|
||||||
#[derive(Hash, HashStable)]
|
#[derive(Hash, HashStable, TypeFoldable, TypeVisitable)]
|
||||||
pub struct UnevaluatedConst<'tcx> {
|
pub struct UnevaluatedConst<'tcx> {
|
||||||
pub def: ty::WithOptConstParam<DefId>,
|
pub def: ty::WithOptConstParam<DefId>,
|
||||||
pub substs: SubstsRef<'tcx>,
|
pub substs: SubstsRef<'tcx>,
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
use rustc_ast::InlineAsmTemplatePiece;
|
use rustc_ast::InlineAsmTemplatePiece;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::mir;
|
|
||||||
use crate::ty;
|
use crate::ty;
|
||||||
|
|
||||||
TrivialTypeTraversalAndLiftImpls! {
|
TrivialTypeTraversalAndLiftImpls! {
|
||||||
|
@ -27,6 +26,12 @@ TrivialTypeTraversalAndLiftImpls! {
|
||||||
GeneratorSavedLocal,
|
GeneratorSavedLocal,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TrivialTypeTraversalImpls! {
|
||||||
|
for <'tcx> {
|
||||||
|
ConstValue<'tcx>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'tcx> TypeFoldable<'tcx> for &'tcx [InlineAsmTemplatePiece] {
|
impl<'tcx> TypeFoldable<'tcx> for &'tcx [InlineAsmTemplatePiece] {
|
||||||
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, _folder: &mut F) -> Result<Self, F::Error> {
|
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, _folder: &mut F) -> Result<Self, F::Error> {
|
||||||
Ok(self)
|
Ok(self)
|
||||||
|
@ -50,44 +55,3 @@ impl<'tcx, R: Idx, C: Idx> TypeFoldable<'tcx> for BitMatrix<R, C> {
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TypeFoldable<'tcx> for mir::UnevaluatedConst<'tcx> {
|
|
||||||
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
|
|
||||||
folder.try_fold_mir_unevaluated(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx> TypeSuperFoldable<'tcx> for mir::UnevaluatedConst<'tcx> {
|
|
||||||
fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
|
|
||||||
self,
|
|
||||||
folder: &mut F,
|
|
||||||
) -> Result<Self, F::Error> {
|
|
||||||
Ok(mir::UnevaluatedConst {
|
|
||||||
def: self.def,
|
|
||||||
substs: self.substs.try_fold_with(folder)?,
|
|
||||||
promoted: self.promoted,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx> TypeFoldable<'tcx> for ConstantKind<'tcx> {
|
|
||||||
#[inline(always)]
|
|
||||||
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
|
|
||||||
folder.try_fold_mir_const(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx> TypeSuperFoldable<'tcx> for ConstantKind<'tcx> {
|
|
||||||
fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
|
|
||||||
self,
|
|
||||||
folder: &mut F,
|
|
||||||
) -> Result<Self, F::Error> {
|
|
||||||
match self {
|
|
||||||
ConstantKind::Ty(c) => Ok(ConstantKind::Ty(c.try_fold_with(folder)?)),
|
|
||||||
ConstantKind::Val(v, t) => Ok(ConstantKind::Val(v, t.try_fold_with(folder)?)),
|
|
||||||
ConstantKind::Unevaluated(uv, t) => {
|
|
||||||
Ok(ConstantKind::Unevaluated(uv.try_fold_with(folder)?, t.try_fold_with(folder)?))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,41 +1,9 @@
|
||||||
//! `TypeVisitable` implementations for MIR types
|
//! `TypeVisitable` implementations for MIR types
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::mir;
|
|
||||||
|
|
||||||
impl<'tcx, R: Idx, C: Idx> TypeVisitable<'tcx> for BitMatrix<R, C> {
|
impl<'tcx, R: Idx, C: Idx> TypeVisitable<'tcx> for BitMatrix<R, C> {
|
||||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<V::BreakTy> {
|
fn visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<V::BreakTy> {
|
||||||
ControlFlow::CONTINUE
|
ControlFlow::CONTINUE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TypeVisitable<'tcx> for mir::UnevaluatedConst<'tcx> {
|
|
||||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
|
||||||
visitor.visit_mir_unevaluated(*self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx> TypeSuperVisitable<'tcx> for mir::UnevaluatedConst<'tcx> {
|
|
||||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
|
||||||
self.substs.visit_with(visitor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx> TypeVisitable<'tcx> for ConstantKind<'tcx> {
|
|
||||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
|
||||||
visitor.visit_mir_const(*self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx> TypeSuperVisitable<'tcx> for ConstantKind<'tcx> {
|
|
||||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
|
||||||
match *self {
|
|
||||||
ConstantKind::Ty(c) => c.visit_with(visitor),
|
|
||||||
ConstantKind::Val(_, t) => t.visit_with(visitor),
|
|
||||||
ConstantKind::Unevaluated(uv, t) => {
|
|
||||||
uv.visit_with(visitor)?;
|
|
||||||
t.visit_with(visitor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1871,14 +1871,6 @@ rustc_queries! {
|
||||||
remap_env_constness
|
remap_env_constness
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Do not call this query directly: invoke `try_normalize_erasing_regions` instead.
|
|
||||||
query try_normalize_mir_const_after_erasing_regions(
|
|
||||||
goal: ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
|
|
||||||
) -> Result<mir::ConstantKind<'tcx>, NoSolution> {
|
|
||||||
desc { "normalizing `{}`", goal.value }
|
|
||||||
remap_env_constness
|
|
||||||
}
|
|
||||||
|
|
||||||
query implied_outlives_bounds(
|
query implied_outlives_bounds(
|
||||||
goal: CanonicalTyGoal<'tcx>
|
goal: CanonicalTyGoal<'tcx>
|
||||||
) -> Result<
|
) -> Result<
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use crate::mir;
|
|
||||||
use crate::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
|
use crate::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
|
||||||
use crate::ty::visit::TypeVisitable;
|
use crate::ty::visit::TypeVisitable;
|
||||||
use crate::ty::{self, Ty, TyCtxt, TypeFlags};
|
use crate::ty::{self, Ty, TyCtxt, TypeFlags};
|
||||||
|
@ -67,8 +66,4 @@ impl<'tcx> TypeFolder<'tcx> for RegionEraserVisitor<'tcx> {
|
||||||
_ => self.tcx.lifetimes.re_erased,
|
_ => self.tcx.lifetimes.re_erased,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold_mir_const(&mut self, c: mir::ConstantKind<'tcx>) -> mir::ConstantKind<'tcx> {
|
|
||||||
c.super_fold_with(self)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,6 @@
|
||||||
//! - ty.super_fold_with(folder)
|
//! - ty.super_fold_with(folder)
|
||||||
//! - u.fold_with(folder)
|
//! - u.fold_with(folder)
|
||||||
//! ```
|
//! ```
|
||||||
use crate::mir;
|
|
||||||
use crate::ty::{self, Binder, BoundTy, Ty, TyCtxt, TypeVisitable};
|
use crate::ty::{self, Binder, BoundTy, Ty, TyCtxt, TypeVisitable};
|
||||||
use rustc_data_structures::fx::FxIndexMap;
|
use rustc_data_structures::fx::FxIndexMap;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
|
@ -134,20 +133,9 @@ pub trait TypeFolder<'tcx>: FallibleTypeFolder<'tcx, Error = !> {
|
||||||
uv.super_fold_with(self)
|
uv.super_fold_with(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold_mir_unevaluated(
|
|
||||||
&mut self,
|
|
||||||
uv: mir::UnevaluatedConst<'tcx>,
|
|
||||||
) -> mir::UnevaluatedConst<'tcx> {
|
|
||||||
uv.super_fold_with(self)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn fold_predicate(&mut self, p: ty::Predicate<'tcx>) -> ty::Predicate<'tcx> {
|
fn fold_predicate(&mut self, p: ty::Predicate<'tcx>) -> ty::Predicate<'tcx> {
|
||||||
p.super_fold_with(self)
|
p.super_fold_with(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold_mir_const(&mut self, c: mir::ConstantKind<'tcx>) -> mir::ConstantKind<'tcx> {
|
|
||||||
bug!("most type folders should not be folding MIR datastructures: {:?}", c)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This trait is implemented for every folding traversal. There is a fold
|
/// This trait is implemented for every folding traversal. There is a fold
|
||||||
|
@ -188,26 +176,12 @@ pub trait FallibleTypeFolder<'tcx>: Sized {
|
||||||
c.try_super_fold_with(self)
|
c.try_super_fold_with(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_fold_mir_unevaluated(
|
|
||||||
&mut self,
|
|
||||||
c: mir::UnevaluatedConst<'tcx>,
|
|
||||||
) -> Result<mir::UnevaluatedConst<'tcx>, Self::Error> {
|
|
||||||
c.try_super_fold_with(self)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn try_fold_predicate(
|
fn try_fold_predicate(
|
||||||
&mut self,
|
&mut self,
|
||||||
p: ty::Predicate<'tcx>,
|
p: ty::Predicate<'tcx>,
|
||||||
) -> Result<ty::Predicate<'tcx>, Self::Error> {
|
) -> Result<ty::Predicate<'tcx>, Self::Error> {
|
||||||
p.try_super_fold_with(self)
|
p.try_super_fold_with(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_fold_mir_const(
|
|
||||||
&mut self,
|
|
||||||
c: mir::ConstantKind<'tcx>,
|
|
||||||
) -> Result<mir::ConstantKind<'tcx>, Self::Error> {
|
|
||||||
bug!("most type folders should not be folding MIR datastructures: {:?}", c)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This blanket implementation of the fallible trait for infallible folders
|
// This blanket implementation of the fallible trait for infallible folders
|
||||||
|
@ -248,23 +222,9 @@ where
|
||||||
Ok(self.fold_ty_unevaluated(c))
|
Ok(self.fold_ty_unevaluated(c))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_fold_mir_unevaluated(
|
|
||||||
&mut self,
|
|
||||||
c: mir::UnevaluatedConst<'tcx>,
|
|
||||||
) -> Result<mir::UnevaluatedConst<'tcx>, !> {
|
|
||||||
Ok(self.fold_mir_unevaluated(c))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn try_fold_predicate(&mut self, p: ty::Predicate<'tcx>) -> Result<ty::Predicate<'tcx>, !> {
|
fn try_fold_predicate(&mut self, p: ty::Predicate<'tcx>) -> Result<ty::Predicate<'tcx>, !> {
|
||||||
Ok(self.fold_predicate(p))
|
Ok(self.fold_predicate(p))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_fold_mir_const(
|
|
||||||
&mut self,
|
|
||||||
c: mir::ConstantKind<'tcx>,
|
|
||||||
) -> Result<mir::ConstantKind<'tcx>, !> {
|
|
||||||
Ok(self.fold_mir_const(c))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -214,15 +214,6 @@ impl<'tcx> TypeFolder<'tcx> for NormalizeAfterErasingRegionsFolder<'tcx> {
|
||||||
fn fold_const(&mut self, c: ty::Const<'tcx>) -> ty::Const<'tcx> {
|
fn fold_const(&mut self, c: ty::Const<'tcx>) -> ty::Const<'tcx> {
|
||||||
self.normalize_generic_arg_after_erasing_regions(c.into()).expect_const()
|
self.normalize_generic_arg_after_erasing_regions(c.into()).expect_const()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn fold_mir_const(&mut self, c: mir::ConstantKind<'tcx>) -> mir::ConstantKind<'tcx> {
|
|
||||||
// FIXME: This *probably* needs canonicalization too!
|
|
||||||
let arg = self.param_env.and(c);
|
|
||||||
self.tcx
|
|
||||||
.try_normalize_mir_const_after_erasing_regions(arg)
|
|
||||||
.unwrap_or_else(|_| bug!("failed to normalize {:?}", c))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TryNormalizeAfterErasingRegionsFolder<'tcx> {
|
struct TryNormalizeAfterErasingRegionsFolder<'tcx> {
|
||||||
|
@ -267,16 +258,4 @@ impl<'tcx> FallibleTypeFolder<'tcx> for TryNormalizeAfterErasingRegionsFolder<'t
|
||||||
Err(_) => Err(NormalizationError::Const(c)),
|
Err(_) => Err(NormalizationError::Const(c)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_fold_mir_const(
|
|
||||||
&mut self,
|
|
||||||
c: mir::ConstantKind<'tcx>,
|
|
||||||
) -> Result<mir::ConstantKind<'tcx>, Self::Error> {
|
|
||||||
// FIXME: This *probably* needs canonicalization too!
|
|
||||||
let arg = self.param_env.and(c);
|
|
||||||
match self.tcx.try_normalize_mir_const_after_erasing_regions(arg) {
|
|
||||||
Ok(c) => Ok(c),
|
|
||||||
Err(_) => Err(NormalizationError::ConstantKind(c)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
// Type substitutions.
|
// Type substitutions.
|
||||||
|
|
||||||
use crate::mir;
|
|
||||||
use crate::ty::codec::{TyDecoder, TyEncoder};
|
use crate::ty::codec::{TyDecoder, TyEncoder};
|
||||||
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder, TypeSuperFoldable};
|
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder, TypeSuperFoldable};
|
||||||
use crate::ty::sty::{ClosureSubsts, GeneratorSubsts, InlineConstSubsts};
|
use crate::ty::sty::{ClosureSubsts, GeneratorSubsts, InlineConstSubsts};
|
||||||
|
@ -662,11 +661,6 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> {
|
||||||
c.super_fold_with(self)
|
c.super_fold_with(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn fold_mir_const(&mut self, c: mir::ConstantKind<'tcx>) -> mir::ConstantKind<'tcx> {
|
|
||||||
c.super_fold_with(self)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> SubstFolder<'a, 'tcx> {
|
impl<'a, 'tcx> SubstFolder<'a, 'tcx> {
|
||||||
|
|
|
@ -38,7 +38,6 @@
|
||||||
//! - ty.super_visit_with(visitor)
|
//! - ty.super_visit_with(visitor)
|
||||||
//! - u.visit_with(visitor)
|
//! - u.visit_with(visitor)
|
||||||
//! ```
|
//! ```
|
||||||
use crate::mir;
|
|
||||||
use crate::ty::{self, flags::FlagComputation, Binder, Ty, TyCtxt, TypeFlags};
|
use crate::ty::{self, flags::FlagComputation, Binder, Ty, TyCtxt, TypeFlags};
|
||||||
use rustc_errors::ErrorGuaranteed;
|
use rustc_errors::ErrorGuaranteed;
|
||||||
|
|
||||||
|
@ -205,20 +204,9 @@ pub trait TypeVisitor<'tcx>: Sized {
|
||||||
uv.super_visit_with(self)
|
uv.super_visit_with(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_mir_unevaluated(
|
|
||||||
&mut self,
|
|
||||||
uv: mir::UnevaluatedConst<'tcx>,
|
|
||||||
) -> ControlFlow<Self::BreakTy> {
|
|
||||||
uv.super_visit_with(self)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn visit_predicate(&mut self, p: ty::Predicate<'tcx>) -> ControlFlow<Self::BreakTy> {
|
fn visit_predicate(&mut self, p: ty::Predicate<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||||
p.super_visit_with(self)
|
p.super_visit_with(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_mir_const(&mut self, c: mir::ConstantKind<'tcx>) -> ControlFlow<Self::BreakTy> {
|
|
||||||
c.super_visit_with(self)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -619,19 +607,6 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_mir_unevaluated(
|
|
||||||
&mut self,
|
|
||||||
uv: mir::UnevaluatedConst<'tcx>,
|
|
||||||
) -> ControlFlow<Self::BreakTy> {
|
|
||||||
let flags = FlagComputation::for_unevaluated_const(uv.shrink());
|
|
||||||
trace!(r.flags=?flags);
|
|
||||||
if flags.intersects(self.flags) {
|
|
||||||
ControlFlow::Break(FoundFlags)
|
|
||||||
} else {
|
|
||||||
ControlFlow::CONTINUE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[instrument(level = "trace", ret)]
|
#[instrument(level = "trace", ret)]
|
||||||
fn visit_predicate(&mut self, predicate: ty::Predicate<'tcx>) -> ControlFlow<Self::BreakTy> {
|
fn visit_predicate(&mut self, predicate: ty::Predicate<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||||
|
|
|
@ -276,9 +276,21 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
|
||||||
ConstantKind::Ty(c) => {
|
ConstantKind::Ty(c) => {
|
||||||
c.visit_with(self);
|
c.visit_with(self);
|
||||||
}
|
}
|
||||||
ConstantKind::Val(_, ty) | ConstantKind::Unevaluated(_, ty) => {
|
ConstantKind::Unevaluated(mir::UnevaluatedConst { def, substs: _, promoted }, ty) => {
|
||||||
Visitor::visit_ty(self, ty, TyContext::Location(location))
|
// Avoid considering `T` unused when constants are of the form:
|
||||||
|
// `<Self as Foo<T>>::foo::promoted[p]`
|
||||||
|
if let Some(p) = promoted {
|
||||||
|
if self.def_id == def.did && !self.tcx.generics_of(def.did).has_self {
|
||||||
|
// If there is a promoted, don't look at the substs - since it will always contain
|
||||||
|
// the generic parameters, instead, traverse the promoted MIR.
|
||||||
|
let promoted = self.tcx.promoted_mir(def.did);
|
||||||
|
self.visit_body(&promoted[p]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Visitor::visit_ty(self, ty, TyContext::Location(location));
|
||||||
}
|
}
|
||||||
|
ConstantKind::Val(_, ty) => Visitor::visit_ty(self, ty, TyContext::Location(location)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,30 +322,6 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_mir_const(&mut self, constant: ConstantKind<'tcx>) -> ControlFlow<Self::BreakTy> {
|
|
||||||
if !constant.has_non_region_param() {
|
|
||||||
return ControlFlow::CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
match constant {
|
|
||||||
ConstantKind::Ty(ct) => ct.visit_with(self),
|
|
||||||
ConstantKind::Unevaluated(mir::UnevaluatedConst { def, substs: _, promoted: Some(p) }, _)
|
|
||||||
// Avoid considering `T` unused when constants are of the form:
|
|
||||||
// `<Self as Foo<T>>::foo::promoted[p]`
|
|
||||||
if self.def_id == def.did && !self.tcx.generics_of(def.did).has_self =>
|
|
||||||
{
|
|
||||||
// If there is a promoted, don't look at the substs - since it will always contain
|
|
||||||
// the generic parameters, instead, traverse the promoted MIR.
|
|
||||||
let promoted = self.tcx.promoted_mir(def.did);
|
|
||||||
self.visit_body(&promoted[p]);
|
|
||||||
ControlFlow::CONTINUE
|
|
||||||
}
|
|
||||||
ConstantKind::Val(..) | ConstantKind::Unevaluated(..) => {
|
|
||||||
constant.super_visit_with(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[instrument(level = "debug", skip(self))]
|
#[instrument(level = "debug", skip(self))]
|
||||||
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||||
if !ty.has_non_region_param() {
|
if !ty.has_non_region_param() {
|
||||||
|
|
|
@ -11,7 +11,6 @@ use crate::traits::{Obligation, ObligationCause, PredicateObligation, Reveal};
|
||||||
use rustc_data_structures::sso::SsoHashMap;
|
use rustc_data_structures::sso::SsoHashMap;
|
||||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||||
use rustc_infer::traits::Normalized;
|
use rustc_infer::traits::Normalized;
|
||||||
use rustc_middle::mir;
|
|
||||||
use rustc_middle::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeSuperFoldable};
|
use rustc_middle::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeSuperFoldable};
|
||||||
use rustc_middle::ty::visit::{TypeSuperVisitable, TypeVisitable};
|
use rustc_middle::ty::visit::{TypeSuperVisitable, TypeVisitable};
|
||||||
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitor};
|
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitor};
|
||||||
|
@ -347,13 +346,6 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_fold_mir_const(
|
|
||||||
&mut self,
|
|
||||||
constant: mir::ConstantKind<'tcx>,
|
|
||||||
) -> Result<mir::ConstantKind<'tcx>, Self::Error> {
|
|
||||||
constant.try_super_fold_with(self)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn try_fold_predicate(
|
fn try_fold_predicate(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|
|
@ -18,9 +18,6 @@ pub(crate) fn provide(p: &mut Providers) {
|
||||||
|
|
||||||
try_normalize_after_erasing_regions(tcx, goal)
|
try_normalize_after_erasing_regions(tcx, goal)
|
||||||
},
|
},
|
||||||
try_normalize_mir_const_after_erasing_regions: |tcx, goal| {
|
|
||||||
try_normalize_after_erasing_regions(tcx, goal)
|
|
||||||
},
|
|
||||||
..*p
|
..*p
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue