@@ -173,7 +173,12 @@ pub fn get_enum_variant_types(ccx: &CrateCtxt,
173
173
generics : ty_generics ( ccx, generics, 0 ) ,
174
174
ty : result_ty
175
175
} ;
176
- tcx. tcache . insert ( local_def ( variant. node . id ) , tpt) ;
176
+
177
+ {
178
+ let mut tcache = tcx. tcache . borrow_mut ( ) ;
179
+ tcache. get ( ) . insert ( local_def ( variant. node . id ) , tpt) ;
180
+ }
181
+
177
182
write_ty_to_tcx ( tcx, variant. node . id , result_ty) ;
178
183
}
179
184
}
@@ -350,7 +355,8 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt,
350
355
ty. repr( tcx) ,
351
356
substs. repr( tcx) ) ;
352
357
353
- tcx. tcache . insert ( m. def_id ,
358
+ let mut tcache = tcx. tcache . borrow_mut ( ) ;
359
+ tcache. get ( ) . insert ( m. def_id ,
354
360
ty_param_bounds_and_ty {
355
361
generics : ty:: Generics {
356
362
type_param_defs : @new_type_param_defs,
@@ -440,7 +446,8 @@ pub fn convert_field(ccx: &CrateCtxt,
440
446
let tt = ccx. to_ty ( & ExplicitRscope , v. node . ty ) ;
441
447
write_ty_to_tcx ( ccx. tcx , v. node . id , tt) ;
442
448
/* add the field to the tcache */
443
- ccx. tcx . tcache . insert ( local_def ( v. node . id ) ,
449
+ let mut tcache = ccx. tcx . tcache . borrow_mut ( ) ;
450
+ tcache. get ( ) . insert ( local_def ( v. node . id ) ,
444
451
ty:: ty_param_bounds_and_ty {
445
452
generics : struct_generics. clone ( ) ,
446
453
ty : tt
@@ -470,20 +477,25 @@ fn convert_methods(ccx: &CrateCtxt,
470
477
m. ident. repr( ccx. tcx) ,
471
478
m. id,
472
479
fty. repr( ccx. tcx) ) ;
473
- tcx. tcache . insert (
474
- local_def ( m. id ) ,
480
+ {
481
+ let mut tcache = tcx. tcache . borrow_mut ( ) ;
482
+ tcache. get ( ) . insert (
483
+ local_def ( m. id ) ,
484
+
485
+ // n.b.: the type of a method is parameterized by both
486
+ // the parameters on the receiver and those on the method
487
+ // itself
488
+ ty_param_bounds_and_ty {
489
+ generics : ty:: Generics {
490
+ type_param_defs : @vec:: append (
491
+ ( * rcvr_ty_generics. type_param_defs ) . clone ( ) ,
492
+ * m_ty_generics. type_param_defs ) ,
493
+ region_param_defs : rcvr_ty_generics. region_param_defs ,
494
+ } ,
495
+ ty : fty
496
+ } ) ;
497
+ }
475
498
476
- // n.b.: the type of a method is parameterized by both
477
- // the parameters on the receiver and those on the method itself
478
- ty_param_bounds_and_ty {
479
- generics : ty:: Generics {
480
- type_param_defs : @vec:: append (
481
- ( * rcvr_ty_generics. type_param_defs ) . clone ( ) ,
482
- * m_ty_generics. type_param_defs ) ,
483
- region_param_defs : rcvr_ty_generics. region_param_defs ,
484
- } ,
485
- ty : fty
486
- } ) ;
487
499
write_ty_to_tcx ( tcx, m. id , fty) ;
488
500
489
501
let mut methods = tcx. methods . borrow_mut ( ) ;
@@ -557,10 +569,14 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::item) {
557
569
let i_ty_generics = ty_generics ( ccx, generics, 0 ) ;
558
570
let selfty = ccx. to_ty ( & ExplicitRscope , selfty) ;
559
571
write_ty_to_tcx ( tcx, it. id , selfty) ;
560
- tcx. tcache . insert ( local_def ( it. id ) ,
561
- ty_param_bounds_and_ty {
562
- generics : i_ty_generics,
563
- ty : selfty} ) ;
572
+
573
+ {
574
+ let mut tcache = tcx. tcache . borrow_mut ( ) ;
575
+ tcache. get ( ) . insert ( local_def ( it. id ) ,
576
+ ty_param_bounds_and_ty {
577
+ generics : i_ty_generics,
578
+ ty : selfty} ) ;
579
+ }
564
580
565
581
// If there is a trait reference, treat the methods as always public.
566
582
// This is to work around some incorrect behavior in privacy checking:
@@ -618,7 +634,11 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::item) {
618
634
// Write the class type
619
635
let tpt = ty_of_item ( ccx, it) ;
620
636
write_ty_to_tcx ( tcx, it. id , tpt. ty ) ;
621
- tcx. tcache . insert ( local_def ( it. id ) , tpt) ;
637
+
638
+ {
639
+ let mut tcache = tcx. tcache . borrow_mut ( ) ;
640
+ tcache. get ( ) . insert ( local_def ( it. id ) , tpt) ;
641
+ }
622
642
623
643
convert_struct ( ccx, struct_def, tpt, it. id ) ;
624
644
}
@@ -658,19 +678,29 @@ pub fn convert_struct(ccx: &CrateCtxt,
658
678
if struct_def. fields . len ( ) == 0 {
659
679
// Enum-like.
660
680
write_ty_to_tcx ( tcx, ctor_id, selfty) ;
661
- tcx. tcache . insert ( local_def ( ctor_id) , tpt) ;
681
+
682
+ {
683
+ let mut tcache = tcx. tcache . borrow_mut ( ) ;
684
+ tcache. get ( ) . insert ( local_def ( ctor_id) , tpt) ;
685
+ }
662
686
} else if struct_def. fields [ 0 ] . node . kind == ast:: unnamed_field {
663
687
// Tuple-like.
664
- let inputs =
688
+ let inputs = {
689
+ let tcache = tcx. tcache . borrow ( ) ;
665
690
struct_def. fields . map (
666
- |field| ccx. tcx . tcache . get (
667
- & local_def ( field. node . id ) ) . ty ) ;
691
+ |field| tcache. get ( ) . get (
692
+ & local_def ( field. node . id ) ) . ty )
693
+ } ;
668
694
let ctor_fn_ty = ty:: mk_ctor_fn ( tcx, ctor_id, inputs, selfty) ;
669
695
write_ty_to_tcx ( tcx, ctor_id, ctor_fn_ty) ;
670
- tcx. tcache . insert ( local_def ( ctor_id) , ty_param_bounds_and_ty {
671
- generics : tpt. generics ,
672
- ty : ctor_fn_ty
673
- } ) ;
696
+ {
697
+ let mut tcache = tcx. tcache . borrow_mut ( ) ;
698
+ tcache. get ( ) . insert ( local_def ( ctor_id) ,
699
+ ty_param_bounds_and_ty {
700
+ generics : tpt. generics ,
701
+ ty : ctor_fn_ty
702
+ } ) ;
703
+ }
674
704
}
675
705
}
676
706
}
@@ -695,7 +725,9 @@ pub fn convert_foreign(ccx: &CrateCtxt, i: &ast::foreign_item) {
695
725
696
726
let tpt = ty_of_foreign_item ( ccx, i, abis) ;
697
727
write_ty_to_tcx ( ccx. tcx , i. id , tpt. ty ) ;
698
- ccx. tcx . tcache . insert ( local_def ( i. id ) , tpt) ;
728
+
729
+ let mut tcache = ccx. tcx . tcache . borrow_mut ( ) ;
730
+ tcache. get ( ) . insert ( local_def ( i. id ) , tpt) ;
699
731
}
700
732
701
733
pub fn instantiate_trait_ref ( ccx : & CrateCtxt ,
@@ -781,15 +813,20 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::item)
781
813
-> ty:: ty_param_bounds_and_ty {
782
814
let def_id = local_def ( it. id ) ;
783
815
let tcx = ccx. tcx ;
784
- match tcx. tcache . find ( & def_id) {
785
- Some ( & tpt) => return tpt,
786
- _ => { }
816
+ {
817
+ let tcache = tcx. tcache . borrow ( ) ;
818
+ match tcache. get ( ) . find ( & def_id) {
819
+ Some ( & tpt) => return tpt,
820
+ _ => { }
821
+ }
787
822
}
788
823
match it. node {
789
824
ast:: item_static( t, _, _) => {
790
825
let typ = ccx. to_ty ( & ExplicitRscope , t) ;
791
826
let tpt = no_params ( typ) ;
792
- tcx. tcache . insert ( local_def ( it. id ) , tpt) ;
827
+
828
+ let mut tcache = tcx. tcache . borrow_mut ( ) ;
829
+ tcache. get ( ) . insert ( local_def ( it. id ) , tpt) ;
793
830
return tpt;
794
831
}
795
832
ast:: item_fn( decl, purity, abi, ref generics, _) => {
@@ -810,13 +847,18 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::item)
810
847
tcx. sess. str_of( it. ident) ,
811
848
it. id,
812
849
ppaux:: ty_to_str( tcx, tpt. ty) ) ;
813
- ccx. tcx . tcache . insert ( local_def ( it. id ) , tpt) ;
850
+
851
+ let mut tcache = ccx. tcx . tcache . borrow_mut ( ) ;
852
+ tcache. get ( ) . insert ( local_def ( it. id ) , tpt) ;
814
853
return tpt;
815
854
}
816
855
ast:: item_ty( t, ref generics) => {
817
- match tcx. tcache . find ( & local_def ( it. id ) ) {
818
- Some ( & tpt) => return tpt,
819
- None => { }
856
+ {
857
+ let mut tcache = tcx. tcache . borrow_mut ( ) ;
858
+ match tcache. get ( ) . find ( & local_def ( it. id ) ) {
859
+ Some ( & tpt) => return tpt,
860
+ None => { }
861
+ }
820
862
}
821
863
822
864
let tpt = {
@@ -827,7 +869,8 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::item)
827
869
}
828
870
} ;
829
871
830
- tcx. tcache . insert ( local_def ( it. id ) , tpt) ;
872
+ let mut tcache = tcx. tcache . borrow_mut ( ) ;
873
+ tcache. get ( ) . insert ( local_def ( it. id ) , tpt) ;
831
874
return tpt;
832
875
}
833
876
ast:: item_enum( _, ref generics) => {
@@ -839,7 +882,9 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::item)
839
882
generics : ty_generics,
840
883
ty : t
841
884
} ;
842
- tcx. tcache . insert ( local_def ( it. id ) , tpt) ;
885
+
886
+ let mut tcache = tcx. tcache . borrow_mut ( ) ;
887
+ tcache. get ( ) . insert ( local_def ( it. id ) , tpt) ;
843
888
return tpt;
844
889
}
845
890
ast:: item_trait( ..) => {
@@ -855,7 +900,9 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::item)
855
900
generics : ty_generics,
856
901
ty : t
857
902
} ;
858
- tcx. tcache . insert ( local_def ( it. id ) , tpt) ;
903
+
904
+ let mut tcache = tcx. tcache . borrow_mut ( ) ;
905
+ tcache. get ( ) . insert ( local_def ( it. id ) , tpt) ;
859
906
return tpt;
860
907
}
861
908
ast:: item_impl( ..) | ast:: item_mod( _) |
@@ -990,7 +1037,9 @@ pub fn ty_of_foreign_fn_decl(ccx: &CrateCtxt,
990
1037
generics : ty_generics,
991
1038
ty : t_fn
992
1039
} ;
993
- ccx. tcx . tcache . insert ( def_id, tpt) ;
1040
+
1041
+ let mut tcache = ccx. tcx . tcache . borrow_mut ( ) ;
1042
+ tcache. get ( ) . insert ( def_id, tpt) ;
994
1043
return tpt;
995
1044
}
996
1045
0 commit comments