Give GeneratorLayout a list of fields for each variant
But don't really use it yet.
This commit is contained in:
parent
70c1b6c530
commit
4de2d8a869
4 changed files with 16 additions and 13 deletions
|
|
@ -2998,7 +2998,7 @@ pub struct UnsafetyCheckResult {
|
|||
/// The layout of generator state
|
||||
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
|
||||
pub struct GeneratorLayout<'tcx> {
|
||||
pub fields: Vec<LocalDecl<'tcx>>,
|
||||
pub variant_fields: Vec<Vec<LocalDecl<'tcx>>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
|
||||
|
|
@ -3187,7 +3187,7 @@ BraceStructTypeFoldableImpl! {
|
|||
|
||||
BraceStructTypeFoldableImpl! {
|
||||
impl<'tcx> TypeFoldable<'tcx> for GeneratorLayout<'tcx> {
|
||||
fields
|
||||
variant_fields
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -475,16 +475,16 @@ impl<'a, 'gcx, 'tcx> GeneratorSubsts<'tcx> {
|
|||
/// This returns the types of the MIR locals which had to be stored across suspension points.
|
||||
/// It is calculated in rustc_mir::transform::generator::StateTransform.
|
||||
/// All the types here must be in the tuple in GeneratorInterior.
|
||||
pub fn state_tys(
|
||||
self,
|
||||
def_id: DefId,
|
||||
tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
) -> impl Iterator<Item=Ty<'tcx>> + Captures<'gcx> + 'a {
|
||||
let state = tcx.generator_layout(def_id).fields.iter();
|
||||
state.map(move |d| d.ty.subst(tcx, self.substs))
|
||||
pub fn state_tys(self, def_id: DefId, tcx: TyCtxt<'a, 'gcx, 'tcx>) ->
|
||||
impl Iterator<Item=Ty<'tcx>> + Captures<'gcx> + 'a
|
||||
{
|
||||
// TODO remove so we can handle variants properly
|
||||
tcx.generator_layout(def_id)
|
||||
.variant_fields[0].iter()
|
||||
.map(move |d| d.ty.subst(tcx, self.substs))
|
||||
}
|
||||
|
||||
/// This is the types of the fields of a generate which
|
||||
/// This is the types of the fields of a generator which
|
||||
/// is available before the generator transformation.
|
||||
/// It includes the upvars and the state discriminant.
|
||||
pub fn pre_transforms_tys(self, def_id: DefId, tcx: TyCtxt<'a, 'gcx, 'tcx>) ->
|
||||
|
|
|
|||
|
|
@ -655,10 +655,12 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
|
|||
ty::Generator(def_id, substs, _) => (def_id, substs),
|
||||
_ => bug!("generator layout without generator substs"),
|
||||
};
|
||||
// TODO handle variant scopes here
|
||||
let state_tys = gen_substs.state_tys(def_id, tcx);
|
||||
|
||||
let upvar_count = upvar_debuginfo.len();
|
||||
generator_layout.fields
|
||||
// TODO remove assumption of only one variant
|
||||
let upvar_count = mir.upvar_decls.len();
|
||||
generator_layout.variant_fields[0]
|
||||
.iter()
|
||||
.zip(state_tys)
|
||||
.enumerate()
|
||||
|
|
|
|||
|
|
@ -549,7 +549,8 @@ fn compute_layout<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
}).unzip();
|
||||
|
||||
let layout = GeneratorLayout {
|
||||
fields: vars
|
||||
// Put everything in one variant, for now.
|
||||
variant_fields: vec![vars]
|
||||
};
|
||||
|
||||
(remap, layout, storage_liveness)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue