Skip to content

Remove some Regions from HAIR #56638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/librustc_mir/build/expr/as_rvalue.rs
Original file line number Diff line number Diff line change
@@ -67,15 +67,14 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
block.and(Rvalue::Repeat(value_operand, count))
}
ExprKind::Borrow {
region,
borrow_kind,
arg,
} => {
let arg_place = match borrow_kind {
BorrowKind::Shared => unpack!(block = this.as_read_only_place(block, arg)),
_ => unpack!(block = this.as_place(block, arg)),
};
block.and(Rvalue::Ref(region, borrow_kind, arg_place))
block.and(Rvalue::Ref(this.hir.tcx().types.re_erased, borrow_kind, arg_place))
}
ExprKind::Binary { op, lhs, rhs } => {
let lhs = unpack!(block = this.as_operand(block, scope, lhs));
@@ -249,11 +248,10 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
BorrowKind::Mut {
allow_two_phase_borrow: false,
},
region,
arg,
} => unpack!(
block = this.limit_capture_mutability(
upvar.span, upvar.ty, scope, block, arg, region,
upvar.span, upvar.ty, scope, block, arg,
)
),
_ => unpack!(block = this.as_operand(block, scope, upvar)),
@@ -500,7 +498,6 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
temp_lifetime: Option<region::Scope>,
mut block: BasicBlock,
arg: ExprRef<'tcx>,
region: &'tcx ty::RegionKind,
) -> BlockAnd<Operand<'tcx>> {
let this = self;

@@ -582,7 +579,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
block,
source_info,
&Place::Local(temp),
Rvalue::Ref(region, borrow_kind, arg_place),
Rvalue::Ref(this.hir.tcx().types.re_erased, borrow_kind, arg_place),
);

// In constants, temp_lifetime is None. We should not need to drop
24 changes: 13 additions & 11 deletions src/librustc_mir/build/matches/mod.rs
Original file line number Diff line number Diff line change
@@ -617,7 +617,7 @@ struct Binding<'tcx> {
var_id: NodeId,
var_ty: Ty<'tcx>,
mutability: Mutability,
binding_mode: BindingMode<'tcx>,
binding_mode: BindingMode,
}

/// Indicates that the type of `source` must be a subtype of the
@@ -1345,7 +1345,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
// Assign each of the bindings. Since we are binding for a
// guard expression, this will never trigger moves out of the
// candidate.
let re_empty = self.hir.tcx().types.re_empty;
let re_erased = self.hir.tcx().types.re_erased;
for binding in bindings {
let source_info = self.source_info(binding.span);

@@ -1361,11 +1361,11 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
self.schedule_drop_for_binding(binding.var_id, binding.span, RefWithinGuard);
match binding.binding_mode {
BindingMode::ByValue => {
let rvalue = Rvalue::Ref(re_empty, BorrowKind::Shared, binding.source.clone());
let rvalue = Rvalue::Ref(re_erased, BorrowKind::Shared, binding.source.clone());
self.cfg
.push_assign(block, source_info, &ref_for_guard, rvalue);
}
BindingMode::ByRef(region, borrow_kind) => {
BindingMode::ByRef(borrow_kind) => {
// Tricky business: For `ref id` and `ref mut id`
// patterns, we want `id` within the guard to
// correspond to a temp of type `& &T` or `& &mut
@@ -1405,10 +1405,10 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
allow_two_phase_borrow: true,
},
};
let rvalue = Rvalue::Ref(region, borrow_kind, binding.source.clone());
let rvalue = Rvalue::Ref(re_erased, borrow_kind, binding.source.clone());
self.cfg
.push_assign(block, source_info, &val_for_guard, rvalue);
let rvalue = Rvalue::Ref(region, BorrowKind::Shared, val_for_guard);
let rvalue = Rvalue::Ref(re_erased, BorrowKind::Shared, val_for_guard);
self.cfg
.push_assign(block, source_info, &ref_for_guard, rvalue);
}
@@ -1426,6 +1426,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
block, bindings
);


let re_erased = self.hir.tcx().types.re_erased;
// Assign each of the bindings. This may trigger moves out of the candidate.
for binding in bindings {
let source_info = self.source_info(binding.span);
@@ -1436,8 +1438,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
BindingMode::ByValue => {
Rvalue::Use(self.consume_by_copy_or_move(binding.source.clone()))
}
BindingMode::ByRef(region, borrow_kind) => {
Rvalue::Ref(region, borrow_kind, binding.source.clone())
BindingMode::ByRef(borrow_kind) => {
Rvalue::Ref(re_erased, borrow_kind, binding.source.clone())
}
};
self.cfg.push_assign(block, source_info, &local, rvalue);
@@ -1483,7 +1485,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
let tcx = self.hir.tcx();
let binding_mode = match mode {
BindingMode::ByValue => ty::BindingMode::BindByValue(mutability.into()),
BindingMode::ByRef { .. } => ty::BindingMode::BindByReference(mutability.into()),
BindingMode::ByRef(_) => ty::BindingMode::BindByReference(mutability.into()),
};
debug!("declare_binding: user_ty={:?}", user_ty);
let local = LocalDecl::<'tcx> {
@@ -1521,7 +1523,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
let ref_for_guard = self.local_decls.push(LocalDecl::<'tcx> {
// See previous comment.
mutability: Mutability::Not,
ty: tcx.mk_imm_ref(tcx.types.re_empty, var_ty),
ty: tcx.mk_imm_ref(tcx.types.re_erased, var_ty),
user_ty: UserTypeProjections::none(),
name: Some(name),
source_info,
@@ -1590,7 +1592,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {

for (matched_place, borrow_kind) in all_fake_borrows {
let borrowed_input =
Rvalue::Ref(tcx.types.re_empty, borrow_kind, matched_place.clone());
Rvalue::Ref(tcx.types.re_erased, borrow_kind, matched_place.clone());
let borrowed_input_ty = borrowed_input.ty(&self.local_decls, tcx);
let borrowed_input_temp = self.temp(borrowed_input_ty, source_info.span);
self.cfg.push_assign(
9 changes: 4 additions & 5 deletions src/librustc_mir/build/matches/test.rs
Original file line number Diff line number Diff line change
@@ -304,17 +304,16 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
let (mty, method) = self.hir.trait_method(eq_def_id, "eq", ty, &[ty.into()]);
let method = self.hir.tcx().intern_lazy_const(ty::LazyConst::Evaluated(method));

let re_erased = self.hir.tcx().types.re_erased;
// take the argument by reference
let region_scope = self.topmost_scope();
let region = self.hir.tcx().mk_region(ty::ReScope(region_scope));
let tam = ty::TypeAndMut {
ty,
mutbl: Mutability::MutImmutable,
};
let ref_ty = self.hir.tcx().mk_ref(region, tam);
let ref_ty = self.hir.tcx().mk_ref(re_erased, tam);

// let lhs_ref_place = &lhs;
let ref_rvalue = Rvalue::Ref(region, BorrowKind::Shared, place);
let ref_rvalue = Rvalue::Ref(re_erased, BorrowKind::Shared, place);
let lhs_ref_place = self.temp(ref_ty, test.span);
self.cfg.push_assign(block, source_info, &lhs_ref_place, ref_rvalue);
let val = Operand::Move(lhs_ref_place);
@@ -324,7 +323,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
self.cfg.push_assign(block, source_info, &rhs_place, Rvalue::Use(expect));

// let rhs_ref_place = &rhs_place;
let ref_rvalue = Rvalue::Ref(region, BorrowKind::Shared, rhs_place);
let ref_rvalue = Rvalue::Ref(re_erased, BorrowKind::Shared, rhs_place);
let rhs_ref_place = self.temp(ref_ty, test.span);
self.cfg.push_assign(block, source_info, &rhs_ref_place, ref_rvalue);
let expect = Operand::Move(rhs_ref_place);
21 changes: 3 additions & 18 deletions src/librustc_mir/hair/cx/expr.rs
Original file line number Diff line number Diff line change
@@ -124,40 +124,31 @@ fn apply_adjustment<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
}),
span,
kind: ExprKind::Borrow {
region: deref.region,
borrow_kind: deref.mutbl.to_borrow_kind(),
arg: expr.to_ref(),
},
};

overloaded_place(cx, hir_expr, adjustment.target, Some(call), vec![expr.to_ref()])
}
Adjust::Borrow(AutoBorrow::Ref(r, m)) => {
Adjust::Borrow(AutoBorrow::Ref(_, m)) => {
ExprKind::Borrow {
region: r,
borrow_kind: m.to_borrow_kind(),
arg: expr.to_ref(),
}
}
Adjust::Borrow(AutoBorrow::RawPtr(m)) => {
// Convert this to a suitable `&foo` and
// then an unsafe coercion. Limit the region to be just this
// expression.
let region = ty::ReScope(region::Scope {
id: hir_expr.hir_id.local_id,
data: region::ScopeData::Node
});
let region = cx.tcx.mk_region(region);
// then an unsafe coercion.
expr = Expr {
temp_lifetime,
ty: cx.tcx.mk_ref(region,
ty: cx.tcx.mk_ref(cx.tcx.types.re_erased,
ty::TypeAndMut {
ty: expr.ty,
mutbl: m,
}),
span,
kind: ExprKind::Borrow {
region,
borrow_kind: m.to_borrow_kind(),
arg: expr.to_ref(),
},
@@ -323,12 +314,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
}

hir::ExprKind::AddrOf(mutbl, ref expr) => {
let region = match expr_ty.sty {
ty::Ref(r, _, _) => r,
_ => span_bug!(expr.span, "type of & not region"),
};
ExprKind::Borrow {
region,
borrow_kind: mutbl.to_borrow_kind(),
arg: expr.to_ref(),
}
@@ -1222,7 +1208,6 @@ fn capture_freevar<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
ty: freevar_ty,
span: closure_expr.span,
kind: ExprKind::Borrow {
region: upvar_borrow.region,
borrow_kind,
arg: captured_var.to_ref(),
},
3 changes: 1 addition & 2 deletions src/librustc_mir/hair/mod.rs
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ use rustc::hir::def_id::DefId;
use rustc::infer::canonical::Canonical;
use rustc::middle::region;
use rustc::ty::subst::Substs;
use rustc::ty::{AdtDef, UpvarSubsts, Region, Ty, Const, LazyConst, UserTypeAnnotation};
use rustc::ty::{AdtDef, UpvarSubsts, Ty, Const, LazyConst, UserTypeAnnotation};
use rustc::ty::layout::VariantIdx;
use rustc::hir;
use syntax::ast;
@@ -235,7 +235,6 @@ pub enum ExprKind<'tcx> {
id: DefId,
},
Borrow {
region: Region<'tcx>,
borrow_kind: BorrowKind,
arg: ExprRef<'tcx>,
},
23 changes: 10 additions & 13 deletions src/librustc_mir/hair/pattern/mod.rs
Original file line number Diff line number Diff line change
@@ -39,9 +39,9 @@ pub enum PatternError {
}

#[derive(Copy, Clone, Debug)]
pub enum BindingMode<'tcx> {
pub enum BindingMode {
ByValue,
ByRef(Region<'tcx>, BorrowKind),
ByRef(BorrowKind),
}

#[derive(Clone, Debug)]
@@ -98,7 +98,7 @@ pub enum PatternKind<'tcx> {
Binding {
mutability: Mutability,
name: ast::Name,
mode: BindingMode<'tcx>,
mode: BindingMode,
var: ast::NodeId,
ty: Ty<'tcx>,
subpattern: Option<Pattern<'tcx>>,
@@ -162,7 +162,7 @@ impl<'tcx> fmt::Display for Pattern<'tcx> {
PatternKind::Binding { mutability, name, mode, ref subpattern, .. } => {
let is_mut = match mode {
BindingMode::ByValue => mutability == Mutability::Mut,
BindingMode::ByRef(_, bk) => {
BindingMode::ByRef(bk) => {
write!(f, "ref ")?;
match bk { BorrowKind::Mut { .. } => true, _ => false }
}
@@ -493,12 +493,9 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {

PatKind::Binding(_, id, ident, ref sub) => {
let var_ty = self.tables.node_id_to_type(pat.hir_id);
let region = match var_ty.sty {
ty::Ref(r, _, _) => Some(r),
ty::Error => { // Avoid ICE
return Pattern { span: pat.span, ty, kind: Box::new(PatternKind::Wild) };
}
_ => None,
if let ty::Error = var_ty.sty {
// Avoid ICE
return Pattern { span: pat.span, ty, kind: Box::new(PatternKind::Wild) };
};
let bm = *self.tables.pat_binding_modes().get(pat.hir_id)
.expect("missing binding mode");
@@ -509,10 +506,10 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
(Mutability::Not, BindingMode::ByValue),
ty::BindByReference(hir::MutMutable) =>
(Mutability::Not, BindingMode::ByRef(
region.unwrap(), BorrowKind::Mut { allow_two_phase_borrow: false })),
BorrowKind::Mut { allow_two_phase_borrow: false })),
ty::BindByReference(hir::MutImmutable) =>
(Mutability::Not, BindingMode::ByRef(
region.unwrap(), BorrowKind::Shared)),
BorrowKind::Shared)),
};

// A ref x pattern is the same node used for x, and as such it has
@@ -1019,7 +1016,7 @@ macro_rules! CloneImpls {

CloneImpls!{ <'tcx>
Span, Field, Mutability, ast::Name, ast::NodeId, usize, ty::Const<'tcx>,
Region<'tcx>, Ty<'tcx>, BindingMode<'tcx>, &'tcx AdtDef,
Region<'tcx>, Ty<'tcx>, BindingMode, &'tcx AdtDef,
&'tcx Substs<'tcx>, &'tcx Kind<'tcx>, UserTypeAnnotation<'tcx>,
UserTypeProjection<'tcx>, PatternTypeProjection<'tcx>
}