Skip to content

Commit c56c01b

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

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

src/librustc/mir/mod.rs

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

30053005
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
@@ -3188,7 +3188,7 @@ BraceStructTypeFoldableImpl! {
31883188

31893189
BraceStructTypeFoldableImpl! {
31903190
impl<'tcx> TypeFoldable<'tcx> for GeneratorLayout<'tcx> {
3191-
fields
3191+
variant_fields
31923192
}
31933193
}
31943194

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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,10 +654,12 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
654654
ty::Generator(def_id, substs, _) => (def_id, substs),
655655
_ => bug!("generator layout without generator substs"),
656656
};
657+
// TODO handle variant scopes here
657658
let state_tys = gen_substs.state_tys(def_id, tcx);
658659

660+
// TODO remove assumption of only one variant
659661
let upvar_count = mir.upvar_decls.len();
660-
generator_layout.fields
662+
generator_layout.variant_fields[0]
661663
.iter()
662664
.zip(state_tys)
663665
.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)