Skip to content

Commit 1b7f5a3

Browse files
committed
Remove NullOp::Box
1 parent 6162529 commit 1b7f5a3

File tree

11 files changed

+2
-92
lines changed

11 files changed

+2
-92
lines changed

compiler/rustc_borrowck/src/lib.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1397,10 +1397,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13971397

13981398
Rvalue::NullaryOp(_op, _ty) => {
13991399
// nullary ops take no dynamic input; no borrowck effect.
1400-
//
1401-
// FIXME: is above actually true? Do we want to track
1402-
// the fact that uninitialized data can be created via
1403-
// `NullOp::Box`?
14041400
}
14051401

14061402
Rvalue::Aggregate(ref aggregate_kind, ref operands) => {

compiler/rustc_codegen_cranelift/src/base.rs

-25
Original file line numberDiff line numberDiff line change
@@ -708,30 +708,6 @@ fn codegen_stmt<'tcx>(
708708
let operand = operand.load_scalar(fx);
709709
lval.write_cvalue(fx, CValue::by_val(operand, box_layout));
710710
}
711-
Rvalue::NullaryOp(NullOp::Box, content_ty) => {
712-
let usize_type = fx.clif_type(fx.tcx.types.usize).unwrap();
713-
let content_ty = fx.monomorphize(content_ty);
714-
let layout = fx.layout_of(content_ty);
715-
let llsize = fx.bcx.ins().iconst(usize_type, layout.size.bytes() as i64);
716-
let llalign = fx.bcx.ins().iconst(usize_type, layout.align.abi.bytes() as i64);
717-
let box_layout = fx.layout_of(fx.tcx.mk_box(content_ty));
718-
719-
// Allocate space:
720-
let def_id =
721-
match fx.tcx.lang_items().require(rustc_hir::LangItem::ExchangeMalloc) {
722-
Ok(id) => id,
723-
Err(s) => {
724-
fx.tcx
725-
.sess
726-
.fatal(&format!("allocation of `{}` {}", box_layout.ty, s));
727-
}
728-
};
729-
let instance = ty::Instance::mono(fx.tcx, def_id).polymorphize(fx.tcx);
730-
let func_ref = fx.get_function_ref(instance);
731-
let call = fx.bcx.ins().call(func_ref, &[llsize, llalign]);
732-
let ptr = fx.bcx.inst_results(call)[0];
733-
lval.write_cvalue(fx, CValue::by_val(ptr, box_layout));
734-
}
735711
Rvalue::NullaryOp(null_op, ty) => {
736712
assert!(
737713
lval.layout()
@@ -742,7 +718,6 @@ fn codegen_stmt<'tcx>(
742718
let val = match null_op {
743719
NullOp::SizeOf => layout.size.bytes(),
744720
NullOp::AlignOf => layout.align.abi.bytes(),
745-
NullOp::Box => unreachable!(),
746721
};
747722
let val =
748723
CValue::const_val(fx, fx.layout_of(fx.tcx.types.usize), val.into());

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

-27
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::traits::*;
88
use crate::MemFlags;
99

1010
use rustc_apfloat::{ieee, Float, Round, Status};
11-
use rustc_hir::lang_items::LangItem;
1211
use rustc_middle::mir;
1312
use rustc_middle::ty::cast::{CastTy, IntTy};
1413
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf};
@@ -486,39 +485,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
486485
)
487486
}
488487

489-
mir::Rvalue::NullaryOp(mir::NullOp::Box, content_ty) => {
490-
let content_ty = self.monomorphize(content_ty);
491-
let content_layout = bx.cx().layout_of(content_ty);
492-
let llsize = bx.cx().const_usize(content_layout.size.bytes());
493-
let llalign = bx.cx().const_usize(content_layout.align.abi.bytes());
494-
let box_layout = bx.cx().layout_of(bx.tcx().mk_box(content_ty));
495-
let llty_ptr = bx.cx().backend_type(box_layout);
496-
497-
// Allocate space:
498-
let def_id = match bx.tcx().lang_items().require(LangItem::ExchangeMalloc) {
499-
Ok(id) => id,
500-
Err(s) => {
501-
bx.cx().sess().fatal(&format!("allocation of `{}` {}", box_layout.ty, s));
502-
}
503-
};
504-
let instance = ty::Instance::mono(bx.tcx(), def_id);
505-
let r = bx.cx().get_fn_addr(instance);
506-
let ty = bx.type_func(&[bx.type_isize(), bx.type_isize()], bx.type_i8p());
507-
let call = bx.call(ty, r, &[llsize, llalign], None);
508-
let val = bx.pointercast(call, llty_ptr);
509-
510-
let operand = OperandRef { val: OperandValue::Immediate(val), layout: box_layout };
511-
(bx, operand)
512-
}
513-
514488
mir::Rvalue::NullaryOp(null_op, ty) => {
515489
let ty = self.monomorphize(ty);
516490
assert!(bx.cx().type_is_sized(ty));
517491
let layout = bx.cx().layout_of(ty);
518492
let val = match null_op {
519493
mir::NullOp::SizeOf => layout.size.bytes(),
520494
mir::NullOp::AlignOf => layout.align.abi.bytes(),
521-
mir::NullOp::Box => unreachable!(),
522495
};
523496
let val = bx.cx().const_usize(val);
524497
let tcx = self.cx.tcx();

compiler/rustc_const_eval/src/interpret/step.rs

-5
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
267267
self.write_immediate(place.to_ref(self), &dest)?;
268268
}
269269

270-
NullaryOp(mir::NullOp::Box, _) => {
271-
M::box_alloc(self, &dest)?;
272-
}
273-
274270
NullaryOp(null_op, ty) => {
275271
let ty = self.subst_from_current_frame_and_normalize_erasing_regions(ty);
276272
let layout = self.layout_of(ty)?;
@@ -285,7 +281,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
285281
let val = match null_op {
286282
mir::NullOp::SizeOf => layout.size.bytes(),
287283
mir::NullOp::AlignOf => layout.align.abi.bytes(),
288-
mir::NullOp::Box => unreachable!(),
289284
};
290285
self.write_scalar(Scalar::from_machine_usize(val, self), &dest)?;
291286
}

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

-1
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,6 @@ impl Visitor<'tcx> for Checker<'mir, 'tcx> {
680680
}
681681

682682
Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, _) => {}
683-
Rvalue::NullaryOp(NullOp::Box, _) => self.check_op(ops::HeapAllocation),
684683
Rvalue::ShallowInitBox(_, _) => {}
685684

686685
Rvalue::UnaryOp(_, ref operand) => {

compiler/rustc_const_eval/src/transform/promote_consts.rs

-1
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,6 @@ impl<'tcx> Validator<'_, 'tcx> {
517517
}
518518

519519
Rvalue::NullaryOp(op, _) => match op {
520-
NullOp::Box => return Err(Unpromotable),
521520
NullOp::SizeOf => {}
522521
NullOp::AlignOf => {}
523522
},

compiler/rustc_middle/src/mir/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -2288,8 +2288,6 @@ pub enum NullOp {
22882288
SizeOf,
22892289
/// Returns the minimum alignment of a type
22902290
AlignOf,
2291-
/// Creates a new uninitialized box for a value of that type
2292-
Box,
22932291
}
22942292

22952293
#[derive(Copy, Clone, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)]

compiler/rustc_middle/src/mir/tcx.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ impl<'tcx> Rvalue<'tcx> {
195195
}
196196
Rvalue::UnaryOp(UnOp::Not | UnOp::Neg, ref operand) => operand.ty(local_decls, tcx),
197197
Rvalue::Discriminant(ref place) => place.ty(local_decls, tcx).ty.discriminant_ty(tcx),
198-
Rvalue::NullaryOp(NullOp::Box, t) => tcx.mk_box(t),
199198
Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, _) => tcx.types.usize,
200199
Rvalue::Aggregate(ref ak, ref ops) => match **ak {
201200
AggregateKind::Array(ty) => tcx.mk_array(ty, ops.len() as u64),
@@ -215,9 +214,7 @@ impl<'tcx> Rvalue<'tcx> {
215214
/// whether its only shallowly initialized (`Rvalue::Box`).
216215
pub fn initialization_state(&self) -> RvalueInitializationState {
217216
match *self {
218-
Rvalue::NullaryOp(NullOp::Box, _) | Rvalue::ShallowInitBox(_, _) => {
219-
RvalueInitializationState::Shallow
220-
}
217+
Rvalue::ShallowInitBox(_, _) => RvalueInitializationState::Shallow,
221218
_ => RvalueInitializationState::Deep,
222219
}
223220
}

compiler/rustc_mir_dataflow/src/move_paths/builder.rs

+1-13
Original file line numberDiff line numberDiff line change
@@ -343,19 +343,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
343343
| Rvalue::AddressOf(..)
344344
| Rvalue::Discriminant(..)
345345
| Rvalue::Len(..)
346-
| Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, _)
347-
| Rvalue::NullaryOp(NullOp::Box, _) => {
348-
// This returns an rvalue with uninitialized contents. We can't
349-
// move out of it here because it is an rvalue - assignments always
350-
// completely initialize their place.
351-
//
352-
// However, this does not matter - MIR building is careful to
353-
// only emit a shallow free for the partially-initialized
354-
// temporary.
355-
//
356-
// In any case, if we want to fix this, we have to register a
357-
// special move and change the `statement_effect` functions.
358-
}
346+
| Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, _) => {}
359347
}
360348
}
361349

compiler/rustc_monomorphize/src/collector.rs

-9
Original file line numberDiff line numberDiff line change
@@ -688,15 +688,6 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
688688
_ => bug!(),
689689
}
690690
}
691-
mir::Rvalue::NullaryOp(mir::NullOp::Box, _) => {
692-
let tcx = self.tcx;
693-
let exchange_malloc_fn_def_id =
694-
tcx.require_lang_item(LangItem::ExchangeMalloc, None);
695-
let instance = Instance::mono(tcx, exchange_malloc_fn_def_id);
696-
if should_codegen_locally(tcx, &instance) {
697-
self.output.push(create_fn_mono_item(self.tcx, instance, span));
698-
}
699-
}
700691
mir::Rvalue::ThreadLocalRef(def_id) => {
701692
assert!(self.tcx.is_thread_local_static(def_id));
702693
let instance = Instance::mono(self.tcx, def_id);

src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs

-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ fn check_rvalue(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId, rvalue: &Rv
193193
}
194194
},
195195
Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, _) | Rvalue::ShallowInitBox(_, _) => Ok(()),
196-
Rvalue::NullaryOp(NullOp::Box, _) => Err((span, "heap allocations are not allowed in const fn".into())),
197196
Rvalue::UnaryOp(_, operand) => {
198197
let ty = operand.ty(body, tcx);
199198
if ty.is_integral() || ty.is_bool() {

0 commit comments

Comments
 (0)