Skip to content

Commit ac29ca7

Browse files
committed
Replace adt_def with name in mir::ProjectionElem::Downcast
1 parent f694222 commit ac29ca7

File tree

15 files changed

+124
-98
lines changed

15 files changed

+124
-98
lines changed

src/librustc/mir/mod.rs

+39-30
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use std::slice;
2525
use std::vec::IntoIter;
2626
use std::{iter, mem, option, u32};
2727
use syntax::ast::{self, Name};
28-
use syntax::symbol::InternedString;
28+
use syntax::symbol::{InternedString, Symbol};
2929
use syntax_pos::{Span, DUMMY_SP};
3030
use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
3131
use crate::ty::subst::{Subst, SubstsRef};
@@ -772,7 +772,7 @@ pub struct LocalDecl<'tcx> {
772772
/// e.g., via `let x: T`, then we carry that type here. The MIR
773773
/// borrow checker needs this information since it can affect
774774
/// region inference.
775-
pub user_ty: UserTypeProjections<'tcx>,
775+
pub user_ty: UserTypeProjections,
776776

777777
/// Name of the local, used in debuginfo and pretty-printing.
778778
///
@@ -1805,7 +1805,7 @@ pub enum StatementKind<'tcx> {
18051805
/// - `Contravariant` -- requires that `T_y :> T`
18061806
/// - `Invariant` -- requires that `T_y == T`
18071807
/// - `Bivariant` -- no effect
1808-
AscribeUserType(Place<'tcx>, ty::Variance, Box<UserTypeProjection<'tcx>>),
1808+
AscribeUserType(Place<'tcx>, ty::Variance, Box<UserTypeProjection>),
18091809

18101810
/// No-op. Useful for deleting instructions without affecting statement indices.
18111811
Nop,
@@ -1939,14 +1939,14 @@ impl_stable_hash_for!(struct Static<'tcx> {
19391939
/// `PlaceProjection` etc below.
19401940
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord,
19411941
Hash, RustcEncodable, RustcDecodable, HashStable)]
1942-
pub struct Projection<'tcx, B, V, T> {
1942+
pub struct Projection<B, V, T> {
19431943
pub base: B,
1944-
pub elem: ProjectionElem<'tcx, V, T>,
1944+
pub elem: ProjectionElem<V, T>,
19451945
}
19461946

19471947
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord,
19481948
Hash, RustcEncodable, RustcDecodable, HashStable)]
1949-
pub enum ProjectionElem<'tcx, V, T> {
1949+
pub enum ProjectionElem<V, T> {
19501950
Deref,
19511951
Field(Field, T),
19521952
Index(V),
@@ -1980,16 +1980,18 @@ pub enum ProjectionElem<'tcx, V, T> {
19801980
/// "Downcast" to a variant of an ADT. Currently, we only introduce
19811981
/// this for ADTs with more than one variant. It may be better to
19821982
/// just introduce it always, or always for enums.
1983-
Downcast(&'tcx AdtDef, VariantIdx),
1983+
///
1984+
/// The included Symbol is the name of the variant, used for printing MIR.
1985+
Downcast(Option<Symbol>, VariantIdx),
19841986
}
19851987

19861988
/// Alias for projections as they appear in places, where the base is a place
19871989
/// and the index is a local.
1988-
pub type PlaceProjection<'tcx> = Projection<'tcx, Place<'tcx>, Local, Ty<'tcx>>;
1990+
pub type PlaceProjection<'tcx> = Projection<Place<'tcx>, Local, Ty<'tcx>>;
19891991

19901992
/// Alias for projections as they appear in places, where the base is a place
19911993
/// and the index is a local.
1992-
pub type PlaceElem<'tcx> = ProjectionElem<'tcx, Local, Ty<'tcx>>;
1994+
pub type PlaceElem<'tcx> = ProjectionElem<Local, Ty<'tcx>>;
19931995

19941996
// at least on 64 bit systems, `PlaceElem` should not be larger than two pointers
19951997
static_assert!(PROJECTION_ELEM_IS_2_PTRS_LARGE:
@@ -1998,7 +2000,7 @@ static_assert!(PROJECTION_ELEM_IS_2_PTRS_LARGE:
19982000

19992001
/// Alias for projections as they appear in `UserTypeProjection`, where we
20002002
/// need neither the `V` parameter for `Index` nor the `T` for `Field`.
2001-
pub type ProjectionKind<'tcx> = ProjectionElem<'tcx, (), ()>;
2003+
pub type ProjectionKind = ProjectionElem<(), ()>;
20022004

20032005
newtype_index! {
20042006
pub struct Field {
@@ -2019,7 +2021,9 @@ impl<'tcx> Place<'tcx> {
20192021
}
20202022

20212023
pub fn downcast(self, adt_def: &'tcx AdtDef, variant_index: VariantIdx) -> Place<'tcx> {
2022-
self.elem(ProjectionElem::Downcast(adt_def, variant_index))
2024+
self.elem(ProjectionElem::Downcast(
2025+
Some(adt_def.variants[variant_index].ident.name),
2026+
variant_index))
20232027
}
20242028

20252029
pub fn index(self, index: Local) -> Place<'tcx> {
@@ -2080,8 +2084,11 @@ impl<'tcx> Debug for Place<'tcx> {
20802084
)
20812085
},
20822086
Projection(ref data) => match data.elem {
2083-
ProjectionElem::Downcast(ref adt_def, index) => {
2084-
write!(fmt, "({:?} as {})", data.base, adt_def.variants[index].ident)
2087+
ProjectionElem::Downcast(Some(name), _index) => {
2088+
write!(fmt, "({:?} as {})", data.base, name)
2089+
}
2090+
ProjectionElem::Downcast(None, index) => {
2091+
write!(fmt, "({:?} as variant#{:?})", data.base, index)
20852092
}
20862093
ProjectionElem::Deref => write!(fmt, "(*{:?})", data.base),
20872094
ProjectionElem::Field(field, ty) => {
@@ -2542,36 +2549,36 @@ pub struct Constant<'tcx> {
25422549
/// inferred region `'1`). The second will lead to the constraint `w:
25432550
/// &'static str`.
25442551
#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, HashStable)]
2545-
pub struct UserTypeProjections<'tcx> {
2546-
pub(crate) contents: Vec<(UserTypeProjection<'tcx>, Span)>,
2552+
pub struct UserTypeProjections {
2553+
pub(crate) contents: Vec<(UserTypeProjection, Span)>,
25472554
}
25482555

25492556
BraceStructTypeFoldableImpl! {
2550-
impl<'tcx> TypeFoldable<'tcx> for UserTypeProjections<'tcx> {
2557+
impl<'tcx> TypeFoldable<'tcx> for UserTypeProjections {
25512558
contents
25522559
}
25532560
}
25542561

2555-
impl<'tcx> UserTypeProjections<'tcx> {
2562+
impl<'tcx> UserTypeProjections {
25562563
pub fn none() -> Self {
25572564
UserTypeProjections { contents: vec![] }
25582565
}
25592566

2560-
pub fn from_projections(projs: impl Iterator<Item=(UserTypeProjection<'tcx>, Span)>) -> Self {
2567+
pub fn from_projections(projs: impl Iterator<Item=(UserTypeProjection, Span)>) -> Self {
25612568
UserTypeProjections { contents: projs.collect() }
25622569
}
25632570

2564-
pub fn projections_and_spans(&self) -> impl Iterator<Item=&(UserTypeProjection<'tcx>, Span)> {
2571+
pub fn projections_and_spans(&self) -> impl Iterator<Item=&(UserTypeProjection, Span)> {
25652572
self.contents.iter()
25662573
}
25672574

2568-
pub fn projections(&self) -> impl Iterator<Item=&UserTypeProjection<'tcx>> {
2575+
pub fn projections(&self) -> impl Iterator<Item=&UserTypeProjection> {
25692576
self.contents.iter().map(|&(ref user_type, _span)| user_type)
25702577
}
25712578

25722579
pub fn push_projection(
25732580
mut self,
2574-
user_ty: &UserTypeProjection<'tcx>,
2581+
user_ty: &UserTypeProjection,
25752582
span: Span,
25762583
) -> Self {
25772584
self.contents.push((user_ty.clone(), span));
@@ -2580,7 +2587,7 @@ impl<'tcx> UserTypeProjections<'tcx> {
25802587

25812588
fn map_projections(
25822589
mut self,
2583-
mut f: impl FnMut(UserTypeProjection<'tcx>) -> UserTypeProjection<'tcx>
2590+
mut f: impl FnMut(UserTypeProjection) -> UserTypeProjection
25842591
) -> Self {
25852592
self.contents = self.contents.drain(..).map(|(proj, span)| (f(proj), span)).collect();
25862593
self
@@ -2628,14 +2635,14 @@ impl<'tcx> UserTypeProjections<'tcx> {
26282635
/// `field[0]` (aka `.0`), indicating that the type of `s` is
26292636
/// determined by finding the type of the `.0` field from `T`.
26302637
#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, HashStable)]
2631-
pub struct UserTypeProjection<'tcx> {
2638+
pub struct UserTypeProjection {
26322639
pub base: UserTypeAnnotationIndex,
2633-
pub projs: Vec<ProjectionElem<'tcx, (), ()>>,
2640+
pub projs: Vec<ProjectionElem<(), ()>>,
26342641
}
26352642

2636-
impl<'tcx> Copy for ProjectionKind<'tcx> { }
2643+
impl Copy for ProjectionKind { }
26372644

2638-
impl<'tcx> UserTypeProjection<'tcx> {
2645+
impl UserTypeProjection {
26392646
pub(crate) fn index(mut self) -> Self {
26402647
self.projs.push(ProjectionElem::Index(()));
26412648
self
@@ -2662,15 +2669,17 @@ impl<'tcx> UserTypeProjection<'tcx> {
26622669
variant_index: VariantIdx,
26632670
field: Field,
26642671
) -> Self {
2665-
self.projs.push(ProjectionElem::Downcast(adt_def, variant_index));
2672+
self.projs.push(ProjectionElem::Downcast(
2673+
Some(adt_def.variants[variant_index].ident.name),
2674+
variant_index));
26662675
self.projs.push(ProjectionElem::Field(field, ()));
26672676
self
26682677
}
26692678
}
26702679

2671-
CloneTypeFoldableAndLiftImpls! { ProjectionKind<'tcx>, }
2680+
CloneTypeFoldableAndLiftImpls! { ProjectionKind, }
26722681

2673-
impl<'tcx> TypeFoldable<'tcx> for UserTypeProjection<'tcx> {
2682+
impl<'tcx> TypeFoldable<'tcx> for UserTypeProjection {
26742683
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
26752684
use crate::mir::ProjectionElem::*;
26762685

@@ -3428,7 +3437,7 @@ impl<'tcx> TypeFoldable<'tcx> for Operand<'tcx> {
34283437
}
34293438
}
34303439

3431-
impl<'tcx, B, V, T> TypeFoldable<'tcx> for Projection<'tcx, B, V, T>
3440+
impl<'tcx, B, V, T> TypeFoldable<'tcx> for Projection<B, V, T>
34323441
where
34333442
B: TypeFoldable<'tcx>,
34343443
V: TypeFoldable<'tcx>,

src/librustc/mir/tcx.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl<'a, 'gcx, 'tcx> PlaceTy<'tcx> {
8686
pub fn projection_ty_core<V, T>(
8787
self,
8888
tcx: TyCtxt<'a, 'gcx, 'tcx>,
89-
elem: &ProjectionElem<'tcx, V, T>,
89+
elem: &ProjectionElem<V, T>,
9090
mut handle_field: impl FnMut(&Self, &Field, &T) -> Ty<'tcx>)
9191
-> PlaceTy<'tcx>
9292
where
@@ -124,12 +124,11 @@ impl<'a, 'gcx, 'tcx> PlaceTy<'tcx> {
124124
}
125125
}
126126
}
127-
ProjectionElem::Downcast(adt_def1, index) =>
127+
ProjectionElem::Downcast(_name, index) =>
128128
match self.to_ty(tcx).sty {
129129
ty::Adt(adt_def, substs) => {
130130
assert!(adt_def.is_enum());
131131
assert!(index.as_usize() < adt_def.variants.len());
132-
assert_eq!(adt_def, adt_def1);
133132
PlaceTy::Downcast { adt_def,
134133
substs,
135134
variant_index: index }

src/librustc/mir/visit.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ macro_rules! make_mir_visitor {
137137
fn visit_ascribe_user_ty(&mut self,
138138
place: & $($mutability)? Place<'tcx>,
139139
variance: & $($mutability)? ty::Variance,
140-
user_ty: & $($mutability)? UserTypeProjection<'tcx>,
140+
user_ty: & $($mutability)? UserTypeProjection,
141141
location: Location) {
142142
self.super_ascribe_user_ty(place, variance, user_ty, location);
143143
}
@@ -205,7 +205,7 @@ macro_rules! make_mir_visitor {
205205

206206
fn visit_user_type_projection(
207207
&mut self,
208-
ty: & $($mutability)? UserTypeProjection<'tcx>,
208+
ty: & $($mutability)? UserTypeProjection,
209209
) {
210210
self.super_user_type_projection(ty);
211211
}
@@ -700,7 +700,7 @@ macro_rules! make_mir_visitor {
700700
fn super_ascribe_user_ty(&mut self,
701701
place: & $($mutability)? Place<'tcx>,
702702
_variance: & $($mutability)? ty::Variance,
703-
user_ty: & $($mutability)? UserTypeProjection<'tcx>,
703+
user_ty: & $($mutability)? UserTypeProjection,
704704
location: Location) {
705705
self.visit_place(
706706
place,
@@ -777,7 +777,7 @@ macro_rules! make_mir_visitor {
777777
min_length: _,
778778
from_end: _ } => {
779779
}
780-
ProjectionElem::Downcast(_adt_def, _variant_index) => {
780+
ProjectionElem::Downcast(_name, _variant_index) => {
781781
}
782782
}
783783
}
@@ -851,7 +851,7 @@ macro_rules! make_mir_visitor {
851851

852852
fn super_user_type_projection(
853853
&mut self,
854-
_ty: & $($mutability)? UserTypeProjection<'tcx>,
854+
_ty: & $($mutability)? UserTypeProjection,
855855
) {
856856
}
857857

src/librustc/ty/context.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ pub struct CtxtInterners<'tcx> {
125125
clauses: InternedSet<'tcx, List<Clause<'tcx>>>,
126126
goal: InternedSet<'tcx, GoalKind<'tcx>>,
127127
goal_list: InternedSet<'tcx, List<Goal<'tcx>>>,
128-
projs: InternedSet<'tcx, List<ProjectionKind<'tcx>>>,
128+
projs: InternedSet<'tcx, List<ProjectionKind>>,
129129
const_: InternedSet<'tcx, Const<'tcx>>,
130130
}
131131

@@ -1802,7 +1802,7 @@ nop_list_lift!{Ty<'a> => Ty<'tcx>}
18021802
nop_list_lift!{ExistentialPredicate<'a> => ExistentialPredicate<'tcx>}
18031803
nop_list_lift!{Predicate<'a> => Predicate<'tcx>}
18041804
nop_list_lift!{CanonicalVarInfo => CanonicalVarInfo}
1805-
nop_list_lift!{ProjectionKind<'a> => ProjectionKind<'tcx>}
1805+
nop_list_lift!{ProjectionKind => ProjectionKind}
18061806

18071807
// this is the impl for `&'a InternalSubsts<'a>`
18081808
nop_list_lift!{Kind<'a> => Kind<'tcx>}
@@ -2261,9 +2261,9 @@ impl<'tcx: 'lcx, 'lcx> Borrow<[Kind<'lcx>]> for Interned<'tcx, InternalSubsts<'t
22612261
}
22622262
}
22632263

2264-
impl<'tcx: 'lcx, 'lcx> Borrow<[ProjectionKind<'lcx>]>
2265-
for Interned<'tcx, List<ProjectionKind<'tcx>>> {
2266-
fn borrow<'a>(&'a self) -> &'a [ProjectionKind<'lcx>] {
2264+
impl<'tcx> Borrow<[ProjectionKind]>
2265+
for Interned<'tcx, List<ProjectionKind>> {
2266+
fn borrow<'a>(&'a self) -> &'a [ProjectionKind] {
22672267
&self.0[..]
22682268
}
22692269
}
@@ -2391,22 +2391,22 @@ direct_interners!('tcx,
23912391
);
23922392

23932393
macro_rules! slice_interners {
2394-
($($field:ident: $method:ident($ty:ident)),+) => (
2394+
($($field:ident: $method:ident($ty:ty)),+) => (
23952395
$(intern_method!( 'tcx, $field: $method(
2396-
&[$ty<'tcx>],
2396+
&[$ty],
23972397
|a, v| List::from_arena(a, v),
23982398
Deref::deref,
2399-
|xs: &[$ty<'_>]| xs.iter().any(keep_local)) -> List<$ty<'tcx>>);)+
2400-
)
2399+
|xs: &[$ty]| xs.iter().any(keep_local)) -> List<$ty>);)+
2400+
);
24012401
}
24022402

24032403
slice_interners!(
2404-
existential_predicates: _intern_existential_predicates(ExistentialPredicate),
2405-
predicates: _intern_predicates(Predicate),
2406-
type_list: _intern_type_list(Ty),
2407-
substs: _intern_substs(Kind),
2408-
clauses: _intern_clauses(Clause),
2409-
goal_list: _intern_goals(Goal),
2404+
existential_predicates: _intern_existential_predicates(ExistentialPredicate<'tcx>),
2405+
predicates: _intern_predicates(Predicate<'tcx>),
2406+
type_list: _intern_type_list(Ty<'tcx>),
2407+
substs: _intern_substs(Kind<'tcx>),
2408+
clauses: _intern_clauses(Clause<'tcx>),
2409+
goal_list: _intern_goals(Goal<'tcx>),
24102410
projs: _intern_projs(ProjectionKind)
24112411
);
24122412

@@ -2774,7 +2774,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
27742774
}
27752775
}
27762776

2777-
pub fn intern_projs(self, ps: &[ProjectionKind<'tcx>]) -> &'tcx List<ProjectionKind<'tcx>> {
2777+
pub fn intern_projs(self, ps: &[ProjectionKind]) -> &'tcx List<ProjectionKind> {
27782778
if ps.len() == 0 {
27792779
List::empty()
27802780
} else {

src/librustc/ty/structural_impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<Ty<'tcx>> {
936936
}
937937
}
938938

939-
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ProjectionKind<'tcx>> {
939+
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ProjectionKind> {
940940
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
941941
let v = self.iter().map(|t| t.fold_with(folder)).collect::<SmallVec<[_; 8]>>();
942942
folder.tcx().intern_projs(&v)

0 commit comments

Comments
 (0)