@@ -583,6 +583,9 @@ pub struct ctxt<'tcx> {
583
583
/// Caches the results of trait selection. This cache is used
584
584
/// for things that do not have to do with the parameters in scope.
585
585
pub selection_cache : traits:: SelectionCache ,
586
+
587
+ /// Caches the representation hints for struct definitions.
588
+ pub repr_hint_cache : RefCell < DefIdMap < Rc < Vec < attr:: ReprAttr > > > > ,
586
589
}
587
590
588
591
pub enum tbox_flag {
@@ -1533,6 +1536,7 @@ pub fn mk_ctxt<'tcx>(s: Session,
1533
1536
associated_types : RefCell :: new ( DefIdMap :: new ( ) ) ,
1534
1537
trait_associated_types : RefCell :: new ( DefIdMap :: new ( ) ) ,
1535
1538
selection_cache : traits:: SelectionCache :: new ( ) ,
1539
+ repr_hint_cache : RefCell :: new ( DefIdMap :: new ( ) ) ,
1536
1540
}
1537
1541
}
1538
1542
@@ -4326,7 +4330,7 @@ pub fn ty_dtor(cx: &ctxt, struct_id: DefId) -> DtorKind {
4326
4330
}
4327
4331
4328
4332
pub fn has_dtor ( cx : & ctxt , struct_id : DefId ) -> bool {
4329
- ty_dtor ( cx , struct_id ) . is_present ( )
4333
+ cx . destructor_for_type . borrow ( ) . contains_key ( & struct_id )
4330
4334
}
4331
4335
4332
4336
pub fn with_path < T > ( cx : & ctxt , id : ast:: DefId , f: |ast_map:: PathElems | -> T ) -> T {
@@ -4513,14 +4517,26 @@ pub fn lookup_simd(tcx: &ctxt, did: DefId) -> bool {
4513
4517
}
4514
4518
4515
4519
/// Obtain the representation annotation for a struct definition.
4516
- pub fn lookup_repr_hints ( tcx : & ctxt , did : DefId ) -> Vec < attr:: ReprAttr > {
4517
- let mut acc = Vec :: new ( ) ;
4520
+ pub fn lookup_repr_hints ( tcx : & ctxt , did : DefId ) -> Rc < Vec < attr:: ReprAttr > > {
4521
+ match tcx. repr_hint_cache . borrow ( ) . find ( & did) {
4522
+ None => { }
4523
+ Some ( ref hints) => return ( * hints) . clone ( ) ,
4524
+ }
4518
4525
4519
- ty:: each_attr ( tcx, did, |meta| {
4520
- acc. extend ( attr:: find_repr_attrs ( tcx. sess . diagnostic ( ) , meta) . into_iter ( ) ) ;
4521
- true
4522
- } ) ;
4526
+ let acc = if did. krate == LOCAL_CRATE {
4527
+ let mut acc = Vec :: new ( ) ;
4528
+ ty:: each_attr ( tcx, did, |meta| {
4529
+ acc. extend ( attr:: find_repr_attrs ( tcx. sess . diagnostic ( ) ,
4530
+ meta) . into_iter ( ) ) ;
4531
+ true
4532
+ } ) ;
4533
+ acc
4534
+ } else {
4535
+ csearch:: get_repr_attrs ( & tcx. sess . cstore , did)
4536
+ } ;
4523
4537
4538
+ let acc = Rc :: new ( acc) ;
4539
+ tcx. repr_hint_cache . borrow_mut ( ) . insert ( did, acc. clone ( ) ) ;
4524
4540
acc
4525
4541
}
4526
4542
0 commit comments