@@ -811,34 +811,48 @@ pub struct CtxtInterners<'tcx> {
811811}
812812
813813impl < ' tcx > CtxtInterners < ' tcx > {
814- fn new ( arena : & ' tcx WorkerLocal < Arena < ' tcx > > ) -> CtxtInterners < ' tcx > {
814+ fn new ( arena : & ' tcx WorkerLocal < Arena < ' tcx > > ) -> CtxtInterners < ' tcx > {
815815 CtxtInterners {
816816 arena,
817- // There are likely to be a lot of types. This should occupy 0.4 MB.
818- type_ : InternedSet :: with_capacity ( 16384 ) ,
819- const_lists : InternedSet :: with_capacity ( 4096 ) ,
820- args : InternedSet :: with_capacity ( 4096 ) ,
821- type_lists : InternedSet :: with_capacity ( 4096 ) ,
817+ // From some experiments, it looks like there usualy are < 2^20 types.
818+ // 2^20 * 24 bytes ~ 25 MB, which is acceptable IMHO.
819+ type_ : InternedSet :: with_capacity ( 1048576 ) ,
820+ // Const lists don't seem to be too common, but I still reserver 128 of them, since
821+ // it is cheap anyway
822+ const_lists : InternedSet :: with_capacity ( 128 ) ,
823+ // From some experiments, it looks like there usualy are < 2^20 arg lists.
824+ // 2^20 * 8 bytes ~ 9 MB, which is acceptable IMHO.
825+ args : InternedSet :: with_capacity ( 1048576 ) ,
826+ // From some experiments, it looks like there usualy are < 2^19 type_lists.
827+ type_lists : InternedSet :: with_capacity ( 524288 ) ,
822828 region : InternedSet :: with_capacity ( 4096 ) ,
823- poly_existential_predicates : InternedSet :: with_capacity ( 1024 ) ,
824- canonical_var_infos : InternedSet :: with_capacity ( 1024 ) ,
825- predicate : InternedSet :: with_capacity ( 1024 ) ,
829+ // There are usually very few `poly_existential_predicates` - for cargo, there were 119.
830+ // So, 256 ought to be more than enough for all cases.
831+ poly_existential_predicates : InternedSet :: with_capacity ( 256 ) ,
832+ // There is usually very few `canonical_var_infos` - for cargo, there were 379.
833+ // So, 512 ought to be more than enough for all cases.
834+ canonical_var_infos : InternedSet :: with_capacity ( 512 ) ,
835+ predicate : InternedSet :: with_capacity ( 1024 ) ,
826836 clauses : InternedSet :: with_capacity ( 1024 ) ,
827- projs : InternedSet :: with_capacity ( 4096 ) ,
828- place_elems : InternedSet :: with_capacity ( 4096 ) ,
837+ // Projs don't seem to be too common, but I still reserver 128 of them, since
838+ // it is cheap anyway
839+ projs : InternedSet :: with_capacity ( 128 ) ,
840+ // There semes to be > 2^16 place_elems.
841+ place_elems : InternedSet :: with_capacity ( 65536 ) ,
829842 const_ : InternedSet :: with_capacity ( 4096 ) ,
830843 pat : InternedSet :: with_capacity ( 1024 ) ,
831844 const_allocation : InternedSet :: with_capacity ( 1024 ) ,
832- bound_variable_kinds : InternedSet :: with_capacity ( 1024 ) ,
833- layout : InternedSet :: with_capacity ( 1024 ) ,
845+ // There is usually < 2^13 bound_variable_kinds
846+ bound_variable_kinds : InternedSet :: with_capacity ( 8192 ) ,
847+ layout : InternedSet :: with_capacity ( 4096 ) ,
834848 adt_def : InternedSet :: with_capacity ( 1024 ) ,
835849 external_constraints : InternedSet :: with_capacity ( 1024 ) ,
836850 predefined_opaques_in_body : InternedSet :: with_capacity ( 1024 ) ,
837851 fields : InternedSet :: with_capacity ( 4096 ) ,
838852 local_def_ids : InternedSet :: with_capacity ( 1024 ) ,
839853 captures : InternedSet :: with_capacity ( 1024 ) ,
840854 offset_of : InternedSet :: with_capacity ( 1024 ) ,
841- valtree : InternedSet :: with_capacity ( 1024 ) ,
855+ valtree : InternedSet :: with_capacity ( 1024 ) ,
842856 }
843857 }
844858
@@ -2550,6 +2564,7 @@ macro_rules! slice_interners {
25502564 ( $( $field: ident: $vis: vis $method: ident( $ty: ty) ) ,+ $( , ) ?) => (
25512565 impl <' tcx> TyCtxt <' tcx> {
25522566 $( $vis fn $method( self , v: & [ $ty] ) -> & ' tcx List <$ty> {
2567+ //eprintln!("{} len:{}",stringify!($field), self.interners.$field.len());
25532568 if v. is_empty( ) {
25542569 List :: empty( )
25552570 } else {
@@ -2848,6 +2863,7 @@ impl<'tcx> TyCtxt<'tcx> {
28482863 // FIXME consider asking the input slice to be sorted to avoid
28492864 // re-interning permutations, in which case that would be asserted
28502865 // here.
2866+
28512867 self . intern_local_def_ids ( clauses)
28522868 }
28532869
0 commit comments