Skip to content

Commit 190802c

Browse files
committed
Pattern match over PlaceRef rather than Place
This prepares the code base for when projection is interned. Place's projection field is going to be `&List<PlaceElem<'tcx>>` so we won't be able to pattern match against it.
1 parent 2705412 commit 190802c

37 files changed

+707
-820
lines changed

src/librustc/mir/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1908,15 +1908,15 @@ impl<'tcx> Place<'tcx> {
19081908
//
19091909
// FIXME: can we safely swap the semantics of `fn base_local` below in here instead?
19101910
pub fn local_or_deref_local(&self) -> Option<Local> {
1911-
match self {
1912-
Place {
1913-
base: PlaceBase::Local(local),
1914-
projection: box [],
1911+
match self.as_ref() {
1912+
PlaceRef {
1913+
base: &PlaceBase::Local(local),
1914+
projection: &[],
19151915
} |
1916-
Place {
1917-
base: PlaceBase::Local(local),
1918-
projection: box [ProjectionElem::Deref],
1919-
} => Some(*local),
1916+
PlaceRef {
1917+
base: &PlaceBase::Local(local),
1918+
projection: &[ProjectionElem::Deref],
1919+
} => Some(local),
19201920
_ => None,
19211921
}
19221922
}

src/librustc_codegen_ssa/mir/analyze.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,7 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
191191
location: Location) {
192192
debug!("visit_assign(place={:?}, rvalue={:?})", place, rvalue);
193193

194-
if let mir::Place {
195-
base: mir::PlaceBase::Local(index),
196-
projection: box [],
197-
} = *place {
194+
if let Some(index) = place.as_local() {
198195
self.assign(index, location);
199196
let decl_span = self.fx.mir.local_decls[index].source_info.span;
200197
if !self.fx.rvalue_creates_operand(rvalue, decl_span) {

src/librustc_codegen_ssa/mir/block.rs

+34-50
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_index::vec::Idx;
22
use rustc::middle::lang_items;
33
use rustc::ty::{self, Ty, TypeFoldable, Instance};
44
use rustc::ty::layout::{self, LayoutOf, HasTyCtxt, FnTypeExt};
5-
use rustc::mir::{self, Place, PlaceBase, Static, StaticKind};
5+
use rustc::mir::{self, PlaceBase, Static, StaticKind};
66
use rustc::mir::interpret::PanicInfo;
77
use rustc_target::abi::call::{ArgType, FnType, PassMode};
88
use rustc_target::spec::abi::Abi;
@@ -630,53 +630,43 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
630630
// checked by const-qualification, which also
631631
// promotes any complex rvalues to constants.
632632
if i == 2 && intrinsic.unwrap().starts_with("simd_shuffle") {
633-
match *arg {
633+
match arg {
634634
// The shuffle array argument is usually not an explicit constant,
635635
// but specified directly in the code. This means it gets promoted
636636
// and we can then extract the value by evaluating the promoted.
637-
mir::Operand::Copy(
638-
Place {
639-
base: PlaceBase::Static(box Static {
640-
kind: StaticKind::Promoted(promoted, _),
637+
mir::Operand::Copy(place) | mir::Operand::Move(place) => {
638+
if let mir::PlaceRef {
639+
base:
640+
&PlaceBase::Static(box Static {
641+
kind: StaticKind::Promoted(promoted, _),
642+
ty,
643+
def_id: _,
644+
}),
645+
projection: &[],
646+
} = place.as_ref()
647+
{
648+
let param_env = ty::ParamEnv::reveal_all();
649+
let cid = mir::interpret::GlobalId {
650+
instance: self.instance,
651+
promoted: Some(promoted),
652+
};
653+
let c = bx.tcx().const_eval(param_env.and(cid));
654+
let (llval, ty) = self.simd_shuffle_indices(
655+
&bx,
656+
terminator.source_info.span,
641657
ty,
642-
def_id: _,
643-
}),
644-
projection: box [],
658+
c,
659+
);
660+
return OperandRef {
661+
val: Immediate(llval),
662+
layout: bx.layout_of(ty),
663+
};
664+
} else {
665+
span_bug!(span, "shuffle indices must be constant");
645666
}
646-
) |
647-
mir::Operand::Move(
648-
Place {
649-
base: PlaceBase::Static(box Static {
650-
kind: StaticKind::Promoted(promoted, _),
651-
ty,
652-
def_id: _,
653-
}),
654-
projection: box [],
655-
}
656-
) => {
657-
let param_env = ty::ParamEnv::reveal_all();
658-
let cid = mir::interpret::GlobalId {
659-
instance: self.instance,
660-
promoted: Some(promoted),
661-
};
662-
let c = bx.tcx().const_eval(param_env.and(cid));
663-
let (llval, ty) = self.simd_shuffle_indices(
664-
&bx,
665-
terminator.source_info.span,
666-
ty,
667-
c,
668-
);
669-
return OperandRef {
670-
val: Immediate(llval),
671-
layout: bx.layout_of(ty),
672-
};
673-
674-
}
675-
mir::Operand::Copy(_) |
676-
mir::Operand::Move(_) => {
677-
span_bug!(span, "shuffle indices must be constant");
678667
}
679-
mir::Operand::Constant(ref constant) => {
668+
669+
mir::Operand::Constant(constant) => {
680670
let c = self.eval_mir_constant(constant);
681671
let (llval, ty) = self.simd_shuffle_indices(
682672
&bx,
@@ -1117,10 +1107,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
11171107
if fn_ret.is_ignore() {
11181108
return ReturnDest::Nothing;
11191109
}
1120-
let dest = if let mir::Place {
1121-
base: mir::PlaceBase::Local(index),
1122-
projection: box [],
1123-
} = *dest {
1110+
let dest = if let Some(index) = dest.as_local() {
11241111
match self.locals[index] {
11251112
LocalRef::Place(dest) => dest,
11261113
LocalRef::UnsizedPlace(_) => bug!("return type must be sized"),
@@ -1178,10 +1165,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
11781165
src: &mir::Operand<'tcx>,
11791166
dst: &mir::Place<'tcx>
11801167
) {
1181-
if let mir::Place {
1182-
base: mir::PlaceBase::Local(index),
1183-
projection: box [],
1184-
} = *dst {
1168+
if let Some(index) = dst.as_local() {
11851169
match self.locals[index] {
11861170
LocalRef::Place(place) => self.codegen_transmute_into(bx, src, place),
11871171
LocalRef::UnsizedPlace(_) => bug!("transmute must not involve unsized locals"),

src/librustc_codegen_ssa/mir/rvalue.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -530,10 +530,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
530530
) -> Bx::Value {
531531
// ZST are passed as operands and require special handling
532532
// because codegen_place() panics if Local is operand.
533-
if let mir::Place {
534-
base: mir::PlaceBase::Local(index),
535-
projection: box [],
536-
} = *place {
533+
if let Some(index) = place.as_local() {
537534
if let LocalRef::Operand(Some(op)) = self.locals[index] {
538535
if let ty::Array(_, n) = op.layout.ty.kind {
539536
let n = n.eval_usize(bx.cx().tcx(), ty::ParamEnv::reveal_all());

src/librustc_codegen_ssa/mir/statement.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
1717
self.set_debug_loc(&mut bx, statement.source_info);
1818
match statement.kind {
1919
mir::StatementKind::Assign(box(ref place, ref rvalue)) => {
20-
if let mir::Place {
21-
base: mir::PlaceBase::Local(index),
22-
projection: box [],
23-
} = place {
24-
match self.locals[*index] {
20+
if let Some(index) = place.as_local() {
21+
match self.locals[index] {
2522
LocalRef::Place(cg_dest) => {
2623
self.codegen_rvalue(bx, cg_dest, rvalue)
2724
}
@@ -30,7 +27,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
3027
}
3128
LocalRef::Operand(None) => {
3229
let (mut bx, operand) = self.codegen_rvalue_operand(bx, rvalue);
33-
if let Some(name) = self.mir.local_decls[*index].name {
30+
if let Some(name) = self.mir.local_decls[index].name {
3431
match operand.val {
3532
OperandValue::Ref(x, ..) |
3633
OperandValue::Immediate(x) => {
@@ -44,7 +41,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
4441
}
4542
}
4643
}
47-
self.locals[*index] = LocalRef::Operand(Some(operand));
44+
self.locals[index] = LocalRef::Operand(Some(operand));
4845
bx
4946
}
5047
LocalRef::Operand(Some(op)) => {

src/librustc_mir/borrow_check/borrow_set.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,7 @@ impl<'a, 'tcx> GatherBorrows<'a, 'tcx> {
315315
// TEMP = &foo
316316
//
317317
// so extract `temp`.
318-
let temp = if let &mir::Place {
319-
base: mir::PlaceBase::Local(temp),
320-
projection: box [],
321-
} = assigned_place {
318+
let temp = if let Some(temp) = assigned_place.as_local() {
322319
temp
323320
} else {
324321
span_bug!(

0 commit comments

Comments
 (0)