Auto merge of #98206 - eggyal:align-to-chalk-folding-api, r=jackh726
Split TypeVisitable from TypeFoldable Impl of rust-lang/compiler-team#520 following MCP approval. r? `@ghost`
This commit is contained in:
@@ -100,7 +100,7 @@ impl From<InjectedExpressionId> for ExpressionOperandId {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable)]
|
||||
#[derive(Clone, PartialEq, TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
|
||||
pub enum CoverageKind {
|
||||
Counter {
|
||||
function_source_hash: u64,
|
||||
@@ -148,18 +148,8 @@ impl Debug for CoverageKind {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Clone,
|
||||
TyEncodable,
|
||||
TyDecodable,
|
||||
Hash,
|
||||
HashStable,
|
||||
TypeFoldable,
|
||||
PartialEq,
|
||||
Eq,
|
||||
PartialOrd,
|
||||
Ord
|
||||
)]
|
||||
#[derive(Clone, TyEncodable, TyDecodable, Hash, HashStable, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[derive(TypeFoldable, TypeVisitable)]
|
||||
pub struct CodeRegion {
|
||||
pub file_name: Symbol,
|
||||
pub start_line: u32,
|
||||
@@ -178,7 +168,8 @@ impl Debug for CodeRegion {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable)]
|
||||
#[derive(Copy, Clone, Debug, PartialEq, TyEncodable, TyDecodable, Hash, HashStable)]
|
||||
#[derive(TypeFoldable, TypeVisitable)]
|
||||
pub enum Op {
|
||||
Subtract,
|
||||
Add,
|
||||
|
||||
@@ -58,6 +58,6 @@ impl<CTX> HashStable<CTX> for GraphIsCyclicCache {
|
||||
}
|
||||
}
|
||||
|
||||
TrivialTypeFoldableAndLiftImpls! {
|
||||
TrivialTypeTraversalAndLiftImpls! {
|
||||
GraphIsCyclicCache,
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ impl From<ErrorGuaranteed> for ErrorHandled {
|
||||
}
|
||||
}
|
||||
|
||||
TrivialTypeFoldableAndLiftImpls! {
|
||||
TrivialTypeTraversalAndLiftImpls! {
|
||||
ErrorHandled,
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use super::{ErrorHandled, EvalToConstValueResult, EvalToValTreeResult, GlobalId};
|
||||
|
||||
use crate::mir;
|
||||
use crate::ty::fold::TypeFoldable;
|
||||
use crate::ty::subst::InternalSubsts;
|
||||
use crate::ty::visit::TypeVisitable;
|
||||
use crate::ty::{self, query::TyCtxtAt, query::TyCtxtEnsure, TyCtxt};
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
|
||||
@@ -8,9 +8,10 @@ use crate::mir::interpret::{
|
||||
use crate::mir::traversal::PostorderCache;
|
||||
use crate::mir::visit::MirVisitable;
|
||||
use crate::ty::codec::{TyDecoder, TyEncoder};
|
||||
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeSuperFoldable, TypeVisitor};
|
||||
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeSuperFoldable};
|
||||
use crate::ty::print::{FmtPrinter, Printer};
|
||||
use crate::ty::subst::{GenericArg, InternalSubsts, Subst, SubstsRef};
|
||||
use crate::ty::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor};
|
||||
use crate::ty::{self, List, Ty, TyCtxt};
|
||||
use crate::ty::{AdtDef, InstanceDef, ScalarInt, UserTypeAnnotationIndex};
|
||||
|
||||
@@ -68,6 +69,7 @@ pub use terminator::*;
|
||||
|
||||
pub mod traversal;
|
||||
mod type_foldable;
|
||||
mod type_visitable;
|
||||
pub mod visit;
|
||||
|
||||
pub use self::generic_graph::graphviz_safe_def_name;
|
||||
@@ -136,7 +138,7 @@ impl MirPhase {
|
||||
|
||||
/// Where a specific `mir::Body` comes from.
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
#[derive(HashStable, TyEncodable, TyDecodable, TypeFoldable)]
|
||||
#[derive(HashStable, TyEncodable, TyDecodable, TypeFoldable, TypeVisitable)]
|
||||
pub struct MirSource<'tcx> {
|
||||
pub instance: InstanceDef<'tcx>,
|
||||
|
||||
@@ -166,7 +168,7 @@ impl<'tcx> MirSource<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, TyEncodable, TyDecodable, Debug, HashStable, TypeFoldable)]
|
||||
#[derive(Clone, TyEncodable, TyDecodable, Debug, HashStable, TypeFoldable, TypeVisitable)]
|
||||
pub struct GeneratorInfo<'tcx> {
|
||||
/// The yield type of the function, if it is a generator.
|
||||
pub yield_ty: Option<Ty<'tcx>>,
|
||||
@@ -183,7 +185,7 @@ pub struct GeneratorInfo<'tcx> {
|
||||
}
|
||||
|
||||
/// The lowered representation of a single function.
|
||||
#[derive(Clone, TyEncodable, TyDecodable, Debug, HashStable, TypeFoldable)]
|
||||
#[derive(Clone, TyEncodable, TyDecodable, Debug, HashStable, TypeFoldable, TypeVisitable)]
|
||||
pub struct Body<'tcx> {
|
||||
/// A list of basic blocks. References to basic block use a newtyped index type [`BasicBlock`]
|
||||
/// that indexes into this vector.
|
||||
@@ -601,7 +603,7 @@ impl<'tcx> IndexMut<BasicBlock> for Body<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, HashStable, TypeFoldable)]
|
||||
#[derive(Copy, Clone, Debug, HashStable, TypeFoldable, TypeVisitable)]
|
||||
pub enum ClearCrossCrate<T> {
|
||||
Clear,
|
||||
Set(T),
|
||||
@@ -762,7 +764,7 @@ pub enum ImplicitSelfKind {
|
||||
None,
|
||||
}
|
||||
|
||||
TrivialTypeFoldableAndLiftImpls! { BindingForm<'tcx>, }
|
||||
TrivialTypeTraversalAndLiftImpls! { BindingForm<'tcx>, }
|
||||
|
||||
mod binding_form_impl {
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
@@ -807,7 +809,7 @@ pub struct BlockTailInfo {
|
||||
///
|
||||
/// This can be a binding declared by the user, a temporary inserted by the compiler, a function
|
||||
/// argument, or the return place.
|
||||
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable)]
|
||||
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
|
||||
pub struct LocalDecl<'tcx> {
|
||||
/// Whether this is a mutable binding (i.e., `let x` or `let mut x`).
|
||||
///
|
||||
@@ -942,7 +944,7 @@ static_assert_size!(LocalDecl<'_>, 56);
|
||||
///
|
||||
/// Not used for non-StaticRef temporaries, the return place, or anonymous
|
||||
/// function parameters.
|
||||
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable)]
|
||||
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
|
||||
pub enum LocalInfo<'tcx> {
|
||||
/// A user-defined local variable or function parameter
|
||||
///
|
||||
@@ -1081,7 +1083,7 @@ impl<'tcx> LocalDecl<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, TyEncodable, TyDecodable, HashStable, TypeFoldable)]
|
||||
#[derive(Clone, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
|
||||
pub enum VarDebugInfoContents<'tcx> {
|
||||
/// NOTE(eddyb) There's an unenforced invariant that this `Place` is
|
||||
/// based on a `Local`, not a `Static`, and contains no indexing.
|
||||
@@ -1099,7 +1101,7 @@ impl<'tcx> Debug for VarDebugInfoContents<'tcx> {
|
||||
}
|
||||
|
||||
/// Debug information pertaining to a user variable.
|
||||
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable)]
|
||||
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
|
||||
pub struct VarDebugInfo<'tcx> {
|
||||
pub name: Symbol,
|
||||
|
||||
@@ -1155,7 +1157,7 @@ impl BasicBlock {
|
||||
// BasicBlockData
|
||||
|
||||
/// See [`BasicBlock`] for documentation on what basic blocks are at a high level.
|
||||
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable)]
|
||||
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
|
||||
pub struct BasicBlockData<'tcx> {
|
||||
/// List of statements in this block.
|
||||
pub statements: Vec<Statement<'tcx>>,
|
||||
@@ -1392,7 +1394,7 @@ impl<O: fmt::Debug> fmt::Debug for AssertKind<O> {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Statements
|
||||
|
||||
#[derive(Clone, TyEncodable, TyDecodable, HashStable, TypeFoldable)]
|
||||
#[derive(Clone, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
|
||||
pub struct Statement<'tcx> {
|
||||
pub source_info: SourceInfo,
|
||||
pub kind: StatementKind<'tcx>,
|
||||
@@ -1758,7 +1760,7 @@ impl SourceScope {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable)]
|
||||
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
|
||||
pub struct SourceScopeData<'tcx> {
|
||||
pub span: Span,
|
||||
pub parent_scope: Option<SourceScope>,
|
||||
@@ -2524,7 +2526,7 @@ impl<'tcx> ConstantKind<'tcx> {
|
||||
/// The first will lead to the constraint `w: &'1 str` (for some
|
||||
/// inferred region `'1`). The second will lead to the constraint `w:
|
||||
/// &'static str`.
|
||||
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable)]
|
||||
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
|
||||
pub struct UserTypeProjections {
|
||||
pub contents: Vec<(UserTypeProjection, Span)>,
|
||||
}
|
||||
@@ -2641,7 +2643,7 @@ impl UserTypeProjection {
|
||||
}
|
||||
}
|
||||
|
||||
TrivialTypeFoldableAndLiftImpls! { ProjectionKind, }
|
||||
TrivialTypeTraversalAndLiftImpls! { ProjectionKind, }
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for UserTypeProjection {
|
||||
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
|
||||
@@ -2650,7 +2652,9 @@ impl<'tcx> TypeFoldable<'tcx> for UserTypeProjection {
|
||||
projs: self.projs.try_fold_with(folder)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeVisitable<'tcx> for UserTypeProjection {
|
||||
fn visit_with<Vs: TypeVisitor<'tcx>>(&self, visitor: &mut Vs) -> ControlFlow<Vs::BreakTy> {
|
||||
self.base.visit_with(visitor)
|
||||
// Note: there's nothing in `self.proj` to visit.
|
||||
|
||||
@@ -73,6 +73,6 @@ impl<CTX> HashStable<CTX> for PredecessorCache {
|
||||
}
|
||||
}
|
||||
|
||||
TrivialTypeFoldableAndLiftImpls! {
|
||||
TrivialTypeTraversalAndLiftImpls! {
|
||||
PredecessorCache,
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ rustc_index::newtype_index! {
|
||||
}
|
||||
|
||||
/// The layout of generator state.
|
||||
#[derive(Clone, TyEncodable, TyDecodable, HashStable, TypeFoldable)]
|
||||
#[derive(Clone, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
|
||||
pub struct GeneratorLayout<'tcx> {
|
||||
/// The type of every local stored inside the generator.
|
||||
pub field_tys: IndexVec<GeneratorSavedLocal, Ty<'tcx>>,
|
||||
|
||||
@@ -73,6 +73,6 @@ impl<CTX> HashStable<CTX> for SwitchSourceCache {
|
||||
}
|
||||
}
|
||||
|
||||
TrivialTypeFoldableAndLiftImpls! {
|
||||
TrivialTypeTraversalAndLiftImpls! {
|
||||
SwitchSourceCache,
|
||||
}
|
||||
|
||||
@@ -179,7 +179,8 @@ pub enum BorrowKind {
|
||||
/// Not all of these are allowed at every [`MirPhase`]. Check the documentation there to see which
|
||||
/// ones you do not have to worry about. The MIR validator will generally enforce such restrictions,
|
||||
/// causing an ICE if they are violated.
|
||||
#[derive(Clone, Debug, PartialEq, TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable)]
|
||||
#[derive(Clone, Debug, PartialEq, TyEncodable, TyDecodable, Hash, HashStable)]
|
||||
#[derive(TypeFoldable, TypeVisitable)]
|
||||
pub enum StatementKind<'tcx> {
|
||||
/// Assign statements roughly correspond to an assignment in Rust proper (`x = ...`) except
|
||||
/// without the possibility of dropping the previous value (that must be done separately, if at
|
||||
@@ -376,13 +377,15 @@ pub enum FakeReadCause {
|
||||
ForIndex,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable)]
|
||||
#[derive(Clone, Debug, PartialEq, TyEncodable, TyDecodable, Hash, HashStable)]
|
||||
#[derive(TypeFoldable, TypeVisitable)]
|
||||
pub struct Coverage {
|
||||
pub kind: CoverageKind,
|
||||
pub code_region: Option<CodeRegion>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable)]
|
||||
#[derive(Clone, Debug, PartialEq, TyEncodable, TyDecodable, Hash, HashStable)]
|
||||
#[derive(TypeFoldable, TypeVisitable)]
|
||||
pub struct CopyNonOverlapping<'tcx> {
|
||||
pub src: Operand<'tcx>,
|
||||
pub dst: Operand<'tcx>,
|
||||
@@ -672,7 +675,8 @@ pub enum AssertKind<O> {
|
||||
ResumedAfterPanic(GeneratorKind),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable)]
|
||||
#[derive(Clone, Debug, PartialEq, TyEncodable, TyDecodable, Hash, HashStable)]
|
||||
#[derive(TypeFoldable, TypeVisitable)]
|
||||
pub enum InlineAsmOperand<'tcx> {
|
||||
In {
|
||||
reg: InlineAsmRegOrRegClass,
|
||||
|
||||
@@ -9,7 +9,7 @@ use crate::ty::{self, Ty, TyCtxt};
|
||||
use rustc_hir as hir;
|
||||
use rustc_target::abi::VariantIdx;
|
||||
|
||||
#[derive(Copy, Clone, Debug, TypeFoldable)]
|
||||
#[derive(Copy, Clone, Debug, TypeFoldable, TypeVisitable)]
|
||||
pub struct PlaceTy<'tcx> {
|
||||
pub ty: Ty<'tcx>,
|
||||
/// Downcast to a particular variant of an enum or a generator, if included.
|
||||
|
||||
@@ -384,6 +384,6 @@ impl<CTX> HashStable<CTX> for PostorderCache {
|
||||
}
|
||||
}
|
||||
|
||||
TrivialTypeFoldableAndLiftImpls! {
|
||||
TrivialTypeTraversalAndLiftImpls! {
|
||||
PostorderCache,
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use super::*;
|
||||
use crate::ty;
|
||||
use rustc_data_structures::functor::IdFunctor;
|
||||
|
||||
TrivialTypeFoldableAndLiftImpls! {
|
||||
TrivialTypeTraversalAndLiftImpls! {
|
||||
BlockTailInfo,
|
||||
MirPhase,
|
||||
SourceInfo,
|
||||
@@ -89,65 +89,12 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
|
||||
};
|
||||
Ok(Terminator { source_info: self.source_info, kind })
|
||||
}
|
||||
|
||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
||||
use crate::mir::TerminatorKind::*;
|
||||
|
||||
match self.kind {
|
||||
SwitchInt { ref discr, switch_ty, .. } => {
|
||||
discr.visit_with(visitor)?;
|
||||
switch_ty.visit_with(visitor)
|
||||
}
|
||||
Drop { ref place, .. } => place.visit_with(visitor),
|
||||
DropAndReplace { ref place, ref value, .. } => {
|
||||
place.visit_with(visitor)?;
|
||||
value.visit_with(visitor)
|
||||
}
|
||||
Yield { ref value, .. } => value.visit_with(visitor),
|
||||
Call { ref func, ref args, ref destination, .. } => {
|
||||
destination.visit_with(visitor)?;
|
||||
func.visit_with(visitor)?;
|
||||
args.visit_with(visitor)
|
||||
}
|
||||
Assert { ref cond, ref msg, .. } => {
|
||||
cond.visit_with(visitor)?;
|
||||
use AssertKind::*;
|
||||
match msg {
|
||||
BoundsCheck { ref len, ref index } => {
|
||||
len.visit_with(visitor)?;
|
||||
index.visit_with(visitor)
|
||||
}
|
||||
Overflow(_, l, r) => {
|
||||
l.visit_with(visitor)?;
|
||||
r.visit_with(visitor)
|
||||
}
|
||||
OverflowNeg(op) | DivisionByZero(op) | RemainderByZero(op) => {
|
||||
op.visit_with(visitor)
|
||||
}
|
||||
ResumedAfterReturn(_) | ResumedAfterPanic(_) => ControlFlow::CONTINUE,
|
||||
}
|
||||
}
|
||||
InlineAsm { ref operands, .. } => operands.visit_with(visitor),
|
||||
Goto { .. }
|
||||
| Resume
|
||||
| Abort
|
||||
| Return
|
||||
| GeneratorDrop
|
||||
| Unreachable
|
||||
| FalseEdge { .. }
|
||||
| FalseUnwind { .. } => ControlFlow::CONTINUE,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for GeneratorKind {
|
||||
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, _: &mut F) -> Result<Self, F::Error> {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<V::BreakTy> {
|
||||
ControlFlow::CONTINUE
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for Place<'tcx> {
|
||||
@@ -157,21 +104,12 @@ impl<'tcx> TypeFoldable<'tcx> for Place<'tcx> {
|
||||
projection: self.projection.try_fold_with(folder)?,
|
||||
})
|
||||
}
|
||||
|
||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
||||
self.local.visit_with(visitor)?;
|
||||
self.projection.visit_with(visitor)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<PlaceElem<'tcx>> {
|
||||
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
|
||||
ty::util::fold_list(self, folder, |tcx, v| tcx.intern_place_elems(v))
|
||||
}
|
||||
|
||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
||||
self.iter().try_for_each(|t| t.visit_with(visitor))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
|
||||
@@ -224,55 +162,6 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
||||
use crate::mir::Rvalue::*;
|
||||
match *self {
|
||||
Use(ref op) => op.visit_with(visitor),
|
||||
Repeat(ref op, _) => op.visit_with(visitor),
|
||||
ThreadLocalRef(did) => did.visit_with(visitor),
|
||||
Ref(region, _, ref place) => {
|
||||
region.visit_with(visitor)?;
|
||||
place.visit_with(visitor)
|
||||
}
|
||||
AddressOf(_, ref place) => place.visit_with(visitor),
|
||||
Len(ref place) => place.visit_with(visitor),
|
||||
Cast(_, ref op, ty) => {
|
||||
op.visit_with(visitor)?;
|
||||
ty.visit_with(visitor)
|
||||
}
|
||||
BinaryOp(_, box (ref rhs, ref lhs)) | CheckedBinaryOp(_, box (ref rhs, ref lhs)) => {
|
||||
rhs.visit_with(visitor)?;
|
||||
lhs.visit_with(visitor)
|
||||
}
|
||||
UnaryOp(_, ref val) => val.visit_with(visitor),
|
||||
Discriminant(ref place) => place.visit_with(visitor),
|
||||
NullaryOp(_, ty) => ty.visit_with(visitor),
|
||||
Aggregate(ref kind, ref fields) => {
|
||||
match **kind {
|
||||
AggregateKind::Array(ty) => {
|
||||
ty.visit_with(visitor)?;
|
||||
}
|
||||
AggregateKind::Tuple => {}
|
||||
AggregateKind::Adt(_, _, substs, user_ty, _) => {
|
||||
substs.visit_with(visitor)?;
|
||||
user_ty.visit_with(visitor)?;
|
||||
}
|
||||
AggregateKind::Closure(_, substs) => {
|
||||
substs.visit_with(visitor)?;
|
||||
}
|
||||
AggregateKind::Generator(_, substs, _) => {
|
||||
substs.visit_with(visitor)?;
|
||||
}
|
||||
}
|
||||
fields.visit_with(visitor)
|
||||
}
|
||||
ShallowInitBox(ref op, ty) => {
|
||||
op.visit_with(visitor)?;
|
||||
ty.visit_with(visitor)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for Operand<'tcx> {
|
||||
@@ -283,13 +172,6 @@ impl<'tcx> TypeFoldable<'tcx> for Operand<'tcx> {
|
||||
Operand::Constant(c) => Operand::Constant(c.try_fold_with(folder)?),
|
||||
})
|
||||
}
|
||||
|
||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
||||
match *self {
|
||||
Operand::Copy(ref place) | Operand::Move(ref place) => place.visit_with(visitor),
|
||||
Operand::Constant(ref c) => c.visit_with(visitor),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for PlaceElem<'tcx> {
|
||||
@@ -307,43 +189,24 @@ impl<'tcx> TypeFoldable<'tcx> for PlaceElem<'tcx> {
|
||||
Subslice { from, to, from_end } => Subslice { from, to, from_end },
|
||||
})
|
||||
}
|
||||
|
||||
fn visit_with<Vs: TypeVisitor<'tcx>>(&self, visitor: &mut Vs) -> ControlFlow<Vs::BreakTy> {
|
||||
use crate::mir::ProjectionElem::*;
|
||||
|
||||
match self {
|
||||
Field(_, ty) => ty.visit_with(visitor),
|
||||
Index(v) => v.visit_with(visitor),
|
||||
_ => ControlFlow::CONTINUE,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for Field {
|
||||
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, _: &mut F) -> Result<Self, F::Error> {
|
||||
Ok(self)
|
||||
}
|
||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<V::BreakTy> {
|
||||
ControlFlow::CONTINUE
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for GeneratorSavedLocal {
|
||||
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, _: &mut F) -> Result<Self, F::Error> {
|
||||
Ok(self)
|
||||
}
|
||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<V::BreakTy> {
|
||||
ControlFlow::CONTINUE
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx, R: Idx, C: Idx> TypeFoldable<'tcx> for BitMatrix<R, C> {
|
||||
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, _: &mut F) -> Result<Self, F::Error> {
|
||||
Ok(self)
|
||||
}
|
||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<V::BreakTy> {
|
||||
ControlFlow::CONTINUE
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for Constant<'tcx> {
|
||||
@@ -354,10 +217,6 @@ impl<'tcx> TypeFoldable<'tcx> for Constant<'tcx> {
|
||||
literal: self.literal.try_fold_with(folder)?,
|
||||
})
|
||||
}
|
||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
||||
self.literal.visit_with(visitor)?;
|
||||
self.user_ty.visit_with(visitor)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ConstantKind<'tcx> {
|
||||
@@ -365,10 +224,6 @@ impl<'tcx> TypeFoldable<'tcx> for ConstantKind<'tcx> {
|
||||
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
|
||||
folder.try_fold_mir_const(self)
|
||||
}
|
||||
|
||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
||||
visitor.visit_mir_const(*self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeSuperFoldable<'tcx> for ConstantKind<'tcx> {
|
||||
@@ -381,11 +236,4 @@ impl<'tcx> TypeSuperFoldable<'tcx> for ConstantKind<'tcx> {
|
||||
ConstantKind::Val(v, t) => Ok(ConstantKind::Val(v, t.try_fold_with(folder)?)),
|
||||
}
|
||||
}
|
||||
|
||||
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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
186
compiler/rustc_middle/src/mir/type_visitable.rs
Normal file
186
compiler/rustc_middle/src/mir/type_visitable.rs
Normal file
@@ -0,0 +1,186 @@
|
||||
//! `TypeVisitable` implementations for MIR types
|
||||
|
||||
use super::*;
|
||||
use crate::ty;
|
||||
|
||||
impl<'tcx> TypeVisitable<'tcx> for Terminator<'tcx> {
|
||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
||||
use crate::mir::TerminatorKind::*;
|
||||
|
||||
match self.kind {
|
||||
SwitchInt { ref discr, switch_ty, .. } => {
|
||||
discr.visit_with(visitor)?;
|
||||
switch_ty.visit_with(visitor)
|
||||
}
|
||||
Drop { ref place, .. } => place.visit_with(visitor),
|
||||
DropAndReplace { ref place, ref value, .. } => {
|
||||
place.visit_with(visitor)?;
|
||||
value.visit_with(visitor)
|
||||
}
|
||||
Yield { ref value, .. } => value.visit_with(visitor),
|
||||
Call { ref func, ref args, ref destination, .. } => {
|
||||
destination.visit_with(visitor)?;
|
||||
func.visit_with(visitor)?;
|
||||
args.visit_with(visitor)
|
||||
}
|
||||
Assert { ref cond, ref msg, .. } => {
|
||||
cond.visit_with(visitor)?;
|
||||
use AssertKind::*;
|
||||
match msg {
|
||||
BoundsCheck { ref len, ref index } => {
|
||||
len.visit_with(visitor)?;
|
||||
index.visit_with(visitor)
|
||||
}
|
||||
Overflow(_, l, r) => {
|
||||
l.visit_with(visitor)?;
|
||||
r.visit_with(visitor)
|
||||
}
|
||||
OverflowNeg(op) | DivisionByZero(op) | RemainderByZero(op) => {
|
||||
op.visit_with(visitor)
|
||||
}
|
||||
ResumedAfterReturn(_) | ResumedAfterPanic(_) => ControlFlow::CONTINUE,
|
||||
}
|
||||
}
|
||||
InlineAsm { ref operands, .. } => operands.visit_with(visitor),
|
||||
Goto { .. }
|
||||
| Resume
|
||||
| Abort
|
||||
| Return
|
||||
| GeneratorDrop
|
||||
| Unreachable
|
||||
| FalseEdge { .. }
|
||||
| FalseUnwind { .. } => ControlFlow::CONTINUE,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeVisitable<'tcx> for GeneratorKind {
|
||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<V::BreakTy> {
|
||||
ControlFlow::CONTINUE
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeVisitable<'tcx> for Place<'tcx> {
|
||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
||||
self.local.visit_with(visitor)?;
|
||||
self.projection.visit_with(visitor)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeVisitable<'tcx> for &'tcx ty::List<PlaceElem<'tcx>> {
|
||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
||||
self.iter().try_for_each(|t| t.visit_with(visitor))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeVisitable<'tcx> for Rvalue<'tcx> {
|
||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
||||
use crate::mir::Rvalue::*;
|
||||
match *self {
|
||||
Use(ref op) => op.visit_with(visitor),
|
||||
Repeat(ref op, _) => op.visit_with(visitor),
|
||||
ThreadLocalRef(did) => did.visit_with(visitor),
|
||||
Ref(region, _, ref place) => {
|
||||
region.visit_with(visitor)?;
|
||||
place.visit_with(visitor)
|
||||
}
|
||||
AddressOf(_, ref place) => place.visit_with(visitor),
|
||||
Len(ref place) => place.visit_with(visitor),
|
||||
Cast(_, ref op, ty) => {
|
||||
op.visit_with(visitor)?;
|
||||
ty.visit_with(visitor)
|
||||
}
|
||||
BinaryOp(_, box (ref rhs, ref lhs)) | CheckedBinaryOp(_, box (ref rhs, ref lhs)) => {
|
||||
rhs.visit_with(visitor)?;
|
||||
lhs.visit_with(visitor)
|
||||
}
|
||||
UnaryOp(_, ref val) => val.visit_with(visitor),
|
||||
Discriminant(ref place) => place.visit_with(visitor),
|
||||
NullaryOp(_, ty) => ty.visit_with(visitor),
|
||||
Aggregate(ref kind, ref fields) => {
|
||||
match **kind {
|
||||
AggregateKind::Array(ty) => {
|
||||
ty.visit_with(visitor)?;
|
||||
}
|
||||
AggregateKind::Tuple => {}
|
||||
AggregateKind::Adt(_, _, substs, user_ty, _) => {
|
||||
substs.visit_with(visitor)?;
|
||||
user_ty.visit_with(visitor)?;
|
||||
}
|
||||
AggregateKind::Closure(_, substs) => {
|
||||
substs.visit_with(visitor)?;
|
||||
}
|
||||
AggregateKind::Generator(_, substs, _) => {
|
||||
substs.visit_with(visitor)?;
|
||||
}
|
||||
}
|
||||
fields.visit_with(visitor)
|
||||
}
|
||||
ShallowInitBox(ref op, ty) => {
|
||||
op.visit_with(visitor)?;
|
||||
ty.visit_with(visitor)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeVisitable<'tcx> for Operand<'tcx> {
|
||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
||||
match *self {
|
||||
Operand::Copy(ref place) | Operand::Move(ref place) => place.visit_with(visitor),
|
||||
Operand::Constant(ref c) => c.visit_with(visitor),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeVisitable<'tcx> for PlaceElem<'tcx> {
|
||||
fn visit_with<Vs: TypeVisitor<'tcx>>(&self, visitor: &mut Vs) -> ControlFlow<Vs::BreakTy> {
|
||||
use crate::mir::ProjectionElem::*;
|
||||
|
||||
match self {
|
||||
Field(_, ty) => ty.visit_with(visitor),
|
||||
Index(v) => v.visit_with(visitor),
|
||||
_ => ControlFlow::CONTINUE,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeVisitable<'tcx> for Field {
|
||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<V::BreakTy> {
|
||||
ControlFlow::CONTINUE
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeVisitable<'tcx> for GeneratorSavedLocal {
|
||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<V::BreakTy> {
|
||||
ControlFlow::CONTINUE
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx, R: Idx, C: Idx> TypeVisitable<'tcx> for BitMatrix<R, C> {
|
||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<V::BreakTy> {
|
||||
ControlFlow::CONTINUE
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeVisitable<'tcx> for Constant<'tcx> {
|
||||
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
||||
self.literal.visit_with(visitor)?;
|
||||
self.user_ty.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),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user