Split out debuginfo from type info in MIR GeneratorLayout
This commit is contained in:
parent
f7c2f2475a
commit
15dbe652ff
5 changed files with 59 additions and 16 deletions
|
|
@ -2994,10 +2994,29 @@ pub struct UnsafetyCheckResult {
|
|||
pub unsafe_blocks: Lrc<[(hir::HirId, bool)]>,
|
||||
}
|
||||
|
||||
newtype_index! {
|
||||
pub struct GeneratorField {
|
||||
derive [HashStable]
|
||||
DEBUG_FORMAT = "_{}",
|
||||
}
|
||||
}
|
||||
|
||||
/// The layout of generator state
|
||||
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
|
||||
pub struct GeneratorLayout<'tcx> {
|
||||
pub variant_fields: IndexVec<VariantIdx, IndexVec<Field, LocalDecl<'tcx>>>,
|
||||
/// The type of every local stored inside the generator.
|
||||
pub field_tys: IndexVec<GeneratorField, Ty<'tcx>>,
|
||||
|
||||
/// Which of the above fields are in each variant. Note that one field may
|
||||
/// be stored in multiple variants.
|
||||
pub variant_fields: IndexVec<VariantIdx, IndexVec<Field, GeneratorField>>,
|
||||
|
||||
/// Names and scopes of all the stored generator locals.
|
||||
/// NOTE(tmandry) This is *strictly* a temporary hack for codegen
|
||||
/// debuginfo generation, and will be removed at some point.
|
||||
/// Do **NOT** use it for anything else, local information should not be
|
||||
/// in the MIR, please rely on local crate HIR or other side-channels.
|
||||
pub __local_debuginfo_codegen_only_do_not_use: IndexVec<GeneratorField, LocalDecl<'tcx>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
|
||||
|
|
@ -3186,7 +3205,9 @@ BraceStructTypeFoldableImpl! {
|
|||
|
||||
BraceStructTypeFoldableImpl! {
|
||||
impl<'tcx> TypeFoldable<'tcx> for GeneratorLayout<'tcx> {
|
||||
variant_fields
|
||||
field_tys,
|
||||
variant_fields,
|
||||
__local_debuginfo_codegen_only_do_not_use,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -3561,6 +3582,15 @@ impl<'tcx> TypeFoldable<'tcx> for Field {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for GeneratorField {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, _: &mut F) -> Self {
|
||||
*self
|
||||
}
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for Constant<'tcx> {
|
||||
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
||||
Constant {
|
||||
|
|
|
|||
|
|
@ -483,7 +483,7 @@ impl<'a, 'gcx, 'tcx> GeneratorSubsts<'tcx> {
|
|||
#[inline]
|
||||
pub fn variant_range(&self, def_id: DefId, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Range<VariantIdx> {
|
||||
// FIXME requires optimized MIR
|
||||
let num_variants = self.state_tys(def_id, tcx).count();
|
||||
let num_variants = tcx.generator_layout(def_id).variant_fields.len();
|
||||
(VariantIdx::new(0)..VariantIdx::new(num_variants))
|
||||
}
|
||||
|
||||
|
|
@ -541,9 +541,12 @@ impl<'a, 'gcx, 'tcx> GeneratorSubsts<'tcx> {
|
|||
pub fn state_tys(self, def_id: DefId, tcx: TyCtxt<'a, 'gcx, 'tcx>) ->
|
||||
impl Iterator<Item=impl Iterator<Item=Ty<'tcx>> + Captures<'gcx> + 'a>
|
||||
{
|
||||
tcx.generator_layout(def_id)
|
||||
.variant_fields.iter()
|
||||
.map(move |v| v.iter().map(move |d| d.ty.subst(tcx, self.substs)))
|
||||
let layout = tcx.generator_layout(def_id);
|
||||
layout.variant_fields.iter().map(move |variant| {
|
||||
variant.iter().map(move |field| {
|
||||
layout.field_tys[*field].subst(tcx, self.substs)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/// This is the types of the fields of a generator which are not stored in a
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue