-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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 #105951 - matthiaskrgr:rollup-aqxz888, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #105835 (Refactor post borrowck cleanup passes) - #105930 (Disable `NormalizeArrayLen`) - #105938 (Update coerce_unsized tracking issue from #27732 to #18598) - #105939 (Improve description of struct-fields GUI test) - #105943 (Add regression test for #102206) - #105944 (Add regression test for #80816) - #105945 (Add regression test for #57404) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
- Loading branch information
Showing
25 changed files
with
207 additions
and
124 deletions.
There are no files selected for viewing
65 changes: 27 additions & 38 deletions
65
compiler/rustc_mir_transform/src/cleanup_post_borrowck.rs
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 |
---|---|---|
@@ -1,59 +1,48 @@ | ||
//! This module provides a pass to replacing the following statements with | ||
//! [`Nop`]s | ||
//! This module provides a pass that removes parts of MIR that are no longer relevant after | ||
//! analysis phase and borrowck. In particular, it removes false edges, user type annotations and | ||
//! replaces following statements with [`Nop`]s: | ||
//! | ||
//! - [`AscribeUserType`] | ||
//! - [`FakeRead`] | ||
//! - [`Assign`] statements with a [`Shallow`] borrow | ||
//! | ||
//! The `CleanFakeReadsAndBorrows` "pass" is actually implemented as two | ||
//! traversals (aka visits) of the input MIR. The first traversal, | ||
//! `DeleteAndRecordFakeReads`, deletes the fake reads and finds the | ||
//! temporaries read by [`ForMatchGuard`] reads, and `DeleteFakeBorrows` | ||
//! deletes the initialization of those temporaries. | ||
//! | ||
//! [`AscribeUserType`]: rustc_middle::mir::StatementKind::AscribeUserType | ||
//! [`Shallow`]: rustc_middle::mir::BorrowKind::Shallow | ||
//! [`FakeRead`]: rustc_middle::mir::StatementKind::FakeRead | ||
//! [`Assign`]: rustc_middle::mir::StatementKind::Assign | ||
//! [`ForMatchGuard`]: rustc_middle::mir::FakeReadCause::ForMatchGuard | ||
//! [`FakeRead`]: rustc_middle::mir::StatementKind::FakeRead | ||
//! [`Nop`]: rustc_middle::mir::StatementKind::Nop | ||
//! [`Shallow`]: rustc_middle::mir::BorrowKind::Shallow | ||
|
||
use crate::MirPass; | ||
use rustc_middle::mir::visit::MutVisitor; | ||
use rustc_middle::mir::{Body, BorrowKind, Location, Rvalue}; | ||
use rustc_middle::mir::{Statement, StatementKind}; | ||
use rustc_middle::mir::{Body, BorrowKind, Rvalue, StatementKind, TerminatorKind}; | ||
use rustc_middle::ty::TyCtxt; | ||
|
||
pub struct CleanupNonCodegenStatements; | ||
pub struct CleanupPostBorrowck; | ||
|
||
pub struct DeleteNonCodegenStatements<'tcx> { | ||
tcx: TyCtxt<'tcx>, | ||
} | ||
impl<'tcx> MirPass<'tcx> for CleanupPostBorrowck { | ||
fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { | ||
for basic_block in body.basic_blocks.as_mut() { | ||
for statement in basic_block.statements.iter_mut() { | ||
match statement.kind { | ||
StatementKind::AscribeUserType(..) | ||
| StatementKind::Assign(box (_, Rvalue::Ref(_, BorrowKind::Shallow, _))) | ||
| StatementKind::FakeRead(..) => statement.make_nop(), | ||
_ => (), | ||
} | ||
} | ||
let terminator = basic_block.terminator_mut(); | ||
match terminator.kind { | ||
TerminatorKind::FalseEdge { real_target, .. } | ||
| TerminatorKind::FalseUnwind { real_target, .. } => { | ||
terminator.kind = TerminatorKind::Goto { target: real_target }; | ||
} | ||
_ => {} | ||
} | ||
} | ||
|
||
impl<'tcx> MirPass<'tcx> for CleanupNonCodegenStatements { | ||
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { | ||
let mut delete = DeleteNonCodegenStatements { tcx }; | ||
delete.visit_body_preserves_cfg(body); | ||
body.user_type_annotations.raw.clear(); | ||
|
||
for decl in &mut body.local_decls { | ||
decl.user_ty = None; | ||
} | ||
} | ||
} | ||
|
||
impl<'tcx> MutVisitor<'tcx> for DeleteNonCodegenStatements<'tcx> { | ||
fn tcx(&self) -> TyCtxt<'tcx> { | ||
self.tcx | ||
} | ||
|
||
fn visit_statement(&mut self, statement: &mut Statement<'tcx>, location: Location) { | ||
match statement.kind { | ||
StatementKind::AscribeUserType(..) | ||
| StatementKind::Assign(box (_, Rvalue::Ref(_, BorrowKind::Shallow, _))) | ||
| StatementKind::FakeRead(..) => statement.make_nop(), | ||
_ => (), | ||
} | ||
self.super_statement(statement, location); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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
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.