Skip to content

Commit

Permalink
Rollup merge of rust-lang#65100 - csmoe:generator, r=nikomatsakis
Browse files Browse the repository at this point in the history
Replace GeneratorSubsts with SubstsRef

Closes rust-lang#42340
r? @nikomatsakis
  • Loading branch information
tmandry authored Oct 6, 2019
2 parents f14d374 + afc0bb9 commit 7739f17
Show file tree
Hide file tree
Showing 35 changed files with 110 additions and 126 deletions.
10 changes: 5 additions & 5 deletions src/librustc/infer/opaque_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,12 +733,12 @@ where
// Skip lifetime parameters of the enclosing item(s)
// Also skip the witness type, because that has no free regions.

for upvar_ty in substs.upvar_tys(def_id, self.tcx) {
for upvar_ty in substs.as_generator().upvar_tys(def_id, self.tcx) {
upvar_ty.visit_with(self);
}

substs.return_ty(def_id, self.tcx).visit_with(self);
substs.yield_ty(def_id, self.tcx).visit_with(self);
substs.as_generator().return_ty(def_id, self.tcx).visit_with(self);
substs.as_generator().yield_ty(def_id, self.tcx).visit_with(self);
}
_ => {
ty.super_visit_with(self);
Expand Down Expand Up @@ -902,7 +902,7 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> {
ty::Generator(def_id, substs, movability) => {
let generics = self.tcx.generics_of(def_id);
let substs =
self.tcx.mk_substs(substs.substs.iter().enumerate().map(|(index, &kind)| {
self.tcx.mk_substs(substs.iter().enumerate().map(|(index, &kind)| {
if index < generics.parent_count {
// Accommodate missing regions in the parent kinds...
self.fold_kind_mapping_missing_regions_to_empty(kind)
Expand All @@ -912,7 +912,7 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> {
}
}));

self.tcx.mk_generator(def_id, ty::GeneratorSubsts { substs }, movability)
self.tcx.mk_generator(def_id, substs, movability)
}

ty::Param(..) => {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::ty::layout::VariantIdx;
use crate::ty::print::{FmtPrinter, Printer};
use crate::ty::subst::{Subst, SubstsRef};
use crate::ty::{
self, AdtDef, CanonicalUserTypeAnnotations, GeneratorSubsts, Region, Ty, TyCtxt,
self, AdtDef, CanonicalUserTypeAnnotations, Region, Ty, TyCtxt,
UserTypeAnnotationIndex,
};

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

Closure(DefId, SubstsRef<'tcx>),
Generator(DefId, GeneratorSubsts<'tcx>, hir::GeneratorMovability),
Generator(DefId, SubstsRef<'tcx>, hir::GeneratorMovability),
}

#[derive(Copy, Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/mir/tcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl<'tcx> Rvalue<'tcx> {
let ty = place.ty(local_decls, tcx).ty;
match ty.kind {
ty::Adt(adt_def, _) => adt_def.repr.discr_type().to_ty(tcx),
ty::Generator(_, substs, _) => substs.discr_ty(tcx),
ty::Generator(_, substs, _) => substs.as_generator().discr_ty(tcx),
_ => {
// This can only be `0`, for now, so `u8` will suffice.
tcx.types.u8
Expand Down
14 changes: 2 additions & 12 deletions src/librustc/mir/visit.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::ty::subst::SubstsRef;
use crate::ty::{CanonicalUserTypeAnnotation, GeneratorSubsts, Ty};
use crate::ty::{CanonicalUserTypeAnnotation, Ty};
use crate::mir::*;
use syntax_pos::Span;

Expand Down Expand Up @@ -230,12 +230,6 @@ macro_rules! make_mir_visitor {
self.super_substs(substs);
}

fn visit_generator_substs(&mut self,
substs: & $($mutability)? GeneratorSubsts<'tcx>,
_: Location) {
self.super_generator_substs(substs);
}

fn visit_local_decl(&mut self,
local: Local,
local_decl: & $($mutability)? LocalDecl<'tcx>) {
Expand Down Expand Up @@ -628,7 +622,7 @@ macro_rules! make_mir_visitor {
generator_substs,
_movability,
) => {
self.visit_generator_substs(generator_substs, location);
self.visit_substs(generator_substs, location);
}
}

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

fn super_generator_substs(&mut self,
_substs: & $($mutability)? GeneratorSubsts<'tcx>) {
}

// Convenience methods

fn visit_location(&mut self, body: & $($mutability)? Body<'tcx>, location: Location) {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ pub struct VtableImplData<'tcx, N> {
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)]
pub struct VtableGeneratorData<'tcx, N> {
pub generator_def_id: DefId,
pub substs: ty::GeneratorSubsts<'tcx>,
pub substs: SubstsRef<'tcx>,
/// Nested obligations. This can be non-empty if the generator
/// signature contains associated types.
pub nested: Vec<N>
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ fn confirm_generator_candidate<'cx, 'tcx>(
obligation: &ProjectionTyObligation<'tcx>,
vtable: VtableGeneratorData<'tcx, PredicateObligation<'tcx>>,
) -> Progress<'tcx> {
let gen_sig = vtable.substs.poly_sig(vtable.generator_def_id, selcx.tcx());
let gen_sig = vtable.substs.as_generator().poly_sig(vtable.generator_def_id, selcx.tcx());
let Normalized {
value: gen_sig,
obligations
Expand Down
11 changes: 6 additions & 5 deletions src/librustc/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2761,8 +2761,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
.collect(),

ty::Generator(def_id, ref substs, _) => {
let witness = substs.witness(def_id, self.tcx());
let witness = substs.as_generator().witness(def_id, self.tcx());
substs
.as_generator()
.upvar_tys(def_id, self.tcx())
.chain(iter::once(witness))
.collect()
Expand Down Expand Up @@ -3324,8 +3325,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
)?);

Ok(VtableGeneratorData {
generator_def_id: generator_def_id,
substs: substs.clone(),
generator_def_id,
substs,
nested: obligations,
})
}
Expand Down Expand Up @@ -3911,9 +3912,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
&mut self,
obligation: &TraitObligation<'tcx>,
closure_def_id: DefId,
substs: ty::GeneratorSubsts<'tcx>,
substs: SubstsRef<'tcx>,
) -> ty::PolyTraitRef<'tcx> {
let gen_sig = substs.poly_sig(closure_def_id, self.tcx());
let gen_sig = substs.as_generator().poly_sig(closure_def_id, self.tcx());

// (1) Feels icky to skip the binder here, but OTOH we know
// that the self-type is an generator type and hence is
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::traits;
use crate::traits::{Clause, Clauses, GoalKind, Goal, Goals};
use crate::ty::{self, DefIdTree, Ty, TypeAndMut};
use crate::ty::{TyS, TyKind, List};
use crate::ty::{AdtKind, AdtDef, GeneratorSubsts, Region, Const};
use crate::ty::{AdtKind, AdtDef, Region, Const};
use crate::ty::{PolyFnSig, InferTy, ParamTy, ProjectionTy, ExistentialPredicate, Predicate};
use crate::ty::RegionKind;
use crate::ty::{TyVar, TyVid, IntVar, IntVid, FloatVar, FloatVid, ConstVid};
Expand Down Expand Up @@ -2510,7 +2510,7 @@ impl<'tcx> TyCtxt<'tcx> {
#[inline]
pub fn mk_generator(self,
id: DefId,
generator_substs: GeneratorSubsts<'tcx>,
generator_substs: SubstsRef<'tcx>,
movability: hir::GeneratorMovability)
-> Ty<'tcx> {
self.mk_ty(Generator(id, generator_substs, movability))
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl FlagComputation {
&ty::Generator(_, ref substs, _) => {
self.add_flags(TypeFlags::HAS_TY_CLOSURE);
self.add_flags(TypeFlags::HAS_FREE_LOCAL_NAMES);
self.add_substs(&substs.substs);
self.add_substs(substs);
}

&ty::GeneratorWitness(ref ts) => {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl<'tcx> Instance<'tcx> {
))
}
ty::Generator(def_id, substs, _) => {
let sig = substs.poly_sig(def_id, tcx);
let sig = substs.as_generator().poly_sig(def_id, tcx);

let env_region = ty::ReLateBound(ty::INNERMOST, ty::BrEnv);
let env_ty = tcx.mk_mut_ref(tcx.mk_region(env_region), ty);
Expand Down Expand Up @@ -395,7 +395,7 @@ fn resolve_associated_item<'tcx>(
traits::VtableGenerator(generator_data) => {
Some(Instance {
def: ty::InstanceDef::Item(generator_data.generator_def_id),
substs: generator_data.substs.substs
substs: generator_data.substs
})
}
traits::VtableClosure(closure_data) => {
Expand Down
19 changes: 9 additions & 10 deletions src/librustc/ty/layout.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::session::{self, DataTypeKind};
use crate::ty::{self, Ty, TyCtxt, TypeFoldable, ReprOptions};
use crate::ty::{self, Ty, TyCtxt, TypeFoldable, ReprOptions, subst::SubstsRef};

use syntax::ast::{self, Ident, IntTy, UintTy};
use syntax::attr;
Expand All @@ -15,7 +15,6 @@ use std::ops::Bound;
use crate::hir;
use crate::ich::StableHashingContext;
use crate::mir::{GeneratorLayout, GeneratorSavedLocal};
use crate::ty::GeneratorSubsts;
use crate::ty::subst::Subst;
use rustc_index::bit_set::BitSet;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
Expand Down Expand Up @@ -671,7 +670,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
tcx.intern_layout(unit)
}

ty::Generator(def_id, substs, _) => self.generator_layout(ty, def_id, &substs)?,
ty::Generator(def_id, substs, _) => self.generator_layout(ty, def_id, substs)?,

ty::Closure(def_id, ref substs) => {
let tys = substs.as_closure().upvar_tys(def_id, tcx);
Expand Down Expand Up @@ -1406,22 +1405,22 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
&self,
ty: Ty<'tcx>,
def_id: hir::def_id::DefId,
substs: &GeneratorSubsts<'tcx>,
substs: SubstsRef<'tcx>,
) -> Result<&'tcx LayoutDetails, LayoutError<'tcx>> {
use SavedLocalEligibility::*;
let tcx = self.tcx;

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

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

// Build a prefix layout, including "promoting" all ineligible
// locals as part of the prefix. We compute the layout of all of
// these fields at once to get optimal packing.
let discr_index = substs.prefix_tys(def_id, tcx).count();
let discr_index = substs.as_generator().prefix_tys(def_id, tcx).count();
// FIXME(eddyb) set the correct vaidity range for the discriminant.
let discr_layout = self.layout_of(substs.discr_ty(tcx))?;
let discr_layout = self.layout_of(substs.as_generator().discr_ty(tcx))?;
let discr = match &discr_layout.abi {
Abi::Scalar(s) => s.clone(),
_ => bug!(),
Expand All @@ -1430,7 +1429,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
.map(|local| subst_field(info.field_tys[local]))
.map(|ty| tcx.mk_maybe_uninit(ty))
.map(|ty| self.layout_of(ty));
let prefix_layouts = substs.prefix_tys(def_id, tcx)
let prefix_layouts = substs.as_generator().prefix_tys(def_id, tcx)
.map(|ty| self.layout_of(ty))
.chain(iter::once(Ok(discr_layout)))
.chain(promoted_layouts)
Expand Down Expand Up @@ -2153,15 +2152,15 @@ where
ty::Generator(def_id, ref substs, _) => {
match this.variants {
Variants::Single { index } => {
substs.state_tys(def_id, tcx)
substs.as_generator().state_tys(def_id, tcx)
.nth(index.as_usize()).unwrap()
.nth(i).unwrap()
}
Variants::Multiple { ref discr, discr_index, .. } => {
if i == discr_index {
return discr_layout(discr);
}
substs.prefix_tys(def_id, tcx).nth(i).unwrap()
substs.as_generator().prefix_tys(def_id, tcx).nth(i).unwrap()
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/outlives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl<'tcx> TyCtxt<'tcx> {

ty::Generator(def_id, ref substs, _) => {
// Same as the closure case
for upvar_ty in substs.upvar_tys(def_id, *self) {
for upvar_ty in substs.as_generator().upvar_tys(def_id, *self) {
self.compute_components(upvar_ty, out);
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/print/obsolete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use rustc::hir::def_id::DefId;
use rustc::mir::interpret::ConstValue;
use rustc::ty::subst::SubstsRef;
use rustc::ty::{self, Const, GeneratorSubsts, Instance, Ty, TyCtxt};
use rustc::ty::{self, Const, Instance, Ty, TyCtxt};
use rustc::{bug, hir};
use std::fmt::Write;
use std::iter;
Expand Down Expand Up @@ -154,7 +154,7 @@ impl DefPathBasedNames<'tcx> {
self.push_type_name(sig.output(), output, debug);
}
}
ty::Generator(def_id, GeneratorSubsts { substs }, _)
ty::Generator(def_id, substs, _)
| ty::Closure(def_id, substs) => {
self.push_def_path(def_id, output);
let generics = self.tcx.generics_of(self.tcx.closure_base_def_id(def_id));
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,8 @@ pub trait PrettyPrinter<'tcx>:
}
ty::Str => p!(write("str")),
ty::Generator(did, substs, movability) => {
let upvar_tys = substs.upvar_tys(did, self.tcx());
let witness = substs.witness(did, self.tcx());
let upvar_tys = substs.as_generator().upvar_tys(did, self.tcx());
let witness = substs.as_generator().witness(did, self.tcx());
if movability == hir::GeneratorMovability::Movable {
p!(write("[generator"));
} else {
Expand Down
17 changes: 9 additions & 8 deletions src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ pub enum TyKind<'tcx> {

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

/// A type representin the types stored inside a generator.
/// This should only appear in GeneratorInteriors.
Expand Down Expand Up @@ -512,7 +512,7 @@ impl<'tcx> GeneratorSubsts<'tcx> {
/// variant indices.
#[inline]
pub fn discriminants(
&'tcx self,
self,
def_id: DefId,
tcx: TyCtxt<'tcx>,
) -> impl Iterator<Item = (VariantIdx, Discr<'tcx>)> + Captures<'tcx> {
Expand All @@ -524,7 +524,7 @@ impl<'tcx> GeneratorSubsts<'tcx> {
/// Calls `f` with a reference to the name of the enumerator for the given
/// variant `v`.
#[inline]
pub fn variant_name(&self, v: VariantIdx) -> Cow<'static, str> {
pub fn variant_name(self, v: VariantIdx) -> Cow<'static, str> {
match v.as_usize() {
Self::UNRESUMED => Cow::from(Self::UNRESUMED_NAME),
Self::RETURNED => Cow::from(Self::RETURNED_NAME),
Expand Down Expand Up @@ -570,7 +570,7 @@ impl<'tcx> GeneratorSubsts<'tcx> {
#[derive(Debug, Copy, Clone)]
pub enum UpvarSubsts<'tcx> {
Closure(SubstsRef<'tcx>),
Generator(GeneratorSubsts<'tcx>),
Generator(SubstsRef<'tcx>),
}

impl<'tcx> UpvarSubsts<'tcx> {
Expand All @@ -582,7 +582,7 @@ impl<'tcx> UpvarSubsts<'tcx> {
) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
let upvar_kinds = match self {
UpvarSubsts::Closure(substs) => substs.as_closure().split(def_id, tcx).upvar_kinds,
UpvarSubsts::Generator(substs) => substs.split(def_id, tcx).upvar_kinds,
UpvarSubsts::Generator(substs) => substs.as_generator().split(def_id, tcx).upvar_kinds,
};
upvar_kinds.iter().map(|t| {
if let GenericArgKind::Type(ty) = t.unpack() {
Expand Down Expand Up @@ -2109,7 +2109,8 @@ impl<'tcx> TyS<'tcx> {
pub fn variant_range(&self, tcx: TyCtxt<'tcx>) -> Option<Range<VariantIdx>> {
match self.kind {
TyKind::Adt(adt, _) => Some(adt.variant_range()),
TyKind::Generator(def_id, substs, _) => Some(substs.variant_range(def_id, tcx)),
TyKind::Generator(def_id, substs, _) =>
Some(substs.as_generator().variant_range(def_id, tcx)),
_ => None,
}
}
Expand All @@ -2126,7 +2127,7 @@ impl<'tcx> TyS<'tcx> {
match self.kind {
TyKind::Adt(adt, _) => Some(adt.discriminant_for_variant(tcx, variant_index)),
TyKind::Generator(def_id, substs, _) =>
Some(substs.discriminant_for_variant(def_id, tcx, variant_index)),
Some(substs.as_generator().discriminant_for_variant(def_id, tcx, variant_index)),
_ => None,
}
}
Expand All @@ -2149,7 +2150,7 @@ impl<'tcx> TyS<'tcx> {
out.extend(substs.regions())
}
Closure(_, ref substs ) |
Generator(_, GeneratorSubsts { ref substs }, _) => {
Generator(_, ref substs, _) => {
out.extend(substs.regions())
}
Projection(ref data) | UnnormalizedProjection(ref data) => {
Expand Down
Loading

0 comments on commit 7739f17

Please sign in to comment.