@@ -26,7 +26,7 @@ use rustc_middle::mir::interpret::{AllocDecodingSession, AllocDecodingState};
2626use rustc_middle:: ty:: Visibility ;
2727use rustc_middle:: ty:: codec:: TyDecoder ;
2828use rustc_middle:: { bug, implement_ty_decoder} ;
29- use rustc_proc_macro:: bridge:: client:: ProcMacro ;
29+ use rustc_proc_macro:: bridge:: client:: Client as ProcMacroClient ;
3030use rustc_serialize:: opaque:: MemDecoder ;
3131use rustc_serialize:: { Decodable , Decoder } ;
3232use rustc_session:: config:: TargetModifier ;
@@ -104,8 +104,8 @@ pub(crate) struct CrateMetadata {
104104 /// These can be introduced using either `#![rustc_coherence_is_core]`
105105 /// or `#[rustc_allow_incoherent_impl]`.
106106 incoherent_impls : FxIndexMap < SimplifiedType , LazyArray < DefIndex > > ,
107- /// Proc macro descriptions for this crate, if it's a proc macro crate.
108- raw_proc_macros : Option < & ' static [ ProcMacro ] > ,
107+ /// Proc macro function pointers for this crate, if it's a proc macro crate.
108+ raw_proc_macros : Option < & ' static [ ProcMacroClient ] > ,
109109 /// Source maps for code from the crate.
110110 source_map_import_info : Lock < Vec < Option < ImportedSourceFile > > > ,
111111 /// For every definition in this crate, maps its `DefPathHash` to its `DefIndex`.
@@ -930,6 +930,16 @@ impl MetadataBlob {
930930
931931 Ok ( ( ) )
932932 }
933+
934+ pub ( crate ) fn get_proc_macro_info ( & self ) -> Vec < ProcMacroKind > {
935+ self . get_root ( )
936+ . proc_macro_data
937+ . unwrap ( )
938+ . macros
939+ . decode ( self )
940+ . map ( |( _id, kind) | kind. decode ( self ) )
941+ . collect :: < Vec < _ > > ( )
942+ }
933943}
934944
935945impl CrateRoot {
@@ -976,19 +986,20 @@ impl CrateMetadata {
976986 bug ! ( "missing `{descr}` for {:?}" , self . local_def_id( id) )
977987 }
978988
979- fn raw_proc_macro ( & self , tcx : TyCtxt < ' _ > , id : DefIndex ) -> & ProcMacro {
989+ fn raw_proc_macro ( & self , tcx : TyCtxt < ' _ > , id : DefIndex ) -> ( ProcMacroClient , ProcMacroKind ) {
980990 // DefIndex's in root.proc_macro_data have a one-to-one correspondence
981991 // with items in 'raw_proc_macros'.
982- let pos = self
992+ let ( pos, ( _id , kind ) ) = self
983993 . root
984994 . proc_macro_data
985995 . as_ref ( )
986996 . unwrap ( )
987997 . macros
988998 . decode ( ( self , tcx) )
989- . position ( |i| i == id)
999+ . enumerate ( )
1000+ . find ( |( _pos, ( i, _) ) | * i == id)
9901001 . unwrap ( ) ;
991- & self . raw_proc_macros . unwrap ( ) [ pos]
1002+ ( self . raw_proc_macros . unwrap ( ) [ pos] , kind . decode ( ( self , tcx ) ) )
9921003 }
9931004
9941005 fn opt_item_name ( & self , item_index : DefIndex ) -> Option < Symbol > {
@@ -1046,20 +1057,20 @@ impl CrateMetadata {
10461057 }
10471058
10481059 fn load_proc_macro < ' tcx > ( & self , tcx : TyCtxt < ' tcx > , id : DefIndex ) -> SyntaxExtension {
1049- let ( name, kind, helper_attrs) = match * self . raw_proc_macro ( tcx, id) {
1050- ProcMacro :: CustomDerive { trait_name, attributes, client } => {
1060+ let ( name, kind, helper_attrs) = match self . raw_proc_macro ( tcx, id) {
1061+ ( client , ProcMacroKind :: CustomDerive { trait_name, attributes } ) => {
10511062 let helper_attrs =
1052- attributes. iter ( ) . cloned ( ) . map ( Symbol :: intern) . collect :: < Vec < _ > > ( ) ;
1063+ attributes. into_iter ( ) . map ( |attr| Symbol :: intern ( & attr ) ) . collect ( ) ;
10531064 (
10541065 trait_name,
10551066 SyntaxExtensionKind :: Derive ( Arc :: new ( DeriveProcMacro { client } ) ) ,
10561067 helper_attrs,
10571068 )
10581069 }
1059- ProcMacro :: Attr { name, client } => {
1070+ ( client , ProcMacroKind :: Attr { name } ) => {
10601071 ( name, SyntaxExtensionKind :: Attr ( Arc :: new ( AttrProcMacro { client } ) ) , Vec :: new ( ) )
10611072 }
1062- ProcMacro :: Bang { name, client } => {
1073+ ( client , ProcMacroKind :: Bang { name } ) => {
10631074 ( name, SyntaxExtensionKind :: Bang ( Arc :: new ( BangProcMacro { client } ) ) , Vec :: new ( ) )
10641075 }
10651076 } ;
@@ -1072,7 +1083,7 @@ impl CrateMetadata {
10721083 self . get_span ( tcx, id) ,
10731084 helper_attrs,
10741085 self . root . edition ,
1075- Symbol :: intern ( name) ,
1086+ Symbol :: intern ( & name) ,
10761087 & attrs,
10771088 false ,
10781089 )
@@ -1269,7 +1280,7 @@ impl CrateMetadata {
12691280 // If we are loading as a proc macro, we want to return
12701281 // the view of this crate as a proc macro crate.
12711282 if id == CRATE_DEF_INDEX {
1272- for child_index in data. macros . decode ( ( self , tcx) ) {
1283+ for ( child_index, _ ) in data. macros . decode ( ( self , tcx) ) {
12731284 yield self . get_mod_child ( tcx, child_index) ;
12741285 }
12751286 }
@@ -1872,7 +1883,7 @@ impl CrateMetadata {
18721883 tcx : TyCtxt < ' _ > ,
18731884 blob : MetadataBlob ,
18741885 root : CrateRoot ,
1875- raw_proc_macros : Option < & ' static [ ProcMacro ] > ,
1886+ raw_proc_macros : Option < & ' static [ ProcMacroClient ] > ,
18761887 cnum : CrateNum ,
18771888 cnum_map : CrateNumMap ,
18781889 dep_kind : CrateDepKind ,
@@ -2022,7 +2033,7 @@ impl CrateMetadata {
20222033 ) -> impl Iterator < Item = DefId > {
20232034 gen move {
20242035 for def_id in self . root . proc_macro_data . as_ref ( ) . into_iter ( ) . flat_map ( move |data| {
2025- data. macros . decode ( ( self , tcx) ) . map ( move |index| DefId { index, krate } )
2036+ data. macros . decode ( ( self , tcx) ) . map ( move |( index, _ ) | DefId { index, krate } )
20262037 } ) {
20272038 yield def_id;
20282039 }
0 commit comments