]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #69968 - eddyb:tupled-closure-captures, r=nikomatsakis
authorMazdak Farrokhzad <twingoow@gmail.com>
Mon, 23 Mar 2020 09:29:11 +0000 (10:29 +0100)
committerGitHub <noreply@github.com>
Mon, 23 Mar 2020 09:29:11 +0000 (10:29 +0100)
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

14 files changed:
1  2 
src/librustc/ty/instance.rs
src/librustc/ty/layout.rs
src/librustc_codegen_llvm/debuginfo/metadata.rs
src/librustc_infer/infer/error_reporting/need_type_info.rs
src/librustc_infer/infer/mod.rs
src/librustc_metadata/rmeta/encoder.rs
src/librustc_mir/borrow_check/diagnostics/move_errors.rs
src/librustc_mir_build/build/mod.rs
src/librustc_trait_selection/traits/error_reporting/mod.rs
src/librustc_trait_selection/traits/error_reporting/suggestions.rs
src/librustc_trait_selection/traits/fulfill.rs
src/librustc_trait_selection/traits/select.rs
src/librustc_typeck/check/mod.rs
src/librustc_typeck/collect.rs

Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge