提交 be9c64b0 编写于 作者: J John Kåre Alsaker

Store generator interior in MIR literals

上级 91dde3eb
......@@ -442,11 +442,15 @@ fn hash_stable<W: StableHasherResult>(&self,
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 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 @@ fn fmt_tuple(fmt: &mut Formatter, lvs: &[Operand]) -> fmt::Result {
}
}),
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 @@ fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F)
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 @@ fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
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 @@ pub fn ty<'a, 'gcx, D>(&self, local_decls: &D, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> T
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 @@ fn visit_closure_substs(&mut self,
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 @@ fn super_rvalue(&mut self,
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 @@ fn super_ty(&mut self, _ty: & $($mutability)* Ty<'tcx>) {
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 @@ fn expr_as_rvalue(&mut self,
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 @@ fn expr_as_rvalue(&mut self,
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::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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册