1
Fork 0

Box generator-related Body fields

This commit is contained in:
Dániel Buga 2021-01-17 13:27:05 +01:00
parent 3b150b7a8f
commit b97eb23cd0
14 changed files with 89 additions and 54 deletions

View file

@ -103,11 +103,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}
}
assert!(
body.yield_ty.is_some() && universal_regions.yield_ty.is_some()
|| body.yield_ty.is_none() && universal_regions.yield_ty.is_none()
);
if let Some(mir_yield_ty) = body.yield_ty {
assert!(body.yield_ty().is_some() == universal_regions.yield_ty.is_some());
if let Some(mir_yield_ty) = body.yield_ty() {
let ur_yield_ty = universal_regions.yield_ty.unwrap();
let yield_span = body.local_decls[RETURN_PLACE].source_info.span;
self.equate_normalized_input_or_output(ur_yield_ty, mir_yield_ty, yield_span);

View file

@ -1651,7 +1651,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}
TerminatorKind::Yield { ref value, .. } => {
let value_ty = value.ty(body, tcx);
match body.yield_ty {
match body.yield_ty() {
None => span_mirbug!(self, term, "yield in non-generator"),
Some(ty) => {
if let Err(terr) = self.sub_types(

View file

@ -134,7 +134,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option<Ty<'tcx>>)
// Check if this is a generator, if so, return the drop glue for it
if let Some(&ty::Generator(gen_def_id, substs, _)) = ty.map(|ty| ty.kind()) {
let body = &**tcx.optimized_mir(gen_def_id).generator_drop.as_ref().unwrap();
let body = tcx.optimized_mir(gen_def_id).generator_drop().unwrap();
return body.clone().subst(tcx, substs);
}

View file

@ -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;
}

View file

@ -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

View file

@ -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);

View file

@ -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)");
}

View file

@ -1177,7 +1177,7 @@ pub fn promote_candidates<'tcx>(
0,
vec![],
body.span,
body.generator_kind,
body.generator_kind(),
);
let promoter = Promoter {

View file

@ -131,7 +131,7 @@ fn dump_matched_mir_node<'tcx, F>(
Some(promoted) => write!(file, "::{:?}`", promoted)?,
}
writeln!(file, " {} {}", disambiguator, pass_name)?;
if let Some(ref layout) = body.generator_layout {
if let Some(ref layout) = body.generator_layout() {
writeln!(file, "/* generator_layout = {:#?} */", layout)?;
}
writeln!(file)?;
@ -956,7 +956,7 @@ fn write_mir_sig(tcx: TyCtxt<'_>, body: &Body<'_>, w: &mut dyn Write) -> io::Res
write!(w, ": {} =", body.return_ty())?;
}
if let Some(yield_ty) = body.yield_ty {
if let Some(yield_ty) = body.yield_ty() {
writeln!(w)?;
writeln!(w, "yields {}", yield_ty)?;
}