@@ -559,51 +559,6 @@ impl CrateRoot<'_> {
559
559
}
560
560
}
561
561
562
- impl CrateMetadata {
563
- crate fn new (
564
- sess : & Session ,
565
- blob : MetadataBlob ,
566
- root : CrateRoot < ' static > ,
567
- raw_proc_macros : Option < & ' static [ ProcMacro ] > ,
568
- cnum : CrateNum ,
569
- cnum_map : CrateNumMap ,
570
- dep_kind : DepKind ,
571
- source : CrateSource ,
572
- private_dep : bool ,
573
- host_hash : Option < Svh > ,
574
- ) -> CrateMetadata {
575
- let def_path_table = record_time ( & sess. perf_stats . decode_def_path_tables_time , || {
576
- root. def_path_table . decode ( ( & blob, sess) )
577
- } ) ;
578
- let trait_impls = root
579
- . impls
580
- . decode ( ( & blob, sess) )
581
- . map ( |trait_impls| ( trait_impls. trait_id , trait_impls. impls ) )
582
- . collect ( ) ;
583
- let alloc_decoding_state =
584
- AllocDecodingState :: new ( root. interpret_alloc_index . decode ( & blob) . collect ( ) ) ;
585
- let dependencies = Lock :: new ( cnum_map. iter ( ) . cloned ( ) . collect ( ) ) ;
586
- CrateMetadata {
587
- blob,
588
- root,
589
- def_path_table,
590
- trait_impls,
591
- raw_proc_macros,
592
- source_map_import_info : Once :: new ( ) ,
593
- alloc_decoding_state,
594
- dep_node_index : AtomicCell :: new ( DepNodeIndex :: INVALID ) ,
595
- cnum,
596
- cnum_map,
597
- dependencies,
598
- dep_kind : Lock :: new ( dep_kind) ,
599
- source,
600
- private_dep,
601
- host_hash,
602
- extern_crate : Lock :: new ( None ) ,
603
- }
604
- }
605
- }
606
-
607
562
impl < ' a , ' tcx > CrateMetadataRef < ' a > {
608
563
fn is_proc_macro ( & self , id : DefIndex ) -> bool {
609
564
self . root . proc_macro_data . and_then ( |data| data. decode ( self ) . find ( |x| * x == id) ) . is_some ( )
@@ -625,10 +580,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
625
580
} )
626
581
}
627
582
628
- fn local_def_id ( & self , index : DefIndex ) -> DefId {
629
- DefId { krate : self . cnum , index }
630
- }
631
-
632
583
fn raw_proc_macro ( & self , id : DefIndex ) -> & ProcMacro {
633
584
// DefIndex's in root.proc_macro_data have a one-to-one correspondence
634
585
// with items in 'raw_proc_macros'.
@@ -1194,18 +1145,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1194
1145
. collect ( )
1195
1146
}
1196
1147
1197
- // Translate a DefId from the current compilation environment to a DefId
1198
- // for an external crate.
1199
- fn reverse_translate_def_id ( & self , did : DefId ) -> Option < DefId > {
1200
- for ( local, & global) in self . cnum_map . iter_enumerated ( ) {
1201
- if global == did. krate {
1202
- return Some ( DefId { krate : local, index : did. index } ) ;
1203
- }
1204
- }
1205
-
1206
- None
1207
- }
1208
-
1209
1148
fn get_inherent_implementations_for_type (
1210
1149
& self ,
1211
1150
tcx : TyCtxt < ' tcx > ,
@@ -1412,11 +1351,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1412
1351
DefPath :: make ( self . cnum , id, |parent| self . def_key ( parent) )
1413
1352
}
1414
1353
1415
- #[ inline]
1416
- fn def_path_hash ( & self , index : DefIndex ) -> DefPathHash {
1417
- self . def_path_table . def_path_hash ( index)
1418
- }
1419
-
1420
1354
/// Imports the source_map from an external crate into the source_map of the crate
1421
1355
/// currently being compiled (the "local crate").
1422
1356
///
@@ -1519,33 +1453,52 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1519
1453
. collect ( )
1520
1454
} )
1521
1455
}
1456
+ }
1522
1457
1523
- /// Get the `DepNodeIndex` corresponding this crate. The result of this
1524
- /// method is cached in the `dep_node_index` field.
1525
- fn get_crate_dep_node_index ( & self , tcx : TyCtxt < ' tcx > ) -> DepNodeIndex {
1526
- let mut dep_node_index = self . dep_node_index . load ( ) ;
1527
-
1528
- if unlikely ! ( dep_node_index == DepNodeIndex :: INVALID ) {
1529
- // We have not cached the DepNodeIndex for this upstream crate yet,
1530
- // so use the dep-graph to find it out and cache it.
1531
- // Note that multiple threads can enter this block concurrently.
1532
- // That is fine because the DepNodeIndex remains constant
1533
- // throughout the whole compilation session, and multiple stores
1534
- // would always write the same value.
1535
-
1536
- let def_path_hash = self . def_path_hash ( CRATE_DEF_INDEX ) ;
1537
- let dep_node = def_path_hash. to_dep_node ( dep_graph:: DepKind :: CrateMetadata ) ;
1538
-
1539
- dep_node_index = tcx. dep_graph . dep_node_index_of ( & dep_node) ;
1540
- assert ! ( dep_node_index != DepNodeIndex :: INVALID ) ;
1541
- self . dep_node_index . store ( dep_node_index) ;
1458
+ impl CrateMetadata {
1459
+ crate fn new (
1460
+ sess : & Session ,
1461
+ blob : MetadataBlob ,
1462
+ root : CrateRoot < ' static > ,
1463
+ raw_proc_macros : Option < & ' static [ ProcMacro ] > ,
1464
+ cnum : CrateNum ,
1465
+ cnum_map : CrateNumMap ,
1466
+ dep_kind : DepKind ,
1467
+ source : CrateSource ,
1468
+ private_dep : bool ,
1469
+ host_hash : Option < Svh > ,
1470
+ ) -> CrateMetadata {
1471
+ let def_path_table = record_time ( & sess. perf_stats . decode_def_path_tables_time , || {
1472
+ root. def_path_table . decode ( ( & blob, sess) )
1473
+ } ) ;
1474
+ let trait_impls = root
1475
+ . impls
1476
+ . decode ( ( & blob, sess) )
1477
+ . map ( |trait_impls| ( trait_impls. trait_id , trait_impls. impls ) )
1478
+ . collect ( ) ;
1479
+ let alloc_decoding_state =
1480
+ AllocDecodingState :: new ( root. interpret_alloc_index . decode ( & blob) . collect ( ) ) ;
1481
+ let dependencies = Lock :: new ( cnum_map. iter ( ) . cloned ( ) . collect ( ) ) ;
1482
+ CrateMetadata {
1483
+ blob,
1484
+ root,
1485
+ def_path_table,
1486
+ trait_impls,
1487
+ raw_proc_macros,
1488
+ source_map_import_info : Once :: new ( ) ,
1489
+ alloc_decoding_state,
1490
+ dep_node_index : AtomicCell :: new ( DepNodeIndex :: INVALID ) ,
1491
+ cnum,
1492
+ cnum_map,
1493
+ dependencies,
1494
+ dep_kind : Lock :: new ( dep_kind) ,
1495
+ source,
1496
+ private_dep,
1497
+ host_hash,
1498
+ extern_crate : Lock :: new ( None ) ,
1542
1499
}
1543
-
1544
- dep_node_index
1545
1500
}
1546
- }
1547
1501
1548
- impl CrateMetadata {
1549
1502
crate fn dependencies ( & self ) -> LockGuard < ' _ , Vec < CrateNum > > {
1550
1503
self . dependencies . borrow ( )
1551
1504
}
@@ -1618,6 +1571,51 @@ impl CrateMetadata {
1618
1571
crate fn hash ( & self ) -> Svh {
1619
1572
self . root . hash
1620
1573
}
1574
+
1575
+ fn local_def_id ( & self , index : DefIndex ) -> DefId {
1576
+ DefId { krate : self . cnum , index }
1577
+ }
1578
+
1579
+ // Translate a DefId from the current compilation environment to a DefId
1580
+ // for an external crate.
1581
+ fn reverse_translate_def_id ( & self , did : DefId ) -> Option < DefId > {
1582
+ for ( local, & global) in self . cnum_map . iter_enumerated ( ) {
1583
+ if global == did. krate {
1584
+ return Some ( DefId { krate : local, index : did. index } ) ;
1585
+ }
1586
+ }
1587
+
1588
+ None
1589
+ }
1590
+
1591
+ #[ inline]
1592
+ fn def_path_hash ( & self , index : DefIndex ) -> DefPathHash {
1593
+ self . def_path_table . def_path_hash ( index)
1594
+ }
1595
+
1596
+ /// Get the `DepNodeIndex` corresponding this crate. The result of this
1597
+ /// method is cached in the `dep_node_index` field.
1598
+ fn get_crate_dep_node_index ( & self , tcx : TyCtxt < ' tcx > ) -> DepNodeIndex {
1599
+ let mut dep_node_index = self . dep_node_index . load ( ) ;
1600
+
1601
+ if unlikely ! ( dep_node_index == DepNodeIndex :: INVALID ) {
1602
+ // We have not cached the DepNodeIndex for this upstream crate yet,
1603
+ // so use the dep-graph to find it out and cache it.
1604
+ // Note that multiple threads can enter this block concurrently.
1605
+ // That is fine because the DepNodeIndex remains constant
1606
+ // throughout the whole compilation session, and multiple stores
1607
+ // would always write the same value.
1608
+
1609
+ let def_path_hash = self . def_path_hash ( CRATE_DEF_INDEX ) ;
1610
+ let dep_node = def_path_hash. to_dep_node ( dep_graph:: DepKind :: CrateMetadata ) ;
1611
+
1612
+ dep_node_index = tcx. dep_graph . dep_node_index_of ( & dep_node) ;
1613
+ assert ! ( dep_node_index != DepNodeIndex :: INVALID ) ;
1614
+ self . dep_node_index . store ( dep_node_index) ;
1615
+ }
1616
+
1617
+ dep_node_index
1618
+ }
1621
1619
}
1622
1620
1623
1621
// Cannot be implemented on 'ProcMacro', as libproc_macro
0 commit comments