@@ -1521,6 +1521,57 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
15211521 DefPath :: make ( self . cnum , id, |parent| self . def_key ( parent) )
15221522 }
15231523
1524+ fn def_path_hash_unlocked (
1525+ & self ,
1526+ index : DefIndex ,
1527+ def_path_hashes : & mut FxHashMap < DefIndex , DefPathHash > ,
1528+ ) -> DefPathHash {
1529+ * def_path_hashes. entry ( index) . or_insert_with ( || {
1530+ self . root . tables . def_path_hashes . get ( self , index) . unwrap ( ) . decode ( self )
1531+ } )
1532+ }
1533+
1534+ #[ inline]
1535+ fn def_path_hash ( & self , index : DefIndex ) -> DefPathHash {
1536+ let mut def_path_hashes = self . def_path_hash_cache . lock ( ) ;
1537+ self . def_path_hash_unlocked ( index, & mut def_path_hashes)
1538+ }
1539+
1540+ fn all_def_path_hashes_and_def_ids ( & self ) -> Vec < ( DefPathHash , DefId ) > {
1541+ let mut def_path_hashes = self . def_path_hash_cache . lock ( ) ;
1542+ ( 0 ..self . num_def_ids ( ) )
1543+ . map ( |index| {
1544+ let index = DefIndex :: from_usize ( index) ;
1545+ ( self . def_path_hash_unlocked ( index, & mut def_path_hashes) , self . local_def_id ( index) )
1546+ } )
1547+ . collect ( )
1548+ }
1549+
1550+ /// Get the `DepNodeIndex` corresponding this crate. The result of this
1551+ /// method is cached in the `dep_node_index` field.
1552+ fn get_crate_dep_node_index ( & self , tcx : TyCtxt < ' tcx > ) -> DepNodeIndex {
1553+ let mut dep_node_index = self . dep_node_index . load ( ) ;
1554+
1555+ if unlikely ! ( dep_node_index == DepNodeIndex :: INVALID ) {
1556+ // We have not cached the DepNodeIndex for this upstream crate yet,
1557+ // so use the dep-graph to find it out and cache it.
1558+ // Note that multiple threads can enter this block concurrently.
1559+ // That is fine because the DepNodeIndex remains constant
1560+ // throughout the whole compilation session, and multiple stores
1561+ // would always write the same value.
1562+
1563+ let def_path_hash = self . def_path_hash ( CRATE_DEF_INDEX ) ;
1564+ let dep_node =
1565+ DepNode :: from_def_path_hash ( def_path_hash, dep_graph:: DepKind :: CrateMetadata ) ;
1566+
1567+ dep_node_index = tcx. dep_graph . dep_node_index_of ( & dep_node) ;
1568+ assert ! ( dep_node_index != DepNodeIndex :: INVALID ) ;
1569+ self . dep_node_index . store ( dep_node_index) ;
1570+ }
1571+
1572+ dep_node_index
1573+ }
1574+
15241575 /// Imports the source_map from an external crate into the source_map of the crate
15251576 /// currently being compiled (the "local crate").
15261577 ///
@@ -1845,59 +1896,6 @@ impl CrateMetadata {
18451896 }
18461897}
18471898
1848- impl < ' a , ' tcx > CrateMetadataRef < ' a > {
1849- fn def_path_hash_unlocked (
1850- & self ,
1851- index : DefIndex ,
1852- def_path_hashes : & mut FxHashMap < DefIndex , DefPathHash > ,
1853- ) -> DefPathHash {
1854- * def_path_hashes. entry ( index) . or_insert_with ( || {
1855- self . root . tables . def_path_hashes . get ( self , index) . unwrap ( ) . decode ( self )
1856- } )
1857- }
1858-
1859- #[ inline]
1860- fn def_path_hash ( & self , index : DefIndex ) -> DefPathHash {
1861- let mut def_path_hashes = self . def_path_hash_cache . lock ( ) ;
1862- self . def_path_hash_unlocked ( index, & mut def_path_hashes)
1863- }
1864-
1865- fn all_def_path_hashes_and_def_ids ( & self ) -> Vec < ( DefPathHash , DefId ) > {
1866- let mut def_path_hashes = self . def_path_hash_cache . lock ( ) ;
1867- ( 0 ..self . num_def_ids ( ) )
1868- . map ( |index| {
1869- let index = DefIndex :: from_usize ( index) ;
1870- ( self . def_path_hash_unlocked ( index, & mut def_path_hashes) , self . local_def_id ( index) )
1871- } )
1872- . collect ( )
1873- }
1874-
1875- /// Get the `DepNodeIndex` corresponding this crate. The result of this
1876- /// method is cached in the `dep_node_index` field.
1877- fn get_crate_dep_node_index ( & self , tcx : TyCtxt < ' tcx > ) -> DepNodeIndex {
1878- let mut dep_node_index = self . dep_node_index . load ( ) ;
1879-
1880- if unlikely ! ( dep_node_index == DepNodeIndex :: INVALID ) {
1881- // We have not cached the DepNodeIndex for this upstream crate yet,
1882- // so use the dep-graph to find it out and cache it.
1883- // Note that multiple threads can enter this block concurrently.
1884- // That is fine because the DepNodeIndex remains constant
1885- // throughout the whole compilation session, and multiple stores
1886- // would always write the same value.
1887-
1888- let def_path_hash = self . def_path_hash ( CRATE_DEF_INDEX ) ;
1889- let dep_node =
1890- DepNode :: from_def_path_hash ( def_path_hash, dep_graph:: DepKind :: CrateMetadata ) ;
1891-
1892- dep_node_index = tcx. dep_graph . dep_node_index_of ( & dep_node) ;
1893- assert ! ( dep_node_index != DepNodeIndex :: INVALID ) ;
1894- self . dep_node_index . store ( dep_node_index) ;
1895- }
1896-
1897- dep_node_index
1898- }
1899- }
1900-
19011899// Cannot be implemented on 'ProcMacro', as libproc_macro
19021900// does not depend on librustc_ast
19031901fn macro_kind ( raw : & ProcMacro ) -> MacroKind {
0 commit comments