Skip to content

change offset from u32 to u64 #71696

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

Closed
Closed
Show file tree
Hide file tree
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
12 changes: 6 additions & 6 deletions src/librustc_middle/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1807,7 +1807,7 @@ pub enum ProjectionElem<V, T> {
/// ```
ConstantIndex {
/// index or -index (in Python terms), depending on from_end
offset: u32,
offset: u64,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can now also remove a bunch of conversions around here:

ConstantIndex { offset, min_length, from_end } => {

/// The thing being indexed must be at least this long. For arrays this
/// is always the exact length.
min_length: u32,
Expand All @@ -1821,8 +1821,8 @@ pub enum ProjectionElem<V, T> {
/// 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.
Expand Down Expand Up @@ -1861,7 +1861,7 @@ impl<'tcx> Copy for PlaceElem<'tcx> {}

// At least on 64 bit systems, `PlaceElem` should not be larger than two pointers.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR seems to make this comment out of date?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm changing it, I haven't pushed it yet

#[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`.
Expand Down Expand Up @@ -2496,7 +2496,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))
}

Expand Down Expand Up @@ -2542,7 +2542,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
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1595,8 +1595,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
desired_action: InitializationRequiringAction,
place_span: (PlaceRef<'tcx>, Span),
maybe_uninits: &BitSet<MovePathIndex>,
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;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary parens.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tcx.mk_array(inner, (to - from))
tcx.mk_array(inner, to - from)

}
ty::Slice(..) => {
assert!(from_end, "slice subslices should use from_end");
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/transform/elaborate_drops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ impl<'a, 'b, 'tcx> DropElaborator<'a, 'tcx> for Elaborator<'a, 'b, 'tcx> {
})
}

fn array_subpath(&self, path: Self::Path, index: u32, size: u32) -> Option<Self::Path> {
fn array_subpath(&self, path: Self::Path, index: u64, size: u64) -> Option<Self::Path> {
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");
debug_assert!(size == *min_length as u64, "min_length should be exact for arrays");
assert!(!from_end, "from_end should not be used for array element ConstantIndex");
*offset == index
}
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_mir/util/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Comment on lines +55 to 56
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK this dance isn't needed anymore, since usize is at most u64 currently, but cc @RalfJung who removed a bunch of as casts from miri recently.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use u64::try_from(...).unwrap() instead of a manual assert_eq!.

I changed Size::from_bytes so that it does the (checked) cast itself, but here it looks like we need it for ConstantIndex and I didn't touch that.

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,
},
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/util/elaborate_drops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub trait DropElaborator<'a, 'tcx>: fmt::Debug {
fn field_subpath(&self, path: Self::Path, field: Field) -> Option<Self::Path>;
fn deref_subpath(&self, path: Self::Path) -> Option<Self::Path>;
fn downcast_subpath(&self, path: Self::Path, variant: VariantIdx) -> Option<Self::Path>;
fn array_subpath(&self, path: Self::Path, index: u32, size: u32) -> Option<Self::Path>;
fn array_subpath(&self, path: Self::Path, index: u64, size: u64) -> Option<Self::Path>;
}

#[derive(Debug)]
Expand Down Expand Up @@ -675,8 +675,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<D::Path>)> = (0..size)
.map(|i| {
Expand Down