Skip to content

Commit cd9fb54

Browse files
authored
Unrolled build for #146564
Rollup merge of #146564 - cjgillot:mir-nolen, r=scottmcm Remove Rvalue::Len again. Now that we have `RawPtrKind::FakeForPtrMetadata`, we can reimplement `Rvalue::Len` using `PtrMetadata(&raw const (fake) place)`. r? ``@scottmcm``
2 parents ba4b643 + de73af9 commit cd9fb54

File tree

53 files changed

+1381
-292
lines changed

Some content is hidden

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

53 files changed

+1381
-292
lines changed

compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,9 +1557,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
15571557
);
15581558
}
15591559

1560-
&(Rvalue::Len(place) | Rvalue::Discriminant(place)) => {
1560+
&Rvalue::Discriminant(place) => {
15611561
let af = match *rvalue {
1562-
Rvalue::Len(..) => Some(ArtificialField::ArrayLength),
15631562
Rvalue::Discriminant(..) => None,
15641563
_ => unreachable!(),
15651564
};

compiler/rustc_borrowck/src/polonius/legacy/loan_invalidations.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,16 +306,11 @@ impl<'a, 'tcx> LoanInvalidationsGenerator<'a, 'tcx> {
306306
self.consume_operand(location, op);
307307
}
308308

309-
&(Rvalue::Len(place) | Rvalue::Discriminant(place)) => {
310-
let af = match rvalue {
311-
Rvalue::Len(..) => Some(ArtificialField::ArrayLength),
312-
Rvalue::Discriminant(..) => None,
313-
_ => unreachable!(),
314-
};
309+
&Rvalue::Discriminant(place) => {
315310
self.access_place(
316311
location,
317312
place,
318-
(Shallow(af), Read(ReadKind::Copy)),
313+
(Shallow(None), Read(ReadKind::Copy)),
319314
LocalMutationIsAllowed::No,
320315
);
321316
}

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,7 +1631,6 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
16311631
| Rvalue::BinaryOp(..)
16321632
| Rvalue::RawPtr(..)
16331633
| Rvalue::ThreadLocalRef(..)
1634-
| Rvalue::Len(..)
16351634
| Rvalue::Discriminant(..)
16361635
| Rvalue::NullaryOp(NullOp::OffsetOf(..), _) => {}
16371636
}
@@ -2201,7 +2200,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
22012200
| Rvalue::Repeat(..)
22022201
| Rvalue::Ref(..)
22032202
| Rvalue::RawPtr(..)
2204-
| Rvalue::Len(..)
22052203
| Rvalue::Cast(..)
22062204
| Rvalue::ShallowInitBox(..)
22072205
| Rvalue::BinaryOp(..)

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -834,12 +834,6 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
834834
fx.bcx.ins().nop();
835835
}
836836
}
837-
Rvalue::Len(place) => {
838-
let place = codegen_place(fx, place);
839-
let usize_layout = fx.layout_of(fx.tcx.types.usize);
840-
let len = codegen_array_len(fx, place);
841-
lval.write_cvalue(fx, CValue::by_val(len, usize_layout));
842-
}
843837
Rvalue::ShallowInitBox(ref operand, content_ty) => {
844838
let content_ty = fx.monomorphize(content_ty);
845839
let box_layout = fx.layout_of(Ty::new_box(fx.tcx, content_ty));

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use rustc_middle::{bug, mir, span_bug};
77
use rustc_session::config::OptLevel;
88
use tracing::{debug, instrument};
99

10+
use super::FunctionCx;
1011
use super::operand::{OperandRef, OperandRefBuilder, OperandValue};
1112
use super::place::{PlaceRef, PlaceValue, codegen_tag_value};
12-
use super::{FunctionCx, LocalRef};
1313
use crate::common::{IntPredicate, TypeKind};
1414
use crate::traits::*;
1515
use crate::{MemFlags, base};
@@ -510,14 +510,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
510510
self.codegen_place_to_pointer(bx, place, mk_ptr)
511511
}
512512

513-
mir::Rvalue::Len(place) => {
514-
let size = self.evaluate_array_len(bx, place);
515-
OperandRef {
516-
val: OperandValue::Immediate(size),
517-
layout: bx.cx().layout_of(bx.tcx().types.usize),
518-
}
519-
}
520-
521513
mir::Rvalue::BinaryOp(op_with_overflow, box (ref lhs, ref rhs))
522514
if let Some(op) = op_with_overflow.overflowing_to_wrapping() =>
523515
{
@@ -749,21 +741,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
749741
}
750742
}
751743

752-
fn evaluate_array_len(&mut self, bx: &mut Bx, place: mir::Place<'tcx>) -> Bx::Value {
753-
// ZST are passed as operands and require special handling
754-
// because codegen_place() panics if Local is operand.
755-
if let Some(index) = place.as_local()
756-
&& let LocalRef::Operand(op) = self.locals[index]
757-
&& let ty::Array(_, n) = op.layout.ty.kind()
758-
{
759-
let n = n.try_to_target_usize(bx.tcx()).expect("expected monomorphic const in codegen");
760-
return bx.cx().const_usize(n);
761-
}
762-
// use common size calculation for non zero-sized types
763-
let cg_value = self.codegen_place(bx, place.as_ref());
764-
cg_value.len(bx.cx())
765-
}
766-
767744
/// Codegen an `Rvalue::RawPtr` or `Rvalue::Ref`
768745
fn codegen_place_to_pointer(
769746
&mut self,

compiler/rustc_const_eval/src/check_consts/check.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
573573
Rvalue::Use(_)
574574
| Rvalue::CopyForDeref(..)
575575
| Rvalue::Repeat(..)
576-
| Rvalue::Discriminant(..)
577-
| Rvalue::Len(_) => {}
576+
| Rvalue::Discriminant(..) => {}
578577

579578
Rvalue::Aggregate(kind, ..) => {
580579
if let AggregateKind::Coroutine(def_id, ..) = kind.as_ref()

compiler/rustc_const_eval/src/check_consts/qualifs.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,7 @@ where
232232
Q::in_any_value_of_ty(cx, rvalue.ty(cx.body, cx.tcx))
233233
}
234234

235-
Rvalue::Discriminant(place) | Rvalue::Len(place) => {
236-
in_place::<Q, _>(cx, in_local, place.as_ref())
237-
}
235+
Rvalue::Discriminant(place) => in_place::<Q, _>(cx, in_local, place.as_ref()),
238236

239237
Rvalue::CopyForDeref(place) => in_place::<Q, _>(cx, in_local, place.as_ref()),
240238

compiler/rustc_const_eval/src/check_consts/resolver.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ where
197197
| mir::Rvalue::CopyForDeref(..)
198198
| mir::Rvalue::ThreadLocalRef(..)
199199
| mir::Rvalue::Repeat(..)
200-
| mir::Rvalue::Len(..)
201200
| mir::Rvalue::BinaryOp(..)
202201
| mir::Rvalue::NullaryOp(..)
203202
| mir::Rvalue::UnaryOp(..)

compiler/rustc_const_eval/src/interpret/step.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use tracing::{info, instrument, trace};
1717

1818
use super::{
1919
FnArg, FnVal, ImmTy, Immediate, InterpCx, InterpResult, Machine, MemPlaceMeta, PlaceTy,
20-
Projectable, Scalar, interp_ok, throw_ub, throw_unsup_format,
20+
Projectable, interp_ok, throw_ub, throw_unsup_format,
2121
};
2222
use crate::interpret::EnteredTraceSpan;
2323
use crate::{enter_trace_span, util};
@@ -225,12 +225,6 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
225225
self.write_repeat(operand, &dest)?;
226226
}
227227

228-
Len(place) => {
229-
let src = self.eval_place(place)?;
230-
let len = src.len(self)?;
231-
self.write_scalar(Scalar::from_target_usize(len, self), &dest)?;
232-
}
233-
234228
Ref(_, borrow_kind, place) => {
235229
let src = self.eval_place(place)?;
236230
let place = self.force_allocation(&src)?;

compiler/rustc_middle/src/mir/pretty.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,6 @@ impl<'tcx> Debug for Rvalue<'tcx> {
10621062
pretty_print_const(b, fmt, false)?;
10631063
write!(fmt, "]")
10641064
}
1065-
Len(ref a) => write!(fmt, "Len({a:?})"),
10661065
Cast(ref kind, ref place, ref ty) => {
10671066
with_no_trimmed_paths!(write!(fmt, "{place:?} as {ty} ({kind:?})"))
10681067
}

0 commit comments

Comments
 (0)