Skip to content

Commit 67df7cb

Browse files
committed
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.
1 parent 33c245b commit 67df7cb

File tree

2 files changed

+11
-37
lines changed

2 files changed

+11
-37
lines changed

Diff for: compiler/rustc_mir_dataflow/src/move_paths/abs_domain.rs

+9-35
Original file line numberDiff line numberDiff line change
@@ -4,60 +4,34 @@
44
//! field-deref on a local variable, `x.field`, has the same meaning
55
//! in both domains). Indexed projections are the exception: `a[x]`
66
//! needs to be treated as mapping to the same move path as `a[y]` as
7-
//! well as `a[13]`, etc.
7+
//! well as `a[13]`, etc. So we map these `x`/`y` values to `()`.
88
//!
99
//! (In theory, the analysis could be extended to work with sets of
1010
//! paths, so that `a[0]` and `a[13]` could be kept distinct, while
1111
//! `a[x]` would still overlap them both. But that is not this
1212
//! representation does today.)
1313
14-
use rustc_middle::mir::{Local, Operand, PlaceElem, ProjectionElem};
15-
use rustc_middle::ty::Ty;
16-
17-
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
18-
pub(crate) struct AbstractOperand;
19-
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
20-
pub(crate) struct AbstractType;
21-
pub(crate) type AbstractElem = ProjectionElem<AbstractOperand, AbstractType>;
14+
use rustc_middle::mir::{PlaceElem, ProjectionElem, ProjectionKind};
2215

2316
pub(crate) trait Lift {
24-
type Abstract;
25-
fn lift(&self) -> Self::Abstract;
26-
}
27-
impl<'tcx> Lift for Operand<'tcx> {
28-
type Abstract = AbstractOperand;
29-
fn lift(&self) -> Self::Abstract {
30-
AbstractOperand
31-
}
32-
}
33-
impl Lift for Local {
34-
type Abstract = AbstractOperand;
35-
fn lift(&self) -> Self::Abstract {
36-
AbstractOperand
37-
}
38-
}
39-
impl<'tcx> Lift for Ty<'tcx> {
40-
type Abstract = AbstractType;
41-
fn lift(&self) -> Self::Abstract {
42-
AbstractType
43-
}
17+
fn lift(&self) -> ProjectionKind;
4418
}
19+
4520
impl<'tcx> Lift for PlaceElem<'tcx> {
46-
type Abstract = AbstractElem;
47-
fn lift(&self) -> Self::Abstract {
21+
fn lift(&self) -> ProjectionKind {
4822
match *self {
4923
ProjectionElem::Deref => ProjectionElem::Deref,
50-
ProjectionElem::Field(f, ty) => ProjectionElem::Field(f, ty.lift()),
51-
ProjectionElem::OpaqueCast(ty) => ProjectionElem::OpaqueCast(ty.lift()),
52-
ProjectionElem::Index(ref i) => ProjectionElem::Index(i.lift()),
24+
ProjectionElem::Field(f, _ty) => ProjectionElem::Field(f, ()),
25+
ProjectionElem::OpaqueCast(_ty) => ProjectionElem::OpaqueCast(()),
26+
ProjectionElem::Index(_i) => ProjectionElem::Index(()),
5327
ProjectionElem::Subslice { from, to, from_end } => {
5428
ProjectionElem::Subslice { from, to, from_end }
5529
}
5630
ProjectionElem::ConstantIndex { offset, min_length, from_end } => {
5731
ProjectionElem::ConstantIndex { offset, min_length, from_end }
5832
}
5933
ProjectionElem::Downcast(a, u) => ProjectionElem::Downcast(a, u),
60-
ProjectionElem::Subtype(ty) => ProjectionElem::Subtype(ty.lift()),
34+
ProjectionElem::Subtype(_ty) => ProjectionElem::Subtype(()),
6135
}
6236
}
6337
}

Diff for: compiler/rustc_mir_dataflow/src/move_paths/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_middle::ty::{Ty, TyCtxt};
88
use rustc_span::Span;
99
use smallvec::SmallVec;
1010

11-
use self::abs_domain::{AbstractElem, Lift};
11+
use self::abs_domain::Lift;
1212
use crate::un_derefer::UnDerefer;
1313

1414
mod abs_domain;
@@ -300,7 +300,7 @@ pub struct MovePathLookup<'tcx> {
300300
/// subsequent search so that it is solely relative to that
301301
/// base-place). For the remaining lookup, we map the projection
302302
/// elem to the associated MovePathIndex.
303-
projections: FxHashMap<(MovePathIndex, AbstractElem), MovePathIndex>,
303+
projections: FxHashMap<(MovePathIndex, ProjectionKind), MovePathIndex>,
304304

305305
un_derefer: UnDerefer<'tcx>,
306306
}

0 commit comments

Comments
 (0)