From 92f2b6243d717b6ff711fdf9fe9d579d41669ee1 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 24 Jul 2019 11:56:24 +0200 Subject: [PATCH] Rustup to rustc 1.38.0-nightly (a7f28678b 2019-07-23) --- src/analyze.rs | 4 +- src/base.rs | 128 +++++++++++++++++++++++++++---------------------- 2 files changed, 72 insertions(+), 60 deletions(-) diff --git a/src/analyze.rs b/src/analyze.rs index 1c3f52d50af..243c660368d 100644 --- a/src/analyze.rs +++ b/src/analyze.rs @@ -47,8 +47,8 @@ pub fn analyze<'a, 'tcx: 'a>(fx: &FunctionCx<'a, 'tcx, impl Backend>) -> HashMap } fn analyze_non_ssa_place(flag_map: &mut HashMap, place: &Place) { - match place { - Place::Base(PlaceBase::Local(local)) => not_ssa(flag_map, local), + match place.base { + PlaceBase::Local(local) => not_ssa(flag_map, local), _ => {} } } diff --git a/src/base.rs b/src/base.rs index 0566170bba1..1adcec046e0 100644 --- a/src/base.rs +++ b/src/base.rs @@ -1148,70 +1148,82 @@ pub fn trans_place<'a, 'tcx: 'a>( fx: &mut FunctionCx<'a, 'tcx, impl Backend>, place: &Place<'tcx>, ) -> CPlace<'tcx> { - match place { - Place::Base(base) => match base { - PlaceBase::Local(local) => fx.get_local_place(*local), - PlaceBase::Static(static_) => match static_.kind { - StaticKind::Static(def_id) => { - crate::constant::codegen_static_ref(fx, def_id, static_.ty) - } - StaticKind::Promoted(promoted) => { - crate::constant::trans_promoted(fx, promoted, static_.ty) - } + let base = match &place.base { + PlaceBase::Local(local) => fx.get_local_place(*local), + PlaceBase::Static(static_) => match static_.kind { + StaticKind::Static(def_id) => { + crate::constant::codegen_static_ref(fx, def_id, static_.ty) + } + StaticKind::Promoted(promoted) => { + crate::constant::trans_promoted(fx, promoted, static_.ty) } } - Place::Projection(projection) => { - let base = trans_place(fx, &projection.base); - match projection.elem { - ProjectionElem::Deref => base.place_deref(fx), - ProjectionElem::Field(field, _ty) => base.place_field(fx, field), - ProjectionElem::Index(local) => { - let index = fx.get_local_place(local).to_cvalue(fx).load_scalar(fx); - base.place_index(fx, index) - } - ProjectionElem::ConstantIndex { - offset, - min_length: _, - from_end, - } => { - let index = if !from_end { - fx.bcx.ins().iconst(fx.pointer_type, offset as i64) - } else { - let len = codegen_array_len(fx, base); - fx.bcx.ins().iadd_imm(len, -(offset as i64)) - }; - base.place_index(fx, index) - } - ProjectionElem::Subslice { from, to } => { - // These indices are generated by slice patterns. - // slice[from:-to] in Python terms. + }; - match base.layout().ty.sty { - ty::Array(elem_ty, len) => { - let elem_layout = fx.layout_of(elem_ty); - let ptr = base.to_addr(fx); - let len = crate::constant::force_eval_const(fx, len).unwrap_usize(fx.tcx); - CPlace::for_addr( - fx.bcx.ins().iadd_imm(ptr, elem_layout.size.bytes() as i64 * from as i64), - fx.layout_of(fx.tcx.mk_array(elem_ty, len - from as u64 - to as u64)), - ) - } - ty::Slice(elem_ty) => { - let elem_layout = fx.layout_of(elem_ty); - let (ptr, len) = base.to_addr_maybe_unsized(fx); - let len = len.unwrap(); - CPlace::for_addr_with_extra( - fx.bcx.ins().iadd_imm(ptr, elem_layout.size.bytes() as i64 * from as i64), - fx.bcx.ins().iadd_imm(len, -(from as i64 + to as i64)), - base.layout(), - ) - } - _ => unreachable!(), - } + trans_place_projection(fx, base, &place.projection) +} + +pub fn trans_place_projection<'a, 'tcx: 'a>( + fx: &mut FunctionCx<'a, 'tcx, impl Backend>, + base: CPlace<'tcx>, + projection: &Option>>, +) -> CPlace<'tcx> { + let projection = if let Some(projection) = projection { + projection + } else { + return base; + }; + + let base = trans_place_projection(fx, base, &projection.base); + + match projection.elem { + ProjectionElem::Deref => base.place_deref(fx), + ProjectionElem::Field(field, _ty) => base.place_field(fx, field), + ProjectionElem::Index(local) => { + let index = fx.get_local_place(local).to_cvalue(fx).load_scalar(fx); + base.place_index(fx, index) + } + ProjectionElem::ConstantIndex { + offset, + min_length: _, + from_end, + } => { + let index = if !from_end { + fx.bcx.ins().iconst(fx.pointer_type, offset as i64) + } else { + let len = codegen_array_len(fx, base); + fx.bcx.ins().iadd_imm(len, -(offset as i64)) + }; + base.place_index(fx, index) + } + ProjectionElem::Subslice { from, to } => { + // These indices are generated by slice patterns. + // slice[from:-to] in Python terms. + + match base.layout().ty.sty { + ty::Array(elem_ty, len) => { + let elem_layout = fx.layout_of(elem_ty); + let ptr = base.to_addr(fx); + let len = crate::constant::force_eval_const(fx, len).unwrap_usize(fx.tcx); + CPlace::for_addr( + fx.bcx.ins().iadd_imm(ptr, elem_layout.size.bytes() as i64 * from as i64), + fx.layout_of(fx.tcx.mk_array(elem_ty, len - from as u64 - to as u64)), + ) } - ProjectionElem::Downcast(_adt_def, variant) => base.downcast_variant(fx, variant), + ty::Slice(elem_ty) => { + let elem_layout = fx.layout_of(elem_ty); + let (ptr, len) = base.to_addr_maybe_unsized(fx); + let len = len.unwrap(); + CPlace::for_addr_with_extra( + fx.bcx.ins().iadd_imm(ptr, elem_layout.size.bytes() as i64 * from as i64), + fx.bcx.ins().iadd_imm(len, -(from as i64 + to as i64)), + base.layout(), + ) + } + _ => unreachable!(), } } + ProjectionElem::Downcast(_adt_def, variant) => base.downcast_variant(fx, variant), } }