@@ -756,16 +756,6 @@ pub struct ctxt<'tcx> {
756
756
/// Caches the representation hints for struct definitions.
757
757
pub repr_hint_cache : RefCell < DefIdMap < Rc < Vec < attr:: ReprAttr > > > > ,
758
758
759
- /// Caches whether types are known to impl Copy. Note that type
760
- /// parameters are never placed into this cache, because their
761
- /// results are dependent on the parameter environment.
762
- pub type_impls_copy_cache : RefCell < HashMap < Ty < ' tcx > , bool > > ,
763
-
764
- /// Caches whether types are known to impl Sized. Note that type
765
- /// parameters are never placed into this cache, because their
766
- /// results are dependent on the parameter environment.
767
- pub type_impls_sized_cache : RefCell < HashMap < Ty < ' tcx > , bool > > ,
768
-
769
759
/// Maps Expr NodeId's to their constant qualification.
770
760
pub const_qualif_map : RefCell < NodeMap < check_const:: ConstQualif > > ,
771
761
@@ -828,6 +818,17 @@ bitflags! {
828
818
TypeFlags :: HAS_SELF . bits |
829
819
TypeFlags :: HAS_REGIONS . bits,
830
820
821
+ // Flags representing the nominal content of a type,
822
+ // computed by FlagsComputetion
823
+ const NOMINAL_FLAGS = TypeFlags :: HAS_PARAMS . bits |
824
+ TypeFlags :: HAS_SELF . bits |
825
+ TypeFlags :: HAS_TY_INFER . bits |
826
+ TypeFlags :: HAS_RE_INFER . bits |
827
+ TypeFlags :: HAS_RE_LATE_BOUND . bits |
828
+ TypeFlags :: HAS_REGIONS . bits |
829
+ TypeFlags :: HAS_TY_ERR . bits |
830
+ TypeFlags :: HAS_PROJECTION . bits,
831
+
831
832
// Caches for type_is_sized, type_moves_by_default
832
833
const SIZEDNESS_CACHED = 1 << 16 ,
833
834
const IS_SIZED = 1 << 17 ,
@@ -2776,8 +2777,6 @@ pub fn mk_ctxt<'tcx>(s: Session,
2776
2777
stability : RefCell :: new ( stability) ,
2777
2778
selection_cache : traits:: SelectionCache :: new ( ) ,
2778
2779
repr_hint_cache : RefCell :: new ( DefIdMap ( ) ) ,
2779
- type_impls_copy_cache : RefCell :: new ( HashMap :: new ( ) ) ,
2780
- type_impls_sized_cache : RefCell :: new ( HashMap :: new ( ) ) ,
2781
2780
const_qualif_map : RefCell :: new ( NodeMap ( ) ) ,
2782
2781
custom_coerce_unsized_kinds : RefCell :: new ( DefIdMap ( ) ) ,
2783
2782
cast_kinds : RefCell :: new ( NodeMap ( ) ) ,
@@ -2908,7 +2907,7 @@ impl FlagComputation {
2908
2907
}
2909
2908
2910
2909
fn add_flags ( & mut self , flags : TypeFlags ) {
2911
- self . flags = self . flags | flags;
2910
+ self . flags = self . flags | ( flags & TypeFlags :: NOMINAL_FLAGS ) ;
2912
2911
}
2913
2912
2914
2913
fn add_depth ( & mut self , depth : u32 ) {
@@ -3917,18 +3916,27 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents {
3917
3916
}
3918
3917
}
3919
3918
3920
- fn type_impls_bound < ' a , ' tcx > ( param_env : & ParameterEnvironment < ' a , ' tcx > ,
3919
+ fn type_impls_bound < ' a , ' tcx > ( param_env : Option < & ParameterEnvironment < ' a , ' tcx > > ,
3920
+ tcx : & ty:: ctxt < ' tcx > ,
3921
3921
ty : Ty < ' tcx > ,
3922
3922
bound : ty:: BuiltinBound ,
3923
3923
span : Span )
3924
3924
-> bool
3925
3925
{
3926
- let infcx = infer:: new_infer_ctxt ( param_env. tcx ) ;
3926
+ let pe;
3927
+ let param_env = match param_env {
3928
+ Some ( e) => e,
3929
+ None => {
3930
+ pe = empty_parameter_environment ( tcx) ;
3931
+ & pe
3932
+ }
3933
+ } ;
3934
+ let infcx = infer:: new_infer_ctxt ( tcx) ;
3927
3935
3928
3936
let is_impld = traits:: type_known_to_meet_builtin_bound ( & infcx, param_env, ty, bound, span) ;
3929
3937
3930
3938
debug ! ( "type_impls_bound({}, {:?}) = {:?}" ,
3931
- ty. repr( param_env . tcx) ,
3939
+ ty. repr( tcx) ,
3932
3940
bound,
3933
3941
is_impld) ;
3934
3942
@@ -3960,7 +3968,11 @@ pub fn type_moves_by_default<'a,'tcx>(param_env: &ParameterEnvironment<'a,'tcx>,
3960
3968
ty_vec( ..) | ty_trait( ..) | ty_tup( ..) |
3961
3969
ty_closure( ..) | ty_enum( ..) | ty_struct( ..) |
3962
3970
ty_projection( ..) | ty_param( ..) | ty_infer( ..) | ty_err => None
3963
- } . unwrap_or ( !type_impls_bound ( param_env, ty, ty:: BoundCopy , span) ) ;
3971
+ } . unwrap_or_else ( || !type_impls_bound ( Some ( param_env) ,
3972
+ param_env. tcx ,
3973
+ ty,
3974
+ ty:: BoundCopy ,
3975
+ span) ) ;
3964
3976
3965
3977
if !type_has_params ( ty) && !type_has_self ( ty) {
3966
3978
ty. flags . set ( ty. flags . get ( ) | if result {
@@ -3973,33 +3985,38 @@ pub fn type_moves_by_default<'a,'tcx>(param_env: &ParameterEnvironment<'a,'tcx>,
3973
3985
result
3974
3986
}
3975
3987
3976
- pub fn type_is_sized < ' a , ' tcx > ( param_env : & ParameterEnvironment < ' a , ' tcx > ,
3988
+ #[ inline]
3989
+ pub fn type_is_sized < ' a , ' tcx > ( param_env : Option < & ParameterEnvironment < ' a , ' tcx > > ,
3990
+ tcx : & ty:: ctxt < ' tcx > ,
3977
3991
span : Span ,
3978
3992
ty : Ty < ' tcx > )
3979
3993
-> bool
3980
3994
{
3981
3995
if ty. flags . get ( ) . intersects ( TypeFlags :: SIZEDNESS_CACHED ) {
3982
3996
let result = ty. flags . get ( ) . intersects ( TypeFlags :: IS_SIZED ) ;
3983
- debug ! ( "type_is_sized({}) = {} (cached)" , ty. repr( param_env. tcx) ,
3984
- result) ;
3985
3997
return result;
3986
3998
}
3987
3999
4000
+ type_is_sized_uncached ( param_env, tcx, span, ty)
4001
+ }
4002
+
4003
+ fn type_is_sized_uncached < ' a , ' tcx > ( param_env : Option < & ParameterEnvironment < ' a , ' tcx > > ,
4004
+ tcx : & ty:: ctxt < ' tcx > ,
4005
+ span : Span ,
4006
+ ty : Ty < ' tcx > ) -> bool {
3988
4007
assert ! ( !ty:: type_needs_infer( ty) ) ;
3989
4008
3990
4009
// Fast-path for primitive types
3991
4010
let result = match ty. sty {
3992
4011
ty_bool | ty_char | ty_int( ..) | ty_uint( ..) | ty_float( ..) |
3993
4012
ty_uniq( ..) | ty_ptr( ..) | ty_rptr( ..) | ty_bare_fn( ..) |
3994
- ty_vec( _, Some ( ..) ) | ty_tup( ..) | ty_closure( ..) => {
3995
- Some ( true )
3996
- }
4013
+ ty_vec( _, Some ( ..) ) | ty_tup( ..) | ty_closure( ..) => Some ( true ) ,
3997
4014
3998
4015
ty_str | ty_trait( ..) | ty_vec( _, None ) => Some ( false ) ,
3999
4016
4000
4017
ty_enum( ..) | ty_struct( ..) | ty_projection( ..) | ty_param( ..) |
4001
4018
ty_infer( ..) | ty_err => None
4002
- } . unwrap_or ( type_impls_bound ( param_env, ty, ty:: BoundSized , span) ) ;
4019
+ } . unwrap_or_else ( || type_impls_bound ( param_env, tcx , ty, ty:: BoundSized , span) ) ;
4003
4020
4004
4021
if !type_has_params ( ty) && !type_has_self ( ty) {
4005
4022
ty. flags . set ( ty. flags . get ( ) | if result {
@@ -4009,8 +4026,6 @@ pub fn type_is_sized<'a,'tcx>(param_env: &ParameterEnvironment<'a,'tcx>,
4009
4026
} ) ;
4010
4027
}
4011
4028
4012
- debug ! ( "type_is_sized({}) = {}" , ty. repr( param_env. tcx) ,
4013
- result) ;
4014
4029
result
4015
4030
}
4016
4031
0 commit comments