Skip to content

Commit 82c4fa1

Browse files
committed
Temp: Initial impl
1 parent d11d586 commit 82c4fa1

File tree

6 files changed

+563
-688
lines changed

6 files changed

+563
-688
lines changed

src/librustc_mir_build/build/block.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@ 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 =
32-
this.in_breakable_scope(None, exit_block, destination.clone(), |this| {
33-
this.ast_block_stmts(destination, block, span, stmts, expr, safety_mode)
34-
});
35-
this.cfg.goto(unpack!(block_exit), source_info, exit_block);
36-
exit_block.unit()
29+
this.in_breakable_scope(None, destination.clone(), span, |this| {
30+
Some(this.ast_block_stmts(
31+
destination,
32+
block,
33+
span,
34+
stmts,
35+
expr,
36+
safety_mode,
37+
))
38+
})
3739
} else {
3840
this.ast_block_stmts(destination, block, span, stmts, expr, safety_mode)
3941
}

src/librustc_mir_build/build/expr/into.rs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -134,26 +134,22 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
134134
// body, even when the exact code in the body cannot unwind
135135

136136
let loop_block = this.cfg.start_new_block();
137-
let exit_block = this.cfg.start_new_block();
138137

139138
// Start the loop.
140139
this.cfg.goto(block, source_info, loop_block);
141140

142141
this.in_breakable_scope(
143142
Some(loop_block),
144-
exit_block,
145143
destination.clone(),
144+
expr_span,
146145
move |this| {
147146
// conduct the test, if necessary
148147
let body_block = this.cfg.start_new_block();
149-
let diverge_cleanup = this.diverge_cleanup();
148+
this.diverge_from(loop_block);
150149
this.cfg.terminate(
151150
loop_block,
152151
source_info,
153-
TerminatorKind::FalseUnwind {
154-
real_target: body_block,
155-
unwind: Some(diverge_cleanup),
156-
},
152+
TerminatorKind::FalseUnwind { real_target: body_block, unwind: None },
157153
);
158154

159155
// The “return” value of the loop body must always be an unit. We therefore
@@ -162,9 +158,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
162158
// Execute the body, branching back to the test.
163159
let body_block_end = unpack!(this.into(&tmp, body_block, body));
164160
this.cfg.goto(body_block_end, source_info, loop_block);
161+
None
165162
},
166-
);
167-
exit_block.unit()
163+
)
168164
}
169165
ExprKind::Call { ty, fun, args, from_hir_call } => {
170166
let intrinsic = match ty.kind {
@@ -211,17 +207,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
211207
.collect();
212208

213209
let success = this.cfg.start_new_block();
214-
let cleanup = this.diverge_cleanup();
215210

216211
this.record_operands_moved(&args);
217212

213+
this.diverge_from(block);
218214
this.cfg.terminate(
219215
block,
220216
source_info,
221217
TerminatorKind::Call {
222218
func: fun,
223219
args,
224-
cleanup: Some(cleanup),
220+
cleanup: None,
225221
// FIXME(varkor): replace this with an uninhabitedness-based check.
226222
// This requires getting access to the current module to call
227223
// `tcx.is_ty_uninhabited_from`, which is currently tricky to do.
@@ -369,16 +365,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
369365
let scope = this.local_scope();
370366
let value = unpack!(block = this.as_operand(block, scope, value));
371367
let resume = this.cfg.start_new_block();
372-
let cleanup = this.generator_drop_cleanup();
368+
this.generator_drop_cleanup(block);
373369
this.cfg.terminate(
374370
block,
375371
source_info,
376-
TerminatorKind::Yield {
377-
value,
378-
resume,
379-
resume_arg: *destination,
380-
drop: cleanup,
381-
},
372+
TerminatorKind::Yield { value, resume, resume_arg: *destination, drop: None },
382373
);
383374
resume.unit()
384375
}

src/librustc_mir_build/build/matches/mod.rs

Lines changed: 5 additions & 7 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::middle::region;
1414
use rustc::mir::*;
15-
use rustc::ty::layout::VariantIdx;
1615
use rustc::ty::{self, CanonicalUserTypeAnnotation, Ty};
1716
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1817
use rustc_hir::HirId;
@@ -250,7 +249,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
250249
arm.guard.as_ref().map(|g| (g, match_scope)),
251250
&fake_borrow_temps,
252251
scrutinee_span,
253-
Some(arm.scope),
252+
// Some(arm.scope),
254253
);
255254

256255
if let Some(source_scope) = scope {
@@ -1564,7 +1563,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
15641563
guard: Option<(&Guard<'tcx>, region::Scope)>,
15651564
fake_borrows: &Vec<(Place<'tcx>, Local)>,
15661565
scrutinee_span: Span,
1567-
schedule_drops: bool,
1566+
//region_scope: region::Scope,
15681567
) -> BasicBlock {
15691568
debug!("bind_and_guard_matched_candidate(candidate={:?})", candidate);
15701569

@@ -1717,11 +1716,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
17171716
unreachable
17181717
});
17191718
let outside_scope = self.cfg.start_new_block();
1720-
self.exit_scope(
1721-
source_info.span,
1722-
region_scope,
1719+
self.exit_top_scope(
17231720
otherwise_post_guard_block,
1724-
outside_scope,
1721+
candidate.otherwise_block.unwrap(),
1722+
source_info,
17251723
);
17261724
self.false_edges(
17271725
outside_scope,

src/librustc_mir_build/build/matches/test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
426426
let bool_ty = self.hir.bool_ty();
427427
let eq_result = self.temp(bool_ty, source_info.span);
428428
let eq_block = self.cfg.start_new_block();
429-
let cleanup = self.diverge_cleanup();
429+
self.diverge_from(block);
430430
self.cfg.terminate(
431431
block,
432432
source_info,
@@ -443,8 +443,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
443443
literal: method,
444444
}),
445445
args: vec![val, expect],
446-
destination: Some((eq_result, eq_block)),
447-
cleanup: Some(cleanup),
446+
destination: Some((eq_result.clone(), eq_block)),
447+
cleanup: None,
448448
from_hir_call: false,
449449
},
450450
);

src/librustc_mir_build/build/mod.rs

Lines changed: 27 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,6 @@ struct Builder<'a, 'tcx> {
317317

318318
var_debug_info: Vec<VarDebugInfo<'tcx>>,
319319

320-
/// Cached block with the `RESUME` terminator; this is created
321-
/// when first set of cleanups are built.
322-
cached_resume_block: Option<BasicBlock>,
323-
/// Cached block with the `RETURN` terminator.
324-
cached_return_block: Option<BasicBlock>,
325320
/// Cached block with the `UNREACHABLE` terminator.
326321
cached_unreachable_block: Option<BasicBlock>,
327322
}
@@ -583,50 +578,34 @@ where
583578
region::Scope { id: body.value.hir_id.local_id, data: region::ScopeData::CallSite };
584579
let arg_scope =
585580
region::Scope { id: body.value.hir_id.local_id, data: region::ScopeData::Arguments };
586-
let mut block = START_BLOCK;
587581
let source_info = builder.source_info(span);
588582
let call_site_s = (call_site_scope, source_info);
589-
unpack!(
590-
block = builder.in_scope(call_site_s, LintLevel::Inherited, |builder| {
591-
if should_abort_on_panic(tcx, fn_def_id, abi) {
592-
builder.schedule_abort();
593-
}
594-
595-
let arg_scope_s = (arg_scope, source_info);
596-
// `return_block` is called when we evaluate a `return` expression, so
597-
// we just use `START_BLOCK` here.
598-
unpack!(
599-
block = builder.in_breakable_scope(
600-
None,
601-
START_BLOCK,
602-
Place::return_place(),
603-
|builder| {
604-
builder.in_scope(arg_scope_s, LintLevel::Inherited, |builder| {
605-
builder.args_and_body(
606-
block,
607-
fn_def_id,
608-
&arguments,
609-
arg_scope,
610-
&body.value,
611-
)
612-
})
613-
},
614-
)
615-
);
616-
// Attribute epilogue to function's closing brace
617-
let fn_end = span.shrink_to_hi();
618-
let source_info = builder.source_info(fn_end);
619-
let return_block = builder.return_block();
620-
builder.cfg.goto(block, source_info, return_block);
621-
builder.cfg.terminate(return_block, source_info, TerminatorKind::Return);
622-
// Attribute any unreachable codepaths to the function's closing brace
623-
if let Some(unreachable_block) = builder.cached_unreachable_block {
624-
builder.cfg.terminate(unreachable_block, source_info, TerminatorKind::Unreachable);
625-
}
626-
return_block.unit()
627-
})
628-
);
629-
assert_eq!(block, builder.return_block());
583+
unpack!(builder.in_scope(call_site_s, LintLevel::Inherited, |builder| {
584+
let arg_scope_s = (arg_scope, source_info);
585+
// Attribute epilogue to function's closing brace
586+
let fn_end = span.shrink_to_hi();
587+
let return_block =
588+
unpack!(builder.in_breakable_scope(None, Place::return_place(), fn_end, |builder| {
589+
Some(builder.in_scope(arg_scope_s, LintLevel::Inherited, |builder| {
590+
builder.args_and_body(
591+
START_BLOCK,
592+
fn_def_id,
593+
&arguments,
594+
arg_scope,
595+
&body.value,
596+
)
597+
}))
598+
},));
599+
let source_info = builder.source_info(fn_end);
600+
builder.cfg.terminate(return_block, source_info, TerminatorKind::Return);
601+
let should_abort = should_abort_on_panic(tcx, fn_def_id, abi);
602+
builder.build_drop_trees(should_abort);
603+
// Attribute any unreachable codepaths to the function's closing brace
604+
if let Some(unreachable_block) = builder.cached_unreachable_block {
605+
builder.cfg.terminate(unreachable_block, source_info, TerminatorKind::Unreachable);
606+
}
607+
return_block.unit()
608+
}));
630609

631610
let mut spread_arg = None;
632611
if abi == Abi::RustCall {
@@ -659,9 +638,6 @@ fn construct_const<'a, 'tcx>(
659638
let source_info = builder.source_info(span);
660639
builder.cfg.terminate(block, source_info, TerminatorKind::Return);
661640

662-
// Constants can't `return` so a return block should not be created.
663-
assert_eq!(builder.cached_return_block, None);
664-
665641
// Constants may be match expressions in which case an unreachable block may
666642
// be created, so terminate it properly.
667643
if let Some(unreachable_block) = builder.cached_unreachable_block {
@@ -735,7 +711,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
735711
fn_span: span,
736712
arg_count,
737713
generator_kind,
738-
scopes: Default::default(),
714+
scopes: scope::Scopes::new(is_generator),
739715
block_context: BlockContext::new(),
740716
source_scopes: IndexVec::new(),
741717
source_scope: OUTERMOST_SOURCE_SCOPE,
@@ -751,8 +727,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
751727
var_indices: Default::default(),
752728
unit_temp: None,
753729
var_debug_info: vec![],
754-
cached_resume_block: None,
755-
cached_return_block: None,
756730
cached_unreachable_block: None,
757731
};
758732

@@ -997,17 +971,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
997971
}
998972
}
999973
}
1000-
1001-
fn return_block(&mut self) -> BasicBlock {
1002-
match self.cached_return_block {
1003-
Some(rb) => rb,
1004-
None => {
1005-
let rb = self.cfg.start_new_block();
1006-
self.cached_return_block = Some(rb);
1007-
rb
1008-
}
1009-
}
1010-
}
1011974
}
1012975

1013976
///////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)