Skip to content

Commit 32e78ca

Browse files
committed
Respond to CR feedback
1 parent 2b6815a commit 32e78ca

File tree

3 files changed

+20
-73
lines changed

3 files changed

+20
-73
lines changed

src/librustc_mir/interpret/intern.rs

+11-62
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ use super::{
1515
AllocId, Allocation, InterpCx, Machine, MemoryKind, MPlaceTy, Scalar, ValueVisitor,
1616
};
1717

18-
struct InternVisitor<'rt, 'mir, 'tcx, M>
19-
where
20-
M: Machine<
18+
pub trait CompileTimeMachine<'mir, 'tcx> =
19+
Machine<
2120
'mir,
2221
'tcx,
2322
MemoryKinds = !,
@@ -27,8 +26,9 @@ where
2726
MemoryExtra = (),
2827
AllocExtra = (),
2928
MemoryMap = FxHashMap<AllocId, (MemoryKind<!>, Allocation)>,
30-
>,
31-
{
29+
>;
30+
31+
struct InternVisitor<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>> {
3232
/// The ectx from which we intern.
3333
ecx: &'rt mut InterpCx<'mir, 'tcx, M>,
3434
/// Previously encountered safe references.
@@ -70,27 +70,14 @@ struct IsStaticOrFn;
7070
/// `immutable` things might become mutable if `ty` is not frozen.
7171
/// `ty` can be `None` if there is no potential interior mutability
7272
/// to account for (e.g. for vtables).
73-
fn intern_shallow<'rt, 'mir, 'tcx, M>(
73+
fn intern_shallow<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>>(
7474
ecx: &'rt mut InterpCx<'mir, 'tcx, M>,
7575
leftover_allocations: &'rt mut FxHashSet<AllocId>,
7676
mode: InternMode,
7777
alloc_id: AllocId,
7878
mutability: Mutability,
7979
ty: Option<Ty<'tcx>>,
80-
) -> InterpResult<'tcx, Option<IsStaticOrFn>>
81-
where
82-
M: Machine<
83-
'mir,
84-
'tcx,
85-
MemoryKinds = !,
86-
PointerTag = (),
87-
ExtraFnVal = !,
88-
FrameExtra = (),
89-
MemoryExtra = (),
90-
AllocExtra = (),
91-
MemoryMap = FxHashMap<AllocId, (MemoryKind<!>, Allocation)>,
92-
>,
93-
{
80+
) -> InterpResult<'tcx, Option<IsStaticOrFn>> {
9481
trace!("InternVisitor::intern {:?} with {:?}", alloc_id, mutability,);
9582
// remove allocation
9683
let tcx = ecx.tcx;
@@ -152,20 +139,7 @@ where
152139
Ok(None)
153140
}
154141

155-
impl<'rt, 'mir, 'tcx, M> InternVisitor<'rt, 'mir, 'tcx, M>
156-
where
157-
M: Machine<
158-
'mir,
159-
'tcx,
160-
MemoryKinds = !,
161-
PointerTag = (),
162-
ExtraFnVal = !,
163-
FrameExtra = (),
164-
MemoryExtra = (),
165-
AllocExtra = (),
166-
MemoryMap = FxHashMap<AllocId, (MemoryKind<!>, Allocation)>,
167-
>,
168-
{
142+
impl<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>> InternVisitor<'rt, 'mir, 'tcx, M> {
169143
fn intern_shallow(
170144
&mut self,
171145
alloc_id: AllocId,
@@ -183,22 +157,10 @@ where
183157
}
184158
}
185159

186-
impl<'rt, 'mir, 'tcx, M>
160+
impl<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>>
187161
ValueVisitor<'mir, 'tcx, M>
188162
for
189163
InternVisitor<'rt, 'mir, 'tcx, M>
190-
where
191-
M: Machine<
192-
'mir,
193-
'tcx,
194-
MemoryKinds = !,
195-
PointerTag = (),
196-
ExtraFnVal = !,
197-
FrameExtra = (),
198-
MemoryExtra = (),
199-
AllocExtra = (),
200-
MemoryMap = FxHashMap<AllocId, (MemoryKind<!>, Allocation)>,
201-
>,
202164
{
203165
type V = MPlaceTy<'tcx>;
204166

@@ -312,25 +274,12 @@ where
312274
}
313275
}
314276

315-
pub fn intern_const_alloc_recursive<M>(
277+
pub fn intern_const_alloc_recursive<M: CompileTimeMachine<'mir, 'tcx>>(
316278
ecx: &mut InterpCx<'mir, 'tcx, M>,
317279
// The `mutability` of the place, ignoring the type.
318280
place_mut: Option<hir::Mutability>,
319281
ret: MPlaceTy<'tcx>,
320-
) -> InterpResult<'tcx>
321-
where
322-
M: Machine<
323-
'mir,
324-
'tcx,
325-
MemoryKinds = !,
326-
PointerTag = (),
327-
ExtraFnVal = !,
328-
FrameExtra = (),
329-
MemoryExtra = (),
330-
AllocExtra = (),
331-
MemoryMap = FxHashMap<AllocId, (MemoryKind<!>, Allocation)>,
332-
>,
333-
{
282+
) -> InterpResult<'tcx> {
334283
let tcx = ecx.tcx;
335284
let (base_mutability, base_intern_mode) = match place_mut {
336285
Some(hir::Mutability::Immutable) => (Mutability::Immutable, InternMode::Static),

src/librustc_mir/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
2727
#![feature(range_is_empty)]
2828
#![feature(stmt_expr_attributes)]
2929
#![feature(bool_to_option)]
30+
#![feature(trait_alias)]
3031

3132
#![recursion_limit="256"]
3233

src/librustc_mir/transform/const_prop.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -649,31 +649,28 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
649649
}
650650

651651
fn should_const_prop(&mut self, op: OpTy<'tcx>) -> bool {
652-
if self.tcx.sess.opts.debugging_opts.mir_opt_level == 0 {
652+
let mir_opt_level = self.tcx.sess.opts.debugging_opts.mir_opt_level;
653+
654+
if mir_opt_level == 0 {
653655
return false;
654656
}
655657

656-
let is_scalar = match *op {
658+
match *op {
657659
interpret::Operand::Immediate(Immediate::Scalar(ScalarMaybeUndef::Scalar(s))) =>
658660
s.is_bits(),
659661
interpret::Operand::Immediate(Immediate::ScalarPair(ScalarMaybeUndef::Scalar(l),
660662
ScalarMaybeUndef::Scalar(r))) =>
661663
l.is_bits() && r.is_bits(),
662-
_ => false
663-
};
664-
665-
if let interpret::Operand::Indirect(_) = *op {
666-
if self.tcx.sess.opts.debugging_opts.mir_opt_level >= 2 {
664+
interpret::Operand::Indirect(_) if mir_opt_level >= 2 => {
667665
intern_const_alloc_recursive(
668666
&mut self.ecx,
669667
None,
670668
op.assert_mem_place()
671669
).expect("failed to intern alloc");
672-
return true;
673-
}
670+
true
671+
},
672+
_ => false
674673
}
675-
676-
return is_scalar;
677674
}
678675
}
679676

0 commit comments

Comments
 (0)