diff options
| author | Wesley Wiser <wwiser@gmail.com> | 2019-11-24 19:09:58 -0500 |
|---|---|---|
| committer | Wesley Wiser <wwiser@gmail.com> | 2019-11-24 19:09:58 -0500 |
| commit | 32e78ca2e38cdc83a8a18ee38cad43a5df72c1de (patch) | |
| tree | 54640f08047937cd0d96c99d53938b04a3b0073b | |
| parent | 2b6815a69e618a96a221d8db24ace87d10ae69f0 (diff) | |
| download | rust-32e78ca2e38cdc83a8a18ee38cad43a5df72c1de.tar.gz rust-32e78ca2e38cdc83a8a18ee38cad43a5df72c1de.zip | |
Respond to CR feedback
| -rw-r--r-- | src/librustc_mir/interpret/intern.rs | 73 | ||||
| -rw-r--r-- | src/librustc_mir/lib.rs | 1 | ||||
| -rw-r--r-- | src/librustc_mir/transform/const_prop.rs | 19 |
3 files changed, 20 insertions, 73 deletions
diff --git a/src/librustc_mir/interpret/intern.rs b/src/librustc_mir/interpret/intern.rs index f3c503b2970..630f3f60344 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<AllocId, (MemoryKind<!>, 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<AllocId>, mode: InternMode, alloc_id: AllocId, mutability: Mutability, ty: Option<Ty<'tcx>>, -) -> InterpResult<'tcx, Option<IsStaticOrFn>> -where - M: Machine< - 'mir, - 'tcx, - MemoryKinds = !, - PointerTag = (), - ExtraFnVal = !, - FrameExtra = (), - MemoryExtra = (), - AllocExtra = (), - MemoryMap = FxHashMap<AllocId, (MemoryKind<!>, Allocation)>, - >, -{ +) -> InterpResult<'tcx, Option<IsStaticOrFn>> { 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<AllocId, (MemoryKind<!>, 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<AllocId, (MemoryKind<!>, Allocation)>, - >, { type V = MPlaceTy<'tcx>; @@ -312,25 +274,12 @@ where } } -pub fn intern_const_alloc_recursive<M>( +pub fn intern_const_alloc_recursive<M: CompileTimeMachine<'mir, 'tcx>>( ecx: &mut InterpCx<'mir, 'tcx, M>, // The `mutability` of the place, ignoring the type. place_mut: Option<hir::Mutability>, ret: MPlaceTy<'tcx>, -) -> InterpResult<'tcx> -where - M: Machine< - 'mir, - 'tcx, - MemoryKinds = !, - PointerTag = (), - ExtraFnVal = !, - FrameExtra = (), - MemoryExtra = (), - AllocExtra = (), - MemoryMap = FxHashMap<AllocId, (MemoryKind<!>, 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 6d19cd63bc3..b5273ea7bc6 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 f7572f36684..58d1a8b7097 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; } } |
