Skip to content

Commit e268ddf

Browse files
committed
erase types in the move-path abstract domain
Leaving types unerased would lead to 2 types with a different "name" getting different move-paths, which would cause major brokenness (see e.g. rust-lang#42903). This does not fix any *known* issue, but is required if we want to use abs_domain with non-erased regions (because the same can easily have different names). cc @RalfJung.
1 parent 0565653 commit e268ddf

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

src/librustc/ich/impls_mir.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,11 @@ impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for mir::L
258258
}
259259
}
260260

261-
impl<'a, 'gcx, 'tcx, B, V> HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
262-
for mir::Projection<'tcx, B, V>
261+
impl<'a, 'gcx, 'tcx, B, V, T> HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
262+
for mir::Projection<'tcx, B, V, T>
263263
where B: HashStable<StableHashingContext<'a, 'gcx, 'tcx>>,
264-
V: HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
264+
V: HashStable<StableHashingContext<'a, 'gcx, 'tcx>>,
265+
T: HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
265266
{
266267
fn hash_stable<W: StableHasherResult>(&self,
267268
hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
@@ -276,17 +277,18 @@ for mir::Projection<'tcx, B, V>
276277
}
277278
}
278279

279-
impl<'a, 'gcx, 'tcx, V> HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
280-
for mir::ProjectionElem<'tcx, V>
281-
where V: HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
280+
impl<'a, 'gcx, 'tcx, V, T> HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
281+
for mir::ProjectionElem<'tcx, V, T>
282+
where V: HashStable<StableHashingContext<'a, 'gcx, 'tcx>>,
283+
T: HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
282284
{
283285
fn hash_stable<W: StableHasherResult>(&self,
284286
hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
285287
hasher: &mut StableHasher<W>) {
286288
mem::discriminant(self).hash_stable(hcx, hasher);
287289
match *self {
288290
mir::ProjectionElem::Deref => {}
289-
mir::ProjectionElem::Field(field, ty) => {
291+
mir::ProjectionElem::Field(field, ref ty) => {
290292
field.hash_stable(hcx, hasher);
291293
ty.hash_stable(hcx, hasher);
292294
}

src/librustc/mir/mod.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -887,15 +887,15 @@ impl_stable_hash_for!(struct Static<'tcx> {
887887
/// shared between `Constant` and `Lvalue`. See the aliases
888888
/// `LvalueProjection` etc below.
889889
#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
890-
pub struct Projection<'tcx, B, V> {
890+
pub struct Projection<'tcx, B, V, T> {
891891
pub base: B,
892-
pub elem: ProjectionElem<'tcx, V>,
892+
pub elem: ProjectionElem<'tcx, V, T>,
893893
}
894894

895895
#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
896-
pub enum ProjectionElem<'tcx, V> {
896+
pub enum ProjectionElem<'tcx, V, T> {
897897
Deref,
898-
Field(Field, Ty<'tcx>),
898+
Field(Field, T),
899899
Index(V),
900900

901901
/// These indices are generated by slice patterns. Easiest to explain
@@ -932,11 +932,11 @@ pub enum ProjectionElem<'tcx, V> {
932932

933933
/// Alias for projections as they appear in lvalues, where the base is an lvalue
934934
/// and the index is an operand.
935-
pub type LvalueProjection<'tcx> = Projection<'tcx, Lvalue<'tcx>, Operand<'tcx>>;
935+
pub type LvalueProjection<'tcx> = Projection<'tcx, Lvalue<'tcx>, Operand<'tcx>, Ty<'tcx>>;
936936

937937
/// Alias for projections as they appear in lvalues, where the base is an lvalue
938938
/// and the index is an operand.
939-
pub type LvalueElem<'tcx> = ProjectionElem<'tcx, Operand<'tcx>>;
939+
pub type LvalueElem<'tcx> = ProjectionElem<'tcx, Operand<'tcx>, Ty<'tcx>>;
940940

941941
newtype_index!(Field, "field");
942942

@@ -1720,16 +1720,16 @@ impl<'tcx> TypeFoldable<'tcx> for Operand<'tcx> {
17201720
}
17211721
}
17221722

1723-
impl<'tcx, B, V> TypeFoldable<'tcx> for Projection<'tcx, B, V>
1724-
where B: TypeFoldable<'tcx>, V: TypeFoldable<'tcx>
1723+
impl<'tcx, B, V, T> TypeFoldable<'tcx> for Projection<'tcx, B, V, T>
1724+
where B: TypeFoldable<'tcx>, V: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>
17251725
{
17261726
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
17271727
use mir::ProjectionElem::*;
17281728

17291729
let base = self.base.fold_with(folder);
17301730
let elem = match self.elem {
17311731
Deref => Deref,
1732-
Field(f, ty) => Field(f, ty.fold_with(folder)),
1732+
Field(f, ref ty) => Field(f, ty.fold_with(folder)),
17331733
Index(ref v) => Index(v.fold_with(folder)),
17341734
ref elem => elem.clone()
17351735
};
@@ -1745,7 +1745,7 @@ impl<'tcx, B, V> TypeFoldable<'tcx> for Projection<'tcx, B, V>
17451745

17461746
self.base.visit_with(visitor) ||
17471747
match self.elem {
1748-
Field(_, ty) => ty.visit_with(visitor),
1748+
Field(_, ref ty) => ty.visit_with(visitor),
17491749
Index(ref v) => v.visit_with(visitor),
17501750
_ => false
17511751
}

src/librustc_mir/dataflow/move_paths/abs_domain.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@
2323
2424
use rustc::mir::LvalueElem;
2525
use rustc::mir::{Operand, ProjectionElem};
26+
use rustc::ty::Ty;
2627

2728
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
2829
pub struct AbstractOperand;
30+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
31+
pub struct AbstractType;
2932
pub type AbstractElem<'tcx> =
30-
ProjectionElem<'tcx, AbstractOperand>;
33+
ProjectionElem<'tcx, AbstractOperand, AbstractType>;
3134

3235
pub trait Lift {
3336
type Abstract;
@@ -37,14 +40,18 @@ impl<'tcx> Lift for Operand<'tcx> {
3740
type Abstract = AbstractOperand;
3841
fn lift(&self) -> Self::Abstract { AbstractOperand }
3942
}
43+
impl<'tcx> Lift for Ty<'tcx> {
44+
type Abstract = AbstractType;
45+
fn lift(&self) -> Self::Abstract { AbstractType }
46+
}
4047
impl<'tcx> Lift for LvalueElem<'tcx> {
4148
type Abstract = AbstractElem<'tcx>;
4249
fn lift(&self) -> Self::Abstract {
4350
match *self {
4451
ProjectionElem::Deref =>
4552
ProjectionElem::Deref,
4653
ProjectionElem::Field(ref f, ty) =>
47-
ProjectionElem::Field(f.clone(), ty.clone()),
54+
ProjectionElem::Field(f.clone(), ty.lift()),
4855
ProjectionElem::Index(ref i) =>
4956
ProjectionElem::Index(i.lift()),
5057
ProjectionElem::Subslice {from, to} =>

0 commit comments

Comments
 (0)