X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustc%2Fmir%2Fmod.rs;h=300b0363e2d3b20ee2f03d032643e5358716c826;hb=dbe880e8ecd088ded3ac63fac1d60f813f11ad4e;hp=bcb245d862b6b81d8625293fe0b51d4328f90c2d;hpb=71710608f009066b5a2dd65ea88ec5c0a79422e4;p=rust.git diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index bcb245d862b..300b0363e2d 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -6,7 +6,7 @@ use crate::hir::def::{CtorKind, Namespace}; use crate::hir::def_id::DefId; -use crate::hir; +use crate::hir::{self, GeneratorKind}; use crate::mir::interpret::{GlobalAlloc, PanicInfo, Scalar}; use crate::mir::visit::MirVisitable; use crate::ty::adjustment::PointerCast; @@ -104,10 +104,6 @@ pub struct Body<'tcx> { /// and used for debuginfo. Indexed by a `SourceScope`. pub source_scopes: IndexVec, - /// Crate-local information for each source scope, that can't (and - /// needn't) be tracked across crates. - pub source_scope_local_data: ClearCrossCrate>, - /// The yield type of the function, if it is a generator. pub yield_ty: Option>, @@ -117,6 +113,10 @@ pub struct Body<'tcx> { /// The layout of a generator. Produced by the state transformation. pub generator_layout: Option>, + /// If this is a generator then record the type of source expression that caused this generator + /// to be created. + pub generator_kind: Option, + /// Declarations of locals. /// /// The first local is the return value pointer, followed by `arg_count` @@ -163,13 +163,13 @@ impl<'tcx> Body<'tcx> { pub fn new( basic_blocks: IndexVec>, source_scopes: IndexVec, - source_scope_local_data: ClearCrossCrate>, local_decls: LocalDecls<'tcx>, user_type_annotations: CanonicalUserTypeAnnotations<'tcx>, arg_count: usize, var_debug_info: Vec>, span: Span, control_flow_destroyed: Vec<(Span, String)>, + generator_kind : Option, ) -> Self { // We need `arg_count` locals, and one for the return place. assert!( @@ -183,10 +183,10 @@ pub fn new( phase: MirPhase::Build, basic_blocks, source_scopes, - source_scope_local_data, yield_ty: None, generator_drop: None, generator_layout: None, + generator_kind, local_decls, user_type_annotations, arg_count, @@ -429,6 +429,13 @@ pub enum ClearCrossCrate { } impl ClearCrossCrate { + pub fn as_ref(&'a self) -> ClearCrossCrate<&'a T> { + match self { + ClearCrossCrate::Clear => ClearCrossCrate::Clear, + ClearCrossCrate::Set(v) => ClearCrossCrate::Set(v), + } + } + pub fn assert_crate_local(self) -> T { match self { ClearCrossCrate::Clear => bug!("unwrapping cross-crate data"), @@ -2021,6 +2028,10 @@ pub struct SourceScope { pub struct SourceScopeData { pub span: Span, pub parent_scope: Option, + + /// Crate-local information for this source scope, that can't (and + /// needn't) be tracked across crates. + pub local_data: ClearCrossCrate, } #[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)] @@ -2979,7 +2990,7 @@ fn super_fold_with>(&self, folder: &mut F) -> Self { index: index.fold_with(folder), }, Panic { .. } | Overflow(_) | OverflowNeg | DivisionByZero | RemainderByZero | - GeneratorResumedAfterReturn | GeneratorResumedAfterPanic => + ResumedAfterReturn(_) | ResumedAfterPanic(_) => msg.clone(), }; Assert { cond: cond.fold_with(folder), expected, msg, target, cleanup } @@ -3025,7 +3036,7 @@ fn super_visit_with>(&self, visitor: &mut V) -> bool { len.visit_with(visitor) || index.visit_with(visitor), Panic { .. } | Overflow(_) | OverflowNeg | DivisionByZero | RemainderByZero | - GeneratorResumedAfterReturn | GeneratorResumedAfterPanic => + ResumedAfterReturn(_) | ResumedAfterPanic(_) => false } } else { @@ -3044,6 +3055,16 @@ fn super_visit_with>(&self, visitor: &mut V) -> bool { } } +impl<'tcx> TypeFoldable<'tcx> for GeneratorKind { + fn super_fold_with>(&self, _: &mut F) -> Self { + *self + } + + fn super_visit_with>(&self, _: &mut V) -> bool { + false + } +} + impl<'tcx> TypeFoldable<'tcx> for Place<'tcx> { fn super_fold_with>(&self, folder: &mut F) -> Self { Place {