diff options
| author | Aman Arora <me@aman-arora.com> | 2021-05-05 15:57:08 -0400 |
|---|---|---|
| committer | Aman Arora <me@aman-arora.com> | 2021-06-28 14:21:55 -0400 |
| commit | fc273e9bf2ab4594e8dcdb737b63bffb3f6b08c9 (patch) | |
| tree | 5d4c81800d048385b8b3d24b8f70bad4ad03bdae /compiler/rustc_middle | |
| parent | 3e9d7ecf784e5ecaf7437d04be3992ad23fa7cb6 (diff) | |
| download | rust-fc273e9bf2ab4594e8dcdb737b63bffb3f6b08c9.tar.gz rust-fc273e9bf2ab4594e8dcdb737b63bffb3f6b08c9.zip | |
Introduce -Zprofile-closures to evaluate the impact of 2229
This creates a CSV with name "closure_profile_XXXXX.csv", where the variable part is the process id of the compiler. To profile a cargo project you can run one of the following depending on if you're compiling a library or a binary: ``` cargo +stage1 rustc --lib -- -Zprofile-closures cargo +stage1 rustc --bin -- -Zprofile-closures ```
Diffstat (limited to 'compiler/rustc_middle')
| -rw-r--r-- | compiler/rustc_middle/src/ty/context.rs | 18 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/mod.rs | 19 |
2 files changed, 32 insertions, 5 deletions
diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 77f955e93b9..6e910d0087f 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -19,11 +19,12 @@ use crate::ty::query::{self, OnDiskCache, TyCtxtAt}; use crate::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, Subst, SubstsRef, UserSubsts}; use crate::ty::TyKind::*; use crate::ty::{ - self, AdtDef, AdtKind, Binder, BindingMode, BoundVar, CanonicalPolyFnSig, Const, ConstVid, - DefIdTree, ExistentialPredicate, FloatTy, FloatVar, FloatVid, GenericParamDefKind, InferConst, - InferTy, IntTy, IntVar, IntVid, List, MainDefinition, ParamConst, ParamTy, PolyFnSig, - Predicate, PredicateInner, PredicateKind, ProjectionTy, Region, RegionKind, ReprOptions, - TraitObjectVisitor, Ty, TyKind, TyS, TyVar, TyVid, TypeAndMut, UintTy, Visibility, + self, AdtDef, AdtKind, Binder, BindingMode, BoundVar, CanonicalPolyFnSig, + ClosureSizeProfileData, Const, ConstVid, DefIdTree, ExistentialPredicate, FloatTy, FloatVar, + FloatVid, GenericParamDefKind, InferConst, InferTy, IntTy, IntVar, IntVid, List, + MainDefinition, ParamConst, ParamTy, PolyFnSig, Predicate, PredicateInner, PredicateKind, + ProjectionTy, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyS, TyVar, + TyVid, TypeAndMut, UintTy, Visibility, }; use rustc_ast as ast; use rustc_ast::expand::allocator::AllocatorKind; @@ -484,6 +485,10 @@ pub struct TypeckResults<'tcx> { /// This hashset records all instances where we behave /// like this to allow `const_to_pat` to reliably handle this situation. pub treat_byte_string_as_slice: ItemLocalSet, + + /// Contains the data for evaluating the effect of feature `capture_disjoint_fields` + /// on closure size. + pub closure_size_eval: FxHashMap<DefId, ClosureSizeProfileData<'tcx>>, } impl<'tcx> TypeckResults<'tcx> { @@ -510,6 +515,7 @@ impl<'tcx> TypeckResults<'tcx> { closure_fake_reads: Default::default(), generator_interior_types: ty::Binder::dummy(Default::default()), treat_byte_string_as_slice: Default::default(), + closure_size_eval: Default::default(), } } @@ -754,6 +760,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for TypeckResults<'tcx> { ref closure_fake_reads, ref generator_interior_types, ref treat_byte_string_as_slice, + ref closure_size_eval, } = *self; hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| { @@ -780,6 +787,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for TypeckResults<'tcx> { closure_fake_reads.hash_stable(hcx, hasher); generator_interior_types.hash_stable(hcx, hasher); treat_byte_string_as_slice.hash_stable(hcx, hasher); + closure_size_eval.hash_stable(hcx, hasher); }) } } diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index a2abbec7492..dc5687de896 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -173,6 +173,25 @@ pub enum Visibility { Invisible, } +#[derive( + Clone, + Debug, + PartialEq, + Eq, + Copy, + Hash, + TyEncodable, + TyDecodable, + HashStable, + TypeFoldable +)] +pub struct ClosureSizeProfileData<'tcx> { + /// Tuple containing the types of closure captures before the feature `capture_disjoint_fields` + pub before_feature_tys: Ty<'tcx>, + /// Tuple containing the types of closure captures after the feature `capture_disjoint_fields` + pub after_feature_tys: Ty<'tcx>, +} + pub trait DefIdTree: Copy { fn parent(self, id: DefId) -> Option<DefId>; |
