@@ -4,7 +4,6 @@ use crate::creader::{CStore, CrateMetadataRef};
4
4
use crate :: rmeta:: * ;
5
5
6
6
use rustc_ast as ast;
7
- use rustc_ast:: ptr:: P ;
8
7
use rustc_data_structures:: captures:: Captures ;
9
8
use rustc_data_structures:: fx:: FxHashMap ;
10
9
use rustc_data_structures:: svh:: Svh ;
@@ -33,7 +32,7 @@ use rustc_session::cstore::{
33
32
use rustc_session:: Session ;
34
33
use rustc_span:: hygiene:: { ExpnIndex , MacroKind } ;
35
34
use rustc_span:: source_map:: { respan, Spanned } ;
36
- use rustc_span:: symbol:: { sym, Ident , Symbol } ;
35
+ use rustc_span:: symbol:: { kw , sym, Ident , Symbol } ;
37
36
use rustc_span:: { self , BytePos , ExpnId , Pos , Span , SyntaxContext , DUMMY_SP } ;
38
37
39
38
use proc_macro:: bridge:: client:: ProcMacro ;
@@ -785,26 +784,11 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
785
784
self . opt_item_ident ( item_index, sess) . expect ( "no encoded ident for item" )
786
785
}
787
786
788
- fn maybe_kind ( self , item_id : DefIndex ) -> Option < EntryKind > {
789
- self . root . tables . kind . get ( self , item_id) . map ( |k| k. decode ( self ) )
790
- }
791
-
792
787
#[ inline]
793
788
pub ( super ) fn map_encoded_cnum_to_current ( self , cnum : CrateNum ) -> CrateNum {
794
789
if cnum == LOCAL_CRATE { self . cnum } else { self . cnum_map [ cnum] }
795
790
}
796
791
797
- fn kind ( self , item_id : DefIndex ) -> EntryKind {
798
- self . maybe_kind ( item_id) . unwrap_or_else ( || {
799
- bug ! (
800
- "CrateMetadata::kind({:?}): id not found, in crate {:?} with number {}" ,
801
- item_id,
802
- self . root. name,
803
- self . cnum,
804
- )
805
- } )
806
- }
807
-
808
792
fn def_kind ( self , item_id : DefIndex ) -> DefKind {
809
793
self . root . tables . opt_def_kind . get ( self , item_id) . unwrap_or_else ( || {
810
794
bug ! (
@@ -856,21 +840,16 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
856
840
)
857
841
}
858
842
859
- fn get_variant ( self , kind : & EntryKind , index : DefIndex , parent_did : DefId ) -> ty:: VariantDef {
860
- let data = match kind {
861
- EntryKind :: Variant ( data) | EntryKind :: Struct ( data) | EntryKind :: Union ( data) => {
862
- data. decode ( self )
863
- }
864
- _ => bug ! ( ) ,
865
- } ;
866
-
843
+ fn get_variant ( self , kind : & DefKind , index : DefIndex , parent_did : DefId ) -> ty:: VariantDef {
867
844
let adt_kind = match kind {
868
- EntryKind :: Variant ( _ ) => ty:: AdtKind :: Enum ,
869
- EntryKind :: Struct ( .. ) => ty:: AdtKind :: Struct ,
870
- EntryKind :: Union ( .. ) => ty:: AdtKind :: Union ,
845
+ DefKind :: Variant => ty:: AdtKind :: Enum ,
846
+ DefKind :: Struct => ty:: AdtKind :: Struct ,
847
+ DefKind :: Union => ty:: AdtKind :: Union ,
871
848
_ => bug ! ( ) ,
872
849
} ;
873
850
851
+ let data = self . root . tables . variant_data . get ( self , index) . unwrap ( ) . decode ( self ) ;
852
+
874
853
let variant_did =
875
854
if adt_kind == ty:: AdtKind :: Enum { Some ( self . local_def_id ( index) ) } else { None } ;
876
855
let ctor_did = data. ctor . map ( |index| self . local_def_id ( index) ) ;
@@ -901,13 +880,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
901
880
}
902
881
903
882
fn get_adt_def ( self , item_id : DefIndex , tcx : TyCtxt < ' tcx > ) -> ty:: AdtDef < ' tcx > {
904
- let kind = self . kind ( item_id) ;
883
+ let kind = self . def_kind ( item_id) ;
905
884
let did = self . local_def_id ( item_id) ;
906
885
907
886
let adt_kind = match kind {
908
- EntryKind :: Enum => ty:: AdtKind :: Enum ,
909
- EntryKind :: Struct ( _ ) => ty:: AdtKind :: Struct ,
910
- EntryKind :: Union ( _ ) => ty:: AdtKind :: Union ,
887
+ DefKind :: Enum => ty:: AdtKind :: Enum ,
888
+ DefKind :: Struct => ty:: AdtKind :: Struct ,
889
+ DefKind :: Union => ty:: AdtKind :: Union ,
911
890
_ => bug ! ( "get_adt_def called on a non-ADT {:?}" , did) ,
912
891
} ;
913
892
let repr = self . root . tables . repr_options . get ( self , item_id) . unwrap ( ) . decode ( self ) ;
@@ -919,7 +898,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
919
898
. get ( self , item_id)
920
899
. unwrap_or_else ( LazyArray :: empty)
921
900
. decode ( self )
922
- . map ( |index| self . get_variant ( & self . kind ( index) , index, did) )
901
+ . map ( |index| self . get_variant ( & self . def_kind ( index) , index, did) )
923
902
. collect ( )
924
903
} else {
925
904
std:: iter:: once ( self . get_variant ( & kind, item_id, did) ) . collect ( )
@@ -1029,10 +1008,9 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1029
1008
let vis = self . get_visibility ( child_index) ;
1030
1009
let span = self . get_span ( child_index, sess) ;
1031
1010
let macro_rules = match kind {
1032
- DefKind :: Macro ( ..) => match self . kind ( child_index) {
1033
- EntryKind :: MacroDef ( _, macro_rules) => macro_rules,
1034
- _ => unreachable ! ( ) ,
1035
- } ,
1011
+ DefKind :: Macro ( ..) => {
1012
+ self . root . tables . macro_rules . get ( self , child_index) . is_some ( )
1013
+ }
1036
1014
_ => false ,
1037
1015
} ;
1038
1016
@@ -1086,14 +1064,10 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1086
1064
}
1087
1065
}
1088
1066
1089
- match self . kind ( id) {
1090
- EntryKind :: Mod ( exports) => {
1091
- for exp in exports. decode ( ( self , sess) ) {
1092
- callback ( exp) ;
1093
- }
1067
+ if let Some ( exports) = self . root . tables . module_reexports . get ( self , id) {
1068
+ for exp in exports. decode ( ( self , sess) ) {
1069
+ callback ( exp) ;
1094
1070
}
1095
- EntryKind :: Enum | EntryKind :: Trait => { }
1096
- _ => bug ! ( "`for_each_module_child` is called on a non-module: {:?}" , self . def_kind( id) ) ,
1097
1071
}
1098
1072
}
1099
1073
@@ -1106,19 +1080,21 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1106
1080
}
1107
1081
1108
1082
fn module_expansion ( self , id : DefIndex , sess : & Session ) -> ExpnId {
1109
- match self . kind ( id) {
1110
- EntryKind :: Mod ( _) | EntryKind :: Enum | EntryKind :: Trait => {
1111
- self . get_expn_that_defined ( id, sess)
1112
- }
1083
+ match self . def_kind ( id) {
1084
+ DefKind :: Mod | DefKind :: Enum | DefKind :: Trait => self . get_expn_that_defined ( id, sess) ,
1113
1085
_ => panic ! ( "Expected module, found {:?}" , self . local_def_id( id) ) ,
1114
1086
}
1115
1087
}
1116
1088
1117
- fn get_fn_has_self_parameter ( self , id : DefIndex ) -> bool {
1118
- match self . kind ( id) {
1119
- EntryKind :: AssocFn { has_self, .. } => has_self,
1120
- _ => false ,
1121
- }
1089
+ fn get_fn_has_self_parameter ( self , id : DefIndex , sess : & ' a Session ) -> bool {
1090
+ self . root
1091
+ . tables
1092
+ . fn_arg_names
1093
+ . get ( self , id)
1094
+ . unwrap_or_else ( LazyArray :: empty)
1095
+ . decode ( ( self , sess) )
1096
+ . nth ( 0 )
1097
+ . map_or ( false , |ident| ident. name == kw:: SelfLower )
1122
1098
}
1123
1099
1124
1100
fn get_associated_item_def_ids (
@@ -1135,15 +1111,17 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1135
1111
. map ( move |child_index| self . local_def_id ( child_index) )
1136
1112
}
1137
1113
1138
- fn get_associated_item ( self , id : DefIndex ) -> ty:: AssocItem {
1114
+ fn get_associated_item ( self , id : DefIndex , sess : & ' a Session ) -> ty:: AssocItem {
1139
1115
let name = self . item_name ( id) ;
1140
1116
1141
- let ( kind, container , has_self ) = match self . kind ( id) {
1142
- EntryKind :: AssocConst ( container ) => ( ty:: AssocKind :: Const , container , false ) ,
1143
- EntryKind :: AssocFn { container , has_self } => ( ty:: AssocKind :: Fn , container , has_self ) ,
1144
- EntryKind :: AssocType ( container ) => ( ty:: AssocKind :: Type , container , false ) ,
1145
- _ => bug ! ( "cannot get associated-item of `{:?}`" , id ) ,
1117
+ let kind = match self . def_kind ( id) {
1118
+ DefKind :: AssocConst => ty:: AssocKind :: Const ,
1119
+ DefKind :: AssocFn => ty:: AssocKind :: Fn ,
1120
+ DefKind :: AssocTy => ty:: AssocKind :: Type ,
1121
+ _ => bug ! ( "cannot get associated-item of `{:?}`" , self . def_key ( id ) ) ,
1146
1122
} ;
1123
+ let has_self = self . get_fn_has_self_parameter ( id, sess) ;
1124
+ let container = self . root . tables . assoc_container . get ( self , id) . unwrap ( ) ;
1147
1125
1148
1126
ty:: AssocItem {
1149
1127
name,
@@ -1156,9 +1134,9 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1156
1134
}
1157
1135
1158
1136
fn get_ctor_def_id_and_kind ( self , node_id : DefIndex ) -> Option < ( DefId , CtorKind ) > {
1159
- match self . kind ( node_id) {
1160
- EntryKind :: Struct ( data ) | EntryKind :: Variant ( data ) => {
1161
- let vdata = data . decode ( self ) ;
1137
+ match self . def_kind ( node_id) {
1138
+ DefKind :: Struct | DefKind :: Variant => {
1139
+ let vdata = self . root . tables . variant_data . get ( self , node_id ) . unwrap ( ) . decode ( self ) ;
1162
1140
vdata. ctor . map ( |index| ( self . local_def_id ( index) , vdata. ctor_kind ) )
1163
1141
}
1164
1142
_ => None ,
@@ -1346,18 +1324,22 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1346
1324
}
1347
1325
1348
1326
fn get_macro ( self , id : DefIndex , sess : & Session ) -> ast:: MacroDef {
1349
- match self . kind ( id) {
1350
- EntryKind :: MacroDef ( mac_args, macro_rules) => {
1351
- ast:: MacroDef { body : P ( mac_args. decode ( ( self , sess) ) ) , macro_rules }
1327
+ match self . def_kind ( id) {
1328
+ DefKind :: Macro ( _) => {
1329
+ let macro_rules = self . root . tables . macro_rules . get ( self , id) . is_some ( ) ;
1330
+ let body =
1331
+ self . root . tables . macro_definition . get ( self , id) . unwrap ( ) . decode ( ( self , sess) ) ;
1332
+ ast:: MacroDef { macro_rules, body : ast:: ptr:: P ( body) }
1352
1333
}
1353
1334
_ => bug ! ( ) ,
1354
1335
}
1355
1336
}
1356
1337
1357
1338
fn is_foreign_item ( self , id : DefIndex ) -> bool {
1358
- match self . kind ( id) {
1359
- EntryKind :: ForeignStatic | EntryKind :: ForeignFn => true ,
1360
- _ => false ,
1339
+ if let Some ( parent) = self . def_key ( id) . parent {
1340
+ matches ! ( self . def_kind( parent) , DefKind :: ForeignMod )
1341
+ } else {
1342
+ false
1361
1343
}
1362
1344
}
1363
1345
0 commit comments