diff --git a/src/librustc_mir/interpret/intern.rs b/src/librustc_mir/interpret/intern.rs index f3c503b2970a..630f3f603449 100644 --- a/src/librustc_mir/interpret/intern.rs +++ b/src/librustc_mir/interpret/intern.rs @@ -15,9 +15,8 @@ use super::{ AllocId, Allocation, InterpCx, Machine, MemoryKind, MPlaceTy, Scalar, ValueVisitor, }; -struct InternVisitor<'rt, 'mir, 'tcx, M> -where - M: Machine< +pub trait CompileTimeMachine<'mir, 'tcx> = + Machine< 'mir, 'tcx, MemoryKinds = !, @@ -27,8 +26,9 @@ where MemoryExtra = (), AllocExtra = (), MemoryMap = FxHashMap, Allocation)>, - >, -{ + >; + +struct InternVisitor<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>> { /// The ectx from which we intern. ecx: &'rt mut InterpCx<'mir, 'tcx, M>, /// Previously encountered safe references. @@ -70,27 +70,14 @@ struct IsStaticOrFn; /// `immutable` things might become mutable if `ty` is not frozen. /// `ty` can be `None` if there is no potential interior mutability /// to account for (e.g. for vtables). -fn intern_shallow<'rt, 'mir, 'tcx, M>( +fn intern_shallow<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>>( ecx: &'rt mut InterpCx<'mir, 'tcx, M>, leftover_allocations: &'rt mut FxHashSet, mode: InternMode, alloc_id: AllocId, mutability: Mutability, ty: Option>, -) -> InterpResult<'tcx, Option> -where - M: Machine< - 'mir, - 'tcx, - MemoryKinds = !, - PointerTag = (), - ExtraFnVal = !, - FrameExtra = (), - MemoryExtra = (), - AllocExtra = (), - MemoryMap = FxHashMap, Allocation)>, - >, -{ +) -> InterpResult<'tcx, Option> { trace!("InternVisitor::intern {:?} with {:?}", alloc_id, mutability,); // remove allocation let tcx = ecx.tcx; @@ -152,20 +139,7 @@ where Ok(None) } -impl<'rt, 'mir, 'tcx, M> InternVisitor<'rt, 'mir, 'tcx, M> -where - M: Machine< - 'mir, - 'tcx, - MemoryKinds = !, - PointerTag = (), - ExtraFnVal = !, - FrameExtra = (), - MemoryExtra = (), - AllocExtra = (), - MemoryMap = FxHashMap, Allocation)>, - >, -{ +impl<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>> InternVisitor<'rt, 'mir, 'tcx, M> { fn intern_shallow( &mut self, alloc_id: AllocId, @@ -183,22 +157,10 @@ where } } -impl<'rt, 'mir, 'tcx, M> +impl<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M> for InternVisitor<'rt, 'mir, 'tcx, M> -where - M: Machine< - 'mir, - 'tcx, - MemoryKinds = !, - PointerTag = (), - ExtraFnVal = !, - FrameExtra = (), - MemoryExtra = (), - AllocExtra = (), - MemoryMap = FxHashMap, Allocation)>, - >, { type V = MPlaceTy<'tcx>; @@ -312,25 +274,12 @@ where } } -pub fn intern_const_alloc_recursive( +pub fn intern_const_alloc_recursive>( ecx: &mut InterpCx<'mir, 'tcx, M>, // The `mutability` of the place, ignoring the type. place_mut: Option, ret: MPlaceTy<'tcx>, -) -> InterpResult<'tcx> -where - M: Machine< - 'mir, - 'tcx, - MemoryKinds = !, - PointerTag = (), - ExtraFnVal = !, - FrameExtra = (), - MemoryExtra = (), - AllocExtra = (), - MemoryMap = FxHashMap, Allocation)>, - >, -{ +) -> InterpResult<'tcx> { let tcx = ecx.tcx; let (base_mutability, base_intern_mode) = match place_mut { Some(hir::Mutability::Immutable) => (Mutability::Immutable, InternMode::Static), diff --git a/src/librustc_mir/lib.rs b/src/librustc_mir/lib.rs index 6d19cd63bc32..b5273ea7bc60 100644 --- a/src/librustc_mir/lib.rs +++ b/src/librustc_mir/lib.rs @@ -27,6 +27,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment! #![feature(range_is_empty)] #![feature(stmt_expr_attributes)] #![feature(bool_to_option)] +#![feature(trait_alias)] #![recursion_limit="256"] diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index f7572f366842..58d1a8b70979 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -649,31 +649,28 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { } fn should_const_prop(&mut self, op: OpTy<'tcx>) -> bool { - if self.tcx.sess.opts.debugging_opts.mir_opt_level == 0 { + let mir_opt_level = self.tcx.sess.opts.debugging_opts.mir_opt_level; + + if mir_opt_level == 0 { return false; } - let is_scalar = match *op { + match *op { interpret::Operand::Immediate(Immediate::Scalar(ScalarMaybeUndef::Scalar(s))) => s.is_bits(), interpret::Operand::Immediate(Immediate::ScalarPair(ScalarMaybeUndef::Scalar(l), ScalarMaybeUndef::Scalar(r))) => l.is_bits() && r.is_bits(), - _ => false - }; - - if let interpret::Operand::Indirect(_) = *op { - if self.tcx.sess.opts.debugging_opts.mir_opt_level >= 2 { + interpret::Operand::Indirect(_) if mir_opt_level >= 2 => { intern_const_alloc_recursive( &mut self.ecx, None, op.assert_mem_place() ).expect("failed to intern alloc"); - return true; - } + true + }, + _ => false } - - return is_scalar; } }