From 4cc2cabee25a2ea74d13720c980bfd0379b9945a Mon Sep 17 00:00:00 2001 From: DPC Date: Sun, 23 Aug 2020 14:54:58 +0200 Subject: [PATCH 1/4] change offset from u32 to u64 --- src/librustc_middle/mir/mod.rs | 14 +++++++------- src/librustc_mir/borrow_check/mod.rs | 4 ++-- src/librustc_mir/dataflow/move_paths/builder.rs | 2 +- src/librustc_mir/shim.rs | 2 +- src/librustc_mir/transform/elaborate_drops.rs | 2 +- src/librustc_mir/util/aggregate.rs | 4 +--- src/librustc_mir/util/elaborate_drops.rs | 6 +++--- src/librustc_mir_build/build/matches/mod.rs | 4 ++-- src/librustc_mir_build/build/matches/util.rs | 8 ++++---- 9 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/librustc_middle/mir/mod.rs b/src/librustc_middle/mir/mod.rs index ad40cf221bc32..7ac7d9b23f172 100644 --- a/src/librustc_middle/mir/mod.rs +++ b/src/librustc_middle/mir/mod.rs @@ -1564,10 +1564,10 @@ pub enum ProjectionElem { /// ``` ConstantIndex { /// index or -index (in Python terms), depending on from_end - offset: u32, + offset: u64, /// The thing being indexed must be at least this long. For arrays this /// is always the exact length. - min_length: u32, + min_length: u64, /// Counting backwards from end? This is always false when indexing an /// array. from_end: bool, @@ -1578,8 +1578,8 @@ pub enum ProjectionElem { /// If `from_end` is true `slice[from..slice.len() - to]`. /// Otherwise `array[from..to]`. Subslice { - from: u32, - to: u32, + from: u64, + to: u64, /// Whether `to` counts from the start or end of the array/slice. /// For `PlaceElem`s this is `true` if and only if the base is a slice. /// For `ProjectionKind`, this can also be `true` for arrays. @@ -1616,7 +1616,7 @@ pub type PlaceElem<'tcx> = ProjectionElem>; // At least on 64 bit systems, `PlaceElem` should not be larger than two pointers. #[cfg(target_arch = "x86_64")] -static_assert_size!(PlaceElem<'_>, 16); +static_assert_size!(PlaceElem<'_>, 24); /// Alias for projections as they appear in `UserTypeProjection`, where we /// need neither the `V` parameter for `Index` nor the `T` for `Field`. @@ -2330,7 +2330,7 @@ impl<'tcx> UserTypeProjections { self.map_projections(|pat_ty_proj| pat_ty_proj.index()) } - pub fn subslice(self, from: u32, to: u32) -> Self { + pub fn subslice(self, from: u64, to: u64) -> Self { self.map_projections(|pat_ty_proj| pat_ty_proj.subslice(from, to)) } @@ -2376,7 +2376,7 @@ impl UserTypeProjection { self } - pub(crate) fn subslice(mut self, from: u32, to: u32) -> Self { + pub(crate) fn subslice(mut self, from: u64, to: u64) -> Self { self.projs.push(ProjectionElem::Subslice { from, to, from_end: true }); self } diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index a61af5c3f0523..b486b8b589cfd 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -1694,8 +1694,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { desired_action: InitializationRequiringAction, place_span: (PlaceRef<'tcx>, Span), maybe_uninits: &BitSet, - from: u32, - to: u32, + from: u64, + to: u64, ) { if let Some(mpi) = self.move_path_for_place(place_span.0) { let move_paths = &self.move_data.move_paths; diff --git a/src/librustc_mir/dataflow/move_paths/builder.rs b/src/librustc_mir/dataflow/move_paths/builder.rs index e567063e0d599..e088dc6a954a3 100644 --- a/src/librustc_mir/dataflow/move_paths/builder.rs +++ b/src/librustc_mir/dataflow/move_paths/builder.rs @@ -480,7 +480,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> { } }; let base_ty = base_place.ty(self.builder.body, self.builder.tcx).ty; - let len: u32 = match base_ty.kind { + let len: u64 = match base_ty.kind { ty::Array(_, size) => { let length = size.eval_usize(self.builder.tcx, self.builder.param_env); length diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index 6a7653b60752d..883c87da35c97 100644 --- a/src/librustc_mir/shim.rs +++ b/src/librustc_mir/shim.rs @@ -295,7 +295,7 @@ impl<'a, 'tcx> DropElaborator<'a, 'tcx> for DropShimElaborator<'a, 'tcx> { fn downcast_subpath(&self, _path: Self::Path, _variant: VariantIdx) -> Option { Some(()) } - fn array_subpath(&self, _path: Self::Path, _index: u32, _size: u32) -> Option { + fn array_subpath(&self, _path: Self::Path, _index: u64, _size: u64) -> Option { None } } diff --git a/src/librustc_mir/transform/elaborate_drops.rs b/src/librustc_mir/transform/elaborate_drops.rs index ad49090bfc50c..5f1930693568c 100644 --- a/src/librustc_mir/transform/elaborate_drops.rs +++ b/src/librustc_mir/transform/elaborate_drops.rs @@ -219,7 +219,7 @@ impl<'a, 'b, 'tcx> DropElaborator<'a, 'tcx> for Elaborator<'a, 'b, 'tcx> { }) } - fn array_subpath(&self, path: Self::Path, index: u32, size: u32) -> Option { + fn array_subpath(&self, path: Self::Path, index: u64, size: u64) -> Option { dataflow::move_path_children_matching(self.ctxt.move_data(), path, |e| match e { ProjectionElem::ConstantIndex { offset, min_length, from_end } => { debug_assert!(size == min_length, "min_length should be exact for arrays"); diff --git a/src/librustc_mir/util/aggregate.rs b/src/librustc_mir/util/aggregate.rs index 1a22eee3a0371..e867e8b40850f 100644 --- a/src/librustc_mir/util/aggregate.rs +++ b/src/librustc_mir/util/aggregate.rs @@ -52,14 +52,12 @@ pub fn expand_aggregate<'tcx>( .enumerate() .map(move |(i, (op, ty))| { let lhs_field = if let AggregateKind::Array(_) = kind { - // FIXME(eddyb) `offset` should be u64. - let offset = i as u32; + let offset = i as u64; assert_eq!(offset as usize, i); tcx.mk_place_elem( lhs, ProjectionElem::ConstantIndex { offset, - // FIXME(eddyb) `min_length` doesn't appear to be used. min_length: offset + 1, from_end: false, }, diff --git a/src/librustc_mir/util/elaborate_drops.rs b/src/librustc_mir/util/elaborate_drops.rs index 20c2f5688eb59..6acbb0ad4db20 100644 --- a/src/librustc_mir/util/elaborate_drops.rs +++ b/src/librustc_mir/util/elaborate_drops.rs @@ -150,7 +150,7 @@ pub trait DropElaborator<'a, 'tcx>: fmt::Debug { /// If this returns `None`, elements of `path` will not get a dedicated drop flag. /// /// This is only relevant for array patterns, which can move out of individual array elements. - fn array_subpath(&self, path: Self::Path, index: u32, size: u32) -> Option; + fn array_subpath(&self, path: Self::Path, index: u64, size: u64) -> Option; } #[derive(Debug)] @@ -744,8 +744,8 @@ where let tcx = self.tcx(); if let Some(size) = opt_size { - let size: u32 = size.try_into().unwrap_or_else(|_| { - bug!("move out check isn't implemented for array sizes bigger than u32::MAX"); + let size: u64 = size.try_into().unwrap_or_else(|_| { + bug!("move out check isn't implemented for array sizes bigger than u64::MAX"); }); let fields: Vec<(Place<'tcx>, Option)> = (0..size) .map(|i| { diff --git a/src/librustc_mir_build/build/matches/mod.rs b/src/librustc_mir_build/build/matches/mod.rs index 5f87cb364b891..3a525d10b0817 100644 --- a/src/librustc_mir_build/build/matches/mod.rs +++ b/src/librustc_mir_build/build/matches/mod.rs @@ -609,8 +609,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { PatKind::Array { ref prefix, ref slice, ref suffix } | PatKind::Slice { ref prefix, ref slice, ref suffix } => { - let from = u32::try_from(prefix.len()).unwrap(); - let to = u32::try_from(suffix.len()).unwrap(); + let from = u64::try_from(prefix.len()).unwrap(); + let to = u64::try_from(suffix.len()).unwrap(); for subpattern in prefix { self.visit_primary_bindings(subpattern, pattern_user_ty.clone().index(), f); } diff --git a/src/librustc_mir_build/build/matches/util.rs b/src/librustc_mir_build/build/matches/util.rs index 605396c5eb639..c6d39947f7d15 100644 --- a/src/librustc_mir_build/build/matches/util.rs +++ b/src/librustc_mir_build/build/matches/util.rs @@ -40,17 +40,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { match_pairs.extend(prefix.iter().enumerate().map(|(idx, subpattern)| { let elem = - ProjectionElem::ConstantIndex { offset: idx as u32, min_length, from_end: false }; + ProjectionElem::ConstantIndex { offset: idx as u64, min_length, from_end: false }; let place = tcx.mk_place_elem(*place, elem); MatchPair::new(place, subpattern) })); if let Some(subslice_pat) = opt_slice { - let suffix_len = suffix.len() as u32; + let suffix_len = suffix.len() as u64; let subslice = tcx.mk_place_elem( *place, ProjectionElem::Subslice { - from: prefix.len() as u32, + from: prefix.len() as u64, to: if exact_size { min_length - suffix_len } else { suffix_len }, from_end: !exact_size, }, @@ -59,7 +59,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } match_pairs.extend(suffix.iter().rev().enumerate().map(|(idx, subpattern)| { - let end_offset = (idx + 1) as u32; + let end_offset = (idx + 1) as u64; let elem = ProjectionElem::ConstantIndex { offset: if exact_size { min_length - end_offset } else { end_offset }, min_length, From dd1cd672e8138820a17bcec4e67f99ff394566b1 Mon Sep 17 00:00:00 2001 From: DPC Date: Tue, 25 Aug 2020 00:59:07 +0200 Subject: [PATCH 2/4] removed not-needed conversion --- src/librustc_mir/util/aggregate.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/librustc_mir/util/aggregate.rs b/src/librustc_mir/util/aggregate.rs index e867e8b40850f..3afe8d2294373 100644 --- a/src/librustc_mir/util/aggregate.rs +++ b/src/librustc_mir/util/aggregate.rs @@ -52,8 +52,7 @@ pub fn expand_aggregate<'tcx>( .enumerate() .map(move |(i, (op, ty))| { let lhs_field = if let AggregateKind::Array(_) = kind { - let offset = i as u64; - assert_eq!(offset as usize, i); + let offset = u64::try_from(i).unwrap(); tcx.mk_place_elem( lhs, ProjectionElem::ConstantIndex { From b1c2b9891dea834f28e921ce40107ea8bcb4cbc6 Mon Sep 17 00:00:00 2001 From: DPC Date: Tue, 25 Aug 2020 03:00:27 +0200 Subject: [PATCH 3/4] cleanup --- src/librustc_mir/borrow_check/type_check/mod.rs | 2 +- src/librustc_mir/interpret/place.rs | 6 +++--- src/librustc_mir/util/aggregate.rs | 1 + src/librustc_mir/util/elaborate_drops.rs | 5 ----- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/librustc_mir/borrow_check/type_check/mod.rs b/src/librustc_mir/borrow_check/type_check/mod.rs index 168a352591d0e..c1fc029cc477e 100644 --- a/src/librustc_mir/borrow_check/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/type_check/mod.rs @@ -649,7 +649,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { PlaceTy::from_ty(match base_ty.kind { ty::Array(inner, _) => { assert!(!from_end, "array subslices should not use from_end"); - tcx.mk_array(inner, (to - from) as u64) + tcx.mk_array(inner, to - from) } ty::Slice(..) => { assert!(from_end, "slice subslices should use from_end"); diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index 20fd8e43361d6..6ba6103b311a3 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -549,17 +549,17 @@ where ConstantIndex { offset, min_length, from_end } => { let n = base.len(self)?; - if n < u64::from(min_length) { + if n < min_length { // This can only be reached in ConstProp and non-rustc-MIR. throw_ub!(BoundsCheckFailed { len: min_length.into(), index: n }); } let index = if from_end { assert!(0 < offset && offset <= min_length); - n.checked_sub(u64::from(offset)).unwrap() + n.checked_sub(offset).unwrap() } else { assert!(offset < min_length); - u64::from(offset) + offset }; self.mplace_index(base, index)? diff --git a/src/librustc_mir/util/aggregate.rs b/src/librustc_mir/util/aggregate.rs index 3afe8d2294373..6a7505291efbe 100644 --- a/src/librustc_mir/util/aggregate.rs +++ b/src/librustc_mir/util/aggregate.rs @@ -4,6 +4,7 @@ use rustc_middle::ty::{Ty, TyCtxt}; use rustc_target::abi::VariantIdx; use std::iter::TrustedLen; +use std::convert::TryFrom; /// Expand `lhs = Rvalue::Aggregate(kind, operands)` into assignments to the fields. /// diff --git a/src/librustc_mir/util/elaborate_drops.rs b/src/librustc_mir/util/elaborate_drops.rs index 6acbb0ad4db20..653dffc22cf74 100644 --- a/src/librustc_mir/util/elaborate_drops.rs +++ b/src/librustc_mir/util/elaborate_drops.rs @@ -10,8 +10,6 @@ use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_target::abi::VariantIdx; use std::fmt; -use std::convert::TryInto; - /// The value of an inserted drop flag. #[derive(Debug, PartialEq, Eq, Copy, Clone)] pub enum DropFlagState { @@ -744,9 +742,6 @@ where let tcx = self.tcx(); if let Some(size) = opt_size { - let size: u64 = size.try_into().unwrap_or_else(|_| { - bug!("move out check isn't implemented for array sizes bigger than u64::MAX"); - }); let fields: Vec<(Place<'tcx>, Option)> = (0..size) .map(|i| { ( From f6a4a76a9afabc3288cc288d46bf0def0431d822 Mon Sep 17 00:00:00 2001 From: DPC Date: Tue, 25 Aug 2020 03:21:31 +0200 Subject: [PATCH 4/4] tidy --- src/librustc_mir/util/aggregate.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_mir/util/aggregate.rs b/src/librustc_mir/util/aggregate.rs index 6a7505291efbe..130409b9df5c0 100644 --- a/src/librustc_mir/util/aggregate.rs +++ b/src/librustc_mir/util/aggregate.rs @@ -3,8 +3,8 @@ use rustc_middle::mir::*; use rustc_middle::ty::{Ty, TyCtxt}; use rustc_target::abi::VariantIdx; -use std::iter::TrustedLen; use std::convert::TryFrom; +use std::iter::TrustedLen; /// Expand `lhs = Rvalue::Aggregate(kind, operands)` into assignments to the fields. ///