Skip to content

Commit 6f8760b

Browse files
authored
Rollup merge of #72989 - pnkfelix:revert-pr-71840, r=matthewjasper
Revert pr 71840 Revert7 PR #71840 to fix issue #72470 This will need a backport to beta if we do not want #72470 to hit stable.
2 parents 63b314c + ce4c953 commit 6f8760b

File tree

58 files changed

+1768
-1638
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1768
-1638
lines changed

Diff for: src/librustc_mir/dataflow/move_paths/builder.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -362,18 +362,17 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
362362
fn gather_terminator(&mut self, term: &Terminator<'tcx>) {
363363
match term.kind {
364364
TerminatorKind::Goto { target: _ }
365-
| TerminatorKind::FalseEdges { .. }
366-
| TerminatorKind::FalseUnwind { .. }
367-
// In some sense returning moves the return place into the current
368-
// call's destination, however, since there are no statements after
369-
// this that could possibly access the return place, this doesn't
370-
// need recording.
371-
| TerminatorKind::Return
372365
| TerminatorKind::Resume
373366
| TerminatorKind::Abort
374367
| TerminatorKind::GeneratorDrop
368+
| TerminatorKind::FalseEdges { .. }
369+
| TerminatorKind::FalseUnwind { .. }
375370
| TerminatorKind::Unreachable => {}
376371

372+
TerminatorKind::Return => {
373+
self.gather_move(Place::return_place());
374+
}
375+
377376
TerminatorKind::Assert { ref cond, .. } => {
378377
self.gather_operand(cond);
379378
}
@@ -417,7 +416,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
417416
ref operands,
418417
options: _,
419418
line_spans: _,
420-
destination: _
419+
destination: _,
421420
} => {
422421
for op in operands {
423422
match *op {

Diff for: src/librustc_mir/util/elaborate_drops.rs

+35-11
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ where
233233
.patch_terminator(bb, TerminatorKind::Goto { target: self.succ });
234234
}
235235
DropStyle::Static => {
236+
let loc = self.terminator_loc(bb);
237+
self.elaborator.clear_drop_flag(loc, self.path, DropFlagMode::Deep);
236238
self.elaborator.patch().patch_terminator(
237239
bb,
238240
TerminatorKind::Drop {
@@ -243,7 +245,9 @@ where
243245
);
244246
}
245247
DropStyle::Conditional => {
246-
let drop_bb = self.complete_drop(self.succ, self.unwind);
248+
let unwind = self.unwind; // FIXME(#43234)
249+
let succ = self.succ;
250+
let drop_bb = self.complete_drop(Some(DropFlagMode::Deep), succ, unwind);
247251
self.elaborator
248252
.patch()
249253
.patch_terminator(bb, TerminatorKind::Goto { target: drop_bb });
@@ -315,7 +319,7 @@ where
315319
// our own drop flag.
316320
path: self.path,
317321
}
318-
.complete_drop(succ, unwind)
322+
.complete_drop(None, succ, unwind)
319323
}
320324
}
321325

@@ -344,7 +348,13 @@ where
344348
// Clear the "master" drop flag at the end. This is needed
345349
// because the "master" drop protects the ADT's discriminant,
346350
// which is invalidated after the ADT is dropped.
347-
(self.drop_flag_reset_block(DropFlagMode::Shallow, self.succ, self.unwind), self.unwind)
351+
let (succ, unwind) = (self.succ, self.unwind); // FIXME(#43234)
352+
(
353+
self.drop_flag_reset_block(DropFlagMode::Shallow, succ, unwind),
354+
unwind.map(|unwind| {
355+
self.drop_flag_reset_block(DropFlagMode::Shallow, unwind, Unwind::InCleanup)
356+
}),
357+
)
348358
}
349359

350360
/// Creates a full drop ladder, consisting of 2 connected half-drop-ladders
@@ -878,7 +888,11 @@ where
878888
self.open_drop_for_adt(def, substs)
879889
}
880890
}
881-
ty::Dynamic(..) => self.complete_drop(self.succ, self.unwind),
891+
ty::Dynamic(..) => {
892+
let unwind = self.unwind; // FIXME(#43234)
893+
let succ = self.succ;
894+
self.complete_drop(Some(DropFlagMode::Deep), succ, unwind)
895+
}
882896
ty::Array(ety, size) => {
883897
let size = size.try_eval_usize(self.tcx(), self.elaborator.param_env());
884898
self.open_drop_for_array(ety, size)
@@ -889,10 +903,20 @@ where
889903
}
890904
}
891905

892-
fn complete_drop(&mut self, succ: BasicBlock, unwind: Unwind) -> BasicBlock {
893-
debug!("complete_drop(succ={:?}, unwind={:?})", succ, unwind);
906+
fn complete_drop(
907+
&mut self,
908+
drop_mode: Option<DropFlagMode>,
909+
succ: BasicBlock,
910+
unwind: Unwind,
911+
) -> BasicBlock {
912+
debug!("complete_drop({:?},{:?})", self, drop_mode);
894913

895914
let drop_block = self.drop_block(succ, unwind);
915+
let drop_block = if let Some(mode) = drop_mode {
916+
self.drop_flag_reset_block(mode, drop_block, unwind)
917+
} else {
918+
drop_block
919+
};
896920

897921
self.drop_flag_test_block(drop_block, succ, unwind)
898922
}
@@ -907,11 +931,6 @@ where
907931
) -> BasicBlock {
908932
debug!("drop_flag_reset_block({:?},{:?})", self, mode);
909933

910-
if unwind.is_cleanup() {
911-
// The drop flag isn't read again on the unwind path, so don't
912-
// bother setting it.
913-
return succ;
914-
}
915934
let block = self.new_block(unwind, TerminatorKind::Goto { target: succ });
916935
let block_start = Location { block, statement_index: 0 };
917936
self.elaborator.clear_drop_flag(block_start, self.path, mode);
@@ -1028,6 +1047,11 @@ where
10281047
self.elaborator.patch().new_temp(ty, self.source_info.span)
10291048
}
10301049

1050+
fn terminator_loc(&mut self, bb: BasicBlock) -> Location {
1051+
let body = self.elaborator.body();
1052+
self.elaborator.patch().terminator_loc(body, bb)
1053+
}
1054+
10311055
fn constant_usize(&self, val: u16) -> Operand<'tcx> {
10321056
Operand::Constant(box Constant {
10331057
span: self.source_info.span,

Diff for: src/librustc_mir/util/graphviz.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,12 @@ where
9898
write!(w, r#"<table border="0" cellborder="1" cellspacing="0">"#)?;
9999

100100
// Basic block number at the top.
101-
let (blk, color) = if data.is_cleanup {
102-
(format!("{} (cleanup)", block.index()), "lightblue")
103-
} else {
104-
(format!("{}", block.index()), "gray")
105-
};
106101
write!(
107102
w,
108-
r#"<tr><td bgcolor="{color}" align="center" colspan="{colspan}">{blk}</td></tr>"#,
103+
r#"<tr><td {attrs} colspan="{colspan}">{blk}</td></tr>"#,
104+
attrs = r#"bgcolor="gray" align="center""#,
109105
colspan = num_cols,
110-
blk = blk,
111-
color = color
106+
blk = block.index()
112107
)?;
113108

114109
init(w)?;

Diff for: src/librustc_mir_build/build/block.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2828
self.in_opt_scope(opt_destruction_scope.map(|de| (de, source_info)), move |this| {
2929
this.in_scope((region_scope, source_info), LintLevel::Inherited, move |this| {
3030
if targeted_by_break {
31-
this.in_breakable_scope(None, destination, span, |this| {
32-
Some(this.ast_block_stmts(
33-
destination,
34-
block,
35-
span,
36-
stmts,
37-
expr,
38-
safety_mode,
39-
))
40-
})
31+
// This is a `break`-able block
32+
let exit_block = this.cfg.start_new_block();
33+
let block_exit =
34+
this.in_breakable_scope(None, exit_block, destination, |this| {
35+
this.ast_block_stmts(destination, block, span, stmts, expr, safety_mode)
36+
});
37+
this.cfg.goto(unpack!(block_exit), source_info, exit_block);
38+
exit_block.unit()
4139
} else {
4240
this.ast_block_stmts(destination, block, span, stmts, expr, safety_mode)
4341
}

Diff for: src/librustc_mir_build/build/expr/into.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -135,30 +135,32 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
135135
// body, even when the exact code in the body cannot unwind
136136

137137
let loop_block = this.cfg.start_new_block();
138+
let exit_block = this.cfg.start_new_block();
138139

139140
// Start the loop.
140141
this.cfg.goto(block, source_info, loop_block);
141142

142-
this.in_breakable_scope(Some(loop_block), destination, expr_span, move |this| {
143+
this.in_breakable_scope(Some(loop_block), exit_block, destination, move |this| {
143144
// conduct the test, if necessary
144145
let body_block = this.cfg.start_new_block();
146+
let diverge_cleanup = this.diverge_cleanup();
145147
this.cfg.terminate(
146148
loop_block,
147149
source_info,
148-
TerminatorKind::FalseUnwind { real_target: body_block, unwind: None },
150+
TerminatorKind::FalseUnwind {
151+
real_target: body_block,
152+
unwind: Some(diverge_cleanup),
153+
},
149154
);
150-
this.diverge_from(loop_block);
151155

152156
// The “return” value of the loop body must always be an unit. We therefore
153157
// introduce a unit temporary as the destination for the loop body.
154158
let tmp = this.get_unit_temp();
155159
// Execute the body, branching back to the test.
156160
let body_block_end = unpack!(this.into(tmp, body_block, body));
157161
this.cfg.goto(body_block_end, source_info, loop_block);
158-
159-
// Loops are only exited by `break` expressions.
160-
None
161-
})
162+
});
163+
exit_block.unit()
162164
}
163165
ExprKind::Call { ty, fun, args, from_hir_call } => {
164166
let intrinsic = match ty.kind {
@@ -200,6 +202,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
200202
.collect();
201203

202204
let success = this.cfg.start_new_block();
205+
let cleanup = this.diverge_cleanup();
203206

204207
this.record_operands_moved(&args);
205208

@@ -209,7 +212,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
209212
TerminatorKind::Call {
210213
func: fun,
211214
args,
212-
cleanup: None,
215+
cleanup: Some(cleanup),
213216
// FIXME(varkor): replace this with an uninhabitedness-based check.
214217
// This requires getting access to the current module to call
215218
// `tcx.is_ty_uninhabited_from`, which is currently tricky to do.
@@ -221,7 +224,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
221224
from_hir_call,
222225
},
223226
);
224-
this.diverge_from(block);
225227
success.unit()
226228
}
227229
}
@@ -425,12 +427,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
425427
let scope = this.local_scope();
426428
let value = unpack!(block = this.as_operand(block, scope, value));
427429
let resume = this.cfg.start_new_block();
430+
let cleanup = this.generator_drop_cleanup();
428431
this.cfg.terminate(
429432
block,
430433
source_info,
431-
TerminatorKind::Yield { value, resume, resume_arg: destination, drop: None },
434+
TerminatorKind::Yield { value, resume, resume_arg: destination, drop: cleanup },
432435
);
433-
this.generator_drop_cleanup(block);
434436
resume.unit()
435437
}
436438

Diff for: src/librustc_mir_build/build/matches/mod.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
225225
outer_source_info: SourceInfo,
226226
fake_borrow_temps: Vec<(Place<'tcx>, Local)>,
227227
) -> BlockAnd<()> {
228+
let match_scope = self.scopes.topmost();
229+
228230
let arm_end_blocks: Vec<_> = arm_candidates
229231
.into_iter()
230232
.map(|(arm, candidate)| {
@@ -245,7 +247,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
245247
let arm_block = this.bind_pattern(
246248
outer_source_info,
247249
candidate,
248-
arm.guard.as_ref(),
250+
arm.guard.as_ref().map(|g| (g, match_scope)),
249251
&fake_borrow_temps,
250252
scrutinee_span,
251253
Some(arm.scope),
@@ -282,7 +284,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
282284
&mut self,
283285
outer_source_info: SourceInfo,
284286
candidate: Candidate<'_, 'tcx>,
285-
guard: Option<&Guard<'tcx>>,
287+
guard: Option<(&Guard<'tcx>, region::Scope)>,
286288
fake_borrow_temps: &Vec<(Place<'tcx>, Local)>,
287289
scrutinee_span: Span,
288290
arm_scope: Option<region::Scope>,
@@ -1588,7 +1590,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
15881590
&mut self,
15891591
candidate: Candidate<'pat, 'tcx>,
15901592
parent_bindings: &[(Vec<Binding<'tcx>>, Vec<Ascription<'tcx>>)],
1591-
guard: Option<&Guard<'tcx>>,
1593+
guard: Option<(&Guard<'tcx>, region::Scope)>,
15921594
fake_borrows: &Vec<(Place<'tcx>, Local)>,
15931595
scrutinee_span: Span,
15941596
schedule_drops: bool,
@@ -1700,7 +1702,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
17001702
// the reference that we create for the arm.
17011703
// * So we eagerly create the reference for the arm and then take a
17021704
// reference to that.
1703-
if let Some(guard) = guard {
1705+
if let Some((guard, region_scope)) = guard {
17041706
let tcx = self.hir.tcx();
17051707
let bindings = parent_bindings
17061708
.iter()
@@ -1744,7 +1746,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
17441746
unreachable
17451747
});
17461748
let outside_scope = self.cfg.start_new_block();
1747-
self.exit_top_scope(otherwise_post_guard_block, outside_scope, source_info);
1749+
self.exit_scope(
1750+
source_info.span,
1751+
region_scope,
1752+
otherwise_post_guard_block,
1753+
outside_scope,
1754+
);
17481755
self.false_edges(
17491756
outside_scope,
17501757
otherwise_block,

Diff for: src/librustc_mir_build/build/matches/test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
423423
let bool_ty = self.hir.bool_ty();
424424
let eq_result = self.temp(bool_ty, source_info.span);
425425
let eq_block = self.cfg.start_new_block();
426+
let cleanup = self.diverge_cleanup();
426427
self.cfg.terminate(
427428
block,
428429
source_info,
@@ -440,11 +441,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
440441
}),
441442
args: vec![val, expect],
442443
destination: Some((eq_result, eq_block)),
443-
cleanup: None,
444+
cleanup: Some(cleanup),
444445
from_hir_call: false,
445446
},
446447
);
447-
self.diverge_from(block);
448448

449449
if let [success_block, fail_block] = *make_target_blocks(self) {
450450
// check the result

0 commit comments

Comments
 (0)