Auto merge of #115105 - cjgillot:dest-prop-default, r=oli-obk

Enable DestinationPropagation by default.

~~Based on https://github.com/rust-lang/rust/pull/115291.~~

This PR proposes to enable the destination propagation pass by default.
This pass is meant to reduce the amount of copies present in MIR.

At the same time, this PR removes the `RenameReturnPlace` pass, as it is currently unsound.
`DestinationPropagation` is not limited to `_0`, but does not handle borrowed locals.
This commit is contained in:
bors 2024-05-30 14:27:46 +00:00
commit cfb730450f
21 changed files with 373 additions and 661 deletions

View File

@ -160,7 +160,7 @@ impl<'tcx> MirPass<'tcx> for DestinationPropagation {
// 2. Despite being an overall perf improvement, this still causes a 30% regression in
// keccak. We can temporarily fix this by bounding function size, but in the long term
// we should fix this by being smarter about invalidating analysis results.
sess.mir_opt_level() >= 3
sess.mir_opt_level() >= 2
}
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {

View File

@ -88,7 +88,6 @@ mod match_branches;
mod mentioned_items;
mod multiple_return_terminators;
mod normalize_array_len;
mod nrvo;
mod prettify;
mod promote_consts;
mod ref_prop;
@ -608,13 +607,12 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
&jump_threading::JumpThreading,
&early_otherwise_branch::EarlyOtherwiseBranch,
&simplify_comparison_integral::SimplifyComparisonIntegral,
&dest_prop::DestinationPropagation,
&o1(simplify_branches::SimplifyConstCondition::Final),
&o1(remove_noop_landing_pads::RemoveNoopLandingPads),
&o1(simplify::SimplifyCfg::Final),
&copy_prop::CopyProp,
&dead_store_elimination::DeadStoreElimination::Final,
&nrvo::RenameReturnPlace,
&dest_prop::DestinationPropagation,
&simplify::SimplifyLocals::Final,
&multiple_return_terminators::MultipleReturnTerminators,
&deduplicate_blocks::DeduplicateBlocks,

View File

@ -1,235 +0,0 @@
//! See the docs for [`RenameReturnPlace`].
use rustc_hir::Mutability;
use rustc_index::bit_set::BitSet;
use rustc_middle::bug;
use rustc_middle::mir::visit::{MutVisitor, NonUseContext, PlaceContext, Visitor};
use rustc_middle::mir::{self, BasicBlock, Local, Location};
use rustc_middle::ty::TyCtxt;
use crate::MirPass;
/// This pass looks for MIR that always copies the same local into the return place and eliminates
/// the copy by renaming all uses of that local to `_0`.
///
/// This allows LLVM to perform an optimization similar to the named return value optimization
/// (NRVO) that is guaranteed in C++. This avoids a stack allocation and `memcpy` for the
/// relatively common pattern of allocating a buffer on the stack, mutating it, and returning it by
/// value like so:
///
/// ```rust
/// fn foo(init: fn(&mut [u8; 1024])) -> [u8; 1024] {
/// let mut buf = [0; 1024];
/// init(&mut buf);
/// buf
/// }
/// ```
///
/// For now, this pass is very simple and only capable of eliminating a single copy. A more general
/// version of copy propagation, such as the one based on non-overlapping live ranges in [#47954] and
/// [#71003], could yield even more benefits.
///
/// [#47954]: https://github.com/rust-lang/rust/pull/47954
/// [#71003]: https://github.com/rust-lang/rust/pull/71003
pub struct RenameReturnPlace;
impl<'tcx> MirPass<'tcx> for RenameReturnPlace {
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
// unsound: #111005
sess.mir_opt_level() > 0 && sess.opts.unstable_opts.unsound_mir_opts
}
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut mir::Body<'tcx>) {
let def_id = body.source.def_id();
let Some(returned_local) = local_eligible_for_nrvo(body) else {
debug!("`{:?}` was ineligible for NRVO", def_id);
return;
};
if !tcx.consider_optimizing(|| format!("RenameReturnPlace {def_id:?}")) {
return;
}
debug!(
"`{:?}` was eligible for NRVO, making {:?} the return place",
def_id, returned_local
);
RenameToReturnPlace { tcx, to_rename: returned_local }.visit_body_preserves_cfg(body);
// Clean up the `NOP`s we inserted for statements made useless by our renaming.
for block_data in body.basic_blocks.as_mut_preserves_cfg() {
block_data.statements.retain(|stmt| stmt.kind != mir::StatementKind::Nop);
}
// Overwrite the debuginfo of `_0` with that of the renamed local.
let (renamed_decl, ret_decl) =
body.local_decls.pick2_mut(returned_local, mir::RETURN_PLACE);
// Sometimes, the return place is assigned a local of a different but coercible type, for
// example `&mut T` instead of `&T`. Overwriting the `LocalInfo` for the return place means
// its type may no longer match the return type of its function. This doesn't cause a
// problem in codegen because these two types are layout-compatible, but may be unexpected.
debug!("_0: {:?} = {:?}: {:?}", ret_decl.ty, returned_local, renamed_decl.ty);
ret_decl.clone_from(renamed_decl);
// The return place is always mutable.
ret_decl.mutability = Mutability::Mut;
}
}
/// MIR that is eligible for the NRVO must fulfill two conditions:
/// 1. The return place must not be read prior to the `Return` terminator.
/// 2. A simple assignment of a whole local to the return place (e.g., `_0 = _1`) must be the
/// only definition of the return place reaching the `Return` terminator.
///
/// If the MIR fulfills both these conditions, this function returns the `Local` that is assigned
/// to the return place along all possible paths through the control-flow graph.
fn local_eligible_for_nrvo(body: &mir::Body<'_>) -> Option<Local> {
if IsReturnPlaceRead::run(body) {
return None;
}
let mut copied_to_return_place = None;
for block in body.basic_blocks.indices() {
// Look for blocks with a `Return` terminator.
if !matches!(body[block].terminator().kind, mir::TerminatorKind::Return) {
continue;
}
// Look for an assignment of a single local to the return place prior to the `Return`.
let returned_local = find_local_assigned_to_return_place(block, body)?;
match body.local_kind(returned_local) {
// FIXME: Can we do this for arguments as well?
mir::LocalKind::Arg => return None,
mir::LocalKind::ReturnPointer => bug!("Return place was assigned to itself?"),
mir::LocalKind::Temp => {}
}
// If multiple different locals are copied to the return place. We can't pick a
// single one to rename.
if copied_to_return_place.is_some_and(|old| old != returned_local) {
return None;
}
copied_to_return_place = Some(returned_local);
}
copied_to_return_place
}
fn find_local_assigned_to_return_place(start: BasicBlock, body: &mir::Body<'_>) -> Option<Local> {
let mut block = start;
let mut seen = BitSet::new_empty(body.basic_blocks.len());
// Iterate as long as `block` has exactly one predecessor that we have not yet visited.
while seen.insert(block) {
trace!("Looking for assignments to `_0` in {:?}", block);
let local = body[block].statements.iter().rev().find_map(as_local_assigned_to_return_place);
if local.is_some() {
return local;
}
match body.basic_blocks.predecessors()[block].as_slice() {
&[pred] => block = pred,
_ => return None,
}
}
None
}
// If this statement is an assignment of an unprojected local to the return place,
// return that local.
fn as_local_assigned_to_return_place(stmt: &mir::Statement<'_>) -> Option<Local> {
if let mir::StatementKind::Assign(box (lhs, rhs)) = &stmt.kind {
if lhs.as_local() == Some(mir::RETURN_PLACE) {
if let mir::Rvalue::Use(mir::Operand::Copy(rhs) | mir::Operand::Move(rhs)) = rhs {
return rhs.as_local();
}
}
}
None
}
struct RenameToReturnPlace<'tcx> {
to_rename: Local,
tcx: TyCtxt<'tcx>,
}
/// Replaces all uses of `self.to_rename` with `_0`.
impl<'tcx> MutVisitor<'tcx> for RenameToReturnPlace<'tcx> {
fn tcx(&self) -> TyCtxt<'tcx> {
self.tcx
}
fn visit_statement(&mut self, stmt: &mut mir::Statement<'tcx>, loc: Location) {
// Remove assignments of the local being replaced to the return place, since it is now the
// return place:
// _0 = _1
if as_local_assigned_to_return_place(stmt) == Some(self.to_rename) {
stmt.kind = mir::StatementKind::Nop;
return;
}
// Remove storage annotations for the local being replaced:
// StorageLive(_1)
if let mir::StatementKind::StorageLive(local) | mir::StatementKind::StorageDead(local) =
stmt.kind
{
if local == self.to_rename {
stmt.kind = mir::StatementKind::Nop;
return;
}
}
self.super_statement(stmt, loc)
}
fn visit_terminator(&mut self, terminator: &mut mir::Terminator<'tcx>, loc: Location) {
// Ignore the implicit "use" of the return place in a `Return` statement.
if let mir::TerminatorKind::Return = terminator.kind {
return;
}
self.super_terminator(terminator, loc);
}
fn visit_local(&mut self, l: &mut Local, ctxt: PlaceContext, _: Location) {
if *l == mir::RETURN_PLACE {
assert_eq!(ctxt, PlaceContext::NonUse(NonUseContext::VarDebugInfo));
} else if *l == self.to_rename {
*l = mir::RETURN_PLACE;
}
}
}
struct IsReturnPlaceRead(bool);
impl IsReturnPlaceRead {
fn run(body: &mir::Body<'_>) -> bool {
let mut vis = IsReturnPlaceRead(false);
vis.visit_body(body);
vis.0
}
}
impl<'tcx> Visitor<'tcx> for IsReturnPlaceRead {
fn visit_local(&mut self, l: Local, ctxt: PlaceContext, _: Location) {
if l == mir::RETURN_PLACE && ctxt.is_use() && !ctxt.is_place_assignment() {
self.0 = true;
}
}
fn visit_terminator(&mut self, terminator: &mir::Terminator<'tcx>, loc: Location) {
// Ignore the implicit "use" of the return place in a `Return` statement.
if let mir::TerminatorKind::Return = terminator.kind {
return;
}
self.super_terminator(terminator, loc);
}
}

View File

@ -1,5 +1,5 @@
- // MIR for `nrvo` before RenameReturnPlace
+ // MIR for `nrvo` after RenameReturnPlace
- // MIR for `nrvo` before DestinationPropagation
+ // MIR for `nrvo` after DestinationPropagation
fn nrvo(_1: for<'a> fn(&'a mut [u8; 1024])) -> [u8; 1024] {
debug init => _1;
@ -10,32 +10,33 @@
let mut _5: &mut [u8; 1024];
let mut _6: &mut [u8; 1024];
scope 1 {
- debug buf => _2;
+ debug buf => _0;
debug buf => _2;
}
bb0: {
- StorageLive(_2);
- _2 = [const 0_u8; 1024];
+ _0 = [const 0_u8; 1024];
StorageLive(_2);
_2 = [const 0_u8; 1024];
StorageLive(_3);
StorageLive(_4);
_4 = _1;
- StorageLive(_4);
- _4 = _1;
+ nop;
+ nop;
StorageLive(_5);
StorageLive(_6);
- _6 = &mut _2;
+ _6 = &mut _0;
_6 = &mut _2;
_5 = &mut (*_6);
_3 = move _4(move _5) -> [return: bb1, unwind unreachable];
- _3 = move _4(move _5) -> [return: bb1, unwind unreachable];
+ _3 = move _1(move _5) -> [return: bb1, unwind unreachable];
}
bb1: {
StorageDead(_5);
StorageDead(_4);
- StorageDead(_4);
+ nop;
StorageDead(_6);
StorageDead(_3);
- _0 = _2;
- StorageDead(_2);
_0 = _2;
StorageDead(_2);
return;
}
}

View File

@ -1,5 +1,5 @@
- // MIR for `nrvo` before RenameReturnPlace
+ // MIR for `nrvo` after RenameReturnPlace
- // MIR for `nrvo` before DestinationPropagation
+ // MIR for `nrvo` after DestinationPropagation
fn nrvo(_1: for<'a> fn(&'a mut [u8; 1024])) -> [u8; 1024] {
debug init => _1;
@ -10,32 +10,33 @@
let mut _5: &mut [u8; 1024];
let mut _6: &mut [u8; 1024];
scope 1 {
- debug buf => _2;
+ debug buf => _0;
debug buf => _2;
}
bb0: {
- StorageLive(_2);
- _2 = [const 0_u8; 1024];
+ _0 = [const 0_u8; 1024];
StorageLive(_2);
_2 = [const 0_u8; 1024];
StorageLive(_3);
StorageLive(_4);
_4 = _1;
- StorageLive(_4);
- _4 = _1;
+ nop;
+ nop;
StorageLive(_5);
StorageLive(_6);
- _6 = &mut _2;
+ _6 = &mut _0;
_6 = &mut _2;
_5 = &mut (*_6);
_3 = move _4(move _5) -> [return: bb1, unwind continue];
- _3 = move _4(move _5) -> [return: bb1, unwind continue];
+ _3 = move _1(move _5) -> [return: bb1, unwind continue];
}
bb1: {
StorageDead(_5);
StorageDead(_4);
- StorageDead(_4);
+ nop;
StorageDead(_6);
StorageDead(_3);
- _0 = _2;
- StorageDead(_2);
_0 = _2;
StorageDead(_2);
return;
}
}

View File

@ -1,8 +1,8 @@
// skip-filecheck
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
//@ test-mir-pass: RenameReturnPlace
//@ test-mir-pass: DestinationPropagation
// EMIT_MIR nrvo_simple.nrvo.RenameReturnPlace.diff
// EMIT_MIR nrvo_borrowed.nrvo.DestinationPropagation.diff
fn nrvo(init: fn(&mut [u8; 1024])) -> [u8; 1024] {
let mut buf = [0; 1024];
init(&mut buf);

View File

@ -1,13 +1,13 @@
// skip-filecheck
// This is a miscompilation, #111005 to track
//@ test-mir-pass: RenameReturnPlace
//@ test-mir-pass: DestinationPropagation
#![feature(custom_mir, core_intrinsics)]
extern crate core;
use core::intrinsics::mir::*;
// EMIT_MIR nrvo_miscompile_111005.wrong.RenameReturnPlace.diff
// EMIT_MIR nrvo_miscompile_111005.wrong.DestinationPropagation.diff
#[custom_mir(dialect = "runtime", phase = "initial")]
pub fn wrong(arg: char) -> char {
mir!({

View File

@ -1,5 +1,5 @@
- // MIR for `wrong` before RenameReturnPlace
+ // MIR for `wrong` after RenameReturnPlace
- // MIR for `wrong` before DestinationPropagation
+ // MIR for `wrong` after DestinationPropagation
fn wrong(_1: char) -> char {
let mut _0: char;
@ -9,8 +9,9 @@
- _2 = _1;
- _0 = _2;
- _2 = const 'b';
+ nop;
+ _0 = _1;
+ _0 = const 'b';
+ _1 = const 'b';
return;
}
}

View File

@ -18,7 +18,7 @@
bb0: {
StorageLive(_1);
StorageLive(_2);
_2 = const 1_u32;
nop;
_1 = Un { us: const 1_u32 };
StorageDead(_2);
StorageLive(_3);

View File

@ -18,7 +18,7 @@
bb0: {
StorageLive(_1);
StorageLive(_2);
_2 = const 1_u32;
nop;
_1 = Un { us: const 1_u32 };
StorageDead(_2);
StorageLive(_3);

View File

@ -4,10 +4,9 @@ fn <impl at $DIR/derived_ord.rs:6:10: 6:20>::partial_cmp(_1: &MultiField, _2: &M
debug self => _1;
debug other => _2;
let mut _0: std::option::Option<std::cmp::Ordering>;
let mut _6: std::option::Option<std::cmp::Ordering>;
let mut _7: i8;
let mut _6: i8;
scope 1 {
debug cmp => _6;
debug cmp => _0;
}
scope 2 (inlined std::cmp::impls::<impl PartialOrd for char>::partial_cmp) {
let mut _3: char;
@ -15,9 +14,9 @@ fn <impl at $DIR/derived_ord.rs:6:10: 6:20>::partial_cmp(_1: &MultiField, _2: &M
let mut _5: std::cmp::Ordering;
}
scope 3 (inlined std::cmp::impls::<impl PartialOrd for i16>::partial_cmp) {
let mut _7: i16;
let mut _8: i16;
let mut _9: i16;
let mut _10: std::cmp::Ordering;
let mut _9: std::cmp::Ordering;
}
bb0: {
@ -28,27 +27,26 @@ fn <impl at $DIR/derived_ord.rs:6:10: 6:20>::partial_cmp(_1: &MultiField, _2: &M
_5 = Cmp(move _3, move _4);
StorageDead(_4);
StorageDead(_3);
_6 = Option::<std::cmp::Ordering>::Some(_5);
_7 = discriminant(_5);
switchInt(move _7) -> [0: bb1, otherwise: bb2];
_0 = Option::<std::cmp::Ordering>::Some(_5);
_6 = discriminant(_5);
switchInt(move _6) -> [0: bb1, otherwise: bb2];
}
bb1: {
StorageLive(_10);
StorageLive(_8);
_8 = ((*_1).1: i16);
StorageLive(_9);
_9 = ((*_2).1: i16);
_10 = Cmp(move _8, move _9);
StorageDead(_9);
StorageLive(_7);
_7 = ((*_1).1: i16);
StorageLive(_8);
_8 = ((*_2).1: i16);
_9 = Cmp(move _7, move _8);
StorageDead(_8);
_0 = Option::<std::cmp::Ordering>::Some(move _10);
StorageDead(_10);
StorageDead(_7);
_0 = Option::<std::cmp::Ordering>::Some(move _9);
StorageDead(_9);
goto -> bb3;
}
bb2: {
_0 = _6;
goto -> bb3;
}

View File

@ -5,27 +5,25 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
debug end => _2;
debug f => _3;
let mut _0: ();
let mut _4: u32;
let mut _9: std::option::Option<u32>;
let mut _11: &impl Fn(u32);
let mut _12: (u32,);
let _13: ();
let mut _7: std::option::Option<u32>;
let mut _9: &impl Fn(u32);
let mut _10: (u32,);
let _11: ();
scope 1 {
debug ((iter: std::ops::Range<u32>).0: u32) => _4;
debug ((iter: std::ops::Range<u32>).0: u32) => _1;
debug ((iter: std::ops::Range<u32>).1: u32) => _2;
let _10: u32;
let _8: u32;
scope 2 {
debug x => _10;
debug x => _8;
}
scope 4 (inlined iter::range::<impl Iterator for std::ops::Range<u32>>::next) {
scope 5 (inlined <std::ops::Range<u32> as iter::range::RangeIteratorImpl>::spec_next) {
let mut _6: bool;
let _7: u32;
let mut _8: u32;
let mut _5: bool;
let _6: u32;
scope 6 {
}
scope 7 (inlined std::cmp::impls::<impl PartialOrd for u32>::lt) {
let mut _5: u32;
let mut _4: u32;
}
}
}
@ -34,27 +32,24 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
}
bb0: {
StorageLive(_4);
_4 = _1;
goto -> bb1;
}
bb1: {
StorageLive(_9);
StorageLive(_7);
StorageLive(_6);
StorageLive(_5);
_5 = _4;
_6 = Lt(move _5, _2);
StorageDead(_5);
switchInt(move _6) -> [0: bb2, otherwise: bb4];
StorageLive(_4);
_4 = _1;
_5 = Lt(move _4, _2);
StorageDead(_4);
switchInt(move _5) -> [0: bb2, otherwise: bb4];
}
bb2: {
StorageDead(_5);
StorageDead(_6);
StorageDead(_7);
StorageDead(_9);
StorageDead(_4);
drop(_3) -> [return: bb3, unwind unreachable];
}
@ -63,29 +58,26 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
}
bb4: {
_7 = _4;
StorageLive(_8);
_8 = <u32 as Step>::forward_unchecked(_7, const 1_usize) -> [return: bb5, unwind unreachable];
_6 = _1;
_1 = <u32 as Step>::forward_unchecked(_6, const 1_usize) -> [return: bb5, unwind unreachable];
}
bb5: {
_4 = move _8;
StorageDead(_8);
_9 = Option::<u32>::Some(_7);
_7 = Option::<u32>::Some(_6);
StorageDead(_5);
StorageDead(_6);
StorageDead(_7);
_10 = ((_9 as Some).0: u32);
StorageLive(_11);
_11 = &_3;
StorageLive(_12);
_12 = (_10,);
_13 = <impl Fn(u32) as Fn<(u32,)>>::call(move _11, move _12) -> [return: bb6, unwind unreachable];
_8 = ((_7 as Some).0: u32);
StorageLive(_9);
_9 = &_3;
StorageLive(_10);
_10 = (_8,);
_11 = <impl Fn(u32) as Fn<(u32,)>>::call(move _9, move _10) -> [return: bb6, unwind unreachable];
}
bb6: {
StorageDead(_12);
StorageDead(_11);
StorageDead(_10);
StorageDead(_9);
StorageDead(_7);
goto -> bb1;
}
}

View File

@ -5,27 +5,25 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
debug end => _2;
debug f => _3;
let mut _0: ();
let mut _4: u32;
let mut _9: std::option::Option<u32>;
let mut _11: &impl Fn(u32);
let mut _12: (u32,);
let _13: ();
let mut _7: std::option::Option<u32>;
let mut _9: &impl Fn(u32);
let mut _10: (u32,);
let _11: ();
scope 1 {
debug ((iter: std::ops::Range<u32>).0: u32) => _4;
debug ((iter: std::ops::Range<u32>).0: u32) => _1;
debug ((iter: std::ops::Range<u32>).1: u32) => _2;
let _10: u32;
let _8: u32;
scope 2 {
debug x => _10;
debug x => _8;
}
scope 4 (inlined iter::range::<impl Iterator for std::ops::Range<u32>>::next) {
scope 5 (inlined <std::ops::Range<u32> as iter::range::RangeIteratorImpl>::spec_next) {
let mut _6: bool;
let _7: u32;
let mut _8: u32;
let mut _5: bool;
let _6: u32;
scope 6 {
}
scope 7 (inlined std::cmp::impls::<impl PartialOrd for u32>::lt) {
let mut _5: u32;
let mut _4: u32;
}
}
}
@ -34,27 +32,24 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
}
bb0: {
StorageLive(_4);
_4 = _1;
goto -> bb1;
}
bb1: {
StorageLive(_9);
StorageLive(_7);
StorageLive(_6);
StorageLive(_5);
_5 = _4;
_6 = Lt(move _5, _2);
StorageDead(_5);
switchInt(move _6) -> [0: bb2, otherwise: bb4];
StorageLive(_4);
_4 = _1;
_5 = Lt(move _4, _2);
StorageDead(_4);
switchInt(move _5) -> [0: bb2, otherwise: bb4];
}
bb2: {
StorageDead(_5);
StorageDead(_6);
StorageDead(_7);
StorageDead(_9);
StorageDead(_4);
drop(_3) -> [return: bb3, unwind continue];
}
@ -63,29 +58,26 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
}
bb4: {
_7 = _4;
StorageLive(_8);
_8 = <u32 as Step>::forward_unchecked(_7, const 1_usize) -> [return: bb5, unwind: bb7];
_6 = _1;
_1 = <u32 as Step>::forward_unchecked(_6, const 1_usize) -> [return: bb5, unwind: bb7];
}
bb5: {
_4 = move _8;
StorageDead(_8);
_9 = Option::<u32>::Some(_7);
_7 = Option::<u32>::Some(_6);
StorageDead(_5);
StorageDead(_6);
StorageDead(_7);
_10 = ((_9 as Some).0: u32);
StorageLive(_11);
_11 = &_3;
StorageLive(_12);
_12 = (_10,);
_13 = <impl Fn(u32) as Fn<(u32,)>>::call(move _11, move _12) -> [return: bb6, unwind: bb7];
_8 = ((_7 as Some).0: u32);
StorageLive(_9);
_9 = &_3;
StorageLive(_10);
_10 = (_8,);
_11 = <impl Fn(u32) as Fn<(u32,)>>::call(move _9, move _10) -> [return: bb6, unwind: bb7];
}
bb6: {
StorageDead(_12);
StorageDead(_11);
StorageDead(_10);
StorageDead(_9);
StorageDead(_7);
goto -> bb1;
}

View File

@ -4,22 +4,22 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
debug slice => _1;
debug f => _2;
let mut _0: ();
let mut _12: std::slice::Iter<'_, T>;
let mut _11: std::slice::Iter<'_, T>;
let mut _12: std::iter::Enumerate<std::slice::Iter<'_, T>>;
let mut _13: std::iter::Enumerate<std::slice::Iter<'_, T>>;
let mut _14: std::iter::Enumerate<std::slice::Iter<'_, T>>;
let mut _15: &mut std::iter::Enumerate<std::slice::Iter<'_, T>>;
let mut _16: std::option::Option<(usize, &T)>;
let mut _17: isize;
let mut _20: &impl Fn(usize, &T);
let mut _21: (usize, &T);
let _22: ();
let mut _14: &mut std::iter::Enumerate<std::slice::Iter<'_, T>>;
let mut _15: std::option::Option<(usize, &T)>;
let mut _16: isize;
let mut _19: &impl Fn(usize, &T);
let mut _20: (usize, &T);
let _21: ();
scope 1 {
debug iter => _14;
let _18: usize;
let _19: &T;
debug iter => _13;
let _17: usize;
let _18: &T;
scope 2 {
debug i => _18;
debug x => _19;
debug i => _17;
debug x => _18;
}
}
scope 3 (inlined core::slice::<impl [T]>::iter) {
@ -28,11 +28,10 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
let mut _7: bool;
let mut _8: *mut T;
let mut _9: *mut T;
let mut _11: *const T;
let mut _10: *const T;
scope 5 {
let _6: std::ptr::NonNull<T>;
scope 6 {
let _10: *const T;
scope 7 {
}
scope 11 (inlined without_provenance::<T>) {
@ -61,16 +60,16 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
}
bb0: {
StorageLive(_12);
StorageLive(_11);
StorageLive(_3);
StorageLive(_6);
StorageLive(_10);
StorageLive(_4);
StorageLive(_5);
_3 = Len((*_1));
_4 = &raw const (*_1);
_5 = _4 as *const T (PtrToPtr);
_6 = NonNull::<T> { pointer: _5 };
StorageLive(_10);
StorageLive(_7);
_7 = const <T as std::mem::SizedTypeProperties>::IS_ZST;
switchInt(move _7) -> [0: bb1, otherwise: bb2];
@ -94,38 +93,35 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
bb3: {
StorageDead(_7);
StorageLive(_11);
_11 = _10;
_12 = std::slice::Iter::<'_, T> { ptr: _6, end_or_len: move _11, _marker: const ZeroSized: PhantomData<&T> };
StorageDead(_11);
StorageDead(_10);
_11 = std::slice::Iter::<'_, T> { ptr: _6, end_or_len: move _10, _marker: const ZeroSized: PhantomData<&T> };
StorageDead(_5);
StorageDead(_4);
StorageDead(_10);
StorageDead(_6);
StorageDead(_3);
_13 = Enumerate::<std::slice::Iter<'_, T>> { iter: _12, count: const 0_usize };
StorageDead(_12);
StorageLive(_14);
_14 = _13;
_12 = Enumerate::<std::slice::Iter<'_, T>> { iter: _11, count: const 0_usize };
StorageDead(_11);
StorageLive(_13);
_13 = _12;
goto -> bb4;
}
bb4: {
StorageLive(_16);
StorageLive(_15);
_15 = &mut _14;
_16 = <Enumerate<std::slice::Iter<'_, T>> as Iterator>::next(move _15) -> [return: bb5, unwind unreachable];
StorageLive(_14);
_14 = &mut _13;
_15 = <Enumerate<std::slice::Iter<'_, T>> as Iterator>::next(move _14) -> [return: bb5, unwind unreachable];
}
bb5: {
StorageDead(_15);
_17 = discriminant(_16);
switchInt(move _17) -> [0: bb6, 1: bb8, otherwise: bb10];
StorageDead(_14);
_16 = discriminant(_15);
switchInt(move _16) -> [0: bb6, 1: bb8, otherwise: bb10];
}
bb6: {
StorageDead(_16);
StorageDead(_14);
StorageDead(_15);
StorageDead(_13);
drop(_2) -> [return: bb7, unwind unreachable];
}
@ -134,19 +130,19 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
}
bb8: {
_18 = (((_16 as Some).0: (usize, &T)).0: usize);
_19 = (((_16 as Some).0: (usize, &T)).1: &T);
_17 = (((_15 as Some).0: (usize, &T)).0: usize);
_18 = (((_15 as Some).0: (usize, &T)).1: &T);
StorageLive(_19);
_19 = &_2;
StorageLive(_20);
_20 = &_2;
StorageLive(_21);
_21 = (_18, _19);
_22 = <impl Fn(usize, &T) as Fn<(usize, &T)>>::call(move _20, move _21) -> [return: bb9, unwind unreachable];
_20 = (_17, _18);
_21 = <impl Fn(usize, &T) as Fn<(usize, &T)>>::call(move _19, move _20) -> [return: bb9, unwind unreachable];
}
bb9: {
StorageDead(_21);
StorageDead(_20);
StorageDead(_16);
StorageDead(_19);
StorageDead(_15);
goto -> bb4;
}

View File

@ -4,22 +4,22 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
debug slice => _1;
debug f => _2;
let mut _0: ();
let mut _12: std::slice::Iter<'_, T>;
let mut _11: std::slice::Iter<'_, T>;
let mut _12: std::iter::Enumerate<std::slice::Iter<'_, T>>;
let mut _13: std::iter::Enumerate<std::slice::Iter<'_, T>>;
let mut _14: std::iter::Enumerate<std::slice::Iter<'_, T>>;
let mut _15: &mut std::iter::Enumerate<std::slice::Iter<'_, T>>;
let mut _16: std::option::Option<(usize, &T)>;
let mut _17: isize;
let mut _20: &impl Fn(usize, &T);
let mut _21: (usize, &T);
let _22: ();
let mut _14: &mut std::iter::Enumerate<std::slice::Iter<'_, T>>;
let mut _15: std::option::Option<(usize, &T)>;
let mut _16: isize;
let mut _19: &impl Fn(usize, &T);
let mut _20: (usize, &T);
let _21: ();
scope 1 {
debug iter => _14;
let _18: usize;
let _19: &T;
debug iter => _13;
let _17: usize;
let _18: &T;
scope 2 {
debug i => _18;
debug x => _19;
debug i => _17;
debug x => _18;
}
}
scope 3 (inlined core::slice::<impl [T]>::iter) {
@ -28,11 +28,10 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
let mut _7: bool;
let mut _8: *mut T;
let mut _9: *mut T;
let mut _11: *const T;
let mut _10: *const T;
scope 5 {
let _6: std::ptr::NonNull<T>;
scope 6 {
let _10: *const T;
scope 7 {
}
scope 11 (inlined without_provenance::<T>) {
@ -61,16 +60,16 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
}
bb0: {
StorageLive(_12);
StorageLive(_11);
StorageLive(_3);
StorageLive(_6);
StorageLive(_10);
StorageLive(_4);
StorageLive(_5);
_3 = Len((*_1));
_4 = &raw const (*_1);
_5 = _4 as *const T (PtrToPtr);
_6 = NonNull::<T> { pointer: _5 };
StorageLive(_10);
StorageLive(_7);
_7 = const <T as std::mem::SizedTypeProperties>::IS_ZST;
switchInt(move _7) -> [0: bb1, otherwise: bb2];
@ -94,38 +93,35 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
bb3: {
StorageDead(_7);
StorageLive(_11);
_11 = _10;
_12 = std::slice::Iter::<'_, T> { ptr: _6, end_or_len: move _11, _marker: const ZeroSized: PhantomData<&T> };
StorageDead(_11);
StorageDead(_10);
_11 = std::slice::Iter::<'_, T> { ptr: _6, end_or_len: move _10, _marker: const ZeroSized: PhantomData<&T> };
StorageDead(_5);
StorageDead(_4);
StorageDead(_10);
StorageDead(_6);
StorageDead(_3);
_13 = Enumerate::<std::slice::Iter<'_, T>> { iter: _12, count: const 0_usize };
StorageDead(_12);
StorageLive(_14);
_14 = _13;
_12 = Enumerate::<std::slice::Iter<'_, T>> { iter: _11, count: const 0_usize };
StorageDead(_11);
StorageLive(_13);
_13 = _12;
goto -> bb4;
}
bb4: {
StorageLive(_16);
StorageLive(_15);
_15 = &mut _14;
_16 = <Enumerate<std::slice::Iter<'_, T>> as Iterator>::next(move _15) -> [return: bb5, unwind: bb11];
StorageLive(_14);
_14 = &mut _13;
_15 = <Enumerate<std::slice::Iter<'_, T>> as Iterator>::next(move _14) -> [return: bb5, unwind: bb11];
}
bb5: {
StorageDead(_15);
_17 = discriminant(_16);
switchInt(move _17) -> [0: bb6, 1: bb8, otherwise: bb10];
StorageDead(_14);
_16 = discriminant(_15);
switchInt(move _16) -> [0: bb6, 1: bb8, otherwise: bb10];
}
bb6: {
StorageDead(_16);
StorageDead(_14);
StorageDead(_15);
StorageDead(_13);
drop(_2) -> [return: bb7, unwind continue];
}
@ -134,19 +130,19 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
}
bb8: {
_18 = (((_16 as Some).0: (usize, &T)).0: usize);
_19 = (((_16 as Some).0: (usize, &T)).1: &T);
_17 = (((_15 as Some).0: (usize, &T)).0: usize);
_18 = (((_15 as Some).0: (usize, &T)).1: &T);
StorageLive(_19);
_19 = &_2;
StorageLive(_20);
_20 = &_2;
StorageLive(_21);
_21 = (_18, _19);
_22 = <impl Fn(usize, &T) as Fn<(usize, &T)>>::call(move _20, move _21) -> [return: bb9, unwind: bb11];
_20 = (_17, _18);
_21 = <impl Fn(usize, &T) as Fn<(usize, &T)>>::call(move _19, move _20) -> [return: bb9, unwind: bb11];
}
bb9: {
StorageDead(_21);
StorageDead(_20);
StorageDead(_16);
StorageDead(_19);
StorageDead(_15);
goto -> bb4;
}

View File

@ -4,19 +4,19 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () {
debug slice => _1;
debug f => _2;
let mut _0: ();
let mut _11: std::slice::Iter<'_, T>;
let mut _12: std::slice::Iter<'_, T>;
let mut _13: std::slice::Iter<'_, T>;
let mut _14: &mut std::slice::Iter<'_, T>;
let mut _15: std::option::Option<&T>;
let mut _16: isize;
let mut _18: &impl Fn(&T);
let mut _19: (&T,);
let _20: ();
let mut _13: &mut std::slice::Iter<'_, T>;
let mut _14: std::option::Option<&T>;
let mut _15: isize;
let mut _17: &impl Fn(&T);
let mut _18: (&T,);
let _19: ();
scope 1 {
debug iter => _13;
let _17: &T;
debug iter => _12;
let _16: &T;
scope 2 {
debug x => _17;
debug x => _16;
}
}
scope 3 (inlined core::slice::<impl [T]>::iter) {
@ -25,11 +25,10 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () {
let mut _7: bool;
let mut _8: *mut T;
let mut _9: *mut T;
let mut _11: *const T;
let mut _10: *const T;
scope 5 {
let _6: std::ptr::NonNull<T>;
scope 6 {
let _10: *const T;
scope 7 {
}
scope 11 (inlined without_provenance::<T>) {
@ -56,13 +55,13 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () {
bb0: {
StorageLive(_3);
StorageLive(_6);
StorageLive(_10);
StorageLive(_4);
StorageLive(_5);
_3 = Len((*_1));
_4 = &raw const (*_1);
_5 = _4 as *const T (PtrToPtr);
_6 = NonNull::<T> { pointer: _5 };
StorageLive(_10);
StorageLive(_7);
_7 = const <T as std::mem::SizedTypeProperties>::IS_ZST;
switchInt(move _7) -> [0: bb1, otherwise: bb2];
@ -86,36 +85,33 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () {
bb3: {
StorageDead(_7);
StorageLive(_11);
_11 = _10;
_12 = std::slice::Iter::<'_, T> { ptr: _6, end_or_len: move _11, _marker: const ZeroSized: PhantomData<&T> };
StorageDead(_11);
StorageDead(_10);
_11 = std::slice::Iter::<'_, T> { ptr: _6, end_or_len: move _10, _marker: const ZeroSized: PhantomData<&T> };
StorageDead(_5);
StorageDead(_4);
StorageDead(_10);
StorageDead(_6);
StorageDead(_3);
StorageLive(_13);
_13 = _12;
StorageLive(_12);
_12 = _11;
goto -> bb4;
}
bb4: {
StorageLive(_15);
StorageLive(_14);
_14 = &mut _13;
_15 = <std::slice::Iter<'_, T> as Iterator>::next(move _14) -> [return: bb5, unwind unreachable];
StorageLive(_13);
_13 = &mut _12;
_14 = <std::slice::Iter<'_, T> as Iterator>::next(move _13) -> [return: bb5, unwind unreachable];
}
bb5: {
StorageDead(_14);
_16 = discriminant(_15);
switchInt(move _16) -> [0: bb6, 1: bb8, otherwise: bb10];
StorageDead(_13);
_15 = discriminant(_14);
switchInt(move _15) -> [0: bb6, 1: bb8, otherwise: bb10];
}
bb6: {
StorageDead(_15);
StorageDead(_13);
StorageDead(_14);
StorageDead(_12);
drop(_2) -> [return: bb7, unwind unreachable];
}
@ -124,18 +120,18 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () {
}
bb8: {
_17 = ((_15 as Some).0: &T);
_16 = ((_14 as Some).0: &T);
StorageLive(_17);
_17 = &_2;
StorageLive(_18);
_18 = &_2;
StorageLive(_19);
_19 = (_17,);
_20 = <impl Fn(&T) as Fn<(&T,)>>::call(move _18, move _19) -> [return: bb9, unwind unreachable];
_18 = (_16,);
_19 = <impl Fn(&T) as Fn<(&T,)>>::call(move _17, move _18) -> [return: bb9, unwind unreachable];
}
bb9: {
StorageDead(_19);
StorageDead(_18);
StorageDead(_15);
StorageDead(_17);
StorageDead(_14);
goto -> bb4;
}

View File

@ -4,19 +4,19 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () {
debug slice => _1;
debug f => _2;
let mut _0: ();
let mut _11: std::slice::Iter<'_, T>;
let mut _12: std::slice::Iter<'_, T>;
let mut _13: std::slice::Iter<'_, T>;
let mut _14: &mut std::slice::Iter<'_, T>;
let mut _15: std::option::Option<&T>;
let mut _16: isize;
let mut _18: &impl Fn(&T);
let mut _19: (&T,);
let _20: ();
let mut _13: &mut std::slice::Iter<'_, T>;
let mut _14: std::option::Option<&T>;
let mut _15: isize;
let mut _17: &impl Fn(&T);
let mut _18: (&T,);
let _19: ();
scope 1 {
debug iter => _13;
let _17: &T;
debug iter => _12;
let _16: &T;
scope 2 {
debug x => _17;
debug x => _16;
}
}
scope 3 (inlined core::slice::<impl [T]>::iter) {
@ -25,11 +25,10 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () {
let mut _7: bool;
let mut _8: *mut T;
let mut _9: *mut T;
let mut _11: *const T;
let mut _10: *const T;
scope 5 {
let _6: std::ptr::NonNull<T>;
scope 6 {
let _10: *const T;
scope 7 {
}
scope 11 (inlined without_provenance::<T>) {
@ -56,13 +55,13 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () {
bb0: {
StorageLive(_3);
StorageLive(_6);
StorageLive(_10);
StorageLive(_4);
StorageLive(_5);
_3 = Len((*_1));
_4 = &raw const (*_1);
_5 = _4 as *const T (PtrToPtr);
_6 = NonNull::<T> { pointer: _5 };
StorageLive(_10);
StorageLive(_7);
_7 = const <T as std::mem::SizedTypeProperties>::IS_ZST;
switchInt(move _7) -> [0: bb1, otherwise: bb2];
@ -86,36 +85,33 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () {
bb3: {
StorageDead(_7);
StorageLive(_11);
_11 = _10;
_12 = std::slice::Iter::<'_, T> { ptr: _6, end_or_len: move _11, _marker: const ZeroSized: PhantomData<&T> };
StorageDead(_11);
StorageDead(_10);
_11 = std::slice::Iter::<'_, T> { ptr: _6, end_or_len: move _10, _marker: const ZeroSized: PhantomData<&T> };
StorageDead(_5);
StorageDead(_4);
StorageDead(_10);
StorageDead(_6);
StorageDead(_3);
StorageLive(_13);
_13 = _12;
StorageLive(_12);
_12 = _11;
goto -> bb4;
}
bb4: {
StorageLive(_15);
StorageLive(_14);
_14 = &mut _13;
_15 = <std::slice::Iter<'_, T> as Iterator>::next(move _14) -> [return: bb5, unwind: bb11];
StorageLive(_13);
_13 = &mut _12;
_14 = <std::slice::Iter<'_, T> as Iterator>::next(move _13) -> [return: bb5, unwind: bb11];
}
bb5: {
StorageDead(_14);
_16 = discriminant(_15);
switchInt(move _16) -> [0: bb6, 1: bb8, otherwise: bb10];
StorageDead(_13);
_15 = discriminant(_14);
switchInt(move _15) -> [0: bb6, 1: bb8, otherwise: bb10];
}
bb6: {
StorageDead(_15);
StorageDead(_13);
StorageDead(_14);
StorageDead(_12);
drop(_2) -> [return: bb7, unwind continue];
}
@ -124,18 +120,18 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () {
}
bb8: {
_17 = ((_15 as Some).0: &T);
_16 = ((_14 as Some).0: &T);
StorageLive(_17);
_17 = &_2;
StorageLive(_18);
_18 = &_2;
StorageLive(_19);
_19 = (_17,);
_20 = <impl Fn(&T) as Fn<(&T,)>>::call(move _18, move _19) -> [return: bb9, unwind: bb11];
_18 = (_16,);
_19 = <impl Fn(&T) as Fn<(&T,)>>::call(move _17, move _18) -> [return: bb9, unwind: bb11];
}
bb9: {
StorageDead(_19);
StorageDead(_18);
StorageDead(_15);
StorageDead(_17);
StorageDead(_14);
goto -> bb4;
}

View File

@ -6,28 +6,27 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
let mut _0: ();
let mut _3: usize;
let mut _4: usize;
let mut _9: std::option::Option<usize>;
let mut _11: usize;
let mut _12: bool;
let mut _14: &impl Fn(usize, &T);
let mut _15: (usize, &T);
let _16: ();
let mut _8: std::option::Option<usize>;
let mut _10: usize;
let mut _11: bool;
let mut _13: &impl Fn(usize, &T);
let mut _14: (usize, &T);
let _15: ();
scope 1 {
debug ((iter: std::ops::Range<usize>).0: usize) => _4;
debug ((iter: std::ops::Range<usize>).1: usize) => _3;
let _10: usize;
let _9: usize;
scope 2 {
debug i => _10;
let _13: &T;
debug i => _9;
let _12: &T;
scope 3 {
debug x => _13;
debug x => _12;
}
}
scope 5 (inlined iter::range::<impl Iterator for std::ops::Range<usize>>::next) {
scope 6 (inlined <std::ops::Range<usize> as iter::range::RangeIteratorImpl>::spec_next) {
let mut _6: bool;
let _7: usize;
let mut _8: usize;
scope 7 {
}
scope 8 (inlined std::cmp::impls::<impl PartialOrd for usize>::lt) {
@ -41,13 +40,12 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
bb0: {
_3 = Len((*_1));
StorageLive(_4);
_4 = const 0_usize;
goto -> bb1;
}
bb1: {
StorageLive(_9);
StorageLive(_8);
StorageLive(_7);
StorageLive(_6);
StorageLive(_5);
@ -60,8 +58,7 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
bb2: {
StorageDead(_6);
StorageDead(_7);
StorageDead(_9);
StorageDead(_4);
StorageDead(_8);
drop(_2) -> [return: bb3, unwind unreachable];
}
@ -71,35 +68,32 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
bb4: {
_7 = _4;
StorageLive(_8);
_8 = <usize as Step>::forward_unchecked(_7, const 1_usize) -> [return: bb5, unwind unreachable];
_4 = <usize as Step>::forward_unchecked(_7, const 1_usize) -> [return: bb5, unwind unreachable];
}
bb5: {
_4 = move _8;
StorageDead(_8);
_9 = Option::<usize>::Some(_7);
_8 = Option::<usize>::Some(_7);
StorageDead(_6);
StorageDead(_7);
_10 = ((_9 as Some).0: usize);
_11 = Len((*_1));
_12 = Lt(_10, _11);
assert(move _12, "index out of bounds: the length is {} but the index is {}", move _11, _10) -> [success: bb6, unwind unreachable];
_9 = ((_8 as Some).0: usize);
_10 = Len((*_1));
_11 = Lt(_9, _10);
assert(move _11, "index out of bounds: the length is {} but the index is {}", move _10, _9) -> [success: bb6, unwind unreachable];
}
bb6: {
_13 = &(*_1)[_10];
_12 = &(*_1)[_9];
StorageLive(_13);
_13 = &_2;
StorageLive(_14);
_14 = &_2;
StorageLive(_15);
_15 = (_10, _13);
_16 = <impl Fn(usize, &T) as Fn<(usize, &T)>>::call(move _14, move _15) -> [return: bb7, unwind unreachable];
_14 = (_9, _12);
_15 = <impl Fn(usize, &T) as Fn<(usize, &T)>>::call(move _13, move _14) -> [return: bb7, unwind unreachable];
}
bb7: {
StorageDead(_15);
StorageDead(_14);
StorageDead(_9);
StorageDead(_13);
StorageDead(_8);
goto -> bb1;
}
}

View File

@ -6,28 +6,27 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
let mut _0: ();
let mut _3: usize;
let mut _4: usize;
let mut _9: std::option::Option<usize>;
let mut _11: usize;
let mut _12: bool;
let mut _14: &impl Fn(usize, &T);
let mut _15: (usize, &T);
let _16: ();
let mut _8: std::option::Option<usize>;
let mut _10: usize;
let mut _11: bool;
let mut _13: &impl Fn(usize, &T);
let mut _14: (usize, &T);
let _15: ();
scope 1 {
debug ((iter: std::ops::Range<usize>).0: usize) => _4;
debug ((iter: std::ops::Range<usize>).1: usize) => _3;
let _10: usize;
let _9: usize;
scope 2 {
debug i => _10;
let _13: &T;
debug i => _9;
let _12: &T;
scope 3 {
debug x => _13;
debug x => _12;
}
}
scope 5 (inlined iter::range::<impl Iterator for std::ops::Range<usize>>::next) {
scope 6 (inlined <std::ops::Range<usize> as iter::range::RangeIteratorImpl>::spec_next) {
let mut _6: bool;
let _7: usize;
let mut _8: usize;
scope 7 {
}
scope 8 (inlined std::cmp::impls::<impl PartialOrd for usize>::lt) {
@ -41,13 +40,12 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
bb0: {
_3 = Len((*_1));
StorageLive(_4);
_4 = const 0_usize;
goto -> bb1;
}
bb1: {
StorageLive(_9);
StorageLive(_8);
StorageLive(_7);
StorageLive(_6);
StorageLive(_5);
@ -60,8 +58,7 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
bb2: {
StorageDead(_6);
StorageDead(_7);
StorageDead(_9);
StorageDead(_4);
StorageDead(_8);
drop(_2) -> [return: bb3, unwind continue];
}
@ -71,35 +68,32 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
bb4: {
_7 = _4;
StorageLive(_8);
_8 = <usize as Step>::forward_unchecked(_7, const 1_usize) -> [return: bb5, unwind: bb8];
_4 = <usize as Step>::forward_unchecked(_7, const 1_usize) -> [return: bb5, unwind: bb8];
}
bb5: {
_4 = move _8;
StorageDead(_8);
_9 = Option::<usize>::Some(_7);
_8 = Option::<usize>::Some(_7);
StorageDead(_6);
StorageDead(_7);
_10 = ((_9 as Some).0: usize);
_11 = Len((*_1));
_12 = Lt(_10, _11);
assert(move _12, "index out of bounds: the length is {} but the index is {}", move _11, _10) -> [success: bb6, unwind: bb8];
_9 = ((_8 as Some).0: usize);
_10 = Len((*_1));
_11 = Lt(_9, _10);
assert(move _11, "index out of bounds: the length is {} but the index is {}", move _10, _9) -> [success: bb6, unwind: bb8];
}
bb6: {
_13 = &(*_1)[_10];
_12 = &(*_1)[_9];
StorageLive(_13);
_13 = &_2;
StorageLive(_14);
_14 = &_2;
StorageLive(_15);
_15 = (_10, _13);
_16 = <impl Fn(usize, &T) as Fn<(usize, &T)>>::call(move _14, move _15) -> [return: bb7, unwind: bb8];
_14 = (_9, _12);
_15 = <impl Fn(usize, &T) as Fn<(usize, &T)>>::call(move _13, move _14) -> [return: bb7, unwind: bb8];
}
bb7: {
StorageDead(_15);
StorageDead(_14);
StorageDead(_9);
StorageDead(_13);
StorageDead(_8);
goto -> bb1;
}

View File

@ -4,22 +4,22 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () {
debug slice => _1;
debug f => _2;
let mut _0: ();
let mut _12: std::slice::Iter<'_, T>;
let mut _11: std::slice::Iter<'_, T>;
let mut _12: std::iter::Rev<std::slice::Iter<'_, T>>;
let mut _13: std::iter::Rev<std::slice::Iter<'_, T>>;
let mut _14: std::iter::Rev<std::slice::Iter<'_, T>>;
let mut _16: std::option::Option<&T>;
let mut _17: isize;
let mut _19: &impl Fn(&T);
let mut _20: (&T,);
let _21: ();
let mut _15: std::option::Option<&T>;
let mut _16: isize;
let mut _18: &impl Fn(&T);
let mut _19: (&T,);
let _20: ();
scope 1 {
debug iter => _14;
let _18: &T;
debug iter => _13;
let _17: &T;
scope 2 {
debug x => _18;
debug x => _17;
}
scope 17 (inlined <Rev<std::slice::Iter<'_, T>> as Iterator>::next) {
let mut _15: &mut std::slice::Iter<'_, T>;
let mut _14: &mut std::slice::Iter<'_, T>;
}
}
scope 3 (inlined core::slice::<impl [T]>::iter) {
@ -28,11 +28,10 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () {
let mut _7: bool;
let mut _8: *mut T;
let mut _9: *mut T;
let mut _11: *const T;
let mut _10: *const T;
scope 5 {
let _6: std::ptr::NonNull<T>;
scope 6 {
let _10: *const T;
scope 7 {
}
scope 11 (inlined without_provenance::<T>) {
@ -61,16 +60,16 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () {
}
bb0: {
StorageLive(_12);
StorageLive(_11);
StorageLive(_3);
StorageLive(_6);
StorageLive(_10);
StorageLive(_4);
StorageLive(_5);
_3 = Len((*_1));
_4 = &raw const (*_1);
_5 = _4 as *const T (PtrToPtr);
_6 = NonNull::<T> { pointer: _5 };
StorageLive(_10);
StorageLive(_7);
_7 = const <T as std::mem::SizedTypeProperties>::IS_ZST;
switchInt(move _7) -> [0: bb1, otherwise: bb2];
@ -94,38 +93,35 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () {
bb3: {
StorageDead(_7);
StorageLive(_11);
_11 = _10;
_12 = std::slice::Iter::<'_, T> { ptr: _6, end_or_len: move _11, _marker: const ZeroSized: PhantomData<&T> };
StorageDead(_11);
StorageDead(_10);
_11 = std::slice::Iter::<'_, T> { ptr: _6, end_or_len: move _10, _marker: const ZeroSized: PhantomData<&T> };
StorageDead(_5);
StorageDead(_4);
StorageDead(_10);
StorageDead(_6);
StorageDead(_3);
_13 = Rev::<std::slice::Iter<'_, T>> { iter: _12 };
StorageDead(_12);
StorageLive(_14);
_14 = _13;
_12 = Rev::<std::slice::Iter<'_, T>> { iter: _11 };
StorageDead(_11);
StorageLive(_13);
_13 = _12;
goto -> bb4;
}
bb4: {
StorageLive(_16);
StorageLive(_15);
_15 = &mut (_14.0: std::slice::Iter<'_, T>);
_16 = <std::slice::Iter<'_, T> as DoubleEndedIterator>::next_back(move _15) -> [return: bb5, unwind unreachable];
StorageLive(_14);
_14 = &mut (_13.0: std::slice::Iter<'_, T>);
_15 = <std::slice::Iter<'_, T> as DoubleEndedIterator>::next_back(move _14) -> [return: bb5, unwind unreachable];
}
bb5: {
StorageDead(_15);
_17 = discriminant(_16);
switchInt(move _17) -> [0: bb6, 1: bb8, otherwise: bb10];
StorageDead(_14);
_16 = discriminant(_15);
switchInt(move _16) -> [0: bb6, 1: bb8, otherwise: bb10];
}
bb6: {
StorageDead(_16);
StorageDead(_14);
StorageDead(_15);
StorageDead(_13);
drop(_2) -> [return: bb7, unwind unreachable];
}
@ -134,18 +130,18 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () {
}
bb8: {
_18 = ((_16 as Some).0: &T);
_17 = ((_15 as Some).0: &T);
StorageLive(_18);
_18 = &_2;
StorageLive(_19);
_19 = &_2;
StorageLive(_20);
_20 = (_18,);
_21 = <impl Fn(&T) as Fn<(&T,)>>::call(move _19, move _20) -> [return: bb9, unwind unreachable];
_19 = (_17,);
_20 = <impl Fn(&T) as Fn<(&T,)>>::call(move _18, move _19) -> [return: bb9, unwind unreachable];
}
bb9: {
StorageDead(_20);
StorageDead(_19);
StorageDead(_16);
StorageDead(_18);
StorageDead(_15);
goto -> bb4;
}

View File

@ -4,22 +4,22 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () {
debug slice => _1;
debug f => _2;
let mut _0: ();
let mut _12: std::slice::Iter<'_, T>;
let mut _11: std::slice::Iter<'_, T>;
let mut _12: std::iter::Rev<std::slice::Iter<'_, T>>;
let mut _13: std::iter::Rev<std::slice::Iter<'_, T>>;
let mut _14: std::iter::Rev<std::slice::Iter<'_, T>>;
let mut _16: std::option::Option<&T>;
let mut _17: isize;
let mut _19: &impl Fn(&T);
let mut _20: (&T,);
let _21: ();
let mut _15: std::option::Option<&T>;
let mut _16: isize;
let mut _18: &impl Fn(&T);
let mut _19: (&T,);
let _20: ();
scope 1 {
debug iter => _14;
let _18: &T;
debug iter => _13;
let _17: &T;
scope 2 {
debug x => _18;
debug x => _17;
}
scope 17 (inlined <Rev<std::slice::Iter<'_, T>> as Iterator>::next) {
let mut _15: &mut std::slice::Iter<'_, T>;
let mut _14: &mut std::slice::Iter<'_, T>;
}
}
scope 3 (inlined core::slice::<impl [T]>::iter) {
@ -28,11 +28,10 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () {
let mut _7: bool;
let mut _8: *mut T;
let mut _9: *mut T;
let mut _11: *const T;
let mut _10: *const T;
scope 5 {
let _6: std::ptr::NonNull<T>;
scope 6 {
let _10: *const T;
scope 7 {
}
scope 11 (inlined without_provenance::<T>) {
@ -61,16 +60,16 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () {
}
bb0: {
StorageLive(_12);
StorageLive(_11);
StorageLive(_3);
StorageLive(_6);
StorageLive(_10);
StorageLive(_4);
StorageLive(_5);
_3 = Len((*_1));
_4 = &raw const (*_1);
_5 = _4 as *const T (PtrToPtr);
_6 = NonNull::<T> { pointer: _5 };
StorageLive(_10);
StorageLive(_7);
_7 = const <T as std::mem::SizedTypeProperties>::IS_ZST;
switchInt(move _7) -> [0: bb1, otherwise: bb2];
@ -94,38 +93,35 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () {
bb3: {
StorageDead(_7);
StorageLive(_11);
_11 = _10;
_12 = std::slice::Iter::<'_, T> { ptr: _6, end_or_len: move _11, _marker: const ZeroSized: PhantomData<&T> };
StorageDead(_11);
StorageDead(_10);
_11 = std::slice::Iter::<'_, T> { ptr: _6, end_or_len: move _10, _marker: const ZeroSized: PhantomData<&T> };
StorageDead(_5);
StorageDead(_4);
StorageDead(_10);
StorageDead(_6);
StorageDead(_3);
_13 = Rev::<std::slice::Iter<'_, T>> { iter: _12 };
StorageDead(_12);
StorageLive(_14);
_14 = _13;
_12 = Rev::<std::slice::Iter<'_, T>> { iter: _11 };
StorageDead(_11);
StorageLive(_13);
_13 = _12;
goto -> bb4;
}
bb4: {
StorageLive(_16);
StorageLive(_15);
_15 = &mut (_14.0: std::slice::Iter<'_, T>);
_16 = <std::slice::Iter<'_, T> as DoubleEndedIterator>::next_back(move _15) -> [return: bb5, unwind: bb11];
StorageLive(_14);
_14 = &mut (_13.0: std::slice::Iter<'_, T>);
_15 = <std::slice::Iter<'_, T> as DoubleEndedIterator>::next_back(move _14) -> [return: bb5, unwind: bb11];
}
bb5: {
StorageDead(_15);
_17 = discriminant(_16);
switchInt(move _17) -> [0: bb6, 1: bb8, otherwise: bb10];
StorageDead(_14);
_16 = discriminant(_15);
switchInt(move _16) -> [0: bb6, 1: bb8, otherwise: bb10];
}
bb6: {
StorageDead(_16);
StorageDead(_14);
StorageDead(_15);
StorageDead(_13);
drop(_2) -> [return: bb7, unwind continue];
}
@ -134,18 +130,18 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () {
}
bb8: {
_18 = ((_16 as Some).0: &T);
_17 = ((_15 as Some).0: &T);
StorageLive(_18);
_18 = &_2;
StorageLive(_19);
_19 = &_2;
StorageLive(_20);
_20 = (_18,);
_21 = <impl Fn(&T) as Fn<(&T,)>>::call(move _19, move _20) -> [return: bb9, unwind: bb11];
_19 = (_17,);
_20 = <impl Fn(&T) as Fn<(&T,)>>::call(move _18, move _19) -> [return: bb9, unwind: bb11];
}
bb9: {
StorageDead(_20);
StorageDead(_19);
StorageDead(_16);
StorageDead(_18);
StorageDead(_15);
goto -> bb4;
}