From 24bfdc98e9f02ff7974328f92a0e7ef67eab5f46 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Sun, 21 Jun 2020 19:34:54 -0400 Subject: [PATCH] Fix debuginfo so that it points to the correct local --- src/librustc_middle/mir/mod.rs | 12 ++++ src/librustc_mir/transform/simplify_try.rs | 69 ++++++++++++++++--- .../32bit/rustc.map.SimplifyLocals.diff | 8 +-- .../64bit/rustc.map.SimplifyLocals.diff | 8 +-- ...ustc.try_identity.SimplifyArmIdentity.diff | 63 +++++++++-------- ....try_identity.SimplifyBranchSame.after.mir | 44 +++--------- ...ustc.try_identity.SimplifyLocals.after.mir | 33 ++------- 7 files changed, 126 insertions(+), 111 deletions(-) diff --git a/src/librustc_middle/mir/mod.rs b/src/librustc_middle/mir/mod.rs index ae59f8c542d8c..a10d6c86ad537 100644 --- a/src/librustc_middle/mir/mod.rs +++ b/src/librustc_middle/mir/mod.rs @@ -256,6 +256,18 @@ impl<'tcx> Body<'tcx> { (&mut self.basic_blocks, &mut self.local_decls) } + #[inline] + pub fn basic_blocks_local_decls_mut_and_var_debug_info( + &mut self, + ) -> ( + &mut IndexVec>, + &mut LocalDecls<'tcx>, + &mut Vec>, + ) { + self.predecessor_cache.invalidate(); + (&mut self.basic_blocks, &mut self.local_decls, &mut self.var_debug_info) + } + /// Returns `true` if a cycle exists in the control-flow graph that is reachable from the /// `START_BLOCK`. pub fn is_cfg_cyclic(&self) -> bool { diff --git a/src/librustc_mir/transform/simplify_try.rs b/src/librustc_mir/transform/simplify_try.rs index 0abaa2175e141..778d19a3da44f 100644 --- a/src/librustc_mir/transform/simplify_try.rs +++ b/src/librustc_mir/transform/simplify_try.rs @@ -11,10 +11,10 @@ use crate::transform::{simplify, MirPass, MirSource}; use itertools::Itertools as _; -use rustc_index::vec::IndexVec; -use rustc_middle::mir::visit::{PlaceContext, Visitor}; +use rustc_index::{bit_set::BitSet, vec::IndexVec}; +use rustc_middle::mir::visit::{NonUseContext, PlaceContext, Visitor}; use rustc_middle::mir::*; -use rustc_middle::ty::{Ty, TyCtxt}; +use rustc_middle::ty::{List, Ty, TyCtxt}; use rustc_target::abi::VariantIdx; use std::iter::{Enumerate, Peekable}; use std::slice::Iter; @@ -74,10 +74,19 @@ struct ArmIdentityInfo<'tcx> { /// The statements that should be removed (turned into nops) stmts_to_remove: Vec, + + /// Indices of debug variables that need to be adjusted to point to + // `{local_0}.{dbg_projection}`. + dbg_info_to_adjust: Vec, + + /// The projection used to rewrite debug info. + dbg_projection: &'tcx List>, } fn get_arm_identity_info<'a, 'tcx>( stmts: &'a [Statement<'tcx>], + locals_count: usize, + debug_info: &'a [VarDebugInfo<'tcx>], ) -> Option> { // This can't possibly match unless there are at least 3 statements in the block // so fail fast on tiny blocks. @@ -190,7 +199,7 @@ fn get_arm_identity_info<'a, 'tcx>( try_eat_storage_stmts(&mut stmt_iter, &mut storage_live_stmts, &mut storage_dead_stmts); let (get_variant_field_stmt, stmt) = stmt_iter.next()?; - let (local_tmp_s0, local_1, vf_s0) = match_get_variant_field(stmt)?; + let (local_tmp_s0, local_1, vf_s0, dbg_projection) = match_get_variant_field(stmt)?; try_eat_storage_stmts(&mut stmt_iter, &mut storage_live_stmts, &mut storage_dead_stmts); @@ -231,6 +240,19 @@ fn get_arm_identity_info<'a, 'tcx>( let stmt_to_overwrite = nop_stmts.iter().find(|stmt_idx| live_idx < **stmt_idx && **stmt_idx < dead_idx); + let mut tmp_assigned_vars = BitSet::new_empty(locals_count); + for (l, r) in &tmp_assigns { + tmp_assigned_vars.insert(*l); + tmp_assigned_vars.insert(*r); + } + + let mut dbg_info_to_adjust = Vec::new(); + for (i, var_info) in debug_info.iter().enumerate() { + if tmp_assigned_vars.contains(var_info.place.local) { + dbg_info_to_adjust.push(i); + } + } + Some(ArmIdentityInfo { local_temp_0: local_tmp_s0, local_1, @@ -246,6 +268,8 @@ fn get_arm_identity_info<'a, 'tcx>( source_info: discr_stmt_source_info, storage_stmts, stmts_to_remove: nop_stmts, + dbg_info_to_adjust, + dbg_projection, }) } @@ -253,6 +277,7 @@ fn optimization_applies<'tcx>( opt_info: &ArmIdentityInfo<'tcx>, local_decls: &IndexVec>, local_uses: &IndexVec, + var_debug_info: &[VarDebugInfo<'tcx>], ) -> bool { trace!("testing if optimization applies..."); @@ -309,6 +334,15 @@ fn optimization_applies<'tcx>( } } + // Check that debug info only points to full Locals and not projections. + for dbg_idx in &opt_info.dbg_info_to_adjust { + let dbg_info = &var_debug_info[*dbg_idx]; + if !dbg_info.place.projection.is_empty() { + trace!("NO: debug info for {:?} had a projection {:?}", dbg_info.name, dbg_info.place); + return false; + } + } + if source_local != opt_info.local_temp_0 { trace!( "NO: start of assignment chain does not match enum variant temp: {:?} != {:?}", @@ -337,11 +371,14 @@ impl<'tcx> MirPass<'tcx> for SimplifyArmIdentity { trace!("running SimplifyArmIdentity on {:?}", source); let local_uses = LocalUseCounter::get_local_uses(body); - let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut(); + let (basic_blocks, local_decls, debug_info) = + body.basic_blocks_local_decls_mut_and_var_debug_info(); for bb in basic_blocks { - if let Some(opt_info) = get_arm_identity_info(&bb.statements) { + if let Some(opt_info) = + get_arm_identity_info(&bb.statements, local_decls.len(), debug_info) + { trace!("got opt_info = {:#?}", opt_info); - if !optimization_applies(&opt_info, local_decls, &local_uses) { + if !optimization_applies(&opt_info, local_decls, &local_uses, &debug_info) { debug!("optimization skipped for {:?}", source); continue; } @@ -377,6 +414,14 @@ impl<'tcx> MirPass<'tcx> for SimplifyArmIdentity { bb.statements.retain(|stmt| stmt.kind != StatementKind::Nop); + // Fix the debug info to point to the right local + for dbg_index in opt_info.dbg_info_to_adjust { + let dbg_info = &mut debug_info[dbg_index]; + assert!(dbg_info.place.projection.is_empty()); + dbg_info.place.local = opt_info.local_0; + dbg_info.place.projection = opt_info.dbg_projection; + } + trace!("block is now {:?}", bb.statements); } } @@ -397,7 +442,9 @@ impl LocalUseCounter { impl<'tcx> Visitor<'tcx> for LocalUseCounter { fn visit_local(&mut self, local: &Local, context: PlaceContext, _location: Location) { - if context.is_storage_marker() { + if context.is_storage_marker() + || context == PlaceContext::NonUse(NonUseContext::VarDebugInfo) + { return; } @@ -409,13 +456,15 @@ impl<'tcx> Visitor<'tcx> for LocalUseCounter { /// ```rust /// _LOCAL_INTO = ((_LOCAL_FROM as Variant).FIELD: TY); /// ``` -fn match_get_variant_field<'tcx>(stmt: &Statement<'tcx>) -> Option<(Local, Local, VarField<'tcx>)> { +fn match_get_variant_field<'tcx>( + stmt: &Statement<'tcx>, +) -> Option<(Local, Local, VarField<'tcx>, &'tcx List>)> { match &stmt.kind { StatementKind::Assign(box (place_into, rvalue_from)) => match rvalue_from { Rvalue::Use(Operand::Copy(pf) | Operand::Move(pf)) => { let local_into = place_into.as_local()?; let (local_from, vf) = match_variant_field_place(*pf)?; - Some((local_into, local_from, vf)) + Some((local_into, local_from, vf, pf.projection)) } _ => None, }, diff --git a/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/32bit/rustc.map.SimplifyLocals.diff b/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/32bit/rustc.map.SimplifyLocals.diff index 318b1b3f72a08..551f6db08a599 100644 --- a/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/32bit/rustc.map.SimplifyLocals.diff +++ b/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/32bit/rustc.map.SimplifyLocals.diff @@ -5,12 +5,12 @@ debug x => _1; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:1:8: 1:9 let mut _0: std::option::Option>; // return place in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:1:31: 1:46 let mut _2: isize; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:3:9: 3:13 - let _3: std::boxed::Box<()>; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:14: 4:15 +- let _3: std::boxed::Box<()>; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:14: 4:15 - let mut _4: std::boxed::Box<()>; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:25: 4:26 - let mut _5: isize; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:1: 6:2 - let mut _6: isize; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:1: 6:2 scope 1 { - debug x => _3; // in scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:14: 4:15 + debug x => ((_0 as Some).0: std::boxed::Box<()>); // in scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:14: 4:15 } bb0: { @@ -19,9 +19,7 @@ } bb1: { - _3 = move ((_1 as Some).0: std::boxed::Box<()>); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:14: 4:15 - ((_0 as Some).0: std::boxed::Box<()>) = move _3; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:20: 4:27 - discriminant(_0) = 1; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:20: 4:27 + _0 = move _1; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:20: 4:27 goto -> bb3; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:2:5: 5:6 } diff --git a/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/64bit/rustc.map.SimplifyLocals.diff b/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/64bit/rustc.map.SimplifyLocals.diff index ace471aaa3c82..388b382b86daf 100644 --- a/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/64bit/rustc.map.SimplifyLocals.diff +++ b/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/64bit/rustc.map.SimplifyLocals.diff @@ -5,12 +5,12 @@ debug x => _1; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:1:8: 1:9 let mut _0: std::option::Option>; // return place in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:1:31: 1:46 let mut _2: isize; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:3:9: 3:13 - let _3: std::boxed::Box<()>; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:14: 4:15 +- let _3: std::boxed::Box<()>; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:14: 4:15 - let mut _4: std::boxed::Box<()>; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:25: 4:26 - let mut _5: isize; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:1: 6:2 - let mut _6: isize; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:1: 6:2 scope 1 { - debug x => _3; // in scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:14: 4:15 + debug x => ((_0 as Some).0: std::boxed::Box<()>); // in scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:14: 4:15 } bb0: { @@ -19,9 +19,7 @@ } bb1: { - _3 = move ((_1 as Some).0: std::boxed::Box<()>); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:14: 4:15 - ((_0 as Some).0: std::boxed::Box<()>) = move _3; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:20: 4:27 - discriminant(_0) = 1; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:20: 4:27 + _0 = move _1; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:20: 4:27 goto -> bb3; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:2:5: 5:6 } diff --git a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyArmIdentity.diff index 2caff43bfb582..e6d794a71508c 100644 --- a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyArmIdentity.diff @@ -15,22 +15,27 @@ let _10: u32; // in scope 0 at $DIR/simplify_try.rs:6:13: 6:15 let mut _11: u32; // in scope 0 at $DIR/simplify_try.rs:7:8: 7:9 scope 1 { - debug y => _2; // in scope 1 at $DIR/simplify_try.rs:6:9: 6:10 +- debug y => _2; // in scope 1 at $DIR/simplify_try.rs:6:9: 6:10 ++ debug y => ((_0 as Ok).0: u32); // in scope 1 at $DIR/simplify_try.rs:6:9: 6:10 } scope 2 { - debug err => _6; // in scope 2 at $DIR/simplify_try.rs:6:14: 6:15 +- debug err => _6; // in scope 2 at $DIR/simplify_try.rs:6:14: 6:15 ++ debug err => ((_0 as Err).0: i32); // in scope 2 at $DIR/simplify_try.rs:6:14: 6:15 scope 3 { scope 7 { - debug t => _9; // in scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL +- debug t => _9; // in scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL ++ debug t => ((_0 as Err).0: i32); // in scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL } scope 8 { - debug v => _8; // in scope 8 at $SRC_DIR/libcore/result.rs:LL:COL +- debug v => _8; // in scope 8 at $SRC_DIR/libcore/result.rs:LL:COL ++ debug v => ((_0 as Err).0: i32); // in scope 8 at $SRC_DIR/libcore/result.rs:LL:COL let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:6:14: 6:15 } } } scope 4 { - debug val => _10; // in scope 4 at $DIR/simplify_try.rs:6:13: 6:15 +- debug val => _10; // in scope 4 at $DIR/simplify_try.rs:6:13: 6:15 ++ debug val => ((_0 as Ok).0: u32); // in scope 4 at $DIR/simplify_try.rs:6:13: 6:15 scope 5 { } } @@ -50,35 +55,37 @@ } bb1: { - StorageLive(_10); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 - _10 = ((_3 as Ok).0: u32); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 - _2 = _10; // scope 5 at $DIR/simplify_try.rs:6:13: 6:15 - StorageDead(_10); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 +- StorageLive(_10); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 +- _10 = ((_3 as Ok).0: u32); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 +- _2 = _10; // scope 5 at $DIR/simplify_try.rs:6:13: 6:15 +- StorageDead(_10); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 ++ _0 = move _3; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:6:15: 6:16 - StorageLive(_11); // scope 1 at $DIR/simplify_try.rs:7:8: 7:9 - _11 = _2; // scope 1 at $DIR/simplify_try.rs:7:8: 7:9 - ((_0 as Ok).0: u32) = move _11; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 - discriminant(_0) = 0; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 - StorageDead(_11); // scope 1 at $DIR/simplify_try.rs:7:9: 7:10 +- StorageLive(_11); // scope 1 at $DIR/simplify_try.rs:7:8: 7:9 +- _11 = _2; // scope 1 at $DIR/simplify_try.rs:7:8: 7:9 +- ((_0 as Ok).0: u32) = move _11; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 +- discriminant(_0) = 0; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 +- StorageDead(_11); // scope 1 at $DIR/simplify_try.rs:7:9: 7:10 StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:8:1: 8:2 goto -> bb3; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 } bb2: { - StorageLive(_6); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - _6 = ((_3 as Err).0: i32); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - StorageLive(_8); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 - StorageLive(_9); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 - _9 = _6; // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 - _8 = move _9; // scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL - StorageDead(_9); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 - StorageLive(_12); // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - _12 = move _8; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - ((_0 as Err).0: i32) = move _12; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - discriminant(_0) = 1; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - StorageDead(_12); // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - StorageDead(_8); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 - StorageDead(_6); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 +- StorageLive(_6); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 +- _6 = ((_3 as Err).0: i32); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 +- StorageLive(_8); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 +- StorageLive(_9); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 +- _9 = _6; // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 +- _8 = move _9; // scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL +- StorageDead(_9); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 +- StorageLive(_12); // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL +- _12 = move _8; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL +- ((_0 as Err).0: i32) = move _12; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL +- discriminant(_0) = 1; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL +- StorageDead(_12); // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL +- StorageDead(_8); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 +- StorageDead(_6); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 ++ _0 = move _3; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:6:15: 6:16 StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:8:1: 8:2 goto -> bb3; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 diff --git a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyBranchSame.after.mir b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyBranchSame.after.mir index 5000a1ec36cc8..24bde51c7d3bb 100644 --- a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyBranchSame.after.mir +++ b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyBranchSame.after.mir @@ -14,22 +14,22 @@ fn try_identity(_1: std::result::Result) -> std::result::Result _2; // in scope 1 at $DIR/simplify_try.rs:6:9: 6:10 + debug y => ((_0 as Ok).0: u32); // in scope 1 at $DIR/simplify_try.rs:6:9: 6:10 } scope 2 { - debug err => _6; // in scope 2 at $DIR/simplify_try.rs:6:14: 6:15 + debug err => ((_0 as Err).0: i32); // in scope 2 at $DIR/simplify_try.rs:6:14: 6:15 scope 3 { scope 7 { - debug t => _9; // in scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL + debug t => ((_0 as Err).0: i32); // in scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL } scope 8 { - debug v => _8; // in scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + debug v => ((_0 as Err).0: i32); // in scope 8 at $SRC_DIR/libcore/result.rs:LL:COL let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:6:14: 6:15 } } } scope 4 { - debug val => _10; // in scope 4 at $DIR/simplify_try.rs:6:13: 6:15 + debug val => ((_0 as Ok).0: u32); // in scope 4 at $DIR/simplify_try.rs:6:13: 6:15 scope 5 { } } @@ -45,45 +45,17 @@ fn try_identity(_1: std::result::Result) -> std::result::Result [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + goto -> bb1; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 } bb1: { - StorageLive(_10); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 - _10 = ((_3 as Ok).0: u32); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 - _2 = _10; // scope 5 at $DIR/simplify_try.rs:6:13: 6:15 - StorageDead(_10); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + _0 = move _3; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:6:15: 6:16 - StorageLive(_11); // scope 1 at $DIR/simplify_try.rs:7:8: 7:9 - _11 = _2; // scope 1 at $DIR/simplify_try.rs:7:8: 7:9 - ((_0 as Ok).0: u32) = move _11; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 - discriminant(_0) = 0; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 - StorageDead(_11); // scope 1 at $DIR/simplify_try.rs:7:9: 7:10 StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:8:1: 8:2 - goto -> bb3; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 + goto -> bb2; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 } bb2: { - StorageLive(_6); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - _6 = ((_3 as Err).0: i32); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - StorageLive(_8); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 - StorageLive(_9); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 - _9 = _6; // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 - _8 = move _9; // scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL - StorageDead(_9); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 - StorageLive(_12); // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - _12 = move _8; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - ((_0 as Err).0: i32) = move _12; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - discriminant(_0) = 1; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - StorageDead(_12); // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - StorageDead(_8); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 - StorageDead(_6); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:6:15: 6:16 - StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:8:1: 8:2 - goto -> bb3; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - } - - bb3: { return; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 } } diff --git a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyLocals.after.mir b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyLocals.after.mir index 77804c12691ee..929f04d4654ad 100644 --- a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyLocals.after.mir +++ b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyLocals.after.mir @@ -3,25 +3,22 @@ fn try_identity(_1: std::result::Result) -> std::result::Result { debug x => _1; // in scope 0 at $DIR/simplify_try.rs:5:17: 5:18 let mut _0: std::result::Result; // return place in scope 0 at $DIR/simplify_try.rs:5:41: 5:57 - let mut _2: isize; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - let _3: i32; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - let _4: u32; // in scope 0 at $DIR/simplify_try.rs:6:13: 6:15 scope 1 { - debug y => _4; // in scope 1 at $DIR/simplify_try.rs:6:9: 6:10 + debug y => ((_0 as Ok).0: u32); // in scope 1 at $DIR/simplify_try.rs:6:9: 6:10 } scope 2 { - debug err => _3; // in scope 2 at $DIR/simplify_try.rs:6:14: 6:15 + debug err => ((_0 as Err).0: i32); // in scope 2 at $DIR/simplify_try.rs:6:14: 6:15 scope 3 { scope 7 { - debug t => _3; // in scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL + debug t => ((_0 as Err).0: i32); // in scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL } scope 8 { - debug v => _3; // in scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + debug v => ((_0 as Err).0: i32); // in scope 8 at $SRC_DIR/libcore/result.rs:LL:COL } } } scope 4 { - debug val => _4; // in scope 4 at $DIR/simplify_try.rs:6:13: 6:15 + debug val => ((_0 as Ok).0: u32); // in scope 4 at $DIR/simplify_try.rs:6:13: 6:15 scope 5 { } } @@ -30,25 +27,7 @@ fn try_identity(_1: std::result::Result) -> std::result::Result [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - } - - bb1: { - _4 = ((_1 as Ok).0: u32); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 - ((_0 as Ok).0: u32) = move _4; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 - discriminant(_0) = 0; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 - goto -> bb3; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 - } - - bb2: { - _3 = ((_1 as Err).0: i32); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - ((_0 as Err).0: i32) = move _3; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - discriminant(_0) = 1; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - goto -> bb3; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - } - - bb3: { + _0 = move _1; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 return; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 } }