Rollup merge of #134152 - nnethercote:simplify-rustc_mir_dataflow-abs_domain, r=compiler-errors
Simplify `rustc_mir_dataflow::abs_domain`. `rustc_mir_dataflow` has a typedef `AbstractElem` that is equal to `ProjectionElem<AbstractOperand, AbstractType>`. `AbstractOperand` and `AbstractType` are both unit types. There is also has a trait `Lift` to convert a `PlaceElem` to an `AbstractElem`. But `rustc_mir_middle` already has a typedef `ProjectionKind` that is equal to `ProjectionElem<(), ()>`, which is equivalent to `AbstractElem`. So this commit reuses `ProjectionKind` in `rustc_mir_dataflow`, removes `AbstractElem`, and simplifies the `Lift` trait. r? ``@pnkfelix``
This commit is contained in:
commit
d71576da0e
2 changed files with 11 additions and 37 deletions
|
@ -4,52 +4,26 @@
|
||||||
//! field-deref on a local variable, `x.field`, has the same meaning
|
//! field-deref on a local variable, `x.field`, has the same meaning
|
||||||
//! in both domains). Indexed projections are the exception: `a[x]`
|
//! in both domains). Indexed projections are the exception: `a[x]`
|
||||||
//! needs to be treated as mapping to the same move path as `a[y]` as
|
//! needs to be treated as mapping to the same move path as `a[y]` as
|
||||||
//! well as `a[13]`, etc.
|
//! well as `a[13]`, etc. So we map these `x`/`y` values to `()`.
|
||||||
//!
|
//!
|
||||||
//! (In theory, the analysis could be extended to work with sets of
|
//! (In theory, the analysis could be extended to work with sets of
|
||||||
//! paths, so that `a[0]` and `a[13]` could be kept distinct, while
|
//! paths, so that `a[0]` and `a[13]` could be kept distinct, while
|
||||||
//! `a[x]` would still overlap them both. But that is not this
|
//! `a[x]` would still overlap them both. But that is not this
|
||||||
//! representation does today.)
|
//! representation does today.)
|
||||||
|
|
||||||
use rustc_middle::mir::{Local, Operand, PlaceElem, ProjectionElem};
|
use rustc_middle::mir::{PlaceElem, ProjectionElem, ProjectionKind};
|
||||||
use rustc_middle::ty::Ty;
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
|
||||||
pub(crate) struct AbstractOperand;
|
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
|
||||||
pub(crate) struct AbstractType;
|
|
||||||
pub(crate) type AbstractElem = ProjectionElem<AbstractOperand, AbstractType>;
|
|
||||||
|
|
||||||
pub(crate) trait Lift {
|
pub(crate) trait Lift {
|
||||||
type Abstract;
|
fn lift(&self) -> ProjectionKind;
|
||||||
fn lift(&self) -> Self::Abstract;
|
|
||||||
}
|
|
||||||
impl<'tcx> Lift for Operand<'tcx> {
|
|
||||||
type Abstract = AbstractOperand;
|
|
||||||
fn lift(&self) -> Self::Abstract {
|
|
||||||
AbstractOperand
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Lift for Local {
|
|
||||||
type Abstract = AbstractOperand;
|
|
||||||
fn lift(&self) -> Self::Abstract {
|
|
||||||
AbstractOperand
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl<'tcx> Lift for Ty<'tcx> {
|
|
||||||
type Abstract = AbstractType;
|
|
||||||
fn lift(&self) -> Self::Abstract {
|
|
||||||
AbstractType
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Lift for PlaceElem<'tcx> {
|
impl<'tcx> Lift for PlaceElem<'tcx> {
|
||||||
type Abstract = AbstractElem;
|
fn lift(&self) -> ProjectionKind {
|
||||||
fn lift(&self) -> Self::Abstract {
|
|
||||||
match *self {
|
match *self {
|
||||||
ProjectionElem::Deref => ProjectionElem::Deref,
|
ProjectionElem::Deref => ProjectionElem::Deref,
|
||||||
ProjectionElem::Field(f, ty) => ProjectionElem::Field(f, ty.lift()),
|
ProjectionElem::Field(f, _ty) => ProjectionElem::Field(f, ()),
|
||||||
ProjectionElem::OpaqueCast(ty) => ProjectionElem::OpaqueCast(ty.lift()),
|
ProjectionElem::OpaqueCast(_ty) => ProjectionElem::OpaqueCast(()),
|
||||||
ProjectionElem::Index(ref i) => ProjectionElem::Index(i.lift()),
|
ProjectionElem::Index(_i) => ProjectionElem::Index(()),
|
||||||
ProjectionElem::Subslice { from, to, from_end } => {
|
ProjectionElem::Subslice { from, to, from_end } => {
|
||||||
ProjectionElem::Subslice { from, to, from_end }
|
ProjectionElem::Subslice { from, to, from_end }
|
||||||
}
|
}
|
||||||
|
@ -57,7 +31,7 @@ impl<'tcx> Lift for PlaceElem<'tcx> {
|
||||||
ProjectionElem::ConstantIndex { offset, min_length, from_end }
|
ProjectionElem::ConstantIndex { offset, min_length, from_end }
|
||||||
}
|
}
|
||||||
ProjectionElem::Downcast(a, u) => ProjectionElem::Downcast(a, u),
|
ProjectionElem::Downcast(a, u) => ProjectionElem::Downcast(a, u),
|
||||||
ProjectionElem::Subtype(ty) => ProjectionElem::Subtype(ty.lift()),
|
ProjectionElem::Subtype(_ty) => ProjectionElem::Subtype(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ use rustc_middle::ty::{Ty, TyCtxt};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
|
||||||
use self::abs_domain::{AbstractElem, Lift};
|
use self::abs_domain::Lift;
|
||||||
use crate::un_derefer::UnDerefer;
|
use crate::un_derefer::UnDerefer;
|
||||||
|
|
||||||
mod abs_domain;
|
mod abs_domain;
|
||||||
|
@ -300,7 +300,7 @@ pub struct MovePathLookup<'tcx> {
|
||||||
/// subsequent search so that it is solely relative to that
|
/// subsequent search so that it is solely relative to that
|
||||||
/// base-place). For the remaining lookup, we map the projection
|
/// base-place). For the remaining lookup, we map the projection
|
||||||
/// elem to the associated MovePathIndex.
|
/// elem to the associated MovePathIndex.
|
||||||
projections: FxHashMap<(MovePathIndex, AbstractElem), MovePathIndex>,
|
projections: FxHashMap<(MovePathIndex, ProjectionKind), MovePathIndex>,
|
||||||
|
|
||||||
un_derefer: UnDerefer<'tcx>,
|
un_derefer: UnDerefer<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue