Skip to content

Commit 6429062

Browse files
committedMar 13, 2020
Auto merge of #69968 - eddyb:tupled-closure-captures, r=<try>
rustc: keep upvars tupled in {Closure,Generator}Substs. Previously, each closure/generator capture's (aka "upvar") type was tracked as one "synthetic" type parameter in the closure/generator substs, and figuring out where the parent `fn`'s generics end and the synthetics start involved slicing at `tcx.generics_of(def_id).parent_count`. Needing to query `generics_of` limited @davidtwco (who wants to compute some `TypeFlags` differently for parent generics vs upvars, and `TyCtxt` is not available there), which is how I got started on this, but it's also possible that the `generics_of` queries are slowing down `{Closure,Generator}Substs` methods. To give an example, for a `foo::<T, U>::{closure#0}` with captures `x: X` and `y: Y`, substs are: * before this PR: `[T, U, /*kind*/, /*signature*/, X, Y]` * after this PR: `[T, U, /*kind*/, /*signature*/, (X, Y)]` You can see that, with this PR, no matter how many captures, the last 3 entries in the substs (or 5 for a generator) are always the "synthetic" ones, with the last one being the tuple of capture types. r? @nikomatsakis cc @Zoxc
2 parents 54b7d21 + da30907 commit 6429062

File tree

65 files changed

+335
-324
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+335
-324
lines changed
 

‎src/librustc/traits/query.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
229229
// (T1..Tn) and closures have same properties as T1..Tn --
230230
// check if *any* of those are trivial.
231231
ty::Tuple(ref tys) => tys.iter().all(|t| trivial_dropck_outlives(tcx, t.expect_ty())),
232-
ty::Closure(def_id, ref substs) => {
233-
substs.as_closure().upvar_tys(def_id, tcx).all(|t| trivial_dropck_outlives(tcx, t))
232+
ty::Closure(_, ref substs) => {
233+
substs.as_closure().upvar_tys().all(|t| trivial_dropck_outlives(tcx, t))
234234
}
235235

236236
ty::Adt(def, _) => {

‎src/librustc/ty/instance.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ impl<'tcx> Instance<'tcx> {
329329
substs: ty::SubstsRef<'tcx>,
330330
requested_kind: ty::ClosureKind,
331331
) -> Instance<'tcx> {
332-
let actual_kind = substs.as_closure().kind(def_id, tcx);
332+
let actual_kind = substs.as_closure().kind();
333333

334334
match needs_fn_once_adapter_shim(actual_kind, requested_kind) {
335335
Ok(true) => Instance::fn_once_adapter_instance(tcx, def_id, substs),
@@ -360,7 +360,7 @@ impl<'tcx> Instance<'tcx> {
360360

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

363-
let sig = substs.as_closure().sig(closure_did, tcx);
363+
let sig = substs.as_closure().sig();
364364
let sig = tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
365365
assert_eq!(sig.inputs().len(), 1);
366366
let substs = tcx.mk_substs_trait(self_ty, &[sig.inputs()[0].into()]);

0 commit comments

Comments
 (0)