Box generator-related Body fields
This commit is contained in:
@@ -222,7 +222,7 @@ impl Validator<'mir, 'tcx> {
|
||||
|
||||
// `async` functions cannot be `const fn`. This is checked during AST lowering, so there's
|
||||
// no need to emit duplicate errors here.
|
||||
if is_async_fn(self.ccx) || body.generator_kind.is_some() {
|
||||
if is_async_fn(self.ccx) || body.generator.is_some() {
|
||||
tcx.sess.delay_span_bug(body.span, "`async` functions cannot be `const fn`");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
|
||||
body.arg_count,
|
||||
Default::default(),
|
||||
body.span,
|
||||
body.generator_kind,
|
||||
body.generator_kind(),
|
||||
);
|
||||
|
||||
// FIXME(oli-obk, eddyb) Optimize locals (or even local paths) to hold
|
||||
|
||||
@@ -1111,7 +1111,7 @@ fn create_generator_resume_function<'tcx>(
|
||||
cases.insert(0, (UNRESUMED, BasicBlock::new(0)));
|
||||
|
||||
// Panic when resumed on the returned or poisoned state
|
||||
let generator_kind = body.generator_kind.unwrap();
|
||||
let generator_kind = body.generator_kind().unwrap();
|
||||
|
||||
if can_unwind {
|
||||
cases.insert(
|
||||
@@ -1236,14 +1236,14 @@ fn create_cases<'tcx>(
|
||||
|
||||
impl<'tcx> MirPass<'tcx> for StateTransform {
|
||||
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||
let yield_ty = if let Some(yield_ty) = body.yield_ty {
|
||||
let yield_ty = if let Some(yield_ty) = body.yield_ty() {
|
||||
yield_ty
|
||||
} else {
|
||||
// This only applies to generators
|
||||
return;
|
||||
};
|
||||
|
||||
assert!(body.generator_drop.is_none());
|
||||
assert!(body.generator_drop().is_none());
|
||||
|
||||
// The first argument is the generator type passed by value
|
||||
let gen_ty = body.local_decls.raw[1].ty;
|
||||
@@ -1340,10 +1340,11 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
|
||||
transform.visit_body(body);
|
||||
|
||||
// Update our MIR struct to reflect the changes we've made
|
||||
body.yield_ty = None;
|
||||
body.arg_count = 2; // self, resume arg
|
||||
body.spread_arg = None;
|
||||
body.generator_layout = Some(layout);
|
||||
|
||||
body.generator.as_mut().unwrap().yield_ty = None;
|
||||
body.generator.as_mut().unwrap().generator_layout = Some(layout);
|
||||
|
||||
// Insert `drop(generator_struct)` which is used to drop upvars for generators in
|
||||
// the unresumed state.
|
||||
@@ -1362,7 +1363,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
|
||||
// Create a copy of our MIR and use it to create the drop shim for the generator
|
||||
let drop_shim = create_generator_drop_shim(tcx, &transform, gen_ty, body, drop_clean);
|
||||
|
||||
body.generator_drop = Some(box drop_shim);
|
||||
body.generator.as_mut().unwrap().generator_drop = Some(drop_shim);
|
||||
|
||||
// Create the Generator::resume function
|
||||
create_generator_resume_function(tcx, transform, body, can_return);
|
||||
|
||||
@@ -214,7 +214,7 @@ impl Inliner<'tcx> {
|
||||
// since their `optimized_mir` is used for layout computation, which can
|
||||
// create a cycle, even when no attempt is made to inline the function
|
||||
// in the other direction.
|
||||
if caller_body.generator_kind.is_some() {
|
||||
if caller_body.generator.is_some() {
|
||||
return Err("local generator (query cycle avoidance)");
|
||||
}
|
||||
|
||||
|
||||
@@ -1177,7 +1177,7 @@ pub fn promote_candidates<'tcx>(
|
||||
0,
|
||||
vec![],
|
||||
body.span,
|
||||
body.generator_kind,
|
||||
body.generator_kind(),
|
||||
);
|
||||
|
||||
let promoter = Promoter {
|
||||
|
||||
Reference in New Issue
Block a user