Skip to content

Commit 7739f17

Browse files
authored
Rollup merge of #65100 - csmoe:generator, r=nikomatsakis
Replace GeneratorSubsts with SubstsRef Closes #42340 r? @nikomatsakis
2 parents f14d374 + afc0bb9 commit 7739f17

File tree

35 files changed

+110
-126
lines changed

35 files changed

+110
-126
lines changed

src/librustc/infer/opaque_types/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -733,12 +733,12 @@ where
733733
// Skip lifetime parameters of the enclosing item(s)
734734
// Also skip the witness type, because that has no free regions.
735735

736-
for upvar_ty in substs.upvar_tys(def_id, self.tcx) {
736+
for upvar_ty in substs.as_generator().upvar_tys(def_id, self.tcx) {
737737
upvar_ty.visit_with(self);
738738
}
739739

740-
substs.return_ty(def_id, self.tcx).visit_with(self);
741-
substs.yield_ty(def_id, self.tcx).visit_with(self);
740+
substs.as_generator().return_ty(def_id, self.tcx).visit_with(self);
741+
substs.as_generator().yield_ty(def_id, self.tcx).visit_with(self);
742742
}
743743
_ => {
744744
ty.super_visit_with(self);
@@ -902,7 +902,7 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> {
902902
ty::Generator(def_id, substs, movability) => {
903903
let generics = self.tcx.generics_of(def_id);
904904
let substs =
905-
self.tcx.mk_substs(substs.substs.iter().enumerate().map(|(index, &kind)| {
905+
self.tcx.mk_substs(substs.iter().enumerate().map(|(index, &kind)| {
906906
if index < generics.parent_count {
907907
// Accommodate missing regions in the parent kinds...
908908
self.fold_kind_mapping_missing_regions_to_empty(kind)
@@ -912,7 +912,7 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> {
912912
}
913913
}));
914914

915-
self.tcx.mk_generator(def_id, ty::GeneratorSubsts { substs }, movability)
915+
self.tcx.mk_generator(def_id, substs, movability)
916916
}
917917

918918
ty::Param(..) => {

src/librustc/mir/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::ty::layout::VariantIdx;
1515
use crate::ty::print::{FmtPrinter, Printer};
1616
use crate::ty::subst::{Subst, SubstsRef};
1717
use crate::ty::{
18-
self, AdtDef, CanonicalUserTypeAnnotations, GeneratorSubsts, Region, Ty, TyCtxt,
18+
self, AdtDef, CanonicalUserTypeAnnotations, Region, Ty, TyCtxt,
1919
UserTypeAnnotationIndex,
2020
};
2121

@@ -2189,7 +2189,7 @@ pub enum AggregateKind<'tcx> {
21892189
Adt(&'tcx AdtDef, VariantIdx, SubstsRef<'tcx>, Option<UserTypeAnnotationIndex>, Option<usize>),
21902190

21912191
Closure(DefId, SubstsRef<'tcx>),
2192-
Generator(DefId, GeneratorSubsts<'tcx>, hir::GeneratorMovability),
2192+
Generator(DefId, SubstsRef<'tcx>, hir::GeneratorMovability),
21932193
}
21942194

21952195
#[derive(Copy, Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)]

src/librustc/mir/tcx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl<'tcx> Rvalue<'tcx> {
197197
let ty = place.ty(local_decls, tcx).ty;
198198
match ty.kind {
199199
ty::Adt(adt_def, _) => adt_def.repr.discr_type().to_ty(tcx),
200-
ty::Generator(_, substs, _) => substs.discr_ty(tcx),
200+
ty::Generator(_, substs, _) => substs.as_generator().discr_ty(tcx),
201201
_ => {
202202
// This can only be `0`, for now, so `u8` will suffice.
203203
tcx.types.u8

src/librustc/mir/visit.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::ty::subst::SubstsRef;
2-
use crate::ty::{CanonicalUserTypeAnnotation, GeneratorSubsts, Ty};
2+
use crate::ty::{CanonicalUserTypeAnnotation, Ty};
33
use crate::mir::*;
44
use syntax_pos::Span;
55

@@ -230,12 +230,6 @@ macro_rules! make_mir_visitor {
230230
self.super_substs(substs);
231231
}
232232

233-
fn visit_generator_substs(&mut self,
234-
substs: & $($mutability)? GeneratorSubsts<'tcx>,
235-
_: Location) {
236-
self.super_generator_substs(substs);
237-
}
238-
239233
fn visit_local_decl(&mut self,
240234
local: Local,
241235
local_decl: & $($mutability)? LocalDecl<'tcx>) {
@@ -628,7 +622,7 @@ macro_rules! make_mir_visitor {
628622
generator_substs,
629623
_movability,
630624
) => {
631-
self.visit_generator_substs(generator_substs, location);
625+
self.visit_substs(generator_substs, location);
632626
}
633627
}
634628

@@ -846,10 +840,6 @@ macro_rules! make_mir_visitor {
846840
fn super_substs(&mut self, _substs: & $($mutability)? SubstsRef<'tcx>) {
847841
}
848842

849-
fn super_generator_substs(&mut self,
850-
_substs: & $($mutability)? GeneratorSubsts<'tcx>) {
851-
}
852-
853843
// Convenience methods
854844

855845
fn visit_location(&mut self, body: & $($mutability)? Body<'tcx>, location: Location) {

src/librustc/traits/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ pub struct VtableImplData<'tcx, N> {
610610
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)]
611611
pub struct VtableGeneratorData<'tcx, N> {
612612
pub generator_def_id: DefId,
613-
pub substs: ty::GeneratorSubsts<'tcx>,
613+
pub substs: SubstsRef<'tcx>,
614614
/// Nested obligations. This can be non-empty if the generator
615615
/// signature contains associated types.
616616
pub nested: Vec<N>

src/librustc/traits/project.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ fn confirm_generator_candidate<'cx, 'tcx>(
12591259
obligation: &ProjectionTyObligation<'tcx>,
12601260
vtable: VtableGeneratorData<'tcx, PredicateObligation<'tcx>>,
12611261
) -> Progress<'tcx> {
1262-
let gen_sig = vtable.substs.poly_sig(vtable.generator_def_id, selcx.tcx());
1262+
let gen_sig = vtable.substs.as_generator().poly_sig(vtable.generator_def_id, selcx.tcx());
12631263
let Normalized {
12641264
value: gen_sig,
12651265
obligations

src/librustc/traits/select.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -2761,8 +2761,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
27612761
.collect(),
27622762

27632763
ty::Generator(def_id, ref substs, _) => {
2764-
let witness = substs.witness(def_id, self.tcx());
2764+
let witness = substs.as_generator().witness(def_id, self.tcx());
27652765
substs
2766+
.as_generator()
27662767
.upvar_tys(def_id, self.tcx())
27672768
.chain(iter::once(witness))
27682769
.collect()
@@ -3324,8 +3325,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
33243325
)?);
33253326

33263327
Ok(VtableGeneratorData {
3327-
generator_def_id: generator_def_id,
3328-
substs: substs.clone(),
3328+
generator_def_id,
3329+
substs,
33293330
nested: obligations,
33303331
})
33313332
}
@@ -3911,9 +3912,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
39113912
&mut self,
39123913
obligation: &TraitObligation<'tcx>,
39133914
closure_def_id: DefId,
3914-
substs: ty::GeneratorSubsts<'tcx>,
3915+
substs: SubstsRef<'tcx>,
39153916
) -> ty::PolyTraitRef<'tcx> {
3916-
let gen_sig = substs.poly_sig(closure_def_id, self.tcx());
3917+
let gen_sig = substs.as_generator().poly_sig(closure_def_id, self.tcx());
39173918

39183919
// (1) Feels icky to skip the binder here, but OTOH we know
39193920
// that the self-type is an generator type and hence is

src/librustc/ty/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::traits;
2929
use crate::traits::{Clause, Clauses, GoalKind, Goal, Goals};
3030
use crate::ty::{self, DefIdTree, Ty, TypeAndMut};
3131
use crate::ty::{TyS, TyKind, List};
32-
use crate::ty::{AdtKind, AdtDef, GeneratorSubsts, Region, Const};
32+
use crate::ty::{AdtKind, AdtDef, Region, Const};
3333
use crate::ty::{PolyFnSig, InferTy, ParamTy, ProjectionTy, ExistentialPredicate, Predicate};
3434
use crate::ty::RegionKind;
3535
use crate::ty::{TyVar, TyVid, IntVar, IntVid, FloatVar, FloatVid, ConstVid};
@@ -2510,7 +2510,7 @@ impl<'tcx> TyCtxt<'tcx> {
25102510
#[inline]
25112511
pub fn mk_generator(self,
25122512
id: DefId,
2513-
generator_substs: GeneratorSubsts<'tcx>,
2513+
generator_substs: SubstsRef<'tcx>,
25142514
movability: hir::GeneratorMovability)
25152515
-> Ty<'tcx> {
25162516
self.mk_ty(Generator(id, generator_substs, movability))

src/librustc/ty/flags.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl FlagComputation {
9494
&ty::Generator(_, ref substs, _) => {
9595
self.add_flags(TypeFlags::HAS_TY_CLOSURE);
9696
self.add_flags(TypeFlags::HAS_FREE_LOCAL_NAMES);
97-
self.add_substs(&substs.substs);
97+
self.add_substs(substs);
9898
}
9999

100100
&ty::GeneratorWitness(ref ts) => {

src/librustc/ty/instance.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl<'tcx> Instance<'tcx> {
7171
))
7272
}
7373
ty::Generator(def_id, substs, _) => {
74-
let sig = substs.poly_sig(def_id, tcx);
74+
let sig = substs.as_generator().poly_sig(def_id, tcx);
7575

7676
let env_region = ty::ReLateBound(ty::INNERMOST, ty::BrEnv);
7777
let env_ty = tcx.mk_mut_ref(tcx.mk_region(env_region), ty);
@@ -395,7 +395,7 @@ fn resolve_associated_item<'tcx>(
395395
traits::VtableGenerator(generator_data) => {
396396
Some(Instance {
397397
def: ty::InstanceDef::Item(generator_data.generator_def_id),
398-
substs: generator_data.substs.substs
398+
substs: generator_data.substs
399399
})
400400
}
401401
traits::VtableClosure(closure_data) => {

src/librustc/ty/layout.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::session::{self, DataTypeKind};
2-
use crate::ty::{self, Ty, TyCtxt, TypeFoldable, ReprOptions};
2+
use crate::ty::{self, Ty, TyCtxt, TypeFoldable, ReprOptions, subst::SubstsRef};
33

44
use syntax::ast::{self, Ident, IntTy, UintTy};
55
use syntax::attr;
@@ -15,7 +15,6 @@ use std::ops::Bound;
1515
use crate::hir;
1616
use crate::ich::StableHashingContext;
1717
use crate::mir::{GeneratorLayout, GeneratorSavedLocal};
18-
use crate::ty::GeneratorSubsts;
1918
use crate::ty::subst::Subst;
2019
use rustc_index::bit_set::BitSet;
2120
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -671,7 +670,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
671670
tcx.intern_layout(unit)
672671
}
673672

674-
ty::Generator(def_id, substs, _) => self.generator_layout(ty, def_id, &substs)?,
673+
ty::Generator(def_id, substs, _) => self.generator_layout(ty, def_id, substs)?,
675674

676675
ty::Closure(def_id, ref substs) => {
677676
let tys = substs.as_closure().upvar_tys(def_id, tcx);
@@ -1406,22 +1405,22 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
14061405
&self,
14071406
ty: Ty<'tcx>,
14081407
def_id: hir::def_id::DefId,
1409-
substs: &GeneratorSubsts<'tcx>,
1408+
substs: SubstsRef<'tcx>,
14101409
) -> Result<&'tcx LayoutDetails, LayoutError<'tcx>> {
14111410
use SavedLocalEligibility::*;
14121411
let tcx = self.tcx;
14131412

1414-
let subst_field = |ty: Ty<'tcx>| { ty.subst(tcx, substs.substs) };
1413+
let subst_field = |ty: Ty<'tcx>| { ty.subst(tcx, substs) };
14151414

14161415
let info = tcx.generator_layout(def_id);
14171416
let (ineligible_locals, assignments) = self.generator_saved_local_eligibility(&info);
14181417

14191418
// Build a prefix layout, including "promoting" all ineligible
14201419
// locals as part of the prefix. We compute the layout of all of
14211420
// these fields at once to get optimal packing.
1422-
let discr_index = substs.prefix_tys(def_id, tcx).count();
1421+
let discr_index = substs.as_generator().prefix_tys(def_id, tcx).count();
14231422
// FIXME(eddyb) set the correct vaidity range for the discriminant.
1424-
let discr_layout = self.layout_of(substs.discr_ty(tcx))?;
1423+
let discr_layout = self.layout_of(substs.as_generator().discr_ty(tcx))?;
14251424
let discr = match &discr_layout.abi {
14261425
Abi::Scalar(s) => s.clone(),
14271426
_ => bug!(),
@@ -1430,7 +1429,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
14301429
.map(|local| subst_field(info.field_tys[local]))
14311430
.map(|ty| tcx.mk_maybe_uninit(ty))
14321431
.map(|ty| self.layout_of(ty));
1433-
let prefix_layouts = substs.prefix_tys(def_id, tcx)
1432+
let prefix_layouts = substs.as_generator().prefix_tys(def_id, tcx)
14341433
.map(|ty| self.layout_of(ty))
14351434
.chain(iter::once(Ok(discr_layout)))
14361435
.chain(promoted_layouts)
@@ -2153,15 +2152,15 @@ where
21532152
ty::Generator(def_id, ref substs, _) => {
21542153
match this.variants {
21552154
Variants::Single { index } => {
2156-
substs.state_tys(def_id, tcx)
2155+
substs.as_generator().state_tys(def_id, tcx)
21572156
.nth(index.as_usize()).unwrap()
21582157
.nth(i).unwrap()
21592158
}
21602159
Variants::Multiple { ref discr, discr_index, .. } => {
21612160
if i == discr_index {
21622161
return discr_layout(discr);
21632162
}
2164-
substs.prefix_tys(def_id, tcx).nth(i).unwrap()
2163+
substs.as_generator().prefix_tys(def_id, tcx).nth(i).unwrap()
21652164
}
21662165
}
21672166
}

src/librustc/ty/outlives.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl<'tcx> TyCtxt<'tcx> {
6969

7070
ty::Generator(def_id, ref substs, _) => {
7171
// Same as the closure case
72-
for upvar_ty in substs.upvar_tys(def_id, *self) {
72+
for upvar_ty in substs.as_generator().upvar_tys(def_id, *self) {
7373
self.compute_components(upvar_ty, out);
7474
}
7575

src/librustc/ty/print/obsolete.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use rustc::hir::def_id::DefId;
99
use rustc::mir::interpret::ConstValue;
1010
use rustc::ty::subst::SubstsRef;
11-
use rustc::ty::{self, Const, GeneratorSubsts, Instance, Ty, TyCtxt};
11+
use rustc::ty::{self, Const, Instance, Ty, TyCtxt};
1212
use rustc::{bug, hir};
1313
use std::fmt::Write;
1414
use std::iter;
@@ -154,7 +154,7 @@ impl DefPathBasedNames<'tcx> {
154154
self.push_type_name(sig.output(), output, debug);
155155
}
156156
}
157-
ty::Generator(def_id, GeneratorSubsts { substs }, _)
157+
ty::Generator(def_id, substs, _)
158158
| ty::Closure(def_id, substs) => {
159159
self.push_def_path(def_id, output);
160160
let generics = self.tcx.generics_of(self.tcx.closure_base_def_id(def_id));

src/librustc/ty/print/pretty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -605,8 +605,8 @@ pub trait PrettyPrinter<'tcx>:
605605
}
606606
ty::Str => p!(write("str")),
607607
ty::Generator(did, substs, movability) => {
608-
let upvar_tys = substs.upvar_tys(did, self.tcx());
609-
let witness = substs.witness(did, self.tcx());
608+
let upvar_tys = substs.as_generator().upvar_tys(did, self.tcx());
609+
let witness = substs.as_generator().witness(did, self.tcx());
610610
if movability == hir::GeneratorMovability::Movable {
611611
p!(write("[generator"));
612612
} else {

src/librustc/ty/sty.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ pub enum TyKind<'tcx> {
163163

164164
/// The anonymous type of a generator. Used to represent the type of
165165
/// `|a| yield a`.
166-
Generator(DefId, GeneratorSubsts<'tcx>, hir::GeneratorMovability),
166+
Generator(DefId, SubstsRef<'tcx>, hir::GeneratorMovability),
167167

168168
/// A type representin the types stored inside a generator.
169169
/// This should only appear in GeneratorInteriors.
@@ -512,7 +512,7 @@ impl<'tcx> GeneratorSubsts<'tcx> {
512512
/// variant indices.
513513
#[inline]
514514
pub fn discriminants(
515-
&'tcx self,
515+
self,
516516
def_id: DefId,
517517
tcx: TyCtxt<'tcx>,
518518
) -> impl Iterator<Item = (VariantIdx, Discr<'tcx>)> + Captures<'tcx> {
@@ -524,7 +524,7 @@ impl<'tcx> GeneratorSubsts<'tcx> {
524524
/// Calls `f` with a reference to the name of the enumerator for the given
525525
/// variant `v`.
526526
#[inline]
527-
pub fn variant_name(&self, v: VariantIdx) -> Cow<'static, str> {
527+
pub fn variant_name(self, v: VariantIdx) -> Cow<'static, str> {
528528
match v.as_usize() {
529529
Self::UNRESUMED => Cow::from(Self::UNRESUMED_NAME),
530530
Self::RETURNED => Cow::from(Self::RETURNED_NAME),
@@ -570,7 +570,7 @@ impl<'tcx> GeneratorSubsts<'tcx> {
570570
#[derive(Debug, Copy, Clone)]
571571
pub enum UpvarSubsts<'tcx> {
572572
Closure(SubstsRef<'tcx>),
573-
Generator(GeneratorSubsts<'tcx>),
573+
Generator(SubstsRef<'tcx>),
574574
}
575575

576576
impl<'tcx> UpvarSubsts<'tcx> {
@@ -582,7 +582,7 @@ impl<'tcx> UpvarSubsts<'tcx> {
582582
) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
583583
let upvar_kinds = match self {
584584
UpvarSubsts::Closure(substs) => substs.as_closure().split(def_id, tcx).upvar_kinds,
585-
UpvarSubsts::Generator(substs) => substs.split(def_id, tcx).upvar_kinds,
585+
UpvarSubsts::Generator(substs) => substs.as_generator().split(def_id, tcx).upvar_kinds,
586586
};
587587
upvar_kinds.iter().map(|t| {
588588
if let GenericArgKind::Type(ty) = t.unpack() {
@@ -2109,7 +2109,8 @@ impl<'tcx> TyS<'tcx> {
21092109
pub fn variant_range(&self, tcx: TyCtxt<'tcx>) -> Option<Range<VariantIdx>> {
21102110
match self.kind {
21112111
TyKind::Adt(adt, _) => Some(adt.variant_range()),
2112-
TyKind::Generator(def_id, substs, _) => Some(substs.variant_range(def_id, tcx)),
2112+
TyKind::Generator(def_id, substs, _) =>
2113+
Some(substs.as_generator().variant_range(def_id, tcx)),
21132114
_ => None,
21142115
}
21152116
}
@@ -2126,7 +2127,7 @@ impl<'tcx> TyS<'tcx> {
21262127
match self.kind {
21272128
TyKind::Adt(adt, _) => Some(adt.discriminant_for_variant(tcx, variant_index)),
21282129
TyKind::Generator(def_id, substs, _) =>
2129-
Some(substs.discriminant_for_variant(def_id, tcx, variant_index)),
2130+
Some(substs.as_generator().discriminant_for_variant(def_id, tcx, variant_index)),
21302131
_ => None,
21312132
}
21322133
}
@@ -2149,7 +2150,7 @@ impl<'tcx> TyS<'tcx> {
21492150
out.extend(substs.regions())
21502151
}
21512152
Closure(_, ref substs ) |
2152-
Generator(_, GeneratorSubsts { ref substs }, _) => {
2153+
Generator(_, ref substs, _) => {
21532154
out.extend(substs.regions())
21542155
}
21552156
Projection(ref data) | UnnormalizedProjection(ref data) => {

0 commit comments

Comments
 (0)