2525#![ recursion_limit = "256" ]  
2626// tidy-alphabetical-end 
2727
28- use  std:: cell:: { Cell ,   Ref ,   RefCell } ; 
28+ use  std:: cell:: Ref ; 
2929use  std:: collections:: BTreeSet ; 
3030use  std:: fmt:: { self } ; 
3131use  std:: sync:: Arc ; 
@@ -572,7 +572,7 @@ impl BindingKey {
572572    } 
573573} 
574574
575- type  Resolutions < ' ra >  = RefCell < FxIndexMap < BindingKey ,  & ' ra  RefCell < NameResolution < ' ra > > > > ; 
575+ type  Resolutions < ' ra >  = CmRefCell < FxIndexMap < BindingKey ,  & ' ra  CmRefCell < NameResolution < ' ra > > > > ; 
576576
577577/// One node in the tree of modules. 
578578/// 
@@ -595,7 +595,7 @@ struct ModuleData<'ra> {
595595/// Resolutions in modules from other crates are not populated until accessed. 
596596lazy_resolutions :  Resolutions < ' ra > , 
597597    /// True if this is a module from other crate that needs to be populated on access. 
598- populate_on_access :  Cell < bool > ,   // FIXME(parallel): Use an atomic in parallel import resolution 
598+ populate_on_access :  CacheCell < bool > , 
599599    /// Used to disambiguate underscore items (`const _: T = ...`) in the module. 
600600underscore_disambiguator :  CmCell < u32 > , 
601601
@@ -658,7 +658,7 @@ impl<'ra> ModuleData<'ra> {
658658            parent, 
659659            kind, 
660660            lazy_resolutions :  Default :: default ( ) , 
661-             populate_on_access :  Cell :: new ( is_foreign) , 
661+             populate_on_access :  CacheCell :: new ( is_foreign) , 
662662            underscore_disambiguator :  CmCell :: new ( 0 ) , 
663663            unexpanded_invocations :  Default :: default ( ) , 
664664            no_implicit_prelude, 
@@ -1034,7 +1034,7 @@ struct ExternPreludeEntry<'ra> {
10341034/// `flag_binding` is `None`, or when `extern crate` introducing `item_binding` used renaming. 
10351035item_binding :  Option < ( NameBinding < ' ra > ,  /* introduced by item */  bool ) > , 
10361036    /// Binding from an `--extern` flag, lazily populated on first use. 
1037- flag_binding :  Option < Cell < ( PendingBinding < ' ra > ,  /* finalized */  bool ) > > , 
1037+ flag_binding :  Option < CacheCell < ( PendingBinding < ' ra > ,  /* finalized */  bool ) > > , 
10381038} 
10391039
10401040impl  ExternPreludeEntry < ' _ >  { 
@@ -1045,7 +1045,7 @@ impl ExternPreludeEntry<'_> {
10451045    fn  flag ( )  -> Self  { 
10461046        ExternPreludeEntry  { 
10471047            item_binding :  None , 
1048-             flag_binding :  Some ( Cell :: new ( ( PendingBinding :: Pending ,  false ) ) ) , 
1048+             flag_binding :  Some ( CacheCell :: new ( ( PendingBinding :: Pending ,  false ) ) ) , 
10491049        } 
10501050    } 
10511051} 
@@ -1150,7 +1150,7 @@ pub struct Resolver<'ra, 'tcx> {
11501150    /// Eagerly populated map of all local non-block modules. 
11511151local_module_map :  FxIndexMap < LocalDefId ,  Module < ' ra > > , 
11521152    /// Lazily populated cache of modules loaded from external crates. 
1153- extern_module_map :  RefCell < FxIndexMap < DefId ,  Module < ' ra > > > , 
1153+ extern_module_map :  CacheRefCell < FxIndexMap < DefId ,  Module < ' ra > > > , 
11541154    binding_parent_modules :  FxHashMap < NameBinding < ' ra > ,  Module < ' ra > > , 
11551155
11561156    /// Maps glob imports to the names of items actually imported. 
@@ -1186,7 +1186,7 @@ pub struct Resolver<'ra, 'tcx> {
11861186    /// Eagerly populated map of all local macro definitions. 
11871187local_macro_map :  FxHashMap < LocalDefId ,  & ' ra  MacroData > , 
11881188    /// Lazily populated cache of macro definitions loaded from external crates. 
1189- extern_macro_map :  RefCell < FxHashMap < DefId ,  & ' ra  MacroData > > , 
1189+ extern_macro_map :  CacheRefCell < FxHashMap < DefId ,  & ' ra  MacroData > > , 
11901190    dummy_ext_bang :  Arc < SyntaxExtension > , 
11911191    dummy_ext_derive :  Arc < SyntaxExtension > , 
11921192    non_macro_attr :  & ' ra  MacroData , 
@@ -1197,11 +1197,10 @@ pub struct Resolver<'ra, 'tcx> {
11971197unused_macro_rules :  FxIndexMap < NodeId ,  DenseBitSet < usize > > , 
11981198    proc_macro_stubs :  FxHashSet < LocalDefId > , 
11991199    /// Traces collected during macro resolution and validated when it's complete. 
1200- // FIXME: Remove interior mutability when speculative resolution produces these as outputs. 
12011200single_segment_macro_resolutions : 
1202-         RefCell < Vec < ( Ident ,  MacroKind ,  ParentScope < ' ra > ,  Option < NameBinding < ' ra > > ,  Option < Span > ) > > , 
1201+         CmRefCell < Vec < ( Ident ,  MacroKind ,  ParentScope < ' ra > ,  Option < NameBinding < ' ra > > ,  Option < Span > ) > > , 
12031202    multi_segment_macro_resolutions : 
1204-         RefCell < Vec < ( Vec < Segment > ,  Span ,  MacroKind ,  ParentScope < ' ra > ,  Option < Res > ,  Namespace ) > > , 
1203+         CmRefCell < Vec < ( Vec < Segment > ,  Span ,  MacroKind ,  ParentScope < ' ra > ,  Option < Res > ,  Namespace ) > > , 
12051204    builtin_attrs :  Vec < ( Ident ,  ParentScope < ' ra > ) > , 
12061205    /// `derive(Copy)` marks items they are applied to so they are treated specially later. 
12071206/// Derive macros cannot modify the item themselves and have to store the markers in the global 
@@ -1301,7 +1300,7 @@ pub struct Resolver<'ra, 'tcx> {
13011300pub  struct  ResolverArenas < ' ra >  { 
13021301    modules :  TypedArena < ModuleData < ' ra > > , 
13031302    imports :  TypedArena < ImportData < ' ra > > , 
1304-     name_resolutions :  TypedArena < RefCell < NameResolution < ' ra > > > , 
1303+     name_resolutions :  TypedArena < CmRefCell < NameResolution < ' ra > > > , 
13051304    ast_paths :  TypedArena < ast:: Path > , 
13061305    macros :  TypedArena < MacroData > , 
13071306    dropless :  DroplessArena , 
@@ -1363,11 +1362,11 @@ impl<'ra> ResolverArenas<'ra> {
13631362    fn  alloc_import ( & ' ra  self ,  import :  ImportData < ' ra > )  -> Import < ' ra >  { 
13641363        Interned :: new_unchecked ( self . imports . alloc ( import) ) 
13651364    } 
1366-     fn  alloc_name_resolution ( & ' ra  self )  -> & ' ra  RefCell < NameResolution < ' ra > >  { 
1365+     fn  alloc_name_resolution ( & ' ra  self )  -> & ' ra  CmRefCell < NameResolution < ' ra > >  { 
13671366        self . name_resolutions . alloc ( Default :: default ( ) ) 
13681367    } 
13691368    fn  alloc_macro_rules_scope ( & ' ra  self ,  scope :  MacroRulesScope < ' ra > )  -> MacroRulesScopeRef < ' ra >  { 
1370-         self . dropless . alloc ( Cell :: new ( scope) ) 
1369+         self . dropless . alloc ( CacheCell :: new ( scope) ) 
13711370    } 
13721371    fn  alloc_macro_rules_binding ( 
13731372        & ' ra  self , 
@@ -1978,7 +1977,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
19781977
19791978    fn  resolutions ( & self ,  module :  Module < ' ra > )  -> & ' ra  Resolutions < ' ra >  { 
19801979        if  module. populate_on_access . get ( )  { 
1981-             // FIXME(batched): Will be fixed in batched import resolution. 
19821980            module. populate_on_access . set ( false ) ; 
19831981            self . build_reduced_graph_external ( module) ; 
19841982        } 
@@ -1997,9 +1995,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
19971995        & self , 
19981996        module :  Module < ' ra > , 
19991997        key :  BindingKey , 
2000-     )  -> & ' ra  RefCell < NameResolution < ' ra > >  { 
1998+     )  -> & ' ra  CmRefCell < NameResolution < ' ra > >  { 
20011999        self . resolutions ( module) 
2002-             . borrow_mut ( ) 
2000+             . borrow_mut_unchecked ( ) 
20032001            . entry ( key) 
20042002            . or_insert_with ( || self . arenas . alloc_name_resolution ( ) ) 
20052003    } 
@@ -2514,6 +2512,13 @@ pub fn provide(providers: &mut Providers) {
25142512/// Prefer constructing it through [`Resolver::cm`] to ensure correctness. 
25152513type  CmResolver < ' r ,  ' ra ,  ' tcx >  = ref_mut:: RefOrMut < ' r ,  Resolver < ' ra ,  ' tcx > > ; 
25162514
2515+ // FIXME: These are cells for caches that can be populated even during speculative resolution, 
2516+ // and should be replaced with mutexes, atomics, or other synchronized data when migrating to 
2517+ // parallel name resolution. 
2518+ use  std:: cell:: { Cell  as  CacheCell ,  RefCell  as  CacheRefCell } ; 
2519+ 
2520+ // FIXME: `*_unchecked` methods in the module below should be eliminated in the process 
2521+ // of migration to parallel name resolution. 
25172522mod  ref_mut { 
25182523    use  std:: cell:: { BorrowMutError ,  Cell ,  Ref ,  RefCell ,  RefMut } ; 
25192524    use  std:: fmt; 
@@ -2581,7 +2586,6 @@ mod ref_mut {
25812586    } 
25822587
25832588    impl < T :  Copy >  Clone  for  CmCell < T >  { 
2584-         #[ inline]  
25852589        fn  clone ( & self )  -> CmCell < T >  { 
25862590            CmCell :: new ( self . get ( ) ) 
25872591        } 
@@ -2624,13 +2628,11 @@ mod ref_mut {
26242628            CmRefCell ( RefCell :: new ( value) ) 
26252629        } 
26262630
2627-         #[ inline]  
26282631        #[ track_caller]  
26292632        pub ( crate )  fn  borrow_mut_unchecked ( & self )  -> RefMut < ' _ ,  T >  { 
26302633            self . 0 . borrow_mut ( ) 
26312634        } 
26322635
2633-         #[ inline]  
26342636        #[ track_caller]  
26352637        pub ( crate )  fn  borrow_mut < ' ra ,  ' tcx > ( & self ,  r :  & Resolver < ' ra ,  ' tcx > )  -> RefMut < ' _ ,  T >  { 
26362638            if  r. assert_speculative  { 
@@ -2639,16 +2641,23 @@ mod ref_mut {
26392641            self . borrow_mut_unchecked ( ) 
26402642        } 
26412643
2642-         #[ inline]  
26432644        #[ track_caller]  
26442645        pub ( crate )  fn  try_borrow_mut_unchecked ( & self )  -> Result < RefMut < ' _ ,  T > ,  BorrowMutError >  { 
26452646            self . 0 . try_borrow_mut ( ) 
26462647        } 
26472648
2648-         #[ inline]  
26492649        #[ track_caller]  
26502650        pub ( crate )  fn  borrow ( & self )  -> Ref < ' _ ,  T >  { 
26512651            self . 0 . borrow ( ) 
26522652        } 
26532653    } 
2654+ 
2655+     impl < T :  Default >  CmRefCell < T >  { 
2656+         pub ( crate )  fn  take < ' ra ,  ' tcx > ( & self ,  r :  & Resolver < ' ra ,  ' tcx > )  -> T  { 
2657+             if  r. assert_speculative  { 
2658+                 panic ! ( "Not allowed to mutate a CmRefCell during speculative resolution" ) ; 
2659+             } 
2660+             self . 0 . take ( ) 
2661+         } 
2662+     } 
26542663} 
0 commit comments