Skip to content

Commit aa91716

Browse files
committed
add new rval, pull deref early
1 parent a25b131 commit aa91716

38 files changed

+251
-101
lines changed

compiler/rustc_borrowck/src/invalidation.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ impl<'cx, 'tcx> InvalidationGenerator<'cx, 'tcx> {
289289
| Rvalue::ShallowInitBox(ref operand, _ /*ty*/) => {
290290
self.consume_operand(location, operand)
291291
}
292+
Rvalue::VirtualRef(ref place) => {
293+
let op = &Operand::Copy(*place);
294+
self.consume_operand(location, op);
295+
}
292296

293297
Rvalue::Len(place) | Rvalue::Discriminant(place) => {
294298
let af = match *rvalue {

compiler/rustc_borrowck/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,23 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
12241224
| Rvalue::ShallowInitBox(ref operand, _ /*ty*/) => {
12251225
self.consume_operand(location, (operand, span), flow_state)
12261226
}
1227+
Rvalue::VirtualRef(place) => {
1228+
self.access_place(
1229+
location,
1230+
(place, span),
1231+
(Deep, Read(ReadKind::Copy)),
1232+
LocalMutationIsAllowed::No,
1233+
flow_state,
1234+
);
1235+
1236+
// Finally, check if path was already moved.
1237+
self.check_if_path_or_subpath_is_moved(
1238+
location,
1239+
InitializationRequiringAction::Use,
1240+
(place.as_ref(), span),
1241+
flow_state,
1242+
);
1243+
}
12271244

12281245
Rvalue::Len(place) | Rvalue::Discriminant(place) => {
12291246
let af = match *rvalue {

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,6 +2274,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
22742274
Rvalue::Use(operand) | Rvalue::UnaryOp(_, operand) => {
22752275
self.check_operand(operand, location);
22762276
}
2277+
Rvalue::VirtualRef(place) => {
2278+
let op = &Operand::Copy(*place);
2279+
self.check_operand(op, location);
2280+
}
22772281

22782282
Rvalue::BinaryOp(_, box (left, right))
22792283
| Rvalue::CheckedBinaryOp(_, box (left, right)) => {
@@ -2304,6 +2308,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
23042308
| Rvalue::BinaryOp(..)
23052309
| Rvalue::CheckedBinaryOp(..)
23062310
| Rvalue::NullaryOp(..)
2311+
| Rvalue::VirtualRef(..)
23072312
| Rvalue::UnaryOp(..)
23082313
| Rvalue::Discriminant(..) => None,
23092314

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,11 @@ fn codegen_stmt<'tcx>(
503503
let val = codegen_operand(fx, operand);
504504
lval.write_cvalue(fx, val);
505505
}
506+
Rvalue::VirtualRef(place) => {
507+
let cplace = codegen_place(fx, place);
508+
let val = cplace.to_cvalue(fx);
509+
lval.write_cvalue(fx, val)
510+
}
506511
Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => {
507512
let place = codegen_place(fx, place);
508513
let ref_ = place.place_ref(fx, lval.layout());

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::traits::*;
88
use crate::MemFlags;
99

1010
use rustc_middle::mir;
11+
use rustc_middle::mir::Operand;
1112
use rustc_middle::ty::cast::{CastTy, IntTy};
1213
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf};
1314
use rustc_middle::ty::{self, adjustment::PointerCast, Instance, Ty, TyCtxt};
@@ -401,6 +402,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
401402
self.codegen_place_to_pointer(bx, place, mk_ref)
402403
}
403404

405+
mir::Rvalue::VirtualRef(place) => {
406+
let operand = self.codegen_operand(&mut bx, &Operand::Copy(place));
407+
(bx, operand)
408+
}
404409
mir::Rvalue::AddressOf(mutability, place) => {
405410
let mk_ptr = move |tcx: TyCtxt<'tcx>, ty: Ty<'tcx>| {
406411
tcx.mk_ptr(ty::TypeAndMut { ty, mutbl: mutability })
@@ -755,6 +760,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
755760
pub fn rvalue_creates_operand(&self, rvalue: &mir::Rvalue<'tcx>, span: Span) -> bool {
756761
match *rvalue {
757762
mir::Rvalue::Ref(..) |
763+
mir::Rvalue::VirtualRef(..) |
758764
mir::Rvalue::AddressOf(..) |
759765
mir::Rvalue::Len(..) |
760766
mir::Rvalue::Cast(..) | // (*)

compiler/rustc_const_eval/src/interpret/step.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
172172
self.copy_op(&op, &dest)?;
173173
}
174174

175+
VirtualRef(ref place) => {
176+
let op = self.eval_place_to_op(*place, Some(dest.layout))?;
177+
self.copy_op(&op, &dest)?;
178+
}
179+
175180
BinaryOp(bin_op, box (ref left, ref right)) => {
176181
let layout = binop_left_homogeneous(bin_op).then_some(dest.layout);
177182
let left = self.read_immediate(&self.eval_operand(left, layout)?)?;

compiler/rustc_const_eval/src/transform/check_consts/check.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
445445
Rvalue::ThreadLocalRef(_) => self.check_op(ops::ThreadLocalAccess),
446446

447447
Rvalue::Use(_)
448+
| Rvalue::VirtualRef(..)
448449
| Rvalue::Repeat(..)
449450
| Rvalue::Discriminant(..)
450451
| Rvalue::Len(_)

compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ where
260260
in_place::<Q, _>(cx, in_local, place.as_ref())
261261
}
262262

263+
Rvalue::VirtualRef(place) => in_place::<Q, _>(cx, in_local, place.as_ref()),
264+
263265
Rvalue::Use(operand)
264266
| Rvalue::Repeat(operand, _)
265267
| Rvalue::UnaryOp(_, operand)

compiler/rustc_const_eval/src/transform/check_consts/resolver.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ where
199199
mir::Rvalue::Cast(..)
200200
| mir::Rvalue::ShallowInitBox(..)
201201
| mir::Rvalue::Use(..)
202+
| mir::Rvalue::VirtualRef(..)
202203
| mir::Rvalue::ThreadLocalRef(..)
203204
| mir::Rvalue::Repeat(..)
204205
| mir::Rvalue::Len(..)

compiler/rustc_const_eval/src/transform/promote_consts.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,10 @@ impl<'tcx> Validator<'_, 'tcx> {
494494
Rvalue::Use(operand) | Rvalue::Repeat(operand, _) => {
495495
self.validate_operand(operand)?;
496496
}
497+
Rvalue::VirtualRef(place) => {
498+
let op = &Operand::Copy(*place);
499+
self.validate_operand(op)?
500+
}
497501

498502
Rvalue::Discriminant(place) | Rvalue::Len(place) => {
499503
self.validate_place(place.as_ref())?

0 commit comments

Comments
 (0)