Skip to content

Commit 179fc42

Browse files
committed
Temp: Initial impl
1 parent 26bbe2c commit 179fc42

File tree

7 files changed

+579
-644
lines changed

7 files changed

+579
-644
lines changed

src/librustc_mir/build/block.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,19 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2626
self.in_opt_scope(opt_destruction_scope.map(|de|(de, source_info)), move |this| {
2727
this.in_scope((region_scope, source_info), LintLevel::Inherited, move |this| {
2828
if targeted_by_break {
29-
// This is a `break`-able block
30-
let exit_block = this.cfg.start_new_block();
31-
let block_exit = this.in_breakable_scope(
32-
None, exit_block, destination.clone(), |this| {
33-
this.ast_block_stmts(destination, block, span, stmts, expr,
34-
safety_mode)
35-
});
36-
this.cfg.terminate(unpack!(block_exit), source_info,
37-
TerminatorKind::Goto { target: exit_block });
38-
exit_block.unit()
29+
this.in_breakable_scope(
30+
None,
31+
destination.clone(),
32+
span,
33+
|this| Some(this.ast_block_stmts(
34+
destination,
35+
block,
36+
span,
37+
stmts,
38+
expr,
39+
safety_mode,
40+
)),
41+
)
3942
} else {
4043
this.ast_block_stmts(destination, block, span, stmts, expr,
4144
safety_mode)

src/librustc_mir/build/expr/as_rvalue.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
257257
ExprKind::Yield { value } => {
258258
let value = unpack!(block = this.as_operand(block, scope, value));
259259
let resume = this.cfg.start_new_block();
260-
let cleanup = this.generator_drop_cleanup();
260+
this.generator_drop_cleanup(block);
261261
this.cfg.terminate(
262262
block,
263263
source_info,
264264
TerminatorKind::Yield {
265265
value: value,
266266
resume: resume,
267-
drop: cleanup,
267+
drop: None,
268268
},
269269
);
270270
resume.and(this.unit_rvalue())

src/librustc_mir/build/expr/into.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
157157
// body, even when the exact code in the body cannot unwind
158158

159159
let loop_block = this.cfg.start_new_block();
160-
let exit_block = this.cfg.start_new_block();
161160

162161
// start the loop
163162
this.cfg.terminate(
@@ -168,18 +167,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
168167

169168
this.in_breakable_scope(
170169
Some(loop_block),
171-
exit_block,
172170
destination.clone(),
171+
expr_span,
173172
move |this| {
174173
// conduct the test, if necessary
175174
let body_block = this.cfg.start_new_block();
176-
let diverge_cleanup = this.diverge_cleanup();
175+
this.diverge_from(loop_block);
177176
this.cfg.terminate(
178177
loop_block,
179178
source_info,
180179
TerminatorKind::FalseUnwind {
181180
real_target: body_block,
182-
unwind: Some(diverge_cleanup),
181+
unwind: None,
183182
},
184183
);
185184

@@ -193,9 +192,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
193192
source_info,
194193
TerminatorKind::Goto { target: loop_block },
195194
);
195+
None
196196
},
197-
);
198-
exit_block.unit()
197+
)
199198
}
200199
ExprKind::Call { ty, fun, args, from_hir_call } => {
201200
let intrinsic = match ty.kind {
@@ -244,17 +243,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
244243
.collect();
245244

246245
let success = this.cfg.start_new_block();
247-
let cleanup = this.diverge_cleanup();
248246

249247
this.record_operands_moved(&args);
250248

249+
this.diverge_from(block);
251250
this.cfg.terminate(
252251
block,
253252
source_info,
254253
TerminatorKind::Call {
255254
func: fun,
256255
args,
257-
cleanup: Some(cleanup),
256+
cleanup: None,
258257
// FIXME(varkor): replace this with an uninhabitedness-based check.
259258
// This requires getting access to the current module to call
260259
// `tcx.is_ty_uninhabited_from`, which is currently tricky to do.

src/librustc_mir/build/matches/mod.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use crate::build::{GuardFrame, GuardFrameLocal, LocalsForNode};
1212
use crate::hair::{self, *};
1313
use rustc::hir::HirId;
1414
use rustc::mir::*;
15-
use rustc::middle::region;
1615
use rustc::ty::{self, CanonicalUserTypeAnnotation, Ty};
1716
use rustc::ty::layout::VariantIdx;
1817
use rustc_index::bit_set::BitSet;
@@ -228,8 +227,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
228227
};
229228

230229
// Step 5. Create everything else: the guards and the arms.
231-
let match_scope = self.scopes.topmost();
232-
233230
let arm_end_blocks: Vec<_> = arm_candidates.into_iter().map(|(arm, mut candidates)| {
234231
let arm_source_info = self.source_info(arm.span);
235232
let arm_scope = (arm.scope, arm_source_info);
@@ -250,7 +247,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
250247
arm.guard.clone(),
251248
&fake_borrow_temps,
252249
scrutinee_span,
253-
match_scope,
250+
//match_scope,
254251
);
255252
} else {
256253
arm_block = this.cfg.start_new_block();
@@ -261,7 +258,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
261258
arm.guard.clone(),
262259
&fake_borrow_temps,
263260
scrutinee_span,
264-
match_scope,
261+
//match_scope,
265262
);
266263
this.cfg.terminate(
267264
binding_end,
@@ -1353,7 +1350,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
13531350
guard: Option<Guard<'tcx>>,
13541351
fake_borrows: &Vec<(PlaceRef<'_, 'tcx>, Local)>,
13551352
scrutinee_span: Span,
1356-
region_scope: region::Scope,
1353+
//region_scope: region::Scope,
13571354
) -> BasicBlock {
13581355
debug!("bind_and_guard_matched_candidate(candidate={:?})", candidate);
13591356

@@ -1524,11 +1521,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
15241521
});
15251522
}
15261523

1527-
self.exit_scope(
1528-
source_info.span,
1529-
region_scope,
1524+
self.exit_top_scope(
15301525
otherwise_post_guard_block,
15311526
candidate.otherwise_block.unwrap(),
1527+
source_info,
15321528
);
15331529

15341530
// We want to ensure that the matched candidates are bound

src/librustc_mir/build/matches/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
449449
let bool_ty = self.hir.bool_ty();
450450
let eq_result = self.temp(bool_ty, source_info.span);
451451
let eq_block = self.cfg.start_new_block();
452-
let cleanup = self.diverge_cleanup();
452+
self.diverge_from(block);
453453
self.cfg.terminate(block, source_info, TerminatorKind::Call {
454454
func: Operand::Constant(box Constant {
455455
span: source_info.span,
@@ -464,7 +464,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
464464
}),
465465
args: vec![val, expect],
466466
destination: Some((eq_result.clone(), eq_block)),
467-
cleanup: Some(cleanup),
467+
cleanup: None,
468468
from_hir_call: false,
469469
});
470470

src/librustc_mir/build/mod.rs

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,6 @@ struct Builder<'a, 'tcx> {
316316
upvar_mutbls: Vec<Mutability>,
317317
unit_temp: Option<Place<'tcx>>,
318318

319-
/// Cached block with the `RESUME` terminator; this is created
320-
/// when first set of cleanups are built.
321-
cached_resume_block: Option<BasicBlock>,
322-
/// Cached block with the `RETURN` terminator.
323-
cached_return_block: Option<BasicBlock>,
324319
/// Cached block with the `UNREACHABLE` terminator.
325320
cached_unreachable_block: Option<BasicBlock>,
326321
}
@@ -614,43 +609,32 @@ where
614609
id: body.value.hir_id.local_id,
615610
data: region::ScopeData::Arguments
616611
};
617-
let mut block = START_BLOCK;
618612
let source_info = builder.source_info(span);
619613
let call_site_s = (call_site_scope, source_info);
620-
unpack!(block = builder.in_scope(call_site_s, LintLevel::Inherited, |builder| {
621-
if should_abort_on_panic(tcx, fn_def_id, abi) {
622-
builder.schedule_abort();
623-
}
624-
614+
unpack!(builder.in_scope(call_site_s, LintLevel::Inherited, |builder| {
625615
let arg_scope_s = (arg_scope, source_info);
626-
// `return_block` is called when we evaluate a `return` expression, so
627-
// we just use `START_BLOCK` here.
628-
unpack!(block = builder.in_breakable_scope(
616+
// Attribute epilogue to function's closing brace
617+
let fn_end = span.shrink_to_hi();
618+
let return_block = unpack!(builder.in_breakable_scope(
629619
None,
630-
START_BLOCK,
631620
Place::return_place(),
621+
fn_end,
632622
|builder| {
633-
builder.in_scope(arg_scope_s, LintLevel::Inherited, |builder| {
634-
builder.args_and_body(block, &arguments, arg_scope, &body.value)
635-
})
623+
Some(builder.in_scope(arg_scope_s, LintLevel::Inherited, |builder| {
624+
builder.args_and_body(START_BLOCK, &arguments, arg_scope, &body.value)
625+
}))
636626
},
637627
));
638-
// Attribute epilogue to function's closing brace
639-
let fn_end = span.shrink_to_hi();
640628
let source_info = builder.source_info(fn_end);
641-
let return_block = builder.return_block();
642-
builder.cfg.terminate(block, source_info,
643-
TerminatorKind::Goto { target: return_block });
644-
builder.cfg.terminate(return_block, source_info,
645-
TerminatorKind::Return);
629+
builder.cfg.terminate(return_block, source_info, TerminatorKind::Return);
630+
let should_abort = should_abort_on_panic(tcx, fn_def_id, abi);
631+
builder.build_drop_trees(should_abort);
646632
// Attribute any unreachable codepaths to the function's closing brace
647633
if let Some(unreachable_block) = builder.cached_unreachable_block {
648-
builder.cfg.terminate(unreachable_block, source_info,
649-
TerminatorKind::Unreachable);
634+
builder.cfg.terminate(unreachable_block, source_info, TerminatorKind::Unreachable);
650635
}
651636
return_block.unit()
652637
}));
653-
assert_eq!(block, builder.return_block());
654638

655639
let mut spread_arg = None;
656640
if abi == Abi::RustCall {
@@ -694,9 +678,6 @@ fn construct_const<'a, 'tcx>(
694678
let source_info = builder.source_info(span);
695679
builder.cfg.terminate(block, source_info, TerminatorKind::Return);
696680

697-
// Constants can't `return` so a return block should not be created.
698-
assert_eq!(builder.cached_return_block, None);
699-
700681
// Constants may be match expressions in which case an unreachable block may
701682
// be created, so terminate it properly.
702683
if let Some(unreachable_block) = builder.cached_unreachable_block {
@@ -738,7 +719,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
738719
fn_span: span,
739720
arg_count,
740721
is_generator,
741-
scopes: Default::default(),
722+
scopes: scope::Scopes::new(is_generator),
742723
block_context: BlockContext::new(),
743724
source_scopes: IndexVec::new(),
744725
source_scope: OUTERMOST_SOURCE_SCOPE,
@@ -755,8 +736,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
755736
upvar_mutbls,
756737
var_indices: Default::default(),
757738
unit_temp: None,
758-
cached_resume_block: None,
759-
cached_return_block: None,
760739
cached_unreachable_block: None,
761740
};
762741

@@ -933,17 +912,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
933912
}
934913
}
935914
}
936-
937-
fn return_block(&mut self) -> BasicBlock {
938-
match self.cached_return_block {
939-
Some(rb) => rb,
940-
None => {
941-
let rb = self.cfg.start_new_block();
942-
self.cached_return_block = Some(rb);
943-
rb
944-
}
945-
}
946-
}
947915
}
948916

949917
///////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)