Skip to content

Make derefer work everwhere #96116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions compiler/rustc_middle/src/mir/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use rustc_index::vec::{Idx, IndexVec};
use rustc_middle::mir::*;
use rustc_middle::ty::Ty;
use rustc_span::Span;
use std::collections::VecDeque;

/// This struct represents a patch to MIR, which can add
/// new statements and basic blocks and patch over block
Expand Down Expand Up @@ -143,8 +142,7 @@ impl<'tcx> MirPatch<'tcx> {
let mut delta = 0;
let mut last_bb = START_BLOCK;
let mut terminator_targets = Vec::new();
let mut inf_and_stmt: VecDeque<(SourceInfo, StatementKind<'_>)> = VecDeque::new();

let mut statements:Vec<Statement<'_>> = Vec::new();
for (mut loc, stmt) in new_statements {
if loc.block != last_bb {
delta = 0;
Expand All @@ -161,7 +159,7 @@ impl<'tcx> MirPatch<'tcx> {
let successors = term.successors().clone();

for i in successors {
inf_and_stmt.push_back((source_info, stmt.clone()));
statements.push(Statement{source_info,kind:stmt.clone()});
terminator_targets.push(i.clone());
}
delta += 1;
Expand All @@ -174,11 +172,11 @@ impl<'tcx> MirPatch<'tcx> {
delta += 1;
}

for target in terminator_targets.iter() {
let inf_and_stmt = inf_and_stmt.pop_front().unwrap();
for target in terminator_targets.iter().rev() {
let stmt = statements.pop().unwrap();
body[*target]
.statements
.insert(0, Statement { source_info: inf_and_stmt.0, kind: inf_and_stmt.1 });
.insert(0, stmt);
}
}

Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_mir_transform/src/deref_separator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ impl<'tcx> MutVisitor<'tcx> for DerefChecker<'tcx> {
}

// We are destroying last temp since it's no longer used.
if prev_temp.is_some() {
self.patcher.add_statement(loc, StatementKind::StorageDead(prev_temp.unwrap()));
if let Some(prev_temp) = prev_temp {
self.patcher.add_statement(loc, StatementKind::StorageDead(prev_temp));
}

prev_temp = Some(temp);
}
}

// Since we won't be able to reach final temp, we destroy it outside the loop.
if prev_temp.is_some() {
if let Some(prev_temp) = prev_temp {
let last_loc = Location { block: loc.block, statement_index: loc.statement_index + 1 };
self.patcher.add_statement(last_loc, StatementKind::StorageDead(prev_temp.unwrap()));
self.patcher.add_statement(last_loc, StatementKind::StorageDead(prev_temp));
}
}
}
Expand Down