Store generator interior in MIR literals
This commit is contained in:
parent
91dde3eb2d
commit
be9c64b0c7
8 changed files with 41 additions and 29 deletions
|
|
@ -442,11 +442,15 @@ for mir::AggregateKind<'tcx> {
|
|||
substs.hash_stable(hcx, hasher);
|
||||
active_field.hash_stable(hcx, hasher);
|
||||
}
|
||||
mir::AggregateKind::Closure(def_id, ref substs) |
|
||||
mir::AggregateKind::Generator(def_id, ref substs) => {
|
||||
mir::AggregateKind::Closure(def_id, ref substs) => {
|
||||
def_id.hash_stable(hcx, hasher);
|
||||
substs.hash_stable(hcx, hasher);
|
||||
}
|
||||
mir::AggregateKind::Generator(def_id, ref substs, ref interior) => {
|
||||
def_id.hash_stable(hcx, hasher);
|
||||
substs.hash_stable(hcx, hasher);
|
||||
interior.hash_stable(hcx, hasher);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ use rustc_data_structures::control_flow_graph::ControlFlowGraph;
|
|||
use hir::def::CtorKind;
|
||||
use hir::def_id::DefId;
|
||||
use ty::subst::{Subst, Substs};
|
||||
use ty::{self, AdtDef, ClosureSubsts, Region, Ty};
|
||||
use ty::{self, AdtDef, ClosureSubsts, Region, Ty, GeneratorInterior};
|
||||
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
|
||||
use util::ppaux;
|
||||
use rustc_back::slice;
|
||||
|
|
@ -1260,7 +1260,7 @@ pub enum AggregateKind<'tcx> {
|
|||
/// number and is present only for union expressions.
|
||||
Adt(&'tcx AdtDef, usize, &'tcx Substs<'tcx>, Option<usize>),
|
||||
Closure(DefId, ClosureSubsts<'tcx>),
|
||||
Generator(DefId, ClosureSubsts<'tcx>),
|
||||
Generator(DefId, ClosureSubsts<'tcx>, GeneratorInterior<'tcx>),
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)]
|
||||
|
|
@ -1423,7 +1423,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
|
|||
}
|
||||
}),
|
||||
|
||||
AggregateKind::Generator(def_id, _) => ty::tls::with(|tcx| {
|
||||
AggregateKind::Generator(def_id, _, _) => ty::tls::with(|tcx| {
|
||||
if let Some(node_id) = tcx.hir.as_local_node_id(def_id) {
|
||||
let name = format!("[generator@{:?}]", tcx.hir.span(node_id));
|
||||
let mut struct_fmt = fmt.debug_struct(&name);
|
||||
|
|
@ -1892,8 +1892,8 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
|
|||
AggregateKind::Adt(def, v, substs.fold_with(folder), n),
|
||||
AggregateKind::Closure(id, substs) =>
|
||||
AggregateKind::Closure(id, substs.fold_with(folder)),
|
||||
AggregateKind::Generator(id, substs) =>
|
||||
AggregateKind::Generator(id, substs.fold_with(folder)),
|
||||
AggregateKind::Generator(id, substs, interior) =>
|
||||
AggregateKind::Generator(id, substs.fold_with(folder), interior.fold_with(folder)),
|
||||
};
|
||||
Aggregate(kind, fields.fold_with(folder))
|
||||
}
|
||||
|
|
@ -1920,7 +1920,8 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
|
|||
AggregateKind::Tuple => false,
|
||||
AggregateKind::Adt(_, _, substs, _) => substs.visit_with(visitor),
|
||||
AggregateKind::Closure(_, substs) => substs.visit_with(visitor),
|
||||
AggregateKind::Generator(_, substs) => substs.visit_with(visitor),
|
||||
AggregateKind::Generator(_, substs, interior) => substs.visit_with(visitor) ||
|
||||
interior.visit_with(visitor),
|
||||
}) || fields.visit_with(visitor)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -202,13 +202,8 @@ impl<'tcx> Rvalue<'tcx> {
|
|||
AggregateKind::Closure(did, substs) => {
|
||||
tcx.mk_closure_from_closure_substs(did, substs)
|
||||
}
|
||||
AggregateKind::Generator(did, substs) => {
|
||||
let node_id = tcx.hir.as_local_node_id(did).unwrap();
|
||||
let interior = *tcx.typeck_tables_of(did)
|
||||
.generator_interiors
|
||||
.get(&node_id)
|
||||
.unwrap();
|
||||
tcx.mk_generator(did, substs, interior.subst(tcx, substs.substs))
|
||||
AggregateKind::Generator(did, substs, interior) => {
|
||||
tcx.mk_generator(did, substs, interior)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
use middle::const_val::ConstVal;
|
||||
use hir::def_id::DefId;
|
||||
use ty::subst::Substs;
|
||||
use ty::{ClosureSubsts, Region, Ty};
|
||||
use ty::{ClosureSubsts, Region, Ty, GeneratorInterior};
|
||||
use mir::*;
|
||||
use rustc_const_math::ConstUsize;
|
||||
use syntax_pos::Span;
|
||||
|
|
@ -226,6 +226,12 @@ macro_rules! make_mir_visitor {
|
|||
self.super_closure_substs(substs);
|
||||
}
|
||||
|
||||
fn visit_generator_interior(&mut self,
|
||||
interior: & $($mutability)* GeneratorInterior<'tcx>,
|
||||
_: Location) {
|
||||
self.super_generator_interior(interior);
|
||||
}
|
||||
|
||||
fn visit_const_val(&mut self,
|
||||
const_val: & $($mutability)* ConstVal,
|
||||
_: Location) {
|
||||
|
|
@ -570,9 +576,11 @@ macro_rules! make_mir_visitor {
|
|||
self.visit_closure_substs(closure_substs, location);
|
||||
}
|
||||
AggregateKind::Generator(ref $($mutability)* def_id,
|
||||
ref $($mutability)* closure_substs) => {
|
||||
ref $($mutability)* closure_substs,
|
||||
ref $($mutability)* interior) => {
|
||||
self.visit_def_id(def_id, location);
|
||||
self.visit_closure_substs(closure_substs, location);
|
||||
self.visit_generator_interior(interior, location);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -742,6 +750,10 @@ macro_rules! make_mir_visitor {
|
|||
fn super_substs(&mut self, _substs: & $($mutability)* &'tcx Substs<'tcx>) {
|
||||
}
|
||||
|
||||
fn super_generator_interior(&mut self,
|
||||
_interior: & $($mutability)* GeneratorInterior<'tcx>) {
|
||||
}
|
||||
|
||||
fn super_closure_substs(&mut self,
|
||||
_substs: & $($mutability)* ClosureSubsts<'tcx>) {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -179,12 +179,12 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
|
||||
block.and(Rvalue::Aggregate(box AggregateKind::Tuple, fields))
|
||||
}
|
||||
ExprKind::Closure { closure_id, substs, upvars, generator } => { // see (*) above
|
||||
ExprKind::Closure { closure_id, substs, upvars, interior } => { // see (*) above
|
||||
let mut operands: Vec<_> =
|
||||
upvars.into_iter()
|
||||
.map(|upvar| unpack!(block = this.as_operand(block, scope, upvar)))
|
||||
.collect();
|
||||
let result = if generator {
|
||||
let result = if let Some(interior) = interior {
|
||||
// Add the state operand
|
||||
operands.push(Operand::Constant(box Constant {
|
||||
span: expr_span,
|
||||
|
|
@ -193,7 +193,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
value: ConstVal::Integral(ConstInt::U32(0)),
|
||||
},
|
||||
}));
|
||||
box AggregateKind::Generator(closure_id, substs)
|
||||
box AggregateKind::Generator(closure_id, substs, interior)
|
||||
} else {
|
||||
box AggregateKind::Closure(closure_id, substs)
|
||||
};
|
||||
|
|
|
|||
|
|
@ -428,11 +428,11 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
|
|||
}
|
||||
}
|
||||
|
||||
hir::ExprClosure(.., is_generator) => {
|
||||
hir::ExprClosure(..) => {
|
||||
let closure_ty = cx.tables().expr_ty(expr);
|
||||
let (def_id, substs) = match closure_ty.sty {
|
||||
ty::TyClosure(def_id, substs) |
|
||||
ty::TyGenerator(def_id, substs, _) => (def_id, substs),
|
||||
let (def_id, substs, interior) = match closure_ty.sty {
|
||||
ty::TyClosure(def_id, substs) => (def_id, substs, None),
|
||||
ty::TyGenerator(def_id, substs, interior) => (def_id, substs, Some(interior)),
|
||||
_ => {
|
||||
span_bug!(expr.span, "closure expr w/o closure type: {:?}", closure_ty);
|
||||
}
|
||||
|
|
@ -447,7 +447,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
|
|||
closure_id: def_id,
|
||||
substs: substs,
|
||||
upvars: upvars,
|
||||
generator: is_generator,
|
||||
interior,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ use rustc::mir::{BinOp, BorrowKind, Field, Literal, UnOp};
|
|||
use rustc::hir::def_id::DefId;
|
||||
use rustc::middle::region::CodeExtent;
|
||||
use rustc::ty::subst::Substs;
|
||||
use rustc::ty::{self, AdtDef, ClosureSubsts, Region, Ty};
|
||||
use rustc::ty::{self, AdtDef, ClosureSubsts, Region, Ty, GeneratorInterior};
|
||||
use rustc::hir;
|
||||
use syntax::ast;
|
||||
use syntax_pos::Span;
|
||||
|
|
@ -239,7 +239,7 @@ pub enum ExprKind<'tcx> {
|
|||
closure_id: DefId,
|
||||
substs: ClosureSubsts<'tcx>,
|
||||
upvars: Vec<ExprRef<'tcx>>,
|
||||
generator: bool,
|
||||
interior: Option<GeneratorInterior<'tcx>>,
|
||||
},
|
||||
Literal {
|
||||
literal: Literal<'tcx>,
|
||||
|
|
|
|||
|
|
@ -76,8 +76,8 @@ struct TransformVisitor<'a, 'tcx: 'a> {
|
|||
// The number of generator states. 0 is unresumed, 1 is poisoned. So this is initialized to 2
|
||||
bb_target_count: u32,
|
||||
|
||||
// Map from a (which block to resume execution at, which block to use to drop the generator) to a
|
||||
// genrator state
|
||||
// Map from a (which block to resume execution at, which block to use to drop the generator)
|
||||
// to a generator state
|
||||
bb_targets: HashMap<(BasicBlock, Option<BasicBlock>), u32>,
|
||||
|
||||
// The original RETURN_POINTER local
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue