Skip to content

Commit 34d39ce

Browse files
committed
Auto merge of #56638 - matthewjasper:remove-ref-region, r=<try>
Remove `Region` from `mir::Rvalue::Ref` This was only used for borrow checking, but we will create a fresh `RegionVid` for each borrow anyway, so there's no need for us to store it in the MIR. Also removes `Region`s from various places where they're no longer needed. Uses `ReErased` for any regions that need to be created in MIR generation. r? @nikomatsakis
2 parents 9772d02 + 74d3462 commit 34d39ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+261
-285
lines changed

src/librustc/ich/impls_mir.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,7 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::Rvalue<'gcx> {
341341
operand.hash_stable(hcx, hasher);
342342
val.hash_stable(hcx, hasher);
343343
}
344-
mir::Rvalue::Ref(region, borrow_kind, ref place) => {
345-
region.hash_stable(hcx, hasher);
344+
mir::Rvalue::Ref(borrow_kind, ref place) => {
346345
borrow_kind.hash_stable(hcx, hasher);
347346
place.hash_stable(hcx, hasher);
348347
}

src/librustc/mir/mod.rs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use syntax::symbol::InternedString;
3838
use syntax_pos::{Span, DUMMY_SP};
3939
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
4040
use ty::subst::{CanonicalUserSubsts, Subst, Substs};
41-
use ty::{self, AdtDef, CanonicalTy, ClosureSubsts, GeneratorSubsts, Region, Ty, TyCtxt};
41+
use ty::{self, AdtDef, CanonicalTy, ClosureSubsts, GeneratorSubsts, Ty, TyCtxt};
4242
use ty::layout::VariantIdx;
4343
use util::ppaux;
4444

@@ -2165,7 +2165,7 @@ pub enum Rvalue<'tcx> {
21652165
Repeat(Operand<'tcx>, u64),
21662166

21672167
/// &x or &mut x
2168-
Ref(Region<'tcx>, BorrowKind, Place<'tcx>),
2168+
Ref(BorrowKind, Place<'tcx>),
21692169

21702170
/// length of a [X] or [X;n] value
21712171
Len(Place<'tcx>),
@@ -2318,25 +2318,14 @@ impl<'tcx> Debug for Rvalue<'tcx> {
23182318
UnaryOp(ref op, ref a) => write!(fmt, "{:?}({:?})", op, a),
23192319
Discriminant(ref place) => write!(fmt, "discriminant({:?})", place),
23202320
NullaryOp(ref op, ref t) => write!(fmt, "{:?}({:?})", op, t),
2321-
Ref(region, borrow_kind, ref place) => {
2321+
Ref(borrow_kind, ref place) => {
23222322
let kind_str = match borrow_kind {
23232323
BorrowKind::Shared => "",
23242324
BorrowKind::Shallow => "shallow ",
23252325
BorrowKind::Mut { .. } | BorrowKind::Unique => "mut ",
23262326
};
23272327

2328-
// When printing regions, add trailing space if necessary.
2329-
let region = if ppaux::verbose() || ppaux::identify_regions() {
2330-
let mut region = region.to_string();
2331-
if region.len() > 0 {
2332-
region.push(' ');
2333-
}
2334-
region
2335-
} else {
2336-
// Do not even print 'static
2337-
String::new()
2338-
};
2339-
write!(fmt, "&{}{}{:?}", region, kind_str, place)
2328+
write!(fmt, "&{}{:?}", kind_str, place)
23402329
}
23412330

23422331
Aggregate(ref kind, ref places) => {
@@ -3236,8 +3225,8 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
32363225
match *self {
32373226
Use(ref op) => Use(op.fold_with(folder)),
32383227
Repeat(ref op, len) => Repeat(op.fold_with(folder), len),
3239-
Ref(region, bk, ref place) => {
3240-
Ref(region.fold_with(folder), bk, place.fold_with(folder))
3228+
Ref(bk, ref place) => {
3229+
Ref(bk, place.fold_with(folder))
32413230
}
32423231
Len(ref place) => Len(place.fold_with(folder)),
32433232
Cast(kind, ref op, ty) => Cast(kind, op.fold_with(folder), ty.fold_with(folder)),
@@ -3278,7 +3267,7 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
32783267
match *self {
32793268
Use(ref op) => op.visit_with(visitor),
32803269
Repeat(ref op, _) => op.visit_with(visitor),
3281-
Ref(region, _, ref place) => region.visit_with(visitor) || place.visit_with(visitor),
3270+
Ref(_, ref place) => place.visit_with(visitor),
32823271
Len(ref place) => place.visit_with(visitor),
32833272
Cast(_, ref op, ty) => op.visit_with(visitor) || ty.visit_with(visitor),
32843273
BinaryOp(_, ref rhs, ref lhs) | CheckedBinaryOp(_, ref rhs, ref lhs) => {

src/librustc/mir/tcx.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,9 @@ impl<'tcx> Rvalue<'tcx> {
229229
Rvalue::Repeat(ref operand, count) => {
230230
tcx.mk_array(operand.ty(local_decls, tcx), count)
231231
}
232-
Rvalue::Ref(reg, bk, ref place) => {
232+
Rvalue::Ref(bk, ref place) => {
233233
let place_ty = place.ty(local_decls, tcx).to_ty(tcx);
234-
tcx.mk_ref(reg,
234+
tcx.mk_ref(tcx.types.re_erased,
235235
ty::TypeAndMut {
236236
ty: place_ty,
237237
mutbl: bk.to_mutbl_lossy()

src/librustc/mir/visit.rs

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use hir::def_id::DefId;
1212
use ty::subst::Substs;
13-
use ty::{ClosureSubsts, GeneratorSubsts, Region, Ty};
13+
use ty::{ClosureSubsts, GeneratorSubsts, Ty};
1414
use mir::*;
1515
use syntax_pos::Span;
1616

@@ -162,21 +162,21 @@ macro_rules! make_mir_visitor {
162162

163163
fn visit_place(&mut self,
164164
place: & $($mutability)* Place<'tcx>,
165-
context: PlaceContext<'tcx>,
165+
context: PlaceContext,
166166
location: Location) {
167167
self.super_place(place, context, location);
168168
}
169169

170170
fn visit_static(&mut self,
171171
static_: & $($mutability)* Static<'tcx>,
172-
context: PlaceContext<'tcx>,
172+
context: PlaceContext,
173173
location: Location) {
174174
self.super_static(static_, context, location);
175175
}
176176

177177
fn visit_projection(&mut self,
178178
place: & $($mutability)* PlaceProjection<'tcx>,
179-
context: PlaceContext<'tcx>,
179+
context: PlaceContext,
180180
location: Location) {
181181
self.super_projection(place, context, location);
182182
}
@@ -235,12 +235,6 @@ macro_rules! make_mir_visitor {
235235
self.super_user_type_annotation(ty);
236236
}
237237

238-
fn visit_region(&mut self,
239-
region: & $($mutability)* ty::Region<'tcx>,
240-
_: Location) {
241-
self.super_region(region);
242-
}
243-
244238
fn visit_const(&mut self,
245239
constant: & $($mutability)* &'tcx ty::Const<'tcx>,
246240
_: Location) {
@@ -273,7 +267,7 @@ macro_rules! make_mir_visitor {
273267

274268
fn visit_local(&mut self,
275269
_local: & $($mutability)* Local,
276-
_context: PlaceContext<'tcx>,
270+
_context: PlaceContext,
277271
_location: Location) {
278272
}
279273

@@ -592,20 +586,19 @@ macro_rules! make_mir_visitor {
592586
self.visit_operand(value, location);
593587
}
594588

595-
Rvalue::Ref(ref $($mutability)* r, bk, ref $($mutability)* path) => {
596-
self.visit_region(r, location);
589+
Rvalue::Ref(bk, ref $($mutability)* path) => {
597590
let ctx = match bk {
598591
BorrowKind::Shared => PlaceContext::NonMutatingUse(
599-
NonMutatingUseContext::SharedBorrow(*r)
592+
NonMutatingUseContext::SharedBorrow
600593
),
601594
BorrowKind::Shallow => PlaceContext::NonMutatingUse(
602-
NonMutatingUseContext::ShallowBorrow(*r)
595+
NonMutatingUseContext::ShallowBorrow
603596
),
604597
BorrowKind::Unique => PlaceContext::NonMutatingUse(
605-
NonMutatingUseContext::UniqueBorrow(*r)
598+
NonMutatingUseContext::UniqueBorrow
606599
),
607600
BorrowKind::Mut { .. } =>
608-
PlaceContext::MutatingUse(MutatingUseContext::Borrow(*r)),
601+
PlaceContext::MutatingUse(MutatingUseContext::Borrow),
609602
};
610603
self.visit_place(path, ctx, location);
611604
}
@@ -738,7 +731,7 @@ macro_rules! make_mir_visitor {
738731

739732
fn super_place(&mut self,
740733
place: & $($mutability)* Place<'tcx>,
741-
context: PlaceContext<'tcx>,
734+
context: PlaceContext,
742735
location: Location) {
743736
match *place {
744737
Place::Local(ref $($mutability)* local) => {
@@ -758,7 +751,7 @@ macro_rules! make_mir_visitor {
758751

759752
fn super_static(&mut self,
760753
static_: & $($mutability)* Static<'tcx>,
761-
_context: PlaceContext<'tcx>,
754+
_context: PlaceContext,
762755
location: Location) {
763756
let Static {
764757
ref $($mutability)* def_id,
@@ -770,7 +763,7 @@ macro_rules! make_mir_visitor {
770763

771764
fn super_projection(&mut self,
772765
proj: & $($mutability)* PlaceProjection<'tcx>,
773-
context: PlaceContext<'tcx>,
766+
context: PlaceContext,
774767
location: Location) {
775768
let Projection {
776769
ref $($mutability)* base,
@@ -899,9 +892,6 @@ macro_rules! make_mir_visitor {
899892
fn super_ty(&mut self, _ty: & $($mutability)* Ty<'tcx>) {
900893
}
901894

902-
fn super_region(&mut self, _region: & $($mutability)* ty::Region<'tcx>) {
903-
}
904-
905895
fn super_const(&mut self, _const: & $($mutability)* &'tcx ty::Const<'tcx>) {
906896
}
907897

@@ -984,19 +974,19 @@ pub enum TyContext {
984974
}
985975

986976
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
987-
pub enum NonMutatingUseContext<'tcx> {
977+
pub enum NonMutatingUseContext {
988978
/// Being inspected in some way, like loading a len.
989979
Inspect,
990980
/// Consumed as part of an operand.
991981
Copy,
992982
/// Consumed as part of an operand.
993983
Move,
994984
/// Shared borrow.
995-
SharedBorrow(Region<'tcx>),
985+
SharedBorrow,
996986
/// Shallow borrow.
997-
ShallowBorrow(Region<'tcx>),
987+
ShallowBorrow,
998988
/// Unique borrow.
999-
UniqueBorrow(Region<'tcx>),
989+
UniqueBorrow,
1000990
/// Used as base for another place, e.g., `x` in `x.y`. Will not mutate the place.
1001991
/// For example, the projection `x.y` is not marked as a mutation in these cases:
1002992
///
@@ -1007,7 +997,7 @@ pub enum NonMutatingUseContext<'tcx> {
1007997
}
1008998

1009999
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
1010-
pub enum MutatingUseContext<'tcx> {
1000+
pub enum MutatingUseContext {
10111001
/// Appears as LHS of an assignment.
10121002
Store,
10131003
/// Can often be treated as a `Store`, but needs to be separate because
@@ -1019,7 +1009,7 @@ pub enum MutatingUseContext<'tcx> {
10191009
/// Being dropped.
10201010
Drop,
10211011
/// Mutable borrow.
1022-
Borrow(Region<'tcx>),
1012+
Borrow,
10231013
/// Used as base for another place, e.g., `x` in `x.y`. Could potentially mutate the place.
10241014
/// For example, the projection `x.y` is marked as a mutation in these cases:
10251015
///
@@ -1042,13 +1032,13 @@ pub enum NonUseContext {
10421032
}
10431033

10441034
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
1045-
pub enum PlaceContext<'tcx> {
1046-
NonMutatingUse(NonMutatingUseContext<'tcx>),
1047-
MutatingUse(MutatingUseContext<'tcx>),
1035+
pub enum PlaceContext {
1036+
NonMutatingUse(NonMutatingUseContext),
1037+
MutatingUse(MutatingUseContext),
10481038
NonUse(NonUseContext),
10491039
}
10501040

1051-
impl<'tcx> PlaceContext<'tcx> {
1041+
impl PlaceContext {
10521042
/// Returns `true` if this place context represents a drop.
10531043
pub fn is_drop(&self) -> bool {
10541044
match *self {
@@ -1060,10 +1050,10 @@ impl<'tcx> PlaceContext<'tcx> {
10601050
/// Returns `true` if this place context represents a borrow.
10611051
pub fn is_borrow(&self) -> bool {
10621052
match *self {
1063-
PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow(..)) |
1064-
PlaceContext::NonMutatingUse(NonMutatingUseContext::ShallowBorrow(..)) |
1065-
PlaceContext::NonMutatingUse(NonMutatingUseContext::UniqueBorrow(..)) |
1066-
PlaceContext::MutatingUse(MutatingUseContext::Borrow(..)) => true,
1053+
PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow) |
1054+
PlaceContext::NonMutatingUse(NonMutatingUseContext::ShallowBorrow) |
1055+
PlaceContext::NonMutatingUse(NonMutatingUseContext::UniqueBorrow) |
1056+
PlaceContext::MutatingUse(MutatingUseContext::Borrow) => true,
10671057
_ => false,
10681058
}
10691059
}

src/librustc_codegen_ssa/mir/analyze.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ impl<'mir, 'a: 'mir, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
163163

164164
fn visit_place(&mut self,
165165
place: &mir::Place<'tcx>,
166-
context: PlaceContext<'tcx>,
166+
context: PlaceContext,
167167
location: Location) {
168168
debug!("visit_place(place={:?}, context={:?})", place, context);
169169
let cx = self.fx.cx;
@@ -215,7 +215,7 @@ impl<'mir, 'a: 'mir, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
215215

216216
fn visit_local(&mut self,
217217
&local: &mir::Local,
218-
context: PlaceContext<'tcx>,
218+
context: PlaceContext,
219219
location: Location) {
220220
match context {
221221
PlaceContext::MutatingUse(MutatingUseContext::Call) => {
@@ -245,11 +245,11 @@ impl<'mir, 'a: 'mir, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
245245
PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect) |
246246
PlaceContext::MutatingUse(MutatingUseContext::Store) |
247247
PlaceContext::MutatingUse(MutatingUseContext::AsmOutput) |
248-
PlaceContext::MutatingUse(MutatingUseContext::Borrow(..)) |
248+
PlaceContext::MutatingUse(MutatingUseContext::Borrow) |
249249
PlaceContext::MutatingUse(MutatingUseContext::Projection) |
250-
PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow(..)) |
251-
PlaceContext::NonMutatingUse(NonMutatingUseContext::UniqueBorrow(..)) |
252-
PlaceContext::NonMutatingUse(NonMutatingUseContext::ShallowBorrow(..)) |
250+
PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow) |
251+
PlaceContext::NonMutatingUse(NonMutatingUseContext::UniqueBorrow) |
252+
PlaceContext::NonMutatingUse(NonMutatingUseContext::ShallowBorrow) |
253253
PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection) => {
254254
self.not_ssa(local);
255255
}

src/librustc_codegen_ssa/mir/rvalue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
385385
})
386386
}
387387

388-
mir::Rvalue::Ref(_, bk, ref place) => {
388+
mir::Rvalue::Ref(bk, ref place) => {
389389
let cg_place = self.codegen_place(&mut bx, place);
390390

391391
let ty = cg_place.layout.ty;

0 commit comments

Comments
 (0)