Skip to content

Commit 1495b6b

Browse files
committed
Don't create an intermediate place when reading discriminants
1 parent b0857a7 commit 1495b6b

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/librustc_mir/interpret/operand.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
508508

509509
// Evaluate a place with the goal of reading from it. This lets us sometimes
510510
// avoid allocations.
511-
fn eval_place_to_op(
511+
pub(super) fn eval_place_to_op(
512512
&self,
513513
mir_place: &mir::Place<'tcx>,
514514
layout: Option<TyLayout<'tcx>>,
@@ -522,7 +522,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
522522
let op = self.eval_place_to_op(&proj.base, None)?;
523523
self.operand_projection(op, &proj.elem)?
524524
}
525-
525+
// FIXME(oli-obk): statics and promoteds have preevaluated `val` fields nowadays
526+
// add nonallocating variants here
526527
_ => self.eval_place_to_mplace(mir_place)?.into(),
527528
};
528529

src/librustc_mir/interpret/place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ where
611611
}
612612

613613
/// Computes a place. You should only use this if you intend to write into this
614-
/// place; for reading, a more efficient alternative is `eval_place_for_read`.
614+
/// place; for reading, a more efficient alternative is `eval_place_to_op`.
615615
pub fn eval_place(
616616
&mut self,
617617
mir_place: &mir::Place<'tcx>

src/librustc_mir/interpret/step.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
266266
}
267267

268268
Discriminant(ref place) => {
269-
let place = self.eval_place(place)?;
270-
let discr_val = self.read_discriminant(self.place_to_op(place)?)?.0;
269+
let op = self.eval_place_to_op(place, None)?;
270+
let discr_val = self.read_discriminant(op)?.0;
271271
let size = dest.layout.size;
272272
self.write_scalar(Scalar::from_uint(discr_val, size), dest)?;
273273
}

0 commit comments

Comments
 (0)