Box generator-related Body fields
This commit is contained in:
parent
3b150b7a8f
commit
b97eb23cd0
14 changed files with 89 additions and 54 deletions
|
@ -146,6 +146,22 @@ impl<'tcx> MirSource<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, TyEncodable, TyDecodable, Debug, HashStable, TypeFoldable)]
|
||||
pub struct GeneratorInfo<'tcx> {
|
||||
/// The yield type of the function, if it is a generator.
|
||||
pub yield_ty: Option<Ty<'tcx>>,
|
||||
|
||||
/// Generator drop glue.
|
||||
pub generator_drop: Option<Body<'tcx>>,
|
||||
|
||||
/// The layout of a generator. Produced by the state transformation.
|
||||
pub generator_layout: Option<GeneratorLayout<'tcx>>,
|
||||
|
||||
/// If this is a generator then record the type of source expression that caused this generator
|
||||
/// to be created.
|
||||
pub generator_kind: GeneratorKind,
|
||||
}
|
||||
|
||||
/// The lowered representation of a single function.
|
||||
#[derive(Clone, TyEncodable, TyDecodable, Debug, HashStable, TypeFoldable)]
|
||||
pub struct Body<'tcx> {
|
||||
|
@ -166,18 +182,7 @@ pub struct Body<'tcx> {
|
|||
/// and used for debuginfo. Indexed by a `SourceScope`.
|
||||
pub source_scopes: IndexVec<SourceScope, SourceScopeData<'tcx>>,
|
||||
|
||||
/// The yield type of the function, if it is a generator.
|
||||
pub yield_ty: Option<Ty<'tcx>>,
|
||||
|
||||
/// Generator drop glue.
|
||||
pub generator_drop: Option<Box<Body<'tcx>>>,
|
||||
|
||||
/// The layout of a generator. Produced by the state transformation.
|
||||
pub generator_layout: Option<GeneratorLayout<'tcx>>,
|
||||
|
||||
/// If this is a generator then record the type of source expression that caused this generator
|
||||
/// to be created.
|
||||
pub generator_kind: Option<GeneratorKind>,
|
||||
pub generator: Option<Box<GeneratorInfo<'tcx>>>,
|
||||
|
||||
/// Declarations of locals.
|
||||
///
|
||||
|
@ -259,10 +264,14 @@ impl<'tcx> Body<'tcx> {
|
|||
source,
|
||||
basic_blocks,
|
||||
source_scopes,
|
||||
yield_ty: None,
|
||||
generator_drop: None,
|
||||
generator_layout: None,
|
||||
generator_kind,
|
||||
generator: generator_kind.map(|generator_kind| {
|
||||
Box::new(GeneratorInfo {
|
||||
yield_ty: None,
|
||||
generator_drop: None,
|
||||
generator_layout: None,
|
||||
generator_kind,
|
||||
})
|
||||
}),
|
||||
local_decls,
|
||||
user_type_annotations,
|
||||
arg_count,
|
||||
|
@ -289,16 +298,13 @@ impl<'tcx> Body<'tcx> {
|
|||
source: MirSource::item(DefId::local(CRATE_DEF_INDEX)),
|
||||
basic_blocks,
|
||||
source_scopes: IndexVec::new(),
|
||||
yield_ty: None,
|
||||
generator_drop: None,
|
||||
generator_layout: None,
|
||||
generator: None,
|
||||
local_decls: IndexVec::new(),
|
||||
user_type_annotations: IndexVec::new(),
|
||||
arg_count: 0,
|
||||
spread_arg: None,
|
||||
span: DUMMY_SP,
|
||||
required_consts: Vec::new(),
|
||||
generator_kind: None,
|
||||
var_debug_info: Vec::new(),
|
||||
is_polymorphic: false,
|
||||
predecessor_cache: PredecessorCache::new(),
|
||||
|
@ -480,6 +486,26 @@ impl<'tcx> Body<'tcx> {
|
|||
pub fn dominators(&self) -> Dominators<BasicBlock> {
|
||||
dominators(self)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn yield_ty(&self) -> Option<Ty<'tcx>> {
|
||||
self.generator.as_ref().and_then(|generator| generator.yield_ty)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn generator_layout(&self) -> Option<&GeneratorLayout<'tcx>> {
|
||||
self.generator.as_ref().and_then(|generator| generator.generator_layout.as_ref())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn generator_drop(&self) -> Option<&Body<'tcx>> {
|
||||
self.generator.as_ref().and_then(|generator| generator.generator_drop.as_ref())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn generator_kind(&self) -> Option<GeneratorKind> {
|
||||
self.generator.as_ref().map(|generator| generator.generator_kind)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug, TyEncodable, TyDecodable, HashStable)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue