Fix merge conflicts with gen
branch
This commit is contained in:
parent
22ebcaca16
commit
b6b9690a76
@ -1367,7 +1367,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
pub fn generator_sig(&self, def_id: DefId) -> Option<ty::PolyGenSig<'tcx>> {
|
||||
if let Some(tables) = self.in_progress_tables {
|
||||
if let Some(id) = self.tcx.hir.as_local_node_id(def_id) {
|
||||
if let Some(&ty) = tables.borrow().generator_sigs.get(&id) {
|
||||
let hir_id = self.tcx.hir.node_to_hir_id(id);
|
||||
if let Some(&ty) = tables.borrow().generator_sigs().get(hir_id) {
|
||||
return ty.map(|t| ty::Binder(t));
|
||||
}
|
||||
}
|
||||
|
@ -728,7 +728,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
||||
let kind = match self.tables.closure_kinds().get(fn_hir_id) {
|
||||
Some(&(kind, _)) => kind,
|
||||
None => {
|
||||
let ty = self.node_ty(fn_node_id)?;
|
||||
let ty = self.node_ty(fn_hir_id)?;
|
||||
match ty.sty {
|
||||
ty::TyGenerator(..) => ty::ClosureKind::FnOnce,
|
||||
_ => span_bug!(span, "missing closure kind"),
|
||||
|
@ -296,7 +296,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
|
||||
hir::ImplItemKind::Type(_) => {}
|
||||
}
|
||||
}
|
||||
hir_map::NodeExpr(&hir::Expr { node: hir::ExprClosure(.., body, _), .. }) => {
|
||||
hir_map::NodeExpr(&hir::Expr { node: hir::ExprClosure(.., body, _, _), .. }) => {
|
||||
self.visit_nested_body(body);
|
||||
}
|
||||
// Nothing to recurse on for these
|
||||
|
@ -340,9 +340,9 @@ pub struct TypeckTables<'tcx> {
|
||||
/// that caused the closure to be this kind.
|
||||
closure_kinds: ItemLocalMap<(ty::ClosureKind, Option<(Span, ast::Name)>)>,
|
||||
|
||||
pub generator_sigs: ItemLocalMap<Option<ty::GenSig<'tcx>>>,
|
||||
generator_sigs: ItemLocalMap<Option<ty::GenSig<'tcx>>>,
|
||||
|
||||
pub generator_interiors: ItemLocalMap<ty::GeneratorInterior<'tcx>>,
|
||||
generator_interiors: ItemLocalMap<ty::GeneratorInterior<'tcx>>,
|
||||
|
||||
/// For each fn, records the "liberated" types of its arguments
|
||||
/// and return type. Liberated means that all bound regions
|
||||
@ -640,6 +640,42 @@ impl<'tcx> TypeckTables<'tcx> {
|
||||
data: &mut self.cast_kinds
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generator_sigs(&self)
|
||||
-> LocalTableInContext<Option<ty::GenSig<'tcx>>>
|
||||
{
|
||||
LocalTableInContext {
|
||||
local_id_root: self.local_id_root,
|
||||
data: &self.generator_sigs,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generator_sigs_mut(&mut self)
|
||||
-> LocalTableInContextMut<Option<ty::GenSig<'tcx>>>
|
||||
{
|
||||
LocalTableInContextMut {
|
||||
local_id_root: self.local_id_root,
|
||||
data: &mut self.generator_sigs,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generator_interiors(&self)
|
||||
-> LocalTableInContext<ty::GeneratorInterior<'tcx>>
|
||||
{
|
||||
LocalTableInContext {
|
||||
local_id_root: self.local_id_root,
|
||||
data: &self.generator_interiors,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generator_interiors_mut(&mut self)
|
||||
-> LocalTableInContextMut<ty::GeneratorInterior<'tcx>>
|
||||
{
|
||||
LocalTableInContextMut {
|
||||
local_id_root: self.local_id_root,
|
||||
data: &mut self.generator_interiors,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for TypeckTables<'gcx> {
|
||||
@ -664,6 +700,8 @@ impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for Typeck
|
||||
ref used_trait_imports,
|
||||
tainted_by_errors,
|
||||
ref free_region_map,
|
||||
ref generator_sigs,
|
||||
ref generator_interiors,
|
||||
} = *self;
|
||||
|
||||
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
|
||||
@ -697,6 +735,8 @@ impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for Typeck
|
||||
ich::hash_stable_itemlocalmap(hcx, hasher, liberated_fn_sigs);
|
||||
ich::hash_stable_itemlocalmap(hcx, hasher, fru_field_types);
|
||||
ich::hash_stable_itemlocalmap(hcx, hasher, cast_kinds);
|
||||
ich::hash_stable_itemlocalmap(hcx, hasher, generator_sigs);
|
||||
ich::hash_stable_itemlocalmap(hcx, hasher, generator_interiors);
|
||||
|
||||
ich::hash_stable_hashset(hcx, hasher, used_trait_imports, |hcx, def_id| {
|
||||
hcx.def_path_hash(*def_id)
|
||||
|
@ -103,7 +103,7 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t
|
||||
Some((closure_self_ty(tcx, id, body_id), None))
|
||||
}
|
||||
ty::TyGenerator(..) => {
|
||||
let gen_ty = tcx.body_tables(body_id).node_id_to_type(id);
|
||||
let gen_ty = tcx.body_tables(body_id).node_id_to_type(fn_hir_id);
|
||||
Some((gen_ty, None))
|
||||
}
|
||||
_ => None,
|
||||
@ -121,7 +121,7 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t
|
||||
let arguments = implicit_argument.into_iter().chain(explicit_arguments);
|
||||
|
||||
let (yield_ty, return_ty) = if body.is_generator {
|
||||
let gen_sig = cx.tables().generator_sigs[&id].clone().unwrap();
|
||||
let gen_sig = cx.tables().generator_sigs()[fn_hir_id].clone().unwrap();
|
||||
(Some(gen_sig.yield_ty), gen_sig.return_ty)
|
||||
} else {
|
||||
(None, fn_sig.output())
|
||||
|
@ -636,9 +636,10 @@ impl MirPass for StateTransform {
|
||||
|
||||
let node_id = source.item_id();
|
||||
let def_id = tcx.hir.local_def_id(source.item_id());
|
||||
let hir_id = tcx.hir.node_to_hir_id(node_id);
|
||||
|
||||
// Get the interior types which typeck computed
|
||||
let interior = *tcx.typeck_tables_of(def_id).generator_interiors.get(&node_id).unwrap();
|
||||
let interior = *tcx.typeck_tables_of(def_id).generator_interiors().get(hir_id).unwrap();
|
||||
|
||||
// The first argument is the generator type passed by value
|
||||
let gen_ty = mir.local_decls.raw[1].ty;
|
||||
|
@ -750,7 +750,8 @@ fn generator_sig<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
def_id: DefId)
|
||||
-> Option<ty::PolyGenSig<'tcx>> {
|
||||
let node_id = tcx.hir.as_local_node_id(def_id).unwrap();
|
||||
tcx.typeck_tables_of(def_id).generator_sigs[&node_id].map(|s| ty::Binder(s))
|
||||
let hir_id = tcx.hir.node_to_hir_id(node_id);
|
||||
tcx.typeck_tables_of(def_id).generator_sigs()[hir_id].map(|s| ty::Binder(s))
|
||||
}
|
||||
|
||||
fn closure_kind<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
@ -1050,25 +1051,26 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
|
||||
fcx.write_ty(arg.hir_id, arg_ty);
|
||||
}
|
||||
|
||||
let fn_hir_id = fcx.tcx.hir.node_to_hir_id(fn_id);
|
||||
let gen_ty = if can_be_generator && body.is_generator {
|
||||
let gen_sig = ty::GenSig {
|
||||
yield_ty: fcx.yield_ty.unwrap(),
|
||||
return_ty: ret_ty,
|
||||
};
|
||||
inherited.tables.borrow_mut().generator_sigs.insert(fn_hir_id, Some(gen_sig));
|
||||
inherited.tables.borrow_mut().generator_sigs_mut().insert(fn_hir_id, Some(gen_sig));
|
||||
|
||||
let witness = fcx.next_ty_var(TypeVariableOrigin::MiscVariable(span));
|
||||
fcx.deferred_generator_interiors.borrow_mut().push((body.id(), witness));
|
||||
let interior = ty::GeneratorInterior::new(witness);
|
||||
|
||||
inherited.tables.borrow_mut().generator_interiors.insert(fn_hir_id, interior);
|
||||
inherited.tables.borrow_mut().generator_interiors_mut().insert(fn_hir_id, interior);
|
||||
|
||||
Some(interior)
|
||||
} else {
|
||||
inherited.tables.borrow_mut().generator_sigs.insert(fn_hir_id, None);
|
||||
inherited.tables.borrow_mut().generator_sigs_mut().insert(fn_hir_id, None);
|
||||
None
|
||||
};
|
||||
inherited.tables.borrow_mut().liberated_fn_sigs.insert(fn_hir_id, fn_sig);
|
||||
inherited.tables.borrow_mut().liberated_fn_sigs_mut().insert(fn_hir_id, fn_sig);
|
||||
|
||||
fcx.check_return_expr(&body.value);
|
||||
|
||||
|
@ -361,19 +361,29 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
|
||||
}
|
||||
|
||||
fn visit_generator_interiors(&mut self) {
|
||||
for (&node_id, interior) in self.fcx.tables.borrow().generator_interiors.iter() {
|
||||
let interior = self.resolve(interior, &node_id);
|
||||
self.tables.generator_interiors.insert(node_id, interior);
|
||||
let common_local_id_root = self.fcx.tables.borrow().local_id_root.unwrap();
|
||||
for (&id, interior) in self.fcx.tables.borrow().generator_interiors().iter() {
|
||||
let hir_id = hir::HirId {
|
||||
owner: common_local_id_root.index,
|
||||
local_id: id,
|
||||
};
|
||||
let interior = self.resolve(interior, &hir_id);
|
||||
self.tables.generator_interiors_mut().insert(hir_id, interior);
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_generator_sigs(&mut self) {
|
||||
for (&node_id, gen_sig) in self.fcx.tables.borrow().generator_sigs.iter() {
|
||||
let common_local_id_root = self.fcx.tables.borrow().local_id_root.unwrap();
|
||||
for (&id, gen_sig) in self.fcx.tables.borrow().generator_sigs().iter() {
|
||||
let hir_id = hir::HirId {
|
||||
owner: common_local_id_root.index,
|
||||
local_id: id,
|
||||
};
|
||||
let gen_sig = gen_sig.map(|s| ty::GenSig {
|
||||
yield_ty: self.resolve(&s.yield_ty, &node_id),
|
||||
return_ty: self.resolve(&s.return_ty, &node_id),
|
||||
yield_ty: self.resolve(&s.yield_ty, &hir_id),
|
||||
return_ty: self.resolve(&s.return_ty, &hir_id),
|
||||
});
|
||||
self.tables.generator_sigs.insert(node_id, gen_sig);
|
||||
self.tables.generator_sigs_mut().insert(hir_id, gen_sig);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1155,7 +1155,8 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
|
||||
NodeExpr(&hir::Expr { node: hir::ExprClosure(.., is_generator), .. }) => {
|
||||
if is_generator {
|
||||
return tcx.typeck_tables_of(def_id).node_id_to_type(node_id);
|
||||
let hir_id = tcx.hir.node_to_hir_id(node_id);
|
||||
return tcx.typeck_tables_of(def_id).node_id_to_type(hir_id);
|
||||
}
|
||||
|
||||
tcx.mk_closure(def_id, Substs::for_item(
|
||||
|
Loading…
x
Reference in New Issue
Block a user