-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #95742 - Dylan-DPC:rollup-8n7o87y, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - #95342 (Ignore "format the world" commit in git blame) - #95353 ([bootstrap] Give a hard error when filtering tests for a file that does not exist) - #95649 (New mir-opt deref_separator) - #95721 (Fix typo in bootstrap/setup.rs) - #95730 (Rename RWLock to RwLock in std::sys.) - #95731 (Check that all hidden types are the same and then deduplicate them.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
- Loading branch information
Showing
37 changed files
with
402 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# format the world | ||
a06baa56b95674fc626b3c3fd680d6a65357fe60 | ||
# format libcore | ||
95e00bfed801e264e9c4ac817004153ca0f19eb6 | ||
# reformat with new rustfmt | ||
971c549ca334b7b7406e61e958efcca9c4152822 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use crate::MirPass; | ||
use rustc_middle::mir::patch::MirPatch; | ||
use rustc_middle::mir::*; | ||
use rustc_middle::ty::TyCtxt; | ||
pub struct Derefer; | ||
|
||
pub fn deref_finder<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { | ||
let mut patch = MirPatch::new(body); | ||
let (basic_blocks, local_decl) = body.basic_blocks_and_local_decls_mut(); | ||
for (block, data) in basic_blocks.iter_enumerated_mut() { | ||
for (i, stmt) in data.statements.iter_mut().enumerate() { | ||
match stmt.kind { | ||
StatementKind::Assign(box (og_place, Rvalue::Ref(region, borrow_knd, place))) => { | ||
for (idx, (p_ref, p_elem)) in place.iter_projections().enumerate() { | ||
if p_elem == ProjectionElem::Deref && !p_ref.projection.is_empty() { | ||
// The type that we are derefing. | ||
let ty = p_ref.ty(local_decl, tcx).ty; | ||
let temp = patch.new_temp(ty, stmt.source_info.span); | ||
|
||
// Because we are assigning this right before original statement | ||
// we are using index i of statement. | ||
let loc = Location { block: block, statement_index: i }; | ||
patch.add_statement(loc, StatementKind::StorageLive(temp)); | ||
|
||
// We are adding current p_ref's projections to our | ||
// temp value. | ||
let deref_place = | ||
Place::from(p_ref.local).project_deeper(p_ref.projection, tcx); | ||
patch.add_assign( | ||
loc, | ||
Place::from(temp), | ||
Rvalue::Use(Operand::Move(deref_place)), | ||
); | ||
|
||
// We are creating a place by using our temp value's location | ||
// and copying derefed values which we need to create new statement. | ||
let temp_place = | ||
Place::from(temp).project_deeper(&place.projection[idx..], tcx); | ||
let new_stmt = Statement { | ||
source_info: stmt.source_info, | ||
kind: StatementKind::Assign(Box::new(( | ||
og_place, | ||
Rvalue::Ref(region, borrow_knd, temp_place), | ||
))), | ||
}; | ||
|
||
// Replace current statement with newly created one. | ||
*stmt = new_stmt; | ||
|
||
// Since our job with the temp is done it should be gone | ||
let loc = Location { block: block, statement_index: i + 1 }; | ||
patch.add_statement(loc, StatementKind::StorageDead(temp)); | ||
|
||
// As all projections are off the base projection, if there are | ||
// multiple derefs in the middle of projection, it might cause | ||
// unsoundness, to not let that happen we break the loop. | ||
break; | ||
} | ||
} | ||
} | ||
_ => (), | ||
} | ||
} | ||
} | ||
patch.apply(body); | ||
} | ||
|
||
impl<'tcx> MirPass<'tcx> for Derefer { | ||
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { | ||
deref_finder(tcx, body); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.