Skip to content

Commit 4de2d8a

Browse files
committed
Give GeneratorLayout a list of fields for each variant
But don't really use it yet.
1 parent 70c1b6c commit 4de2d8a

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

src/librustc/mir/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2998,7 +2998,7 @@ pub struct UnsafetyCheckResult {
29982998
/// The layout of generator state
29992999
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
30003000
pub struct GeneratorLayout<'tcx> {
3001-
pub fields: Vec<LocalDecl<'tcx>>,
3001+
pub variant_fields: Vec<Vec<LocalDecl<'tcx>>>,
30023002
}
30033003

30043004
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
@@ -3187,7 +3187,7 @@ BraceStructTypeFoldableImpl! {
31873187

31883188
BraceStructTypeFoldableImpl! {
31893189
impl<'tcx> TypeFoldable<'tcx> for GeneratorLayout<'tcx> {
3190-
fields
3190+
variant_fields
31913191
}
31923192
}
31933193

src/librustc/ty/sty.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -475,16 +475,16 @@ impl<'a, 'gcx, 'tcx> GeneratorSubsts<'tcx> {
475475
/// This returns the types of the MIR locals which had to be stored across suspension points.
476476
/// It is calculated in rustc_mir::transform::generator::StateTransform.
477477
/// All the types here must be in the tuple in GeneratorInterior.
478-
pub fn state_tys(
479-
self,
480-
def_id: DefId,
481-
tcx: TyCtxt<'a, 'gcx, 'tcx>,
482-
) -> impl Iterator<Item=Ty<'tcx>> + Captures<'gcx> + 'a {
483-
let state = tcx.generator_layout(def_id).fields.iter();
484-
state.map(move |d| d.ty.subst(tcx, self.substs))
478+
pub fn state_tys(self, def_id: DefId, tcx: TyCtxt<'a, 'gcx, 'tcx>) ->
479+
impl Iterator<Item=Ty<'tcx>> + Captures<'gcx> + 'a
480+
{
481+
// TODO remove so we can handle variants properly
482+
tcx.generator_layout(def_id)
483+
.variant_fields[0].iter()
484+
.map(move |d| d.ty.subst(tcx, self.substs))
485485
}
486486

487-
/// This is the types of the fields of a generate which
487+
/// This is the types of the fields of a generator which
488488
/// is available before the generator transformation.
489489
/// It includes the upvars and the state discriminant.
490490
pub fn pre_transforms_tys(self, def_id: DefId, tcx: TyCtxt<'a, 'gcx, 'tcx>) ->

src/librustc_codegen_ssa/mir/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,10 +655,12 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
655655
ty::Generator(def_id, substs, _) => (def_id, substs),
656656
_ => bug!("generator layout without generator substs"),
657657
};
658+
// TODO handle variant scopes here
658659
let state_tys = gen_substs.state_tys(def_id, tcx);
659660

660-
let upvar_count = upvar_debuginfo.len();
661-
generator_layout.fields
661+
// TODO remove assumption of only one variant
662+
let upvar_count = mir.upvar_decls.len();
663+
generator_layout.variant_fields[0]
662664
.iter()
663665
.zip(state_tys)
664666
.enumerate()

src/librustc_mir/transform/generator.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,8 @@ fn compute_layout<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
549549
}).unzip();
550550

551551
let layout = GeneratorLayout {
552-
fields: vars
552+
// Put everything in one variant, for now.
553+
variant_fields: vec![vars]
553554
};
554555

555556
(remap, layout, storage_liveness)

0 commit comments

Comments
 (0)