Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace ClosureSubsts with SubstsRef #64817

Merged
merged 4 commits into from
Oct 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/librustc/infer/error_reporting/need_type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {

let ty_msg = match local_visitor.found_ty {
Some(ty::TyS { kind: ty::Closure(def_id, substs), .. }) => {
let fn_sig = substs.closure_sig(*def_id, self.tcx);
let fn_sig = substs.as_closure().sig(*def_id, self.tcx);
let args = closure_args(&fn_sig);
let ret = fn_sig.output().skip_binder().to_string();
format!(" for the closure `fn({}) -> {}`", args, ret)
Expand Down Expand Up @@ -255,7 +255,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {

let suffix = match local_visitor.found_ty {
Some(ty::TyS { kind: ty::Closure(def_id, substs), .. }) => {
let fn_sig = substs.closure_sig(*def_id, self.tcx);
let fn_sig = substs.as_closure().sig(*def_id, self.tcx);
let ret = fn_sig.output().skip_binder().to_string();

if let Some(ExprKind::Closure(_, decl, body_id, ..)) = local_visitor.found_closure {
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1481,9 +1481,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
pub fn closure_kind(
&self,
closure_def_id: DefId,
closure_substs: ty::ClosureSubsts<'tcx>,
closure_substs: SubstsRef<'tcx>,
) -> Option<ty::ClosureKind> {
let closure_kind_ty = closure_substs.closure_kind_ty(closure_def_id, self.tcx);
let closure_kind_ty = closure_substs.as_closure().kind_ty(closure_def_id, self.tcx);
let closure_kind_ty = self.shallow_resolve(closure_kind_ty);
closure_kind_ty.to_opt_closure_kind()
}
Expand All @@ -1495,9 +1495,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
pub fn closure_sig(
&self,
def_id: DefId,
substs: ty::ClosureSubsts<'tcx>,
substs: SubstsRef<'tcx>,
) -> ty::PolyFnSig<'tcx> {
let closure_sig_ty = substs.closure_sig_ty(def_id, self.tcx);
let closure_sig_ty = substs.as_closure().sig_ty(def_id, self.tcx);
let closure_sig_ty = self.shallow_resolve(closure_sig_ty);
closure_sig_ty.fn_sig(self.tcx)
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/infer/opaque_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,11 +722,11 @@ where
ty::Closure(def_id, ref substs) => {
// Skip lifetime parameters of the enclosing item(s)

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

substs.closure_sig_ty(def_id, self.tcx).visit_with(self);
substs.as_closure().sig_ty(def_id, self.tcx).visit_with(self);
}

ty::Generator(def_id, ref substs, _) => {
Expand Down Expand Up @@ -886,7 +886,7 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> {

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 @@ -896,7 +896,7 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> {
}
}));

self.tcx.mk_closure(def_id, ty::ClosureSubsts { substs })
self.tcx.mk_closure(def_id, substs)
}

ty::Generator(def_id, substs, movability) => {
Expand Down
10 changes: 6 additions & 4 deletions src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,16 +740,18 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
let ty = self.node_ty(fn_hir_id)?;
let kind = match ty.kind {
ty::Generator(..) => ty::ClosureKind::FnOnce,
ty::Closure(closure_def_id, closure_substs) => {
ty::Closure(closure_def_id, substs) => {
match self.infcx {
// During upvar inference we may not know the
// closure kind, just use the LATTICE_BOTTOM value.
Some(infcx) =>
infcx.closure_kind(closure_def_id, closure_substs)
.unwrap_or(ty::ClosureKind::LATTICE_BOTTOM),
infcx.closure_kind(
closure_def_id,
substs
).unwrap_or(ty::ClosureKind::LATTICE_BOTTOM),

None =>
closure_substs.closure_kind(closure_def_id, self.tcx),
substs.as_closure().kind(closure_def_id, self.tcx),
}
}
_ => span_bug!(span, "unexpected type for fn in mem_categorization: {:?}", ty),
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, ClosureSubsts, GeneratorSubsts, Region, Ty, TyCtxt,
self, AdtDef, CanonicalUserTypeAnnotations, GeneratorSubsts, Region, Ty, TyCtxt,
UserTypeAnnotationIndex,
};

Expand Down Expand Up @@ -2188,7 +2188,7 @@ pub enum AggregateKind<'tcx> {
/// active field index would identity the field `c`
Adt(&'tcx AdtDef, VariantIdx, SubstsRef<'tcx>, Option<UserTypeAnnotationIndex>, Option<usize>),

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

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, ClosureSubsts, GeneratorSubsts, Ty};
use crate::ty::{CanonicalUserTypeAnnotation, GeneratorSubsts, Ty};
use crate::mir::*;
use syntax_pos::Span;

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

fn visit_closure_substs(&mut self,
substs: & $($mutability)? ClosureSubsts<'tcx>,
_: Location) {
self.super_closure_substs(substs);
}

fn visit_generator_substs(&mut self,
substs: & $($mutability)? GeneratorSubsts<'tcx>,
_: Location) {
Expand Down Expand Up @@ -618,7 +612,7 @@ macro_rules! make_mir_visitor {
_,
closure_substs
) => {
self.visit_closure_substs(closure_substs, location);
self.visit_substs(closure_substs, location);
}
AggregateKind::Generator(
_,
Expand Down Expand Up @@ -838,10 +832,6 @@ macro_rules! make_mir_visitor {
_substs: & $($mutability)? GeneratorSubsts<'tcx>) {
}

fn super_closure_substs(&mut self,
_substs: & $($mutability)? ClosureSubsts<'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 @@ -619,7 +619,7 @@ pub struct VtableGeneratorData<'tcx, N> {
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)]
pub struct VtableClosureData<'tcx, N> {
pub closure_def_id: DefId,
pub substs: ty::ClosureSubsts<'tcx>,
pub substs: SubstsRef<'tcx>,
/// Nested obligations. This can be non-empty if the closure
/// signature contains associated types.
pub nested: Vec<N>
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,8 @@ fn confirm_closure_candidate<'cx, 'tcx>(
) -> Progress<'tcx> {
let tcx = selcx.tcx();
let infcx = selcx.infcx();
let closure_sig_ty = vtable.substs.closure_sig_ty(vtable.closure_def_id, tcx);
let closure_sig_ty = vtable.substs
.as_closure().sig_ty(vtable.closure_def_id, tcx);
let closure_sig = infcx.shallow_resolve(closure_sig_ty).fn_sig(tcx);
let Normalized {
value: closure_sig,
Expand Down
1 change: 1 addition & 0 deletions src/librustc/traits/query/dropck_outlives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
// check if *any* of those are trivial.
ty::Tuple(ref tys) => tys.iter().all(|t| trivial_dropck_outlives(tcx, t.expect_ty())),
ty::Closure(def_id, ref substs) => substs
.as_closure()
.upvar_tys(def_id, tcx)
.all(|t| trivial_dropck_outlives(tcx, t)),

Expand Down
22 changes: 16 additions & 6 deletions src/librustc/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2051,7 +2051,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
"assemble_unboxed_candidates: kind={:?} obligation={:?}",
kind, obligation
);
match self.infcx.closure_kind(closure_def_id, closure_substs) {
match self.infcx.closure_kind(
closure_def_id,
closure_substs
) {
Some(closure_kind) => {
debug!(
"assemble_unboxed_candidates: closure_kind = {:?}",
Expand Down Expand Up @@ -2669,7 +2672,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ty::Closure(def_id, substs) => {
// (*) binder moved here
Where(ty::Binder::bind(
substs.upvar_tys(def_id, self.tcx()).collect(),
substs.as_closure().upvar_tys(def_id, self.tcx()).collect(),
))
}

Expand Down Expand Up @@ -2753,7 +2756,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
tys.iter().map(|k| k.expect_ty()).collect()
}

ty::Closure(def_id, ref substs) => substs.upvar_tys(def_id, self.tcx()).collect(),
ty::Closure(def_id, ref substs) => substs.as_closure()
.upvar_tys(def_id, self.tcx())
.collect(),

ty::Generator(def_id, ref substs, _) => {
let witness = substs.witness(def_id, self.tcx());
Expand Down Expand Up @@ -3370,17 +3375,22 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
)?);

// FIXME: chalk

if !self.tcx().sess.opts.debugging_opts.chalk {
obligations.push(Obligation::new(
obligation.cause.clone(),
obligation.param_env,
ty::Predicate::ClosureKind(closure_def_id, substs, kind),
ty::Predicate::ClosureKind(
closure_def_id,
substs,
kind
),
));
}

Ok(VtableClosureData {
closure_def_id,
substs: substs.clone(),
substs: substs,
nested: obligations,
})
}
Expand Down Expand Up @@ -3869,7 +3879,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
&mut self,
obligation: &TraitObligation<'tcx>,
closure_def_id: DefId,
substs: ty::ClosureSubsts<'tcx>,
substs: SubstsRef<'tcx>,
) -> ty::PolyTraitRef<'tcx> {
debug!(
"closure_trait_ref_unnormalized(obligation={:?}, closure_def_id={:?}, substs={:?})",
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, ClosureSubsts, GeneratorSubsts, Region, Const};
use crate::ty::{AdtKind, AdtDef, GeneratorSubsts, 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 @@ -2482,7 +2482,7 @@ impl<'tcx> TyCtxt<'tcx> {
}

#[inline]
pub fn mk_closure(self, closure_id: DefId, closure_substs: ClosureSubsts<'tcx>)
pub fn mk_closure(self, closure_id: DefId, closure_substs: SubstsRef<'tcx>)
-> Ty<'tcx> {
self.mk_ty(Closure(closure_id, closure_substs))
}
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 @@ -106,7 +106,7 @@ impl FlagComputation {
&ty::Closure(_, 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::Bound(debruijn, _) => {
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/ty/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl<'tcx> Instance<'tcx> {
// Shims currently have type FnPtr. Not sure this should remain.
ty::FnPtr(_) => ty.fn_sig(tcx),
ty::Closure(def_id, substs) => {
let sig = substs.closure_sig(def_id, tcx);
let sig = substs.as_closure().sig(def_id, tcx);

let env_ty = tcx.closure_env_ty(def_id, substs).unwrap();
sig.map_bound(|sig| tcx.mk_fn_sig(
Expand Down Expand Up @@ -315,14 +315,14 @@ impl<'tcx> Instance<'tcx> {
pub fn resolve_closure(
tcx: TyCtxt<'tcx>,
def_id: DefId,
substs: ty::ClosureSubsts<'tcx>,
substs: ty::SubstsRef<'tcx>,
requested_kind: ty::ClosureKind,
) -> Instance<'tcx> {
let actual_kind = substs.closure_kind(def_id, tcx);
let actual_kind = substs.as_closure().kind(def_id, tcx);

match needs_fn_once_adapter_shim(actual_kind, requested_kind) {
Ok(true) => Instance::fn_once_adapter_instance(tcx, def_id, substs),
_ => Instance::new(def_id, substs.substs)
_ => Instance::new(def_id, substs)
}
}

Expand All @@ -335,7 +335,7 @@ impl<'tcx> Instance<'tcx> {
pub fn fn_once_adapter_instance(
tcx: TyCtxt<'tcx>,
closure_did: DefId,
substs: ty::ClosureSubsts<'tcx>,
substs: ty::SubstsRef<'tcx>,
) -> Instance<'tcx> {
debug!("fn_once_adapter_shim({:?}, {:?})",
closure_did,
Expand All @@ -348,7 +348,7 @@ impl<'tcx> Instance<'tcx> {

let self_ty = tcx.mk_closure(closure_did, substs);

let sig = substs.closure_sig(closure_did, tcx);
let sig = substs.as_closure().sig(closure_did, tcx);
let sig = tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
assert_eq!(sig.inputs().len(), 1);
let substs = tcx.mk_substs_trait(self_ty, &[sig.inputs()[0].into()]);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
ty::Generator(def_id, substs, _) => self.generator_layout(ty, def_id, &substs)?,

ty::Closure(def_id, ref substs) => {
let tys = substs.upvar_tys(def_id, tcx);
let tys = substs.as_closure().upvar_tys(def_id, tcx);
univariant(&tys.map(|ty| self.layout_of(ty)).collect::<Result<Vec<_>, _>>()?,
&ReprOptions::default(),
StructKind::AlwaysSized)?
Expand Down Expand Up @@ -2147,7 +2147,7 @@ where

// Tuples, generators and closures.
ty::Closure(def_id, ref substs) => {
substs.upvar_tys(def_id, tcx).nth(i).unwrap()
substs.as_closure().upvar_tys(def_id, tcx).nth(i).unwrap()
}

ty::Generator(def_id, ref substs, _) => {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ pub enum Predicate<'tcx> {
/// No direct syntax. May be thought of as `where T: FnFoo<...>`
/// for some substitutions `...` and `T` being a closure type.
/// Satisfied (or refuted) once we know the closure's kind.
ClosureKind(DefId, ClosureSubsts<'tcx>, ClosureKind),
ClosureKind(DefId, SubstsRef<'tcx>, ClosureKind),

/// `T1 <: T2`
Subtype(PolySubtypePredicate<'tcx>),
Expand Down Expand Up @@ -1457,7 +1457,7 @@ impl<'tcx> Predicate<'tcx> {
WalkTysIter::None
}
ty::Predicate::ClosureKind(_closure_def_id, closure_substs, _kind) => {
WalkTysIter::Types(closure_substs.substs.types())
WalkTysIter::Types(closure_substs.types())
}
ty::Predicate::ConstEvaluatable(_, substs) => {
WalkTysIter::Types(substs.types())
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 @@ -62,7 +62,7 @@ impl<'tcx> TyCtxt<'tcx> {
// projection).
match ty.kind {
ty::Closure(def_id, ref substs) => {
for upvar_ty in substs.upvar_tys(def_id, *self) {
for upvar_ty in substs.as_closure().upvar_tys(def_id, *self) {
self.compute_components(upvar_ty, out);
}
}
Expand Down
6 changes: 3 additions & 3 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, ClosureSubsts, Const, GeneratorSubsts, Instance, Ty, TyCtxt};
use rustc::ty::{self, Const, GeneratorSubsts, Instance, Ty, TyCtxt};
use rustc::{bug, hir};
use std::fmt::Write;
use std::iter;
Expand Down Expand Up @@ -154,8 +154,8 @@ impl DefPathBasedNames<'tcx> {
self.push_type_name(sig.output(), output, debug);
}
}
ty::Generator(def_id, GeneratorSubsts { ref substs }, _)
| ty::Closure(def_id, ClosureSubsts { ref substs }) => {
ty::Generator(def_id, GeneratorSubsts { 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));
let substs = substs.truncate_to(self.tcx, generics);
Expand Down
Loading