Skip to content

Commit 42bd138

Browse files
committed
Auto merge of #98145 - ouz-a:some_branch, r=oli-obk
Pull Derefer before ElaborateDrops _Follow up work to #97025 #96549 #96116 #95887 #95649_ This moves `Derefer` before `ElaborateDrops` and creates a new `Rvalue` called `VirtualRef` that allows us to bypass many constraints for `DerefTemp`. r? `@oli-obk`
2 parents ca4e394 + b4c3a2a commit 42bd138

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+401
-227
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::CopyForDeref(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
@@ -1236,6 +1236,23 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
12361236
| Rvalue::ShallowInitBox(ref operand, _ /*ty*/) => {
12371237
self.consume_operand(location, (operand, span), flow_state)
12381238
}
1239+
Rvalue::CopyForDeref(place) => {
1240+
self.access_place(
1241+
location,
1242+
(place, span),
1243+
(Deep, Read(ReadKind::Copy)),
1244+
LocalMutationIsAllowed::No,
1245+
flow_state,
1246+
);
1247+
1248+
// Finally, check if path was already moved.
1249+
self.check_if_path_or_subpath_is_moved(
1250+
location,
1251+
InitializationRequiringAction::Use,
1252+
(place.as_ref(), span),
1253+
flow_state,
1254+
);
1255+
}
12391256

12401257
Rvalue::Len(place) | Rvalue::Discriminant(place) => {
12411258
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
@@ -2269,6 +2269,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
22692269
Rvalue::Use(operand) | Rvalue::UnaryOp(_, operand) => {
22702270
self.check_operand(operand, location);
22712271
}
2272+
Rvalue::CopyForDeref(place) => {
2273+
let op = &Operand::Copy(*place);
2274+
self.check_operand(op, location);
2275+
}
22722276

22732277
Rvalue::BinaryOp(_, box (left, right))
22742278
| Rvalue::CheckedBinaryOp(_, box (left, right)) => {
@@ -2299,6 +2303,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
22992303
| Rvalue::BinaryOp(..)
23002304
| Rvalue::CheckedBinaryOp(..)
23012305
| Rvalue::NullaryOp(..)
2306+
| Rvalue::CopyForDeref(..)
23022307
| Rvalue::UnaryOp(..)
23032308
| Rvalue::Discriminant(..) => None,
23042309

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::CopyForDeref(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};
@@ -344,6 +345,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
344345
self.codegen_place_to_pointer(bx, place, mk_ref)
345346
}
346347

348+
mir::Rvalue::CopyForDeref(place) => {
349+
let operand = self.codegen_operand(&mut bx, &Operand::Copy(place));
350+
(bx, operand)
351+
}
347352
mir::Rvalue::AddressOf(mutability, place) => {
348353
let mk_ptr = move |tcx: TyCtxt<'tcx>, ty: Ty<'tcx>| {
349354
tcx.mk_ptr(ty::TypeAndMut { ty, mutbl: mutability })
@@ -698,6 +703,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
698703
pub fn rvalue_creates_operand(&self, rvalue: &mir::Rvalue<'tcx>, span: Span) -> bool {
699704
match *rvalue {
700705
mir::Rvalue::Ref(..) |
706+
mir::Rvalue::CopyForDeref(..) |
701707
mir::Rvalue::AddressOf(..) |
702708
mir::Rvalue::Len(..) |
703709
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, /*allow_transmute*/ false)?;
173173
}
174174

175+
CopyForDeref(ref place) => {
176+
let op = self.eval_place_to_op(*place, Some(dest.layout))?;
177+
self.copy_op(&op, &dest, /* allow_transmute*/ false)?;
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
@@ -446,6 +446,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
446446
Rvalue::ThreadLocalRef(_) => self.check_op(ops::ThreadLocalAccess),
447447

448448
Rvalue::Use(_)
449+
| Rvalue::CopyForDeref(..)
449450
| Rvalue::Repeat(..)
450451
| Rvalue::Discriminant(..)
451452
| 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::CopyForDeref(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::CopyForDeref(..)
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::CopyForDeref(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)