diff --git a/compiler/rustc_mir_transform/src/elaborate_drop.rs b/compiler/rustc_mir_transform/src/elaborate_drop.rs index 134b3a831d511..b1470eda6619f 100644 --- a/compiler/rustc_mir_transform/src/elaborate_drop.rs +++ b/compiler/rustc_mir_transform/src/elaborate_drop.rs @@ -1,5 +1,6 @@ use std::{fmt, iter, mem}; +use itertools::Itertools; use rustc_abi::{FIRST_VARIANT, FieldIdx, VariantIdx}; use rustc_hir::lang_items::LangItem; use rustc_hir::{CoroutineDesugaring, CoroutineKind}; @@ -798,6 +799,7 @@ where (tcx.mk_place_field(base_place, field_idx, field_ty), subpath) }) + .filter(|path| self.should_retain_for_ladder(path)) .collect() } @@ -875,6 +877,19 @@ where ) } + /// Whether this drop is useful. This is purely an optimization to avoid generating useless blocks. + fn should_retain_for_ladder(&self, (place, subpath): &(Place<'tcx>, Option)) -> bool { + if !self.place_ty(*place).needs_drop(self.tcx(), self.elaborator.typing_env()) { + return false; + } + if let Some(subpath) = subpath + && let DropStyle::Dead = self.elaborator.drop_style(*subpath, DropFlagMode::Deep) + { + return false; + } + true + } + /// Creates a full drop ladder, consisting of 2 connected half-drop-ladders /// /// For example, with 3 fields, the drop ladder is @@ -915,7 +930,7 @@ where #[instrument(level = "debug", skip(self), ret)] fn drop_ladder( &mut self, - fields: Vec<(Place<'tcx>, Option)>, + mut fields: Vec<(Place<'tcx>, Option)>, succ: BasicBlock, unwind: Unwind, dropline: Option, @@ -925,10 +940,7 @@ where "Dropline is set for cleanup drop ladder" ); - let mut fields = fields; - fields.retain(|&(place, _)| { - self.place_ty(place).needs_drop(self.tcx(), self.elaborator.typing_env()) - }); + fields.retain(|path| self.should_retain_for_ladder(path)); debug!("drop_ladder - fields needing drop: {:?}", fields); @@ -1149,15 +1161,21 @@ where if !have_otherwise { values.pop(); } else if !have_otherwise_with_drop_glue { - normal_blocks.push(self.goto_block(succ, unwind)); + normal_blocks.push(succ); if let Unwind::To(unwind) = unwind { - unwind_blocks.push(self.goto_block(unwind, Unwind::InCleanup)); + unwind_blocks.push(unwind); + } + if let Some(dropline) = dropline { + dropline_blocks.push(dropline); } } else { normal_blocks.push(self.drop_block(succ, unwind)); if let Unwind::To(unwind) = unwind { unwind_blocks.push(self.drop_block(unwind, Unwind::InCleanup)); } + if let Some(dropline) = dropline { + dropline_blocks.push(self.drop_block(dropline, unwind)); + } } ( @@ -1179,27 +1197,29 @@ where succ: BasicBlock, unwind: Unwind, ) -> BasicBlock { - // If there are multiple variants, then if something - // is present within the enum the discriminant, tracked - // by the rest path, must be initialized. - // - // Additionally, we do not want to switch on the - // discriminant after it is free-ed, because that - // way lies only trouble. - let discr_ty = adt.repr().discr_type().to_ty(self.tcx()); - let discr = Place::from(self.new_temp(discr_ty)); - let discr_rv = Rvalue::Discriminant(self.place); - let switch_block = self.new_block_with_statements( - unwind, - vec![self.assign(discr, discr_rv)], - TerminatorKind::SwitchInt { - discr: Operand::Move(discr), - targets: SwitchTargets::new( - values.iter().copied().zip(blocks.iter().copied()), - *blocks.last().unwrap(), - ), - }, - ); + let switch_block = blocks.iter().copied().all_equal_value().unwrap_or_else(|_| { + // If there are multiple variants, then if something + // is present within the enum the discriminant, tracked + // by the rest path, must be initialized. + // + // Additionally, we do not want to switch on the + // discriminant after it is free-ed, because that + // way lies only trouble. + let discr_ty = adt.repr().discr_type().to_ty(self.tcx()); + let discr = Place::from(self.new_temp(discr_ty)); + let discr_rv = Rvalue::Discriminant(self.place); + self.new_block_with_statements( + unwind, + vec![self.assign(discr, discr_rv)], + TerminatorKind::SwitchInt { + discr: Operand::Move(discr), + targets: SwitchTargets::new( + values.iter().copied().zip(blocks.iter().copied()), + *blocks.last().unwrap(), + ), + }, + ) + }); self.drop_flag_test_block(switch_block, succ, unwind) } @@ -1580,11 +1600,6 @@ where } } - fn goto_block(&mut self, target: BasicBlock, unwind: Unwind) -> BasicBlock { - let block = TerminatorKind::Goto { target }; - self.new_block(unwind, block) - } - /// Returns the block to jump to in order to test the drop flag and execute the drop. /// /// Depending on the required `DropStyle`, this might be a generated block with an `if` diff --git a/tests/mir-opt/building/fallible_struct_drop.build.ElaborateDrops.diff b/tests/mir-opt/building/fallible_struct_drop.build.ElaborateDrops.diff new file mode 100644 index 0000000000000..d2a4f5025bd45 --- /dev/null +++ b/tests/mir-opt/building/fallible_struct_drop.build.ElaborateDrops.diff @@ -0,0 +1,726 @@ +- // MIR for `build` before ElaborateDrops ++ // MIR for `build` after ElaborateDrops + + fn build(_1: u64) -> Result { + debug s => _1; + let mut _0: std::result::Result; + let mut _2: Big; + let mut _3: std::string::String; + let mut _4: std::ops::ControlFlow, std::string::String>; + let mut _5: std::result::Result; + let mut _6: u64; + let mut _7: u64; + let mut _8: isize; + let _9: std::result::Result; + let mut _10: !; + let mut _11: std::result::Result; + let _12: std::string::String; + let mut _13: std::string::String; + let mut _14: std::ops::ControlFlow, std::string::String>; + let mut _15: std::result::Result; + let mut _16: u64; + let mut _17: u64; + let mut _18: isize; + let _19: std::result::Result; + let mut _20: !; + let mut _21: std::result::Result; + let _22: std::string::String; + let mut _23: std::string::String; + let mut _24: std::ops::ControlFlow, std::string::String>; + let mut _25: std::result::Result; + let mut _26: u64; + let mut _27: u64; + let mut _28: isize; + let _29: std::result::Result; + let mut _30: !; + let mut _31: std::result::Result; + let _32: std::string::String; + let mut _33: std::string::String; + let mut _34: std::ops::ControlFlow, std::string::String>; + let mut _35: std::result::Result; + let mut _36: u64; + let mut _37: u64; + let mut _38: isize; + let _39: std::result::Result; + let mut _40: !; + let mut _41: std::result::Result; + let _42: std::string::String; + let mut _43: std::string::String; + let mut _44: std::ops::ControlFlow, std::string::String>; + let mut _45: std::result::Result; + let mut _46: u64; + let mut _47: u64; + let mut _48: isize; + let _49: std::result::Result; + let mut _50: !; + let mut _51: std::result::Result; + let _52: std::string::String; ++ let mut _53: bool; ++ let mut _54: bool; ++ let mut _55: bool; ++ let mut _56: bool; + scope 1 { + debug residual => _9; + scope 2 { + } + } + scope 3 { + debug val => _12; + scope 4 { + } + } + scope 5 { + debug residual => _19; + scope 6 { + } + } + scope 7 { + debug val => _22; + scope 8 { + } + } + scope 9 { + debug residual => _29; + scope 10 { + } + } + scope 11 { + debug val => _32; + scope 12 { + } + } + scope 13 { + debug residual => _39; + scope 14 { + } + } + scope 15 { + debug val => _42; + scope 16 { + } + } + scope 17 { + debug residual => _49; + scope 18 { + } + } + scope 19 { + debug val => _52; + scope 20 { + } + } + + bb0: { ++ _56 = const false; ++ _55 = const false; ++ _54 = const false; ++ _53 = const false; + StorageLive(_2); + StorageLive(_3); + StorageLive(_4); + StorageLive(_5); + StorageLive(_6); + StorageLive(_7); + _7 = copy _1; + _6 = BitXor(move _7, const 0_u64); + StorageDead(_7); + _5 = make_one(move _6) -> [return: bb1, unwind continue]; + } + + bb1: { + StorageDead(_6); + _4 = as Try>::branch(move _5) -> [return: bb2, unwind: bb91]; + } + + bb2: { ++ _56 = const true; + StorageDead(_5); + PlaceMention(_4); + _8 = discriminant(_4); + switchInt(move _8) -> [0: bb4, 1: bb5, otherwise: bb3]; + } + + bb3: { + unreachable; + } + + bb4: { + StorageLive(_12); + _12 = move ((_4 as Continue).0: std::string::String); + _3 = move _12; +- drop(_12) -> [return: bb7, unwind: bb90]; ++ goto -> bb7; + } + + bb5: { + StorageLive(_9); + _9 = copy ((_4 as Break).0: std::result::Result); + StorageLive(_11); + _11 = copy _9; + _0 = as FromResidual>>::from_residual(move _11) -> [return: bb6, unwind: bb90]; + } + + bb6: { + StorageDead(_11); + StorageDead(_9); + StorageDead(_3); + StorageDead(_2); + goto -> bb60; + } + + bb7: { + StorageDead(_12); + StorageLive(_13); + StorageLive(_14); + StorageLive(_15); + StorageLive(_16); + StorageLive(_17); + _17 = copy _1; + _16 = BitXor(move _17, const 1_u64); + StorageDead(_17); + _15 = make_one(move _16) -> [return: bb8, unwind: bb89]; + } + + bb8: { + StorageDead(_16); + _14 = as Try>::branch(move _15) -> [return: bb9, unwind: bb88]; + } + + bb9: { ++ _55 = const true; + StorageDead(_15); + PlaceMention(_14); + _18 = discriminant(_14); + switchInt(move _18) -> [0: bb10, 1: bb11, otherwise: bb3]; + } + + bb10: { + StorageLive(_22); + _22 = move ((_14 as Continue).0: std::string::String); + _13 = move _22; +- drop(_22) -> [return: bb13, unwind: bb86]; ++ goto -> bb13; + } + + bb11: { + StorageLive(_19); + _19 = copy ((_14 as Break).0: std::result::Result); + StorageLive(_21); + _21 = copy _19; + _0 = as FromResidual>>::from_residual(move _21) -> [return: bb12, unwind: bb86]; + } + + bb12: { + StorageDead(_21); + StorageDead(_19); + StorageDead(_13); + drop(_3) -> [return: bb57, unwind: bb87]; + } + + bb13: { + StorageDead(_22); + StorageLive(_23); + StorageLive(_24); + StorageLive(_25); + StorageLive(_26); + StorageLive(_27); + _27 = copy _1; + _26 = BitXor(move _27, const 2_u64); + StorageDead(_27); + _25 = make_one(move _26) -> [return: bb14, unwind: bb85]; + } + + bb14: { + StorageDead(_26); + _24 = as Try>::branch(move _25) -> [return: bb15, unwind: bb84]; + } + + bb15: { ++ _54 = const true; + StorageDead(_25); + PlaceMention(_24); + _28 = discriminant(_24); + switchInt(move _28) -> [0: bb16, 1: bb17, otherwise: bb3]; + } + + bb16: { + StorageLive(_32); + _32 = move ((_24 as Continue).0: std::string::String); + _23 = move _32; +- drop(_32) -> [return: bb19, unwind: bb81]; ++ goto -> bb19; + } + + bb17: { + StorageLive(_29); + _29 = copy ((_24 as Break).0: std::result::Result); + StorageLive(_31); + _31 = copy _29; + _0 = as FromResidual>>::from_residual(move _31) -> [return: bb18, unwind: bb81]; + } + + bb18: { + StorageDead(_31); + StorageDead(_29); + StorageDead(_23); + drop(_13) -> [return: bb53, unwind: bb82]; + } + + bb19: { + StorageDead(_32); + StorageLive(_33); + StorageLive(_34); + StorageLive(_35); + StorageLive(_36); + StorageLive(_37); + _37 = copy _1; + _36 = BitXor(move _37, const 3_u64); + StorageDead(_37); + _35 = make_one(move _36) -> [return: bb20, unwind: bb80]; + } + + bb20: { + StorageDead(_36); + _34 = as Try>::branch(move _35) -> [return: bb21, unwind: bb79]; + } + + bb21: { ++ _53 = const true; + StorageDead(_35); + PlaceMention(_34); + _38 = discriminant(_34); + switchInt(move _38) -> [0: bb22, 1: bb23, otherwise: bb3]; + } + + bb22: { + StorageLive(_42); + _42 = move ((_34 as Continue).0: std::string::String); + _33 = move _42; +- drop(_42) -> [return: bb25, unwind: bb75]; ++ goto -> bb25; + } + + bb23: { + StorageLive(_39); + _39 = copy ((_34 as Break).0: std::result::Result); + StorageLive(_41); + _41 = copy _39; + _0 = as FromResidual>>::from_residual(move _41) -> [return: bb24, unwind: bb75]; + } + + bb24: { + StorageDead(_41); + StorageDead(_39); + StorageDead(_33); + drop(_23) -> [return: bb48, unwind: bb76]; + } + + bb25: { + StorageDead(_42); + StorageLive(_43); + StorageLive(_44); + StorageLive(_45); + StorageLive(_46); + StorageLive(_47); + _47 = copy _1; + _46 = BitXor(move _47, const 4_u64); + StorageDead(_47); + _45 = make_one(move _46) -> [return: bb26, unwind: bb74]; + } + + bb26: { + StorageDead(_46); + _44 = as Try>::branch(move _45) -> [return: bb27, unwind: bb73]; + } + + bb27: { + StorageDead(_45); + PlaceMention(_44); + _48 = discriminant(_44); + switchInt(move _48) -> [0: bb28, 1: bb29, otherwise: bb3]; + } + + bb28: { + StorageLive(_52); + _52 = move ((_44 as Continue).0: std::string::String); + _43 = move _52; +- drop(_52) -> [return: bb31, unwind: bb68]; ++ goto -> bb31; + } + + bb29: { + StorageLive(_49); + _49 = copy ((_44 as Break).0: std::result::Result); + StorageLive(_51); + _51 = copy _49; + _0 = as FromResidual>>::from_residual(move _51) -> [return: bb30, unwind: bb68]; + } + + bb30: { + StorageDead(_51); + StorageDead(_49); + StorageDead(_43); + drop(_33) -> [return: bb43, unwind: bb69]; + } + + bb31: { + StorageDead(_52); + _2 = Big { f0: move _3, f1: move _13, f2: move _23, f3: move _33, f4: move _43 }; +- drop(_43) -> [return: bb32, unwind: bb63]; ++ goto -> bb32; + } + + bb32: { + StorageDead(_43); +- drop(_33) -> [return: bb33, unwind: bb64]; ++ goto -> bb33; + } + + bb33: { + StorageDead(_33); +- drop(_23) -> [return: bb34, unwind: bb65]; ++ goto -> bb34; + } + + bb34: { + StorageDead(_23); +- drop(_13) -> [return: bb35, unwind: bb66]; ++ goto -> bb35; + } + + bb35: { + StorageDead(_13); +- drop(_3) -> [return: bb36, unwind: bb67]; ++ goto -> bb36; + } + + bb36: { + StorageDead(_3); + _0 = Result::::Ok(move _2); +- drop(_2) -> [return: bb37, unwind: bb72]; ++ goto -> bb37; + } + + bb37: { + StorageDead(_2); +- drop(_44) -> [return: bb38, unwind: bb78]; ++ goto -> bb93; + } + + bb38: { + StorageDead(_44); +- drop(_34) -> [return: bb39, unwind: bb83]; ++ goto -> bb94; + } + + bb39: { ++ _53 = const false; + StorageDead(_34); +- drop(_24) -> [return: bb40, unwind: bb87]; ++ goto -> bb95; + } + + bb40: { ++ _54 = const false; + StorageDead(_24); +- drop(_14) -> [return: bb41, unwind: bb90]; ++ goto -> bb96; + } + + bb41: { ++ _55 = const false; + StorageDead(_14); +- drop(_4) -> [return: bb42, unwind continue]; ++ goto -> bb97; + } + + bb42: { ++ _56 = const false; + StorageDead(_4); + goto -> bb62; + } + + bb43: { + StorageDead(_33); + drop(_23) -> [return: bb44, unwind: bb70]; + } + + bb44: { + StorageDead(_23); + drop(_13) -> [return: bb45, unwind: bb71]; + } + + bb45: { + StorageDead(_13); + drop(_3) -> [return: bb46, unwind: bb72]; + } + + bb46: { + StorageDead(_3); + StorageDead(_2); +- drop(_44) -> [return: bb47, unwind: bb78]; ++ goto -> bb98; + } + + bb47: { + StorageDead(_44); + goto -> bb51; + } + + bb48: { + StorageDead(_23); + drop(_13) -> [return: bb49, unwind: bb77]; + } + + bb49: { + StorageDead(_13); + drop(_3) -> [return: bb50, unwind: bb78]; + } + + bb50: { + StorageDead(_3); + StorageDead(_2); + goto -> bb51; + } + + bb51: { +- drop(_34) -> [return: bb52, unwind: bb83]; ++ goto -> bb99; + } + + bb52: { ++ _53 = const false; + StorageDead(_34); + goto -> bb55; + } + + bb53: { + StorageDead(_13); + drop(_3) -> [return: bb54, unwind: bb83]; + } + + bb54: { + StorageDead(_3); + StorageDead(_2); + goto -> bb55; + } + + bb55: { +- drop(_24) -> [return: bb56, unwind: bb87]; ++ goto -> bb100; + } + + bb56: { ++ _54 = const false; + StorageDead(_24); + goto -> bb58; + } + + bb57: { + StorageDead(_3); + StorageDead(_2); + goto -> bb58; + } + + bb58: { +- drop(_14) -> [return: bb59, unwind: bb90]; ++ goto -> bb101; + } + + bb59: { ++ _55 = const false; + StorageDead(_14); + goto -> bb60; + } + + bb60: { +- drop(_4) -> [return: bb61, unwind continue]; ++ goto -> bb102; + } + + bb61: { ++ _56 = const false; + StorageDead(_4); + goto -> bb62; + } + + bb62: { + return; + } + + bb63 (cleanup): { +- drop(_33) -> [return: bb64, unwind terminate(cleanup)]; ++ goto -> bb64; + } + + bb64 (cleanup): { +- drop(_23) -> [return: bb65, unwind terminate(cleanup)]; ++ goto -> bb65; + } + + bb65 (cleanup): { +- drop(_13) -> [return: bb66, unwind terminate(cleanup)]; ++ goto -> bb66; + } + + bb66 (cleanup): { +- drop(_3) -> [return: bb67, unwind terminate(cleanup)]; ++ goto -> bb67; + } + + bb67 (cleanup): { +- drop(_2) -> [return: bb72, unwind terminate(cleanup)]; ++ goto -> bb72; + } + + bb68 (cleanup): { + drop(_33) -> [return: bb69, unwind terminate(cleanup)]; + } + + bb69 (cleanup): { + drop(_23) -> [return: bb70, unwind terminate(cleanup)]; + } + + bb70 (cleanup): { + drop(_13) -> [return: bb71, unwind terminate(cleanup)]; + } + + bb71 (cleanup): { + drop(_3) -> [return: bb72, unwind terminate(cleanup)]; + } + + bb72 (cleanup): { +- drop(_44) -> [return: bb78, unwind terminate(cleanup)]; ++ goto -> bb78; + } + + bb73 (cleanup): { +- drop(_45) -> [return: bb74, unwind terminate(cleanup)]; ++ goto -> bb74; + } + + bb74 (cleanup): { + drop(_33) -> [return: bb75, unwind terminate(cleanup)]; + } + + bb75 (cleanup): { + drop(_23) -> [return: bb76, unwind terminate(cleanup)]; + } + + bb76 (cleanup): { + drop(_13) -> [return: bb77, unwind terminate(cleanup)]; + } + + bb77 (cleanup): { + drop(_3) -> [return: bb78, unwind terminate(cleanup)]; + } + + bb78 (cleanup): { +- drop(_34) -> [return: bb83, unwind terminate(cleanup)]; ++ goto -> bb83; + } + + bb79 (cleanup): { +- drop(_35) -> [return: bb80, unwind terminate(cleanup)]; ++ goto -> bb80; + } + + bb80 (cleanup): { + drop(_23) -> [return: bb81, unwind terminate(cleanup)]; + } + + bb81 (cleanup): { + drop(_13) -> [return: bb82, unwind terminate(cleanup)]; + } + + bb82 (cleanup): { + drop(_3) -> [return: bb83, unwind terminate(cleanup)]; + } + + bb83 (cleanup): { +- drop(_24) -> [return: bb87, unwind terminate(cleanup)]; ++ goto -> bb87; + } + + bb84 (cleanup): { +- drop(_25) -> [return: bb85, unwind terminate(cleanup)]; ++ goto -> bb85; + } + + bb85 (cleanup): { + drop(_13) -> [return: bb86, unwind terminate(cleanup)]; + } + + bb86 (cleanup): { + drop(_3) -> [return: bb87, unwind terminate(cleanup)]; + } + + bb87 (cleanup): { +- drop(_14) -> [return: bb90, unwind terminate(cleanup)]; ++ goto -> bb90; + } + + bb88 (cleanup): { +- drop(_15) -> [return: bb89, unwind terminate(cleanup)]; ++ goto -> bb89; + } + + bb89 (cleanup): { + drop(_3) -> [return: bb90, unwind terminate(cleanup)]; + } + + bb90 (cleanup): { +- drop(_4) -> [return: bb92, unwind terminate(cleanup)]; ++ goto -> bb92; + } + + bb91 (cleanup): { +- drop(_5) -> [return: bb92, unwind terminate(cleanup)]; ++ goto -> bb92; + } + + bb92 (cleanup): { + resume; ++ } ++ ++ bb93: { ++ goto -> bb38; ++ } ++ ++ bb94: { ++ goto -> bb39; ++ } ++ ++ bb95: { ++ goto -> bb40; ++ } ++ ++ bb96: { ++ goto -> bb41; ++ } ++ ++ bb97: { ++ goto -> bb42; ++ } ++ ++ bb98: { ++ goto -> bb47; ++ } ++ ++ bb99: { ++ goto -> bb52; ++ } ++ ++ bb100: { ++ goto -> bb56; ++ } ++ ++ bb101: { ++ goto -> bb59; ++ } ++ ++ bb102: { ++ goto -> bb61; + } + } + diff --git a/tests/mir-opt/building/fallible_struct_drop.build.built.after.mir b/tests/mir-opt/building/fallible_struct_drop.build.built.after.mir new file mode 100644 index 0000000000000..7e1e58d788880 --- /dev/null +++ b/tests/mir-opt/building/fallible_struct_drop.build.built.after.mir @@ -0,0 +1,794 @@ +// MIR for `build` after built + +fn build(_1: u64) -> Result { + debug s => _1; + let mut _0: std::result::Result; + let mut _2: Big; + let mut _3: std::string::String; + let mut _4: std::ops::ControlFlow, std::string::String>; + let mut _5: std::result::Result; + let mut _6: u64; + let mut _7: u64; + let mut _8: isize; + let _9: std::result::Result; + let mut _10: !; + let mut _11: std::result::Result; + let _12: std::string::String; + let mut _13: std::string::String; + let mut _14: std::ops::ControlFlow, std::string::String>; + let mut _15: std::result::Result; + let mut _16: u64; + let mut _17: u64; + let mut _18: isize; + let _19: std::result::Result; + let mut _20: !; + let mut _21: std::result::Result; + let _22: std::string::String; + let mut _23: std::string::String; + let mut _24: std::ops::ControlFlow, std::string::String>; + let mut _25: std::result::Result; + let mut _26: u64; + let mut _27: u64; + let mut _28: isize; + let _29: std::result::Result; + let mut _30: !; + let mut _31: std::result::Result; + let _32: std::string::String; + let mut _33: std::string::String; + let mut _34: std::ops::ControlFlow, std::string::String>; + let mut _35: std::result::Result; + let mut _36: u64; + let mut _37: u64; + let mut _38: isize; + let _39: std::result::Result; + let mut _40: !; + let mut _41: std::result::Result; + let _42: std::string::String; + let mut _43: std::string::String; + let mut _44: std::ops::ControlFlow, std::string::String>; + let mut _45: std::result::Result; + let mut _46: u64; + let mut _47: u64; + let mut _48: isize; + let _49: std::result::Result; + let mut _50: !; + let mut _51: std::result::Result; + let _52: std::string::String; + scope 1 { + debug residual => _9; + scope 2 { + } + } + scope 3 { + debug val => _12; + scope 4 { + } + } + scope 5 { + debug residual => _19; + scope 6 { + } + } + scope 7 { + debug val => _22; + scope 8 { + } + } + scope 9 { + debug residual => _29; + scope 10 { + } + } + scope 11 { + debug val => _32; + scope 12 { + } + } + scope 13 { + debug residual => _39; + scope 14 { + } + } + scope 15 { + debug val => _42; + scope 16 { + } + } + scope 17 { + debug residual => _49; + scope 18 { + } + } + scope 19 { + debug val => _52; + scope 20 { + } + } + + bb0: { + StorageLive(_2); + StorageLive(_3); + StorageLive(_4); + StorageLive(_5); + StorageLive(_6); + StorageLive(_7); + _7 = copy _1; + _6 = BitXor(move _7, const 0_u64); + StorageDead(_7); + _5 = make_one(move _6) -> [return: bb1, unwind: bb131]; + } + + bb1: { + StorageDead(_6); + _4 = as Try>::branch(move _5) -> [return: bb2, unwind: bb130]; + } + + bb2: { + StorageDead(_5); + PlaceMention(_4); + _8 = discriminant(_4); + switchInt(move _8) -> [0: bb6, 1: bb4, otherwise: bb3]; + } + + bb3: { + FakeRead(ForMatchedPlace(None), _4); + unreachable; + } + + bb4: { + falseEdge -> [real: bb8, imaginary: bb6]; + } + + bb5: { + goto -> bb3; + } + + bb6: { + StorageLive(_12); + _12 = move ((_4 as Continue).0: std::string::String); + _3 = move _12; + drop(_12) -> [return: bb12, unwind: bb129]; + } + + bb7: { + goto -> bb3; + } + + bb8: { + StorageLive(_9); + _9 = copy ((_4 as Break).0: std::result::Result); + StorageLive(_11); + _11 = copy _9; + _0 = as FromResidual>>::from_residual(move _11) -> [return: bb9, unwind: bb129]; + } + + bb9: { + StorageDead(_11); + goto -> bb98; + } + + bb10: { + unreachable; + } + + bb11: { + StorageDead(_9); + goto -> bb13; + } + + bb12: { + StorageDead(_12); + goto -> bb13; + } + + bb13: { + StorageLive(_13); + StorageLive(_14); + StorageLive(_15); + StorageLive(_16); + StorageLive(_17); + _17 = copy _1; + _16 = BitXor(move _17, const 1_u64); + StorageDead(_17); + _15 = make_one(move _16) -> [return: bb14, unwind: bb128]; + } + + bb14: { + StorageDead(_16); + _14 = as Try>::branch(move _15) -> [return: bb15, unwind: bb127]; + } + + bb15: { + StorageDead(_15); + PlaceMention(_14); + _18 = discriminant(_14); + switchInt(move _18) -> [0: bb19, 1: bb17, otherwise: bb16]; + } + + bb16: { + FakeRead(ForMatchedPlace(None), _14); + unreachable; + } + + bb17: { + falseEdge -> [real: bb21, imaginary: bb19]; + } + + bb18: { + goto -> bb16; + } + + bb19: { + StorageLive(_22); + _22 = move ((_14 as Continue).0: std::string::String); + _13 = move _22; + drop(_22) -> [return: bb25, unwind: bb125]; + } + + bb20: { + goto -> bb16; + } + + bb21: { + StorageLive(_19); + _19 = copy ((_14 as Break).0: std::result::Result); + StorageLive(_21); + _21 = copy _19; + _0 = as FromResidual>>::from_residual(move _21) -> [return: bb22, unwind: bb125]; + } + + bb22: { + StorageDead(_21); + goto -> bb94; + } + + bb23: { + unreachable; + } + + bb24: { + StorageDead(_19); + goto -> bb26; + } + + bb25: { + StorageDead(_22); + goto -> bb26; + } + + bb26: { + StorageLive(_23); + StorageLive(_24); + StorageLive(_25); + StorageLive(_26); + StorageLive(_27); + _27 = copy _1; + _26 = BitXor(move _27, const 2_u64); + StorageDead(_27); + _25 = make_one(move _26) -> [return: bb27, unwind: bb124]; + } + + bb27: { + StorageDead(_26); + _24 = as Try>::branch(move _25) -> [return: bb28, unwind: bb123]; + } + + bb28: { + StorageDead(_25); + PlaceMention(_24); + _28 = discriminant(_24); + switchInt(move _28) -> [0: bb32, 1: bb30, otherwise: bb29]; + } + + bb29: { + FakeRead(ForMatchedPlace(None), _24); + unreachable; + } + + bb30: { + falseEdge -> [real: bb34, imaginary: bb32]; + } + + bb31: { + goto -> bb29; + } + + bb32: { + StorageLive(_32); + _32 = move ((_24 as Continue).0: std::string::String); + _23 = move _32; + drop(_32) -> [return: bb38, unwind: bb120]; + } + + bb33: { + goto -> bb29; + } + + bb34: { + StorageLive(_29); + _29 = copy ((_24 as Break).0: std::result::Result); + StorageLive(_31); + _31 = copy _29; + _0 = as FromResidual>>::from_residual(move _31) -> [return: bb35, unwind: bb120]; + } + + bb35: { + StorageDead(_31); + goto -> bb89; + } + + bb36: { + unreachable; + } + + bb37: { + StorageDead(_29); + goto -> bb39; + } + + bb38: { + StorageDead(_32); + goto -> bb39; + } + + bb39: { + StorageLive(_33); + StorageLive(_34); + StorageLive(_35); + StorageLive(_36); + StorageLive(_37); + _37 = copy _1; + _36 = BitXor(move _37, const 3_u64); + StorageDead(_37); + _35 = make_one(move _36) -> [return: bb40, unwind: bb119]; + } + + bb40: { + StorageDead(_36); + _34 = as Try>::branch(move _35) -> [return: bb41, unwind: bb118]; + } + + bb41: { + StorageDead(_35); + PlaceMention(_34); + _38 = discriminant(_34); + switchInt(move _38) -> [0: bb45, 1: bb43, otherwise: bb42]; + } + + bb42: { + FakeRead(ForMatchedPlace(None), _34); + unreachable; + } + + bb43: { + falseEdge -> [real: bb47, imaginary: bb45]; + } + + bb44: { + goto -> bb42; + } + + bb45: { + StorageLive(_42); + _42 = move ((_34 as Continue).0: std::string::String); + _33 = move _42; + drop(_42) -> [return: bb51, unwind: bb114]; + } + + bb46: { + goto -> bb42; + } + + bb47: { + StorageLive(_39); + _39 = copy ((_34 as Break).0: std::result::Result); + StorageLive(_41); + _41 = copy _39; + _0 = as FromResidual>>::from_residual(move _41) -> [return: bb48, unwind: bb114]; + } + + bb48: { + StorageDead(_41); + goto -> bb83; + } + + bb49: { + unreachable; + } + + bb50: { + StorageDead(_39); + goto -> bb52; + } + + bb51: { + StorageDead(_42); + goto -> bb52; + } + + bb52: { + StorageLive(_43); + StorageLive(_44); + StorageLive(_45); + StorageLive(_46); + StorageLive(_47); + _47 = copy _1; + _46 = BitXor(move _47, const 4_u64); + StorageDead(_47); + _45 = make_one(move _46) -> [return: bb53, unwind: bb113]; + } + + bb53: { + StorageDead(_46); + _44 = as Try>::branch(move _45) -> [return: bb54, unwind: bb112]; + } + + bb54: { + StorageDead(_45); + PlaceMention(_44); + _48 = discriminant(_44); + switchInt(move _48) -> [0: bb58, 1: bb56, otherwise: bb55]; + } + + bb55: { + FakeRead(ForMatchedPlace(None), _44); + unreachable; + } + + bb56: { + falseEdge -> [real: bb60, imaginary: bb58]; + } + + bb57: { + goto -> bb55; + } + + bb58: { + StorageLive(_52); + _52 = move ((_44 as Continue).0: std::string::String); + _43 = move _52; + drop(_52) -> [return: bb64, unwind: bb107]; + } + + bb59: { + goto -> bb55; + } + + bb60: { + StorageLive(_49); + _49 = copy ((_44 as Break).0: std::result::Result); + StorageLive(_51); + _51 = copy _49; + _0 = as FromResidual>>::from_residual(move _51) -> [return: bb61, unwind: bb107]; + } + + bb61: { + StorageDead(_51); + goto -> bb77; + } + + bb62: { + unreachable; + } + + bb63: { + StorageDead(_49); + goto -> bb65; + } + + bb64: { + StorageDead(_52); + goto -> bb65; + } + + bb65: { + _2 = Big { f0: move _3, f1: move _13, f2: move _23, f3: move _33, f4: move _43 }; + drop(_43) -> [return: bb66, unwind: bb102]; + } + + bb66: { + StorageDead(_43); + drop(_33) -> [return: bb67, unwind: bb103]; + } + + bb67: { + StorageDead(_33); + drop(_23) -> [return: bb68, unwind: bb104]; + } + + bb68: { + StorageDead(_23); + drop(_13) -> [return: bb69, unwind: bb105]; + } + + bb69: { + StorageDead(_13); + drop(_3) -> [return: bb70, unwind: bb106]; + } + + bb70: { + StorageDead(_3); + _0 = Result::::Ok(move _2); + drop(_2) -> [return: bb71, unwind: bb111]; + } + + bb71: { + StorageDead(_2); + drop(_44) -> [return: bb72, unwind: bb117]; + } + + bb72: { + StorageDead(_44); + drop(_34) -> [return: bb73, unwind: bb122]; + } + + bb73: { + StorageDead(_34); + drop(_24) -> [return: bb74, unwind: bb126]; + } + + bb74: { + StorageDead(_24); + drop(_14) -> [return: bb75, unwind: bb129]; + } + + bb75: { + StorageDead(_14); + drop(_4) -> [return: bb76, unwind: bb131]; + } + + bb76: { + StorageDead(_4); + goto -> bb101; + } + + bb77: { + StorageDead(_49); + StorageDead(_43); + drop(_33) -> [return: bb78, unwind: bb108]; + } + + bb78: { + StorageDead(_33); + drop(_23) -> [return: bb79, unwind: bb109]; + } + + bb79: { + StorageDead(_23); + drop(_13) -> [return: bb80, unwind: bb110]; + } + + bb80: { + StorageDead(_13); + drop(_3) -> [return: bb81, unwind: bb111]; + } + + bb81: { + StorageDead(_3); + StorageDead(_2); + drop(_44) -> [return: bb82, unwind: bb117]; + } + + bb82: { + StorageDead(_44); + goto -> bb87; + } + + bb83: { + StorageDead(_39); + StorageDead(_33); + drop(_23) -> [return: bb84, unwind: bb115]; + } + + bb84: { + StorageDead(_23); + drop(_13) -> [return: bb85, unwind: bb116]; + } + + bb85: { + StorageDead(_13); + drop(_3) -> [return: bb86, unwind: bb117]; + } + + bb86: { + StorageDead(_3); + StorageDead(_2); + goto -> bb87; + } + + bb87: { + drop(_34) -> [return: bb88, unwind: bb122]; + } + + bb88: { + StorageDead(_34); + goto -> bb92; + } + + bb89: { + StorageDead(_29); + StorageDead(_23); + drop(_13) -> [return: bb90, unwind: bb121]; + } + + bb90: { + StorageDead(_13); + drop(_3) -> [return: bb91, unwind: bb122]; + } + + bb91: { + StorageDead(_3); + StorageDead(_2); + goto -> bb92; + } + + bb92: { + drop(_24) -> [return: bb93, unwind: bb126]; + } + + bb93: { + StorageDead(_24); + goto -> bb96; + } + + bb94: { + StorageDead(_19); + StorageDead(_13); + drop(_3) -> [return: bb95, unwind: bb126]; + } + + bb95: { + StorageDead(_3); + StorageDead(_2); + goto -> bb96; + } + + bb96: { + drop(_14) -> [return: bb97, unwind: bb129]; + } + + bb97: { + StorageDead(_14); + goto -> bb99; + } + + bb98: { + StorageDead(_9); + StorageDead(_3); + StorageDead(_2); + goto -> bb99; + } + + bb99: { + drop(_4) -> [return: bb100, unwind: bb131]; + } + + bb100: { + StorageDead(_4); + goto -> bb101; + } + + bb101: { + return; + } + + bb102 (cleanup): { + drop(_33) -> [return: bb103, unwind terminate(cleanup)]; + } + + bb103 (cleanup): { + drop(_23) -> [return: bb104, unwind terminate(cleanup)]; + } + + bb104 (cleanup): { + drop(_13) -> [return: bb105, unwind terminate(cleanup)]; + } + + bb105 (cleanup): { + drop(_3) -> [return: bb106, unwind terminate(cleanup)]; + } + + bb106 (cleanup): { + drop(_2) -> [return: bb111, unwind terminate(cleanup)]; + } + + bb107 (cleanup): { + drop(_33) -> [return: bb108, unwind terminate(cleanup)]; + } + + bb108 (cleanup): { + drop(_23) -> [return: bb109, unwind terminate(cleanup)]; + } + + bb109 (cleanup): { + drop(_13) -> [return: bb110, unwind terminate(cleanup)]; + } + + bb110 (cleanup): { + drop(_3) -> [return: bb111, unwind terminate(cleanup)]; + } + + bb111 (cleanup): { + drop(_44) -> [return: bb117, unwind terminate(cleanup)]; + } + + bb112 (cleanup): { + drop(_45) -> [return: bb113, unwind terminate(cleanup)]; + } + + bb113 (cleanup): { + drop(_33) -> [return: bb114, unwind terminate(cleanup)]; + } + + bb114 (cleanup): { + drop(_23) -> [return: bb115, unwind terminate(cleanup)]; + } + + bb115 (cleanup): { + drop(_13) -> [return: bb116, unwind terminate(cleanup)]; + } + + bb116 (cleanup): { + drop(_3) -> [return: bb117, unwind terminate(cleanup)]; + } + + bb117 (cleanup): { + drop(_34) -> [return: bb122, unwind terminate(cleanup)]; + } + + bb118 (cleanup): { + drop(_35) -> [return: bb119, unwind terminate(cleanup)]; + } + + bb119 (cleanup): { + drop(_23) -> [return: bb120, unwind terminate(cleanup)]; + } + + bb120 (cleanup): { + drop(_13) -> [return: bb121, unwind terminate(cleanup)]; + } + + bb121 (cleanup): { + drop(_3) -> [return: bb122, unwind terminate(cleanup)]; + } + + bb122 (cleanup): { + drop(_24) -> [return: bb126, unwind terminate(cleanup)]; + } + + bb123 (cleanup): { + drop(_25) -> [return: bb124, unwind terminate(cleanup)]; + } + + bb124 (cleanup): { + drop(_13) -> [return: bb125, unwind terminate(cleanup)]; + } + + bb125 (cleanup): { + drop(_3) -> [return: bb126, unwind terminate(cleanup)]; + } + + bb126 (cleanup): { + drop(_14) -> [return: bb129, unwind terminate(cleanup)]; + } + + bb127 (cleanup): { + drop(_15) -> [return: bb128, unwind terminate(cleanup)]; + } + + bb128 (cleanup): { + drop(_3) -> [return: bb129, unwind terminate(cleanup)]; + } + + bb129 (cleanup): { + drop(_4) -> [return: bb131, unwind terminate(cleanup)]; + } + + bb130 (cleanup): { + drop(_5) -> [return: bb131, unwind terminate(cleanup)]; + } + + bb131 (cleanup): { + resume; + } +} diff --git a/tests/mir-opt/building/fallible_struct_drop.rs b/tests/mir-opt/building/fallible_struct_drop.rs new file mode 100644 index 0000000000000..ff297499088fd --- /dev/null +++ b/tests/mir-opt/building/fallible_struct_drop.rs @@ -0,0 +1,28 @@ +//@ needs-unwind +//@ skip-filecheck + +#[inline(never)] +pub fn make_one(x: u64) -> Result { + if x == u64::MAX { Err(()) } else { Ok(x.to_string()) } +} + +pub struct Big { + f0: String, + f1: String, + f2: String, + f3: String, + f4: String, +} + +// EMIT_MIR fallible_struct_drop.build.built.after.mir +// EMIT_MIR fallible_struct_drop.build.ElaborateDrops.diff +#[inline(never)] +pub fn build(s: u64) -> Result { + Ok(Big { + f0: make_one(s ^ 0)?, + f1: make_one(s ^ 1)?, + f2: make_one(s ^ 2)?, + f3: make_one(s ^ 3)?, + f4: make_one(s ^ 4)?, + }) +} diff --git a/tests/mir-opt/coroutine/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-unwind.mir b/tests/mir-opt/coroutine/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-unwind.mir index 83bfc3992b93b..c7f87c203eade 100644 --- a/tests/mir-opt/coroutine/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-unwind.mir +++ b/tests/mir-opt/coroutine/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-unwind.mir @@ -32,7 +32,7 @@ fn a::{closure#0}(_1: Pin<&mut {async fn body of a()}>, _2: &mut Context<'_>) bb0: { _23 = copy (_1.0: &mut {async fn body of a()}); _22 = discriminant((*_23)); - switchInt(move _22) -> [0: bb17, 2: bb23, 3: bb21, 4: bb22, otherwise: bb24]; + switchInt(move _22) -> [0: bb16, 2: bb22, 3: bb20, 4: bb21, otherwise: bb23]; } bb1: { @@ -47,11 +47,11 @@ fn a::{closure#0}(_1: Pin<&mut {async fn body of a()}>, _2: &mut Context<'_>) bb3 (cleanup): { nop; - goto -> bb15; + goto -> bb4; } bb4 (cleanup): { - goto -> bb20; + goto -> bb19; } bb5: { @@ -108,49 +108,45 @@ fn a::{closure#0}(_1: Pin<&mut {async fn body of a()}>, _2: &mut Context<'_>) goto -> bb13; } - bb15 (cleanup): { - goto -> bb4; + bb15: { + _0 = Poll::<()>::Ready(const ()); + return; } bb16: { - _0 = Poll::<()>::Ready(const ()); - return; + goto -> bb18; } bb17: { - goto -> bb19; + goto -> bb15; } bb18: { - goto -> bb16; - } - - bb19: { - drop(((*_23).0: T)) -> [return: bb18, unwind: bb4]; + drop(((*_23).0: T)) -> [return: bb17, unwind: bb4]; } - bb20 (cleanup): { + bb19 (cleanup): { discriminant((*_23)) = 2; resume; } - bb21: { + bb20: { StorageLive(_5); _5 = move _2; goto -> bb7; } - bb22: { + bb21: { StorageLive(_12); _12 = move _2; goto -> bb14; } - bb23: { - assert(const false, "`async fn` resumed after panicking") -> [success: bb23, unwind continue]; + bb22: { + assert(const false, "`async fn` resumed after panicking") -> [success: bb22, unwind continue]; } - bb24: { + bb23: { _0 = Poll::<()>::Ready(const ()); return; } diff --git a/tests/mir-opt/early_otherwise_branch_unwind.poll.EarlyOtherwiseBranch.diff b/tests/mir-opt/early_otherwise_branch_unwind.poll.EarlyOtherwiseBranch.diff index b6450e43b09e6..0c4a54e8d17a3 100644 --- a/tests/mir-opt/early_otherwise_branch_unwind.poll.EarlyOtherwiseBranch.diff +++ b/tests/mir-opt/early_otherwise_branch_unwind.poll.EarlyOtherwiseBranch.diff @@ -10,8 +10,7 @@ let _5: std::vec::Vec; let _6: u8; let mut _7: bool; - let mut _8: bool; - let mut _9: isize; + let mut _8: isize; scope 1 { debug _trailers => _5; } @@ -21,9 +20,7 @@ bb0: { _7 = const false; - _8 = const false; _7 = const true; - _8 = const true; _4 = discriminant(_1); switchInt(copy _4) -> [0: bb2, 1: bb4, otherwise: bb1]; } @@ -39,17 +36,17 @@ bb3: { _2 = discriminant(((((_1 as Ready).0: std::result::Result>, u8>) as Ok).0: std::option::Option>)); - switchInt(copy _2) -> [0: bb5, 1: bb7, otherwise: bb1]; + switchInt(move _2) -> [0: bb5, 1: bb7, otherwise: bb1]; } bb4: { _0 = const (); - goto -> bb17; + goto -> bb15; } bb5: { _0 = const (); - goto -> bb17; + goto -> bb15; } bb6: { @@ -57,19 +54,19 @@ _6 = copy ((((_1 as Ready).0: std::result::Result>, u8>) as Err).0: u8); _0 = const (); StorageDead(_6); - goto -> bb17; + goto -> bb15; } bb7: { StorageLive(_5); _5 = move ((((((_1 as Ready).0: std::result::Result>, u8>) as Ok).0: std::option::Option>) as Some).0: std::vec::Vec); _0 = const (); - drop(_5) -> [return: bb8, unwind: bb20]; + drop(_5) -> [return: bb8, unwind: bb17]; } bb8: { StorageDead(_5); - goto -> bb17; + goto -> bb15; } bb9 (cleanup): { @@ -81,7 +78,7 @@ } bb11: { - switchInt(copy _7) -> [0: bb12, otherwise: bb16]; + switchInt(copy _7) -> [0: bb12, otherwise: bb14]; } bb12: { @@ -90,37 +87,24 @@ } bb13: { - switchInt(copy _8) -> [0: bb14, otherwise: bb15]; + goto -> bb12; } bb14: { - _8 = const false; - goto -> bb12; + _8 = discriminant(((_1 as Ready).0: std::result::Result>, u8>)); + switchInt(move _8) -> [0: bb13, otherwise: bb12]; } bb15: { - goto -> bb14; - } - - bb16: { - _9 = discriminant(((_1 as Ready).0: std::result::Result>, u8>)); - switchInt(move _9) -> [0: bb13, otherwise: bb12]; - } - - bb17: { switchInt(copy _4) -> [0: bb11, otherwise: bb10]; } - bb18 (cleanup): { - switchInt(copy _3) -> [0: bb19, otherwise: bb9]; - } - - bb19 (cleanup): { + bb16 (cleanup): { goto -> bb9; } - bb20 (cleanup): { - switchInt(copy _4) -> [0: bb18, otherwise: bb9]; + bb17 (cleanup): { + switchInt(copy _4) -> [0: bb16, otherwise: bb9]; } } diff --git a/tests/mir-opt/early_otherwise_branch_unwind.unwind.EarlyOtherwiseBranch.diff b/tests/mir-opt/early_otherwise_branch_unwind.unwind.EarlyOtherwiseBranch.diff index 2b2c007e082a7..3599b017876ef 100644 --- a/tests/mir-opt/early_otherwise_branch_unwind.unwind.EarlyOtherwiseBranch.diff +++ b/tests/mir-opt/early_otherwise_branch_unwind.unwind.EarlyOtherwiseBranch.diff @@ -9,17 +9,14 @@ let mut _4: isize; let _5: T; let mut _6: bool; - let mut _7: bool; - let mut _8: isize; + let mut _7: isize; scope 1 { debug _v => _5; } bb0: { _6 = const false; - _7 = const false; _6 = const true; - _7 = const true; _4 = discriminant(_1); switchInt(copy _4) -> [0: bb4, 1: bb2, otherwise: bb1]; } @@ -35,34 +32,34 @@ bb3: { _2 = discriminant(((((_1 as Some).0: std::option::Option>) as Some).0: std::option::Option)); - switchInt(copy _2) -> [0: bb6, 1: bb7, otherwise: bb1]; + switchInt(move _2) -> [0: bb6, 1: bb7, otherwise: bb1]; } bb4: { _0 = const (); - goto -> bb17; + goto -> bb15; } bb5: { _0 = const (); - goto -> bb17; + goto -> bb15; } bb6: { _0 = const (); - goto -> bb17; + goto -> bb15; } bb7: { StorageLive(_5); _5 = move ((((((_1 as Some).0: std::option::Option>) as Some).0: std::option::Option) as Some).0: T); _0 = const (); - drop(_5) -> [return: bb8, unwind: bb20]; + drop(_5) -> [return: bb8, unwind: bb17]; } bb8: { StorageDead(_5); - goto -> bb17; + goto -> bb15; } bb9 (cleanup): { @@ -74,7 +71,7 @@ } bb11: { - switchInt(copy _6) -> [0: bb12, otherwise: bb16]; + switchInt(copy _6) -> [0: bb12, otherwise: bb14]; } bb12: { @@ -83,37 +80,24 @@ } bb13: { - switchInt(copy _7) -> [0: bb14, otherwise: bb15]; + goto -> bb12; } bb14: { - _7 = const false; - goto -> bb12; + _7 = discriminant(((_1 as Some).0: std::option::Option>)); + switchInt(move _7) -> [1: bb13, otherwise: bb12]; } bb15: { - goto -> bb14; - } - - bb16: { - _8 = discriminant(((_1 as Some).0: std::option::Option>)); - switchInt(move _8) -> [1: bb13, otherwise: bb12]; - } - - bb17: { switchInt(copy _4) -> [1: bb11, otherwise: bb10]; } - bb18 (cleanup): { - switchInt(copy _3) -> [1: bb19, otherwise: bb9]; - } - - bb19 (cleanup): { + bb16 (cleanup): { goto -> bb9; } - bb20 (cleanup): { - switchInt(copy _4) -> [1: bb18, otherwise: bb9]; + bb17 (cleanup): { + switchInt(copy _4) -> [1: bb16, otherwise: bb9]; } } diff --git a/tests/mir-opt/gvn_copy_aggregate.remove_storage_dead.GVN.diff b/tests/mir-opt/gvn_copy_aggregate.remove_storage_dead.GVN.diff index c9cfc7efcd1a6..c2b55cef5bb24 100644 --- a/tests/mir-opt/gvn_copy_aggregate.remove_storage_dead.GVN.diff +++ b/tests/mir-opt/gvn_copy_aggregate.remove_storage_dead.GVN.diff @@ -9,8 +9,6 @@ let mut _4: fn() -> AlwaysSome; let _5: T; let mut _6: T; - let mut _7: isize; - let mut _8: isize; scope 1 { debug v => _2; } @@ -34,12 +32,11 @@ - _5 = move ((_3 as Some).0: T); - _2 = move _5; - StorageDead(_5); +- StorageDead(_3); + nop; + _5 = copy ((_3 as Some).0: T); + _2 = copy _5; + nop; - _7 = discriminant(_3); -- StorageDead(_3); + nop; StorageLive(_6); - _6 = move _2; diff --git a/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-abort.diff b/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-abort.diff index e2726464ef3ad..67363aa7deca4 100644 --- a/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-abort.diff +++ b/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-abort.diff @@ -86,7 +86,7 @@ bb9: { StorageDead(_2); - drop(_1) -> [return: bb10, unwind: bb12]; -+ goto -> bb19; ++ goto -> bb17; } bb10: { @@ -110,38 +110,30 @@ + goto -> bb10; + } + -+ bb14 (cleanup): { -+ drop(((_1 as F).0: K)) -> [return: bb12, unwind terminate(cleanup)]; -+ } -+ -+ bb15 (cleanup): { -+ switchInt(copy _7) -> [0: bb12, otherwise: bb14]; -+ } -+ -+ bb16: { ++ bb14: { + drop(_1) -> [return: bb13, unwind: bb12]; + } + -+ bb17 (cleanup): { ++ bb15 (cleanup): { + drop(_1) -> [return: bb12, unwind terminate(cleanup)]; + } + -+ bb18: { ++ bb16: { + _9 = discriminant(_1); -+ switchInt(move _9) -> [0: bb13, otherwise: bb16]; ++ switchInt(move _9) -> [0: bb13, otherwise: bb14]; + } + -+ bb19: { -+ switchInt(copy _7) -> [0: bb13, otherwise: bb18]; ++ bb17: { ++ switchInt(copy _7) -> [0: bb13, otherwise: bb16]; + } + -+ bb20 (cleanup): { ++ bb18 (cleanup): { + _10 = discriminant(_1); -+ switchInt(move _10) -> [0: bb15, otherwise: bb17]; ++ switchInt(move _10) -> [0: bb12, otherwise: bb15]; + } + -+ bb21 (cleanup): { -+ switchInt(copy _7) -> [0: bb12, otherwise: bb20]; ++ bb19 (cleanup): { ++ switchInt(copy _7) -> [0: bb12, otherwise: bb18]; } } diff --git a/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-unwind.diff b/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-unwind.diff index 7efa3330e66a7..15e16c563aec7 100644 --- a/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-unwind.diff +++ b/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-unwind.diff @@ -86,7 +86,7 @@ bb9: { StorageDead(_2); - drop(_1) -> [return: bb10, unwind continue]; -+ goto -> bb19; ++ goto -> bb17; } bb10: { @@ -110,38 +110,30 @@ + goto -> bb10; + } + -+ bb14 (cleanup): { -+ drop(((_1 as F).0: K)) -> [return: bb12, unwind terminate(cleanup)]; -+ } -+ -+ bb15 (cleanup): { -+ switchInt(copy _7) -> [0: bb12, otherwise: bb14]; -+ } -+ -+ bb16: { ++ bb14: { + drop(_1) -> [return: bb13, unwind: bb12]; + } + -+ bb17 (cleanup): { ++ bb15 (cleanup): { + drop(_1) -> [return: bb12, unwind terminate(cleanup)]; + } + -+ bb18: { ++ bb16: { + _9 = discriminant(_1); -+ switchInt(move _9) -> [0: bb13, otherwise: bb16]; ++ switchInt(move _9) -> [0: bb13, otherwise: bb14]; + } + -+ bb19: { -+ switchInt(copy _7) -> [0: bb13, otherwise: bb18]; ++ bb17: { ++ switchInt(copy _7) -> [0: bb13, otherwise: bb16]; + } + -+ bb20 (cleanup): { ++ bb18 (cleanup): { + _10 = discriminant(_1); -+ switchInt(move _10) -> [0: bb15, otherwise: bb17]; ++ switchInt(move _10) -> [0: bb12, otherwise: bb15]; + } + -+ bb21 (cleanup): { -+ switchInt(copy _7) -> [0: bb12, otherwise: bb20]; ++ bb19 (cleanup): { ++ switchInt(copy _7) -> [0: bb12, otherwise: bb18]; } } diff --git a/tests/mir-opt/match_arm_scopes.complicated_match.panic-abort.SimplifyCfg-initial.after-ElaborateDrops.after.diff b/tests/mir-opt/match_arm_scopes.complicated_match.panic-abort.SimplifyCfg-initial.after-ElaborateDrops.after.diff index 484bc7dad1289..984e1965e03c5 100644 --- a/tests/mir-opt/match_arm_scopes.complicated_match.panic-abort.SimplifyCfg-initial.after-ElaborateDrops.after.diff +++ b/tests/mir-opt/match_arm_scopes.complicated_match.panic-abort.SimplifyCfg-initial.after-ElaborateDrops.after.diff @@ -226,7 +226,7 @@ - bb22: { - drop(_2) -> [return: bb24, unwind: bb26]; + bb19: { -+ goto -> bb26; ++ goto -> bb24; } - bb23: { @@ -245,7 +245,7 @@ - bb25 (cleanup): { - drop(_2) -> [return: bb26, unwind terminate(cleanup)]; + bb22 (cleanup): { -+ goto -> bb27; ++ goto -> bb23; } - bb26 (cleanup): { @@ -255,18 +255,6 @@ + + bb24: { + goto -> bb21; -+ } -+ -+ bb25 (cleanup): { -+ goto -> bb23; -+ } -+ -+ bb26: { -+ goto -> bb24; -+ } -+ -+ bb27 (cleanup): { -+ goto -> bb23; } } diff --git a/tests/mir-opt/match_arm_scopes.complicated_match.panic-unwind.SimplifyCfg-initial.after-ElaborateDrops.after.diff b/tests/mir-opt/match_arm_scopes.complicated_match.panic-unwind.SimplifyCfg-initial.after-ElaborateDrops.after.diff index 484bc7dad1289..984e1965e03c5 100644 --- a/tests/mir-opt/match_arm_scopes.complicated_match.panic-unwind.SimplifyCfg-initial.after-ElaborateDrops.after.diff +++ b/tests/mir-opt/match_arm_scopes.complicated_match.panic-unwind.SimplifyCfg-initial.after-ElaborateDrops.after.diff @@ -226,7 +226,7 @@ - bb22: { - drop(_2) -> [return: bb24, unwind: bb26]; + bb19: { -+ goto -> bb26; ++ goto -> bb24; } - bb23: { @@ -245,7 +245,7 @@ - bb25 (cleanup): { - drop(_2) -> [return: bb26, unwind terminate(cleanup)]; + bb22 (cleanup): { -+ goto -> bb27; ++ goto -> bb23; } - bb26 (cleanup): { @@ -255,18 +255,6 @@ + + bb24: { + goto -> bb21; -+ } -+ -+ bb25 (cleanup): { -+ goto -> bb23; -+ } -+ -+ bb26: { -+ goto -> bb24; -+ } -+ -+ bb27 (cleanup): { -+ goto -> bb23; } } diff --git a/tests/mir-opt/no_drop_for_inactive_variant.unwrap.SimplifyCfg-pre-optimizations.after.panic-abort.mir b/tests/mir-opt/no_drop_for_inactive_variant.unwrap.SimplifyCfg-pre-optimizations.after.panic-abort.mir index 7933a36c92c26..0d737649d25c4 100644 --- a/tests/mir-opt/no_drop_for_inactive_variant.unwrap.SimplifyCfg-pre-optimizations.after.panic-abort.mir +++ b/tests/mir-opt/no_drop_for_inactive_variant.unwrap.SimplifyCfg-pre-optimizations.after.panic-abort.mir @@ -6,9 +6,6 @@ fn unwrap(_1: Option) -> T { let mut _2: isize; let _3: T; let mut _4: !; - let mut _5: isize; - let mut _6: isize; - let mut _7: isize; scope 1 { debug x => _3; } @@ -32,7 +29,6 @@ fn unwrap(_1: Option) -> T { _3 = move ((_1 as Some).0: T); _0 = move _3; StorageDead(_3); - _5 = discriminant(_1); return; } } diff --git a/tests/mir-opt/no_drop_for_inactive_variant.unwrap.SimplifyCfg-pre-optimizations.after.panic-unwind.mir b/tests/mir-opt/no_drop_for_inactive_variant.unwrap.SimplifyCfg-pre-optimizations.after.panic-unwind.mir index 04176b82ccd57..7efbd48a5cb71 100644 --- a/tests/mir-opt/no_drop_for_inactive_variant.unwrap.SimplifyCfg-pre-optimizations.after.panic-unwind.mir +++ b/tests/mir-opt/no_drop_for_inactive_variant.unwrap.SimplifyCfg-pre-optimizations.after.panic-unwind.mir @@ -6,9 +6,6 @@ fn unwrap(_1: Option) -> T { let mut _2: isize; let _3: T; let mut _4: !; - let mut _5: isize; - let mut _6: isize; - let mut _7: isize; scope 1 { debug x => _3; } @@ -32,12 +29,10 @@ fn unwrap(_1: Option) -> T { _3 = move ((_1 as Some).0: T); _0 = move _3; StorageDead(_3); - _5 = discriminant(_1); return; } bb4 (cleanup): { - _7 = discriminant(_1); resume; } } diff --git a/tests/mir-opt/otherwise_drops.result_ok.ElaborateDrops.diff b/tests/mir-opt/otherwise_drops.result_ok.ElaborateDrops.diff index 9bd4db723d401..c9f2f8438990c 100644 --- a/tests/mir-opt/otherwise_drops.result_ok.ElaborateDrops.diff +++ b/tests/mir-opt/otherwise_drops.result_ok.ElaborateDrops.diff @@ -8,8 +8,6 @@ let _3: std::string::String; let mut _4: std::string::String; + let mut _5: bool; -+ let mut _6: isize; -+ let mut _7: isize; scope 1 { debug s => _3; } @@ -50,7 +48,7 @@ bb5: { - drop(_1) -> [return: bb6, unwind: bb9]; -+ goto -> bb16; ++ goto -> bb10; } bb6: { @@ -73,36 +71,6 @@ + + bb10: { + goto -> bb6; -+ } -+ -+ bb11 (cleanup): { -+ goto -> bb9; -+ } -+ -+ bb12 (cleanup): { -+ goto -> bb9; -+ } -+ -+ bb13: { -+ goto -> bb10; -+ } -+ -+ bb14: { -+ goto -> bb10; -+ } -+ -+ bb15 (cleanup): { -+ goto -> bb9; -+ } -+ -+ bb16: { -+ _6 = discriminant(_1); -+ switchInt(move _6) -> [0: bb13, otherwise: bb14]; -+ } -+ -+ bb17 (cleanup): { -+ _7 = discriminant(_1); -+ switchInt(move _7) -> [0: bb11, otherwise: bb15]; } } diff --git a/tests/mir-opt/simplify_locals_removes_unused_discriminant_reads.map.SimplifyLocals-before-const-prop.diff b/tests/mir-opt/simplify_locals_removes_unused_discriminant_reads.map.SimplifyLocals-before-const-prop.diff index 5611d679b7801..6c726ead3c806 100644 --- a/tests/mir-opt/simplify_locals_removes_unused_discriminant_reads.map.SimplifyLocals-before-const-prop.diff +++ b/tests/mir-opt/simplify_locals_removes_unused_discriminant_reads.map.SimplifyLocals-before-const-prop.diff @@ -8,8 +8,6 @@ let _3: std::boxed::Box<()>; let mut _4: std::boxed::Box<()>; - let mut _5: bool; -- let mut _6: isize; -- let mut _7: isize; scope 1 { debug x => _3; } @@ -42,7 +40,6 @@ } bb4: { -- _6 = discriminant(_1); return; } } diff --git a/tests/mir-opt/tail_expr_drop_order_unwind.method_1.ElaborateDrops.after.panic-abort.mir b/tests/mir-opt/tail_expr_drop_order_unwind.method_1.ElaborateDrops.after.panic-abort.mir index 7d7cb76960edb..b7423ecc6a02f 100644 --- a/tests/mir-opt/tail_expr_drop_order_unwind.method_1.ElaborateDrops.after.panic-abort.mir +++ b/tests/mir-opt/tail_expr_drop_order_unwind.method_1.ElaborateDrops.after.panic-abort.mir @@ -12,9 +12,6 @@ fn method_1(_1: Guard) -> () { let _8: OtherDrop; let _9: (); let mut _10: bool; - let mut _11: isize; - let mut _12: isize; - let mut _13: isize; scope 1 { debug other_drop => _8; } @@ -73,7 +70,7 @@ fn method_1(_1: Guard) -> () { } bb7: { - goto -> bb21; + goto -> bb15; } bb8: { @@ -93,7 +90,7 @@ fn method_1(_1: Guard) -> () { } bb11 (cleanup): { - goto -> bb25; + goto -> bb12; } bb12 (cleanup): { @@ -111,47 +108,4 @@ fn method_1(_1: Guard) -> () { bb15: { goto -> bb8; } - - bb16 (cleanup): { - goto -> bb12; - } - - bb17 (cleanup): { - goto -> bb12; - } - - bb18: { - goto -> bb15; - } - - bb19: { - goto -> bb15; - } - - bb20 (cleanup): { - goto -> bb12; - } - - bb21: { - _11 = discriminant(_2); - switchInt(move _11) -> [0: bb18, otherwise: bb19]; - } - - bb22 (cleanup): { - _12 = discriminant(_2); - switchInt(move _12) -> [0: bb16, otherwise: bb20]; - } - - bb23 (cleanup): { - goto -> bb12; - } - - bb24 (cleanup): { - goto -> bb12; - } - - bb25 (cleanup): { - _13 = discriminant(_2); - switchInt(move _13) -> [0: bb23, otherwise: bb24]; - } } diff --git a/tests/mir-opt/tail_expr_drop_order_unwind.method_1.ElaborateDrops.after.panic-unwind.mir b/tests/mir-opt/tail_expr_drop_order_unwind.method_1.ElaborateDrops.after.panic-unwind.mir index 7d7cb76960edb..b7423ecc6a02f 100644 --- a/tests/mir-opt/tail_expr_drop_order_unwind.method_1.ElaborateDrops.after.panic-unwind.mir +++ b/tests/mir-opt/tail_expr_drop_order_unwind.method_1.ElaborateDrops.after.panic-unwind.mir @@ -12,9 +12,6 @@ fn method_1(_1: Guard) -> () { let _8: OtherDrop; let _9: (); let mut _10: bool; - let mut _11: isize; - let mut _12: isize; - let mut _13: isize; scope 1 { debug other_drop => _8; } @@ -73,7 +70,7 @@ fn method_1(_1: Guard) -> () { } bb7: { - goto -> bb21; + goto -> bb15; } bb8: { @@ -93,7 +90,7 @@ fn method_1(_1: Guard) -> () { } bb11 (cleanup): { - goto -> bb25; + goto -> bb12; } bb12 (cleanup): { @@ -111,47 +108,4 @@ fn method_1(_1: Guard) -> () { bb15: { goto -> bb8; } - - bb16 (cleanup): { - goto -> bb12; - } - - bb17 (cleanup): { - goto -> bb12; - } - - bb18: { - goto -> bb15; - } - - bb19: { - goto -> bb15; - } - - bb20 (cleanup): { - goto -> bb12; - } - - bb21: { - _11 = discriminant(_2); - switchInt(move _11) -> [0: bb18, otherwise: bb19]; - } - - bb22 (cleanup): { - _12 = discriminant(_2); - switchInt(move _12) -> [0: bb16, otherwise: bb20]; - } - - bb23 (cleanup): { - goto -> bb12; - } - - bb24 (cleanup): { - goto -> bb12; - } - - bb25 (cleanup): { - _13 = discriminant(_2); - switchInt(move _13) -> [0: bb23, otherwise: bb24]; - } }