Skip to content

Commit 4bceb29

Browse files
committed
Clean up todos
Also add some span_bugs where it is unreachable
1 parent 217ff6b commit 4bceb29

File tree

9 files changed

+63
-78
lines changed

9 files changed

+63
-78
lines changed

compiler/rustc_codegen_cranelift/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#![warn(rust_2018_idioms)]
1212
#![warn(unused_lifetimes)]
1313
#![warn(unreachable_pub)]
14-
#![feature(box_patterns)]
1514

1615
extern crate snap;
1716
#[macro_use]

compiler/rustc_mir/src/borrow_check/mod.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -629,18 +629,11 @@ impl<'cx, 'tcx> dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tc
629629

630630
StatementKind::CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping {
631631
..
632-
/*
633-
src,
634-
dst,
635-
count,
636-
*/
637632
}) => {
638-
unreachable!()
639-
/*
640-
self.consume_operand(location, (src, span), flow_state);
641-
self.consume_operand(location, (dst, span), flow_state);
642-
self.consume_operand(location, (count, span), flow_state);
643-
*/
633+
span_bug!(
634+
span,
635+
"Unexpected CopyNonOverlapping, should only appear after lower_intrinsics",
636+
)
644637
}
645638
StatementKind::Nop
646639
| StatementKind::Coverage(..)

compiler/rustc_mir/src/borrow_check/type_check/mod.rs

+5-34
Original file line numberDiff line numberDiff line change
@@ -1521,40 +1521,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
15211521
}
15221522
}
15231523
StatementKind::CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping {
1524-
ref src,
1525-
ref dst,
1526-
ref count,
1527-
}) => {
1528-
let op_src_ty = self.normalize(src.ty(body, self.tcx()), location);
1529-
let op_dst_ty = self.normalize(dst.ty(body, self.tcx()), location);
1530-
// since CopyNonOverlapping is parametrized by 1 type,
1531-
// we only need to check that they are equal and not keep an extra parameter.
1532-
if let Err(terr) = self.eq_types(
1533-
op_src_ty,
1534-
op_dst_ty,
1535-
location.to_locations(),
1536-
ConstraintCategory::Internal,
1537-
) {
1538-
span_mirbug!(
1539-
self,
1540-
stmt,
1541-
"bad arg ({:?} != {:?}): {:?}",
1542-
op_src_ty,
1543-
op_dst_ty,
1544-
terr
1545-
);
1546-
}
1547-
1548-
let op_cnt_ty = self.normalize(count.ty(body, self.tcx()), location);
1549-
if let Err(terr) = self.eq_types(
1550-
op_cnt_ty,
1551-
tcx.types.usize,
1552-
location.to_locations(),
1553-
ConstraintCategory::Internal,
1554-
) {
1555-
span_mirbug!(self, stmt, "bad arg ({:?} != usize): {:?}", op_cnt_ty, terr);
1556-
}
1557-
}
1524+
..
1525+
}) => span_bug!(
1526+
stmt.source_info.span,
1527+
"Unexpected StatementKind::CopyNonOverlapping, should only appear after lowering_intrinsics",
1528+
),
15581529
StatementKind::FakeRead(..)
15591530
| StatementKind::StorageLive(..)
15601531
| StatementKind::StorageDead(..)

compiler/rustc_mir/src/dataflow/impls/borrows.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,8 @@ impl<'tcx> dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
305305
| mir::StatementKind::Retag { .. }
306306
| mir::StatementKind::AscribeUserType(..)
307307
| mir::StatementKind::Coverage(..)
308+
| mir::StatementKind::CopyNonOverlapping(..)
308309
| mir::StatementKind::Nop => {}
309-
310-
mir::StatementKind::CopyNonOverlapping(..) => todo!(),
311310
}
312311
}
313312

compiler/rustc_mir/src/dataflow/impls/storage_liveness.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,8 @@ impl<'mir, 'tcx> dataflow::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'mir,
149149
| StatementKind::FakeRead(..)
150150
| StatementKind::Nop
151151
| StatementKind::Retag(..)
152+
| StatementKind::CopyNonOverlapping(..)
152153
| StatementKind::StorageLive(..) => {}
153-
154-
StatementKind::CopyNonOverlapping(..) => todo!(),
155154
}
156155
}
157156

compiler/rustc_mir/src/dataflow/move_paths/builder.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,8 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
318318
StatementKind::Retag { .. }
319319
| StatementKind::AscribeUserType(..)
320320
| StatementKind::Coverage(..)
321+
| StatementKind::CopyNonOverlapping(..)
321322
| StatementKind::Nop => {}
322-
323-
StatementKind::CopyNonOverlapping(..) => todo!(),
324323
}
325324
}
326325

compiler/rustc_mir/src/interpret/intrinsics.rs

+1-19
Original file line numberDiff line numberDiff line change
@@ -323,26 +323,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
323323
let result = Scalar::from_uint(truncated_bits, layout.size);
324324
self.write_scalar(result, dest)?;
325325
}
326-
sym::copy_nonoverlapping => {
327-
self.copy_nonoverlapping(args[0], args[1], args[2])?;
328-
}
329326
sym::copy => {
330-
let elem_ty = instance.substs.type_at(0);
331-
let elem_layout = self.layout_of(elem_ty)?;
332-
let count = self.read_scalar(&args[2])?.to_machine_usize(self)?;
333-
let elem_align = elem_layout.align.abi;
334-
335-
let size = elem_layout.size.checked_mul(count, self).ok_or_else(|| {
336-
err_ub_format!("overflow computing total size of `{}`", intrinsic_name)
337-
})?;
338-
let src = self.read_scalar(&args[0])?.check_init()?;
339-
let src = self.memory.check_ptr_access(src, size, elem_align)?;
340-
let dest = self.read_scalar(&args[1])?.check_init()?;
341-
let dest = self.memory.check_ptr_access(dest, size, elem_align)?;
342-
343-
if let (Some(src), Some(dest)) = (src, dest) {
344-
self.memory.copy(src, dest, size, false)?;
345-
}
327+
self.copy(&args[0], &args[1], &args[2], /*nonoverlapping*/ false)?;
346328
}
347329
sym::offset => {
348330
let ptr = self.read_scalar(&args[0])?.check_init()?;

compiler/rustc_mir/src/interpret/step.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
120120

121121
let src = self.eval_operand(src, None)?;
122122
let dst = self.eval_operand(dst, None)?;
123-
self.copy_nonoverlapping(src, dst, count)?;
123+
self.copy(&src, &dst, &count, /* nonoverlapping */ true)?;
124124
}
125125

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

153-
pub(crate) fn copy_nonoverlapping(
153+
pub(crate) fn copy(
154154
&mut self,
155-
src: OpTy<'tcx, <M as Machine<'mir, 'tcx>>::PointerTag>,
156-
dst: OpTy<'tcx, <M as Machine<'mir, 'tcx>>::PointerTag>,
157-
count: OpTy<'tcx, <M as Machine<'mir, 'tcx>>::PointerTag>,
155+
src: &OpTy<'tcx, <M as Machine<'mir, 'tcx>>::PointerTag>,
156+
dst: &OpTy<'tcx, <M as Machine<'mir, 'tcx>>::PointerTag>,
157+
count: &OpTy<'tcx, <M as Machine<'mir, 'tcx>>::PointerTag>,
158+
nonoverlapping: bool,
158159
) -> InterpResult<'tcx> {
159160
let count = self.read_scalar(&count)?.to_machine_usize(self)?;
160161
let layout = self.layout_of(src.layout.ty.builtin_deref(true).unwrap().ty)?;
@@ -170,7 +171,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
170171
})?;
171172

172173
if let (Some(src), Some(dst)) = (src, dst) {
173-
self.memory.copy(src, dst, size, /*nonoverlapping*/ true)?;
174+
self.memory.copy(src, dst, size, nonoverlapping)?;
174175
}
175176
Ok(())
176177
}

compiler/rustc_mir/src/transform/validate.rs

+43-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,49 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
294294
);
295295
}
296296
}
297-
_ => {}
297+
StatementKind::CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping {
298+
ref src,
299+
ref dst,
300+
ref count,
301+
}) => {
302+
let src_ty = src.ty(&self.body.local_decls, self.tcx);
303+
let op_src_ty = if let Some(src_deref) = src_ty.builtin_deref(true) {
304+
src_deref.ty
305+
} else {
306+
self.fail(
307+
location,
308+
format!("Expected src to be ptr in copy_nonoverlapping, got: {}", src_ty),
309+
);
310+
return;
311+
};
312+
let dst_ty = dst.ty(&self.body.local_decls, self.tcx);
313+
let op_dst_ty = if let Some(dst_deref) = dst_ty.builtin_deref(true) {
314+
dst_deref.ty
315+
} else {
316+
self.fail(
317+
location,
318+
format!("Expected dst to be ptr in copy_nonoverlapping, got: {}", dst_ty),
319+
);
320+
return;
321+
};
322+
// since CopyNonOverlapping is parametrized by 1 type,
323+
// we only need to check that they are equal and not keep an extra parameter.
324+
if op_src_ty != op_dst_ty {
325+
self.fail(location, format!("bad arg ({:?} != {:?})", op_src_ty, op_dst_ty));
326+
}
327+
328+
let op_cnt_ty = count.ty(&self.body.local_decls, self.tcx);
329+
if op_cnt_ty != self.tcx.types.usize {
330+
self.fail(location, format!("bad arg ({:?} != usize)", op_cnt_ty))
331+
}
332+
}
333+
StatementKind::SetDiscriminant { .. }
334+
| StatementKind::StorageLive(..)
335+
| StatementKind::StorageDead(..)
336+
| StatementKind::LlvmInlineAsm(..)
337+
| StatementKind::Retag(_, _)
338+
| StatementKind::Coverage(_)
339+
| StatementKind::Nop => {}
298340
}
299341

300342
self.super_statement(statement, location);

0 commit comments

Comments
 (0)