Skip to content

Commit

Permalink
Clean up todos
Browse files Browse the repository at this point in the history
Also add some span_bugs where it is unreachable
  • Loading branch information
JulianKnodt committed Mar 9, 2021
1 parent 217ff6b commit 4bceb29
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 78 deletions.
1 change: 0 additions & 1 deletion compiler/rustc_codegen_cranelift/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#![warn(rust_2018_idioms)]
#![warn(unused_lifetimes)]
#![warn(unreachable_pub)]
#![feature(box_patterns)]

extern crate snap;
#[macro_use]
Expand Down
15 changes: 4 additions & 11 deletions compiler/rustc_mir/src/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,18 +629,11 @@ impl<'cx, 'tcx> dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tc

StatementKind::CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping {
..
/*
src,
dst,
count,
*/
}) => {
unreachable!()
/*
self.consume_operand(location, (src, span), flow_state);
self.consume_operand(location, (dst, span), flow_state);
self.consume_operand(location, (count, span), flow_state);
*/
span_bug!(
span,
"Unexpected CopyNonOverlapping, should only appear after lower_intrinsics",
)
}
StatementKind::Nop
| StatementKind::Coverage(..)
Expand Down
39 changes: 5 additions & 34 deletions compiler/rustc_mir/src/borrow_check/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1521,40 +1521,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}
}
StatementKind::CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping {
ref src,
ref dst,
ref count,
}) => {
let op_src_ty = self.normalize(src.ty(body, self.tcx()), location);
let op_dst_ty = self.normalize(dst.ty(body, self.tcx()), location);
// since CopyNonOverlapping is parametrized by 1 type,
// we only need to check that they are equal and not keep an extra parameter.
if let Err(terr) = self.eq_types(
op_src_ty,
op_dst_ty,
location.to_locations(),
ConstraintCategory::Internal,
) {
span_mirbug!(
self,
stmt,
"bad arg ({:?} != {:?}): {:?}",
op_src_ty,
op_dst_ty,
terr
);
}

let op_cnt_ty = self.normalize(count.ty(body, self.tcx()), location);
if let Err(terr) = self.eq_types(
op_cnt_ty,
tcx.types.usize,
location.to_locations(),
ConstraintCategory::Internal,
) {
span_mirbug!(self, stmt, "bad arg ({:?} != usize): {:?}", op_cnt_ty, terr);
}
}
..
}) => span_bug!(
stmt.source_info.span,
"Unexpected StatementKind::CopyNonOverlapping, should only appear after lowering_intrinsics",
),
StatementKind::FakeRead(..)
| StatementKind::StorageLive(..)
| StatementKind::StorageDead(..)
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_mir/src/dataflow/impls/borrows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,8 @@ impl<'tcx> dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
| mir::StatementKind::Retag { .. }
| mir::StatementKind::AscribeUserType(..)
| mir::StatementKind::Coverage(..)
| mir::StatementKind::CopyNonOverlapping(..)
| mir::StatementKind::Nop => {}

mir::StatementKind::CopyNonOverlapping(..) => todo!(),
}
}

Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_mir/src/dataflow/impls/storage_liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,8 @@ impl<'mir, 'tcx> dataflow::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'mir,
| StatementKind::FakeRead(..)
| StatementKind::Nop
| StatementKind::Retag(..)
| StatementKind::CopyNonOverlapping(..)
| StatementKind::StorageLive(..) => {}

StatementKind::CopyNonOverlapping(..) => todo!(),
}
}

Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_mir/src/dataflow/move_paths/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,8 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
StatementKind::Retag { .. }
| StatementKind::AscribeUserType(..)
| StatementKind::Coverage(..)
| StatementKind::CopyNonOverlapping(..)
| StatementKind::Nop => {}

StatementKind::CopyNonOverlapping(..) => todo!(),
}
}

Expand Down
20 changes: 1 addition & 19 deletions compiler/rustc_mir/src/interpret/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,26 +323,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
let result = Scalar::from_uint(truncated_bits, layout.size);
self.write_scalar(result, dest)?;
}
sym::copy_nonoverlapping => {
self.copy_nonoverlapping(args[0], args[1], args[2])?;
}
sym::copy => {
let elem_ty = instance.substs.type_at(0);
let elem_layout = self.layout_of(elem_ty)?;
let count = self.read_scalar(&args[2])?.to_machine_usize(self)?;
let elem_align = elem_layout.align.abi;

let size = elem_layout.size.checked_mul(count, self).ok_or_else(|| {
err_ub_format!("overflow computing total size of `{}`", intrinsic_name)
})?;
let src = self.read_scalar(&args[0])?.check_init()?;
let src = self.memory.check_ptr_access(src, size, elem_align)?;
let dest = self.read_scalar(&args[1])?.check_init()?;
let dest = self.memory.check_ptr_access(dest, size, elem_align)?;

if let (Some(src), Some(dest)) = (src, dest) {
self.memory.copy(src, dest, size, false)?;
}
self.copy(&args[0], &args[1], &args[2], /*nonoverlapping*/ false)?;
}
sym::offset => {
let ptr = self.read_scalar(&args[0])?.check_init()?;
Expand Down
13 changes: 7 additions & 6 deletions compiler/rustc_mir/src/interpret/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {

let src = self.eval_operand(src, None)?;
let dst = self.eval_operand(dst, None)?;
self.copy_nonoverlapping(src, dst, count)?;
self.copy(&src, &dst, &count, /* nonoverlapping */ true)?;
}

// Statements we do not track.
Expand Down Expand Up @@ -150,11 +150,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
Ok(())
}

pub(crate) fn copy_nonoverlapping(
pub(crate) fn copy(
&mut self,
src: OpTy<'tcx, <M as Machine<'mir, 'tcx>>::PointerTag>,
dst: OpTy<'tcx, <M as Machine<'mir, 'tcx>>::PointerTag>,
count: OpTy<'tcx, <M as Machine<'mir, 'tcx>>::PointerTag>,
src: &OpTy<'tcx, <M as Machine<'mir, 'tcx>>::PointerTag>,
dst: &OpTy<'tcx, <M as Machine<'mir, 'tcx>>::PointerTag>,
count: &OpTy<'tcx, <M as Machine<'mir, 'tcx>>::PointerTag>,
nonoverlapping: bool,
) -> InterpResult<'tcx> {
let count = self.read_scalar(&count)?.to_machine_usize(self)?;
let layout = self.layout_of(src.layout.ty.builtin_deref(true).unwrap().ty)?;
Expand All @@ -170,7 +171,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
})?;

if let (Some(src), Some(dst)) = (src, dst) {
self.memory.copy(src, dst, size, /*nonoverlapping*/ true)?;
self.memory.copy(src, dst, size, nonoverlapping)?;
}
Ok(())
}
Expand Down
44 changes: 43 additions & 1 deletion compiler/rustc_mir/src/transform/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,49 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
);
}
}
_ => {}
StatementKind::CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping {
ref src,
ref dst,
ref count,
}) => {
let src_ty = src.ty(&self.body.local_decls, self.tcx);
let op_src_ty = if let Some(src_deref) = src_ty.builtin_deref(true) {
src_deref.ty
} else {
self.fail(
location,
format!("Expected src to be ptr in copy_nonoverlapping, got: {}", src_ty),
);
return;
};
let dst_ty = dst.ty(&self.body.local_decls, self.tcx);
let op_dst_ty = if let Some(dst_deref) = dst_ty.builtin_deref(true) {
dst_deref.ty
} else {
self.fail(
location,
format!("Expected dst to be ptr in copy_nonoverlapping, got: {}", dst_ty),
);
return;
};
// since CopyNonOverlapping is parametrized by 1 type,
// we only need to check that they are equal and not keep an extra parameter.
if op_src_ty != op_dst_ty {
self.fail(location, format!("bad arg ({:?} != {:?})", op_src_ty, op_dst_ty));
}

let op_cnt_ty = count.ty(&self.body.local_decls, self.tcx);
if op_cnt_ty != self.tcx.types.usize {
self.fail(location, format!("bad arg ({:?} != usize)", op_cnt_ty))
}
}
StatementKind::SetDiscriminant { .. }
| StatementKind::StorageLive(..)
| StatementKind::StorageDead(..)
| StatementKind::LlvmInlineAsm(..)
| StatementKind::Retag(_, _)
| StatementKind::Coverage(_)
| StatementKind::Nop => {}
}

self.super_statement(statement, location);
Expand Down

0 comments on commit 4bceb29

Please sign in to comment.