1
Fork 0

Merge hir::GeneratorMovability into ast::Movability.

This commit is contained in:
Camille GILLOT 2019-11-09 18:06:57 +01:00
parent f03cbc313d
commit 5b30da10b6
17 changed files with 32 additions and 42 deletions

View file

@ -494,7 +494,7 @@ impl LoweringContext<'_> {
decl, decl,
body_id, body_id,
span, span,
Some(hir::GeneratorMovability::Static) Some(hir::Movability::Static)
); );
let generator = hir::Expr { let generator = hir::Expr {
hir_id: self.lower_node_id(closure_node_id), hir_id: self.lower_node_id(closure_node_id),
@ -725,7 +725,7 @@ impl LoweringContext<'_> {
fn_decl_span: Span, fn_decl_span: Span,
generator_kind: Option<hir::GeneratorKind>, generator_kind: Option<hir::GeneratorKind>,
movability: Movability, movability: Movability,
) -> Option<hir::GeneratorMovability> { ) -> Option<hir::Movability> {
match generator_kind { match generator_kind {
Some(hir::GeneratorKind::Gen) => { Some(hir::GeneratorKind::Gen) => {
if !decl.inputs.is_empty() { if !decl.inputs.is_empty() {
@ -736,10 +736,7 @@ impl LoweringContext<'_> {
"generators cannot have explicit parameters" "generators cannot have explicit parameters"
); );
} }
Some(match movability { Some(movability)
Movability::Movable => hir::GeneratorMovability::Movable,
Movability::Static => hir::GeneratorMovability::Static,
})
}, },
Some(hir::GeneratorKind::Async(_)) => { Some(hir::GeneratorKind::Async(_)) => {
bug!("non-`async` closure body turned `async` during lowering"); bug!("non-`async` closure body turned `async` during lowering");

View file

@ -22,7 +22,7 @@ use syntax_pos::{Span, DUMMY_SP, MultiSpan};
use syntax::source_map::Spanned; use syntax::source_map::Spanned;
use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, AsmDialect}; use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, AsmDialect};
use syntax::ast::{Attribute, Label, LitKind, StrStyle, FloatTy, IntTy, UintTy}; use syntax::ast::{Attribute, Label, LitKind, StrStyle, FloatTy, IntTy, UintTy};
pub use syntax::ast::{Mutability, Constness, Unsafety}; pub use syntax::ast::{Mutability, Constness, Unsafety, Movability};
use syntax::attr::{InlineAttr, OptimizeAttr}; use syntax::attr::{InlineAttr, OptimizeAttr};
use syntax::symbol::{Symbol, kw}; use syntax::symbol::{Symbol, kw};
use syntax::tokenstream::TokenStream; use syntax::tokenstream::TokenStream;
@ -1628,8 +1628,8 @@ pub enum ExprKind {
/// The `Span` is the argument block `|...|`. /// The `Span` is the argument block `|...|`.
/// ///
/// This may also be a generator literal or an `async block` as indicated by the /// This may also be a generator literal or an `async block` as indicated by the
/// `Option<GeneratorMovability>`. /// `Option<Movability>`.
Closure(CaptureClause, P<FnDecl>, BodyId, Span, Option<GeneratorMovability>), Closure(CaptureClause, P<FnDecl>, BodyId, Span, Option<Movability>),
/// A block (e.g., `'label: { ... }`). /// A block (e.g., `'label: { ... }`).
Block(P<Block>, Option<Label>), Block(P<Block>, Option<Label>),
@ -1802,17 +1802,6 @@ pub struct Destination {
pub target_id: Result<HirId, LoopIdError>, pub target_id: Result<HirId, LoopIdError>,
} }
/// Whether a generator contains self-references, causing it to be `!Unpin`.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, HashStable,
RustcEncodable, RustcDecodable, Hash, Debug)]
pub enum GeneratorMovability {
/// May contain self-references, `!Unpin`.
Static,
/// Must not contain self-references, `Unpin`.
Movable,
}
/// The yield kind that caused an `ExprKind::Yield`. /// The yield kind that caused an `ExprKind::Yield`.
#[derive(Copy, Clone, PartialEq, Eq, Debug, RustcEncodable, RustcDecodable, HashStable)] #[derive(Copy, Clone, PartialEq, Eq, Debug, RustcEncodable, RustcDecodable, HashStable)]
pub enum YieldSource { pub enum YieldSource {

View file

@ -168,6 +168,7 @@ impl_stable_hash_for!(enum ::syntax::ast::Defaultness { Default, Final });
impl_stable_hash_for!(struct ::syntax::ast::Lifetime { id, ident }); impl_stable_hash_for!(struct ::syntax::ast::Lifetime { id, ident });
impl_stable_hash_for!(enum ::syntax::ast::StrStyle { Cooked, Raw(pounds) }); impl_stable_hash_for!(enum ::syntax::ast::StrStyle { Cooked, Raw(pounds) });
impl_stable_hash_for!(enum ::syntax::ast::AttrStyle { Outer, Inner }); impl_stable_hash_for!(enum ::syntax::ast::AttrStyle { Outer, Inner });
impl_stable_hash_for!(enum ::syntax::ast::Movability { Static, Movable });
impl<'a> HashStable<StableHashingContext<'a>> for [ast::Attribute] { impl<'a> HashStable<StableHashingContext<'a>> for [ast::Attribute] {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {

View file

@ -2161,7 +2161,7 @@ pub enum AggregateKind<'tcx> {
Adt(&'tcx AdtDef, VariantIdx, SubstsRef<'tcx>, Option<UserTypeAnnotationIndex>, Option<usize>), Adt(&'tcx AdtDef, VariantIdx, SubstsRef<'tcx>, Option<UserTypeAnnotationIndex>, Option<usize>),
Closure(DefId, SubstsRef<'tcx>), Closure(DefId, SubstsRef<'tcx>),
Generator(DefId, SubstsRef<'tcx>, hir::GeneratorMovability), Generator(DefId, SubstsRef<'tcx>, hir::Movability),
} }
#[derive(Copy, Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)] #[derive(Copy, Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)]

View file

@ -2195,11 +2195,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
if self.tcx().lang_items().unpin_trait() == Some(def_id) => if self.tcx().lang_items().unpin_trait() == Some(def_id) =>
{ {
match movability { match movability {
hir::GeneratorMovability::Static => { hir::Movability::Static => {
// Immovable generators are never `Unpin`, so // Immovable generators are never `Unpin`, so
// suppress the normal auto-impl candidate for it. // suppress the normal auto-impl candidate for it.
} }
hir::GeneratorMovability::Movable => { hir::Movability::Movable => {
// Movable generators are always `Unpin`, so add an // Movable generators are always `Unpin`, so add an
// unconditional builtin candidate. // unconditional builtin candidate.
candidates.vec.push(BuiltinCandidate { candidates.vec.push(BuiltinCandidate {

View file

@ -2516,7 +2516,7 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn mk_generator(self, pub fn mk_generator(self,
id: DefId, id: DefId,
generator_substs: SubstsRef<'tcx>, generator_substs: SubstsRef<'tcx>,
movability: hir::GeneratorMovability) movability: hir::Movability)
-> Ty<'tcx> { -> Ty<'tcx> {
self.mk_ty(Generator(id, generator_substs, movability)) self.mk_ty(Generator(id, generator_substs, movability))
} }

View file

@ -607,10 +607,9 @@ pub trait PrettyPrinter<'tcx>:
ty::Generator(did, substs, movability) => { ty::Generator(did, substs, movability) => {
let upvar_tys = substs.as_generator().upvar_tys(did, self.tcx()); let upvar_tys = substs.as_generator().upvar_tys(did, self.tcx());
let witness = substs.as_generator().witness(did, self.tcx()); let witness = substs.as_generator().witness(did, self.tcx());
if movability == hir::GeneratorMovability::Movable { match movability {
p!(write("[generator")); hir::Movability::Movable => p!(write("[generator")),
} else { hir::Movability::Static => p!(write("[static generator")),
p!(write("[static generator"));
} }
// FIXME(eddyb) should use `def_span`. // FIXME(eddyb) should use `def_span`.

View file

@ -162,7 +162,7 @@ pub enum TyKind<'tcx> {
/// The anonymous type of a generator. Used to represent the type of /// The anonymous type of a generator. Used to represent the type of
/// `|a| yield a`. /// `|a| yield a`.
Generator(DefId, SubstsRef<'tcx>, hir::GeneratorMovability), Generator(DefId, SubstsRef<'tcx>, hir::Movability),
/// A type representin the types stored inside a generator. /// A type representin the types stored inside a generator.
/// This should only appear in GeneratorInteriors. /// This should only appear in GeneratorInteriors.

View file

@ -235,7 +235,7 @@ fn do_mir_borrowck<'a, 'tcx>(
let movable_generator = match tcx.hir().get(id) { let movable_generator = match tcx.hir().get(id) {
Node::Expr(&hir::Expr { Node::Expr(&hir::Expr {
kind: hir::ExprKind::Closure(.., Some(hir::GeneratorMovability::Static)), kind: hir::ExprKind::Closure(.., Some(hir::Movability::Static)),
.. ..
}) => false, }) => false,
_ => true, _ => true,

View file

@ -90,7 +90,7 @@ pub enum DefiningTy<'tcx> {
/// The MIR is a generator. The signature is that generators take /// The MIR is a generator. The signature is that generators take
/// no parameters and return the result of /// no parameters and return the result of
/// `ClosureSubsts::generator_return_ty`. /// `ClosureSubsts::generator_return_ty`.
Generator(DefId, SubstsRef<'tcx>, hir::GeneratorMovability), Generator(DefId, SubstsRef<'tcx>, hir::Movability),
/// The MIR is a fn item with the given `DefId` and substs. The signature /// The MIR is a fn item with the given `DefId` and substs. The signature
/// of the function can be bound then with the `fn_sig` query. /// of the function can be bound then with the `fn_sig` query.

View file

@ -257,7 +257,7 @@ pub enum ExprKind<'tcx> {
closure_id: DefId, closure_id: DefId,
substs: UpvarSubsts<'tcx>, substs: UpvarSubsts<'tcx>,
upvars: Vec<ExprRef<'tcx>>, upvars: Vec<ExprRef<'tcx>>,
movability: Option<hir::GeneratorMovability>, movability: Option<hir::Movability>,
}, },
Literal { Literal {
literal: &'tcx Const<'tcx>, literal: &'tcx Const<'tcx>,

View file

@ -1192,7 +1192,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
(substs.upvar_tys(def_id, tcx).collect(), (substs.upvar_tys(def_id, tcx).collect(),
substs.witness(def_id, tcx), substs.witness(def_id, tcx),
substs.discr_ty(tcx), substs.discr_ty(tcx),
movability == hir::GeneratorMovability::Movable) movability == hir::Movability::Movable)
} }
_ => bug!(), _ => bug!(),
}; };

View file

@ -7,7 +7,7 @@ use rustc::ty::TyCtxt;
use rustc::hir::def_id::DefId; use rustc::hir::def_id::DefId;
use rustc::hir::map::Map; use rustc::hir::map::Map;
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap}; use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
use rustc::hir::{self, Node, Destination, GeneratorMovability}; use rustc::hir::{self, Node, Destination, Movability};
use syntax::struct_span_err; use syntax::struct_span_err;
use syntax_pos::Span; use syntax_pos::Span;
use errors::Applicability; use errors::Applicability;
@ -59,7 +59,7 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
self.with_context(Loop(source), |v| v.visit_block(&b)); self.with_context(Loop(source), |v| v.visit_block(&b));
} }
hir::ExprKind::Closure(_, ref function_decl, b, span, movability) => { hir::ExprKind::Closure(_, ref function_decl, b, span, movability) => {
let cx = if let Some(GeneratorMovability::Static) = movability { let cx = if let Some(Movability::Static) = movability {
AsyncClosure(span) AsyncClosure(span)
} else { } else {
Closure(span) Closure(span)

View file

@ -76,6 +76,6 @@ crate fn generator(tcx: TyCtxt<'tcx>, def_id: DefId) -> Ty<'tcx> {
tcx.mk_generator( tcx.mk_generator(
def_id, def_id,
InternalSubsts::bound_vars_for_item(tcx, def_id), InternalSubsts::bound_vars_for_item(tcx, def_id),
hir::GeneratorMovability::Movable hir::Movability::Movable
) )
} }

View file

@ -39,7 +39,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
_capture: hir::CaptureClause, _capture: hir::CaptureClause,
decl: &'tcx hir::FnDecl, decl: &'tcx hir::FnDecl,
body_id: hir::BodyId, body_id: hir::BodyId,
gen: Option<hir::GeneratorMovability>, gen: Option<hir::Movability>,
expected: Expectation<'tcx>, expected: Expectation<'tcx>,
) -> Ty<'tcx> { ) -> Ty<'tcx> {
debug!( debug!(
@ -64,7 +64,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
opt_kind: Option<ty::ClosureKind>, opt_kind: Option<ty::ClosureKind>,
decl: &'tcx hir::FnDecl, decl: &'tcx hir::FnDecl,
body: &'tcx hir::Body, body: &'tcx hir::Body,
gen: Option<hir::GeneratorMovability>, gen: Option<hir::Movability>,
expected_sig: Option<ExpectedSig<'tcx>>, expected_sig: Option<ExpectedSig<'tcx>>,
) -> Ty<'tcx> { ) -> Ty<'tcx> {
debug!( debug!(

View file

@ -1090,7 +1090,7 @@ struct GeneratorTypes<'tcx> {
interior: Ty<'tcx>, interior: Ty<'tcx>,
/// Indicates if the generator is movable or static (immovable). /// Indicates if the generator is movable or static (immovable).
movability: hir::GeneratorMovability, movability: hir::Movability,
} }
/// Helper used for fns and closures. Does the grungy work of checking a function /// Helper used for fns and closures. Does the grungy work of checking a function
@ -1106,7 +1106,7 @@ fn check_fn<'a, 'tcx>(
decl: &'tcx hir::FnDecl, decl: &'tcx hir::FnDecl,
fn_id: hir::HirId, fn_id: hir::HirId,
body: &'tcx hir::Body, body: &'tcx hir::Body,
can_be_generator: Option<hir::GeneratorMovability>, can_be_generator: Option<hir::Movability>,
) -> (FnCtxt<'a, 'tcx>, Option<GeneratorTypes<'tcx>>) { ) -> (FnCtxt<'a, 'tcx>, Option<GeneratorTypes<'tcx>>) {
let mut fn_sig = fn_sig.clone(); let mut fn_sig = fn_sig.clone();

View file

@ -1339,10 +1339,14 @@ pub enum CaptureBy {
Ref, Ref,
} }
/// The movability of a generator / closure literal. /// The movability of a generator / closure literal:
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)] /// whether a generator contains self-references, causing it to be `!Unpin`.
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash,
RustcEncodable, RustcDecodable, Debug, Copy)]
pub enum Movability { pub enum Movability {
/// May contain self-references, `!Unpin`.
Static, Static,
/// Must not contain self-references, `Unpin`.
Movable, Movable,
} }