Skip to content

Commit 5aba3da

Browse files
committed
Update match branches
This updates all places where match branches check on StatementKind or UseContext. This doesn't properly implement them, but adds TODOs where they are, and also adds some best guesses to what they should be in some cases.
1 parent a058d44 commit 5aba3da

File tree

19 files changed

+1346
-24
lines changed

19 files changed

+1346
-24
lines changed

compiler/rustc_codegen_ssa/src/mir/analyze.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,17 +293,15 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
293293
| MutatingUseContext::AsmOutput
294294
| MutatingUseContext::Borrow
295295
| MutatingUseContext::AddressOf
296-
| MutatingUseContext::Projection
297-
| MutatingUseContext::CopyNonOverlapping,
296+
| MutatingUseContext::Projection,
298297
)
299298
| PlaceContext::NonMutatingUse(
300299
NonMutatingUseContext::Inspect
301300
| NonMutatingUseContext::SharedBorrow
302301
| NonMutatingUseContext::UniqueBorrow
303302
| NonMutatingUseContext::ShallowBorrow
304303
| NonMutatingUseContext::AddressOf
305-
| NonMutatingUseContext::Projection
306-
| NonMutatingUseContext::CopyNonOverlapping,
304+
| NonMutatingUseContext::Projection,
307305
) => {
308306
self.not_ssa(local);
309307
}

compiler/rustc_codegen_ssa/src/mir/statement.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,22 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
120120
ref dst,
121121
ref size,
122122
}) => {
123-
let dst_val = self.codegen_place(&mut bx, dst.as_ref());
124-
let src_val = self.codegen_place(&mut bx, src.as_ref());
123+
let dst_val = self.codegen_operand(&mut bx, dst);
124+
let src_val = self.codegen_operand(&mut bx, src);
125125
let size_val = self.codegen_operand(&mut bx, size);
126126
let size = size_val.immediate_or_packed_pair(&mut bx);
127+
let dst = dst_val.immediate_or_packed_pair(&mut bx);
128+
let src = src_val.immediate_or_packed_pair(&mut bx);
129+
use crate::MemFlags;
130+
let flags =
131+
(!MemFlags::UNALIGNED) & (!MemFlags::VOLATILE) & (!MemFlags::NONTEMPORAL);
127132
bx.memcpy(
128-
dst_val.llval,
129-
dst_val.align,
130-
src_val.llval,
131-
src_val.align,
133+
dst,
134+
dst_val.layout.layout.align.pref,
135+
src,
136+
src_val.layout.layout.align.pref,
132137
size,
133-
// TODO probably want to have this change based on alignment above?
134-
crate::MemFlags::empty(),
138+
flags,
135139
);
136140
bx
137141
}

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,7 @@ impl Debug for Statement<'_> {
16421642
ref src,
16431643
ref dst,
16441644
ref size,
1645-
}) => write!(fmt, "copy_nonoverlapping(src={:?}, dst={:?},bytes={:?})", src, dst, size),
1645+
}) => write!(fmt, "copy_nonoverlapping(src={:?}, dst={:?}, size={:?})", src, dst, size),
16461646
Nop => write!(fmt, "nop"),
16471647
}
16481648
}
@@ -1656,8 +1656,8 @@ pub struct Coverage {
16561656

16571657
#[derive(Clone, Debug, PartialEq, TyEncodable, TyDecodable, HashStable, TypeFoldable)]
16581658
pub struct CopyNonOverlapping<'tcx> {
1659-
pub src: Place<'tcx>,
1660-
pub dst: Place<'tcx>,
1659+
pub src: Operand<'tcx>,
1660+
pub dst: Operand<'tcx>,
16611661
pub size: Operand<'tcx>,
16621662
}
16631663

compiler/rustc_middle/src/mir/visit.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -439,14 +439,12 @@ macro_rules! make_mir_visitor {
439439
ref $($mutability)? dst,
440440
ref $($mutability)? size,
441441
}) => {
442-
self.visit_place(
442+
self.visit_operand(
443443
src,
444-
PlaceContext::NonMutatingUse(NonMutatingUseContext::CopyNonOverlapping),
445444
location
446445
);
447-
self.visit_place(
446+
self.visit_operand(
448447
dst,
449-
PlaceContext::MutatingUse(MutatingUseContext::CopyNonOverlapping),
450448
location
451449
);
452450
self.visit_operand(size, location)
@@ -1166,8 +1164,6 @@ pub enum NonMutatingUseContext {
11661164
/// f(&x.y);
11671165
///
11681166
Projection,
1169-
/// Source from copy_nonoverlapping.
1170-
CopyNonOverlapping,
11711167
}
11721168

11731169
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
@@ -1197,8 +1193,6 @@ pub enum MutatingUseContext {
11971193
Projection,
11981194
/// Retagging, a "Stacked Borrows" shadow state operation
11991195
Retag,
1200-
/// Memory written to in copy_nonoverlapping.
1201-
CopyNonOverlapping,
12021196
}
12031197

12041198
#[derive(Copy, Clone, Debug, PartialEq, Eq)]

compiler/rustc_mir/src/borrow_check/invalidation.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,21 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
9292
self.consume_operand(location, input);
9393
}
9494
}
95+
StatementKind::CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping {
96+
ref src,
97+
ref dst,
98+
ref size,
99+
}) => {
100+
self.consume_operand(location, src);
101+
self.consume_operand(location, dst);
102+
self.consume_operand(location, size);
103+
match dst {
104+
Operand::Move(ref place) | Operand::Copy(ref place) => {
105+
self.mutate_place(location, *place, Deep, JustWrite);
106+
}
107+
_ => {}
108+
}
109+
}
95110
StatementKind::Nop
96111
| StatementKind::Coverage(..)
97112
| StatementKind::AscribeUserType(..)

compiler/rustc_mir/src/borrow_check/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,8 @@ impl<'cx, 'tcx> dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tc
626626
self.consume_operand(location, (input, span), flow_state);
627627
}
628628
}
629+
630+
StatementKind::CopyNonOverlapping(..) => todo!(),
629631
StatementKind::Nop
630632
| StatementKind::Coverage(..)
631633
| StatementKind::AscribeUserType(..)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,6 +1520,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
15201520
);
15211521
}
15221522
}
1523+
StatementKind::CopyNonOverlapping(..) => todo!(),
15231524
StatementKind::FakeRead(..)
15241525
| StatementKind::StorageLive(..)
15251526
| StatementKind::StorageDead(..)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ impl<'tcx> dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
306306
| mir::StatementKind::AscribeUserType(..)
307307
| mir::StatementKind::Coverage(..)
308308
| mir::StatementKind::Nop => {}
309+
310+
mir::StatementKind::CopyNonOverlapping(..) => todo!(),
309311
}
310312
}
311313

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ impl<'mir, 'tcx> dataflow::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'mir,
150150
| StatementKind::Nop
151151
| StatementKind::Retag(..)
152152
| StatementKind::StorageLive(..) => {}
153+
154+
StatementKind::CopyNonOverlapping(..) => todo!(),
153155
}
154156
}
155157

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
319319
| StatementKind::AscribeUserType(..)
320320
| StatementKind::Coverage(..)
321321
| StatementKind::Nop => {}
322+
323+
StatementKind::CopyNonOverlapping(..) => todo!(),
322324
}
323325
}
324326

compiler/rustc_mir/src/interpret/step.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,23 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
113113
M::retag(self, *kind, &dest)?;
114114
}
115115

116+
// Call CopyNonOverlapping
117+
CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping { dst, src, size }) => {
118+
let size = self.eval_operand(size, None)?;
119+
120+
let dst = {
121+
let dst = self.eval_operand(dst, None)?;
122+
dst.assert_mem_place(self)
123+
};
124+
let src = {
125+
let src = self.eval_operand(src, None)?;
126+
src.assert_mem_place(self)
127+
};
128+
// Not sure how to convert an MPlaceTy<'_, <M as Machine<'_, '_>>::PointerTag>
129+
// to a pointer, or OpTy to a size
130+
self.memory.copy(src, dst, size, /*nonoverlapping*/ true)?;
131+
}
132+
116133
// Statements we do not track.
117134
AscribeUserType(..) => {}
118135

compiler/rustc_mir/src/transform/check_consts/validation.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
808808
| StatementKind::Retag { .. }
809809
| StatementKind::AscribeUserType(..)
810810
| StatementKind::Coverage(..)
811+
| StatementKind::CopyNonOverlapping(..)
811812
| StatementKind::Nop => {}
812813
}
813814
}

compiler/rustc_mir/src/transform/check_unsafety.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
115115
| StatementKind::Retag { .. }
116116
| StatementKind::AscribeUserType(..)
117117
| StatementKind::Coverage(..)
118+
| StatementKind::CopyNonOverlapping(..)
118119
| StatementKind::Nop => {
119120
// safe (at least as emitted during MIR construction)
120121
}

compiler/rustc_mir/src/transform/dest_prop.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ impl Conflicts<'a> {
582582
| StatementKind::FakeRead(..)
583583
| StatementKind::AscribeUserType(..)
584584
| StatementKind::Coverage(..)
585+
| StatementKind::CopyNonOverlapping(..)
585586
| StatementKind::Nop => {}
586587
}
587588
}

compiler/rustc_mir/src/transform/generator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,7 @@ impl Visitor<'tcx> for EnsureGeneratorFieldAssignmentsNeverAlias<'_> {
14531453
| StatementKind::Retag(..)
14541454
| StatementKind::AscribeUserType(..)
14551455
| StatementKind::Coverage(..)
1456+
| StatementKind::CopyNonOverlapping(..)
14561457
| StatementKind::Nop => {}
14571458
}
14581459
}

0 commit comments

Comments
 (0)