|
1 |
| -//! This module provides two passes: |
| 1 | +//! This module provides a pass to replacing the following statements with |
| 2 | +//! [`Nop`]s |
2 | 3 | //!
|
3 |
| -//! - [`CleanAscribeUserType`], that replaces all [`AscribeUserType`] |
4 |
| -//! statements with [`Nop`]. |
5 |
| -//! - [`CleanFakeReadsAndBorrows`], that replaces all [`FakeRead`] statements |
6 |
| -//! and borrows that are read by [`ForMatchGuard`] fake reads with [`Nop`]. |
| 4 | +//! - [`AscribeUserType`] |
| 5 | +//! - [`FakeRead`] |
| 6 | +//! - [`Assign`] statements with a [`Shallow`] borrow |
7 | 7 | //!
|
8 | 8 | //! The `CleanFakeReadsAndBorrows` "pass" is actually implemented as two
|
9 | 9 | //! traversals (aka visits) of the input MIR. The first traversal,
|
10 | 10 | //! [`DeleteAndRecordFakeReads`], deletes the fake reads and finds the
|
11 | 11 | //! temporaries read by [`ForMatchGuard`] reads, and [`DeleteFakeBorrows`]
|
12 | 12 | //! deletes the initialization of those temporaries.
|
13 | 13 | //!
|
14 |
| -//! [`CleanAscribeUserType`]: cleanup_post_borrowck::CleanAscribeUserType |
15 |
| -//! [`CleanFakeReadsAndBorrows`]: cleanup_post_borrowck::CleanFakeReadsAndBorrows |
16 |
| -//! [`DeleteAndRecordFakeReads`]: cleanup_post_borrowck::DeleteAndRecordFakeReads |
17 |
| -//! [`DeleteFakeBorrows`]: cleanup_post_borrowck::DeleteFakeBorrows |
18 | 14 | //! [`AscribeUserType`]: rustc::mir::StatementKind::AscribeUserType
|
19 |
| -//! [`Nop`]: rustc::mir::StatementKind::Nop |
| 15 | +//! [`Shallow`]: rustc::mir::BorrowKind::Shallow |
20 | 16 | //! [`FakeRead`]: rustc::mir::StatementKind::FakeRead
|
21 |
| -//! [`ForMatchGuard`]: rustc::mir::FakeReadCause::ForMatchGuard |
22 |
| -
|
23 |
| -use rustc_data_structures::fx::FxHashSet; |
| 17 | +//! [`Nop`]: rustc::mir::StatementKind::Nop |
24 | 18 |
|
25 |
| -use rustc::mir::{BasicBlock, FakeReadCause, Local, Location, Mir, Place}; |
| 19 | +use rustc::mir::{BasicBlock, BorrowKind, Rvalue, Location, Mir}; |
26 | 20 | use rustc::mir::{Statement, StatementKind};
|
27 | 21 | use rustc::mir::visit::MutVisitor;
|
28 | 22 | use rustc::ty::TyCtxt;
|
29 | 23 | use crate::transform::{MirPass, MirSource};
|
30 | 24 |
|
31 |
| -pub struct CleanAscribeUserType; |
| 25 | +pub struct CleanupNonCodegenStatements; |
32 | 26 |
|
33 |
| -pub struct DeleteAscribeUserType; |
| 27 | +pub struct DeleteNonCodegenStatements; |
34 | 28 |
|
35 |
| -impl MirPass for CleanAscribeUserType { |
| 29 | +impl MirPass for CleanupNonCodegenStatements { |
36 | 30 | fn run_pass<'a, 'tcx>(&self,
|
37 | 31 | _tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
38 | 32 | _source: MirSource<'tcx>,
|
39 | 33 | mir: &mut Mir<'tcx>) {
|
40 |
| - let mut delete = DeleteAscribeUserType; |
| 34 | + let mut delete = DeleteNonCodegenStatements; |
41 | 35 | delete.visit_mir(mir);
|
42 | 36 | }
|
43 | 37 | }
|
44 | 38 |
|
45 |
| -impl<'tcx> MutVisitor<'tcx> for DeleteAscribeUserType { |
46 |
| - fn visit_statement(&mut self, |
47 |
| - block: BasicBlock, |
48 |
| - statement: &mut Statement<'tcx>, |
49 |
| - location: Location) { |
50 |
| - if let StatementKind::AscribeUserType(..) = statement.kind { |
51 |
| - statement.make_nop(); |
52 |
| - } |
53 |
| - self.super_statement(block, statement, location); |
54 |
| - } |
55 |
| -} |
56 |
| - |
57 |
| -pub struct CleanFakeReadsAndBorrows; |
58 |
| - |
59 |
| -#[derive(Default)] |
60 |
| -pub struct DeleteAndRecordFakeReads { |
61 |
| - fake_borrow_temporaries: FxHashSet<Local>, |
62 |
| -} |
63 |
| - |
64 |
| -pub struct DeleteFakeBorrows { |
65 |
| - fake_borrow_temporaries: FxHashSet<Local>, |
66 |
| -} |
67 |
| - |
68 |
| -// Removes any FakeReads from the MIR |
69 |
| -impl MirPass for CleanFakeReadsAndBorrows { |
70 |
| - fn run_pass<'a, 'tcx>(&self, |
71 |
| - _tcx: TyCtxt<'a, 'tcx, 'tcx>, |
72 |
| - _source: MirSource<'tcx>, |
73 |
| - mir: &mut Mir<'tcx>) { |
74 |
| - let mut delete_reads = DeleteAndRecordFakeReads::default(); |
75 |
| - delete_reads.visit_mir(mir); |
76 |
| - let mut delete_borrows = DeleteFakeBorrows { |
77 |
| - fake_borrow_temporaries: delete_reads.fake_borrow_temporaries, |
78 |
| - }; |
79 |
| - delete_borrows.visit_mir(mir); |
80 |
| - } |
81 |
| -} |
82 |
| - |
83 |
| -impl<'tcx> MutVisitor<'tcx> for DeleteAndRecordFakeReads { |
84 |
| - fn visit_statement(&mut self, |
85 |
| - block: BasicBlock, |
86 |
| - statement: &mut Statement<'tcx>, |
87 |
| - location: Location) { |
88 |
| - if let StatementKind::FakeRead(cause, ref place) = statement.kind { |
89 |
| - if let FakeReadCause::ForMatchGuard = cause { |
90 |
| - match *place { |
91 |
| - Place::Local(local) => self.fake_borrow_temporaries.insert(local), |
92 |
| - _ => bug!("Fake match guard read of non-local: {:?}", place), |
93 |
| - }; |
94 |
| - } |
95 |
| - statement.make_nop(); |
96 |
| - } |
97 |
| - self.super_statement(block, statement, location); |
98 |
| - } |
99 |
| -} |
100 |
| - |
101 |
| -impl<'tcx> MutVisitor<'tcx> for DeleteFakeBorrows { |
| 39 | +impl<'tcx> MutVisitor<'tcx> for DeleteNonCodegenStatements { |
102 | 40 | fn visit_statement(&mut self,
|
103 | 41 | block: BasicBlock,
|
104 | 42 | statement: &mut Statement<'tcx>,
|
105 | 43 | location: Location) {
|
106 |
| - if let StatementKind::Assign(Place::Local(local), _) = statement.kind { |
107 |
| - if self.fake_borrow_temporaries.contains(&local) { |
108 |
| - statement.make_nop(); |
109 |
| - } |
| 44 | + match statement.kind { |
| 45 | + StatementKind::AscribeUserType(..) |
| 46 | + | StatementKind::Assign(_, box Rvalue::Ref(_, BorrowKind::Shallow, _)) |
| 47 | + | StatementKind::FakeRead(..) => statement.make_nop(), |
| 48 | + _ => (), |
110 | 49 | }
|
111 | 50 | self.super_statement(block, statement, location);
|
112 | 51 | }
|
|
0 commit comments