22
33use crate :: cstore:: { self , CStore , CrateSource , MetadataBlob } ;
44use crate :: locator:: { self , CratePaths } ;
5- use crate :: decoder:: proc_macro_def_path_table;
6- use crate :: schema:: CrateRoot ;
5+ use crate :: schema:: { CrateRoot } ;
76use rustc_data_structures:: sync:: { Lrc , RwLock , Lock } ;
87
98use rustc:: hir:: def_id:: CrateNum ;
@@ -26,11 +25,11 @@ use std::{cmp, fs};
2625use syntax:: ast;
2726use syntax:: attr;
2827use syntax:: ext:: allocator:: { global_allocator_spans, AllocatorKind } ;
29- use syntax:: ext:: base:: { SyntaxExtension , SyntaxExtensionKind } ;
3028use syntax:: symbol:: { Symbol , sym} ;
3129use syntax:: { span_err, span_fatal} ;
3230use syntax_pos:: { Span , DUMMY_SP } ;
3331use log:: { debug, info, log_enabled} ;
32+ use proc_macro:: bridge:: client:: ProcMacro ;
3433
3534pub struct Library {
3635 pub dylib : Option < ( PathBuf , PathKind ) > ,
@@ -230,24 +229,13 @@ impl<'a> CrateLoader<'a> {
230229
231230 let dependencies: Vec < CrateNum > = cnum_map. iter ( ) . cloned ( ) . collect ( ) ;
232231
233- let proc_macros = crate_root. proc_macro_decls_static . map ( |_| {
232+ let raw_proc_macros = crate_root. proc_macro_data . map ( |_| {
234233 if self . sess . opts . debugging_opts . dual_proc_macros {
235- let host_lib = host_lib. unwrap ( ) ;
236- self . load_derive_macros (
237- & host_lib. metadata . get_root ( ) ,
238- host_lib. dylib . map ( |p| p. 0 ) ,
239- span
240- )
234+ let host_lib = host_lib. as_ref ( ) . unwrap ( ) ;
235+ self . dlsym_proc_macros ( host_lib. dylib . as_ref ( ) . map ( |p| p. 0 . clone ( ) ) ,
236+ & host_lib. metadata . get_root ( ) , span)
241237 } else {
242- self . load_derive_macros ( & crate_root, dylib. clone ( ) . map ( |p| p. 0 ) , span)
243- }
244- } ) ;
245-
246- let def_path_table = record_time ( & self . sess . perf_stats . decode_def_path_tables_time , || {
247- if let Some ( proc_macros) = & proc_macros {
248- proc_macro_def_path_table ( & crate_root, proc_macros)
249- } else {
250- crate_root. def_path_table . decode ( ( & metadata, self . sess ) )
238+ self . dlsym_proc_macros ( dylib. clone ( ) . map ( |p| p. 0 ) , & crate_root, span)
251239 }
252240 } ) ;
253241
@@ -260,13 +248,16 @@ impl<'a> CrateLoader<'a> {
260248 . map ( |trait_impls| ( trait_impls. trait_id , trait_impls. impls ) )
261249 . collect ( ) ;
262250
251+ let def_path_table = record_time ( & self . sess . perf_stats . decode_def_path_tables_time , || {
252+ crate_root. def_path_table . decode ( ( & metadata, self . sess ) )
253+ } ) ;
254+
263255 let cmeta = cstore:: CrateMetadata {
264256 name : crate_root. name ,
265257 imported_name : ident,
266258 extern_crate : Lock :: new ( None ) ,
267259 def_path_table : Lrc :: new ( def_path_table) ,
268260 trait_impls,
269- proc_macros,
270261 root : crate_root,
271262 blob : metadata,
272263 cnum_map,
@@ -280,7 +271,10 @@ impl<'a> CrateLoader<'a> {
280271 rlib,
281272 rmeta,
282273 } ,
283- private_dep
274+ private_dep,
275+ span,
276+ host_lib,
277+ raw_proc_macros
284278 } ;
285279
286280 let cmeta = Lrc :: new ( cmeta) ;
@@ -300,8 +294,6 @@ impl<'a> CrateLoader<'a> {
300294 // message we emit
301295 let mut proc_macro_locator = locate_ctxt. clone ( ) ;
302296
303- // Try to load a proc macro
304- proc_macro_locator. is_proc_macro = Some ( true ) ;
305297
306298 // Load the proc macro crate for the target
307299 let ( locator, target_result) = if self . sess . opts . debugging_opts . dual_proc_macros {
@@ -389,7 +381,7 @@ impl<'a> CrateLoader<'a> {
389381 match result {
390382 ( LoadResult :: Previous ( cnum) , None ) => {
391383 let data = self . cstore . get_crate_data ( cnum) ;
392- if data. root . proc_macro_decls_static . is_some ( ) {
384+ if data. root . proc_macro_data . is_some ( ) {
393385 dep_kind = DepKind :: UnexportedMacrosOnly ;
394386 }
395387 data. dep_kind . with_lock ( |data_dep_kind| {
@@ -482,7 +474,7 @@ impl<'a> CrateLoader<'a> {
482474 dep_kind : DepKind )
483475 -> cstore:: CrateNumMap {
484476 debug ! ( "resolving deps of external crate" ) ;
485- if crate_root. proc_macro_decls_static . is_some ( ) {
477+ if crate_root. proc_macro_data . is_some ( ) {
486478 return cstore:: CrateNumMap :: new ( ) ;
487479 }
488480
@@ -574,19 +566,13 @@ impl<'a> CrateLoader<'a> {
574566 }
575567 }
576568
577- /// Loads custom derive macros.
578- ///
579- /// Note that this is intentionally similar to how we load plugins today,
580- /// but also intentionally separate. Plugins are likely always going to be
581- /// implemented as dynamic libraries, but we have a possible future where
582- /// custom derive (and other macro-1.1 style features) are implemented via
583- /// executables and custom IPC.
584- fn load_derive_macros ( & mut self , root : & CrateRoot < ' _ > , dylib : Option < PathBuf > , span : Span )
585- -> Vec < ( ast:: Name , Lrc < SyntaxExtension > ) > {
586- use std:: { env, mem} ;
569+ fn dlsym_proc_macros ( & self ,
570+ dylib : Option < PathBuf > ,
571+ root : & CrateRoot < ' _ > ,
572+ span : Span
573+ ) -> & ' static [ ProcMacro ] {
574+ use std:: env;
587575 use crate :: dynamic_lib:: DynamicLibrary ;
588- use proc_macro:: bridge:: client:: ProcMacro ;
589- use syntax:: ext:: proc_macro:: { BangProcMacro , AttrProcMacro , ProcMacroDerive } ;
590576
591577 let path = match dylib {
592578 Some ( dylib) => dylib,
@@ -608,38 +594,11 @@ impl<'a> CrateLoader<'a> {
608594 * ( sym as * const & [ ProcMacro ] )
609595 } ;
610596
611- let extensions = decls. iter ( ) . map ( |& decl| {
612- let ( name, kind, helper_attrs) = match decl {
613- ProcMacro :: CustomDerive { trait_name, attributes, client } => {
614- let helper_attrs =
615- attributes. iter ( ) . cloned ( ) . map ( Symbol :: intern) . collect :: < Vec < _ > > ( ) ;
616- (
617- trait_name,
618- SyntaxExtensionKind :: Derive ( Box :: new ( ProcMacroDerive {
619- client, attrs : helper_attrs. clone ( )
620- } ) ) ,
621- helper_attrs,
622- )
623- }
624- ProcMacro :: Attr { name, client } => (
625- name, SyntaxExtensionKind :: Attr ( Box :: new ( AttrProcMacro { client } ) ) , Vec :: new ( )
626- ) ,
627- ProcMacro :: Bang { name, client } => (
628- name, SyntaxExtensionKind :: Bang ( Box :: new ( BangProcMacro { client } ) ) , Vec :: new ( )
629- )
630- } ;
631-
632- ( Symbol :: intern ( name) , Lrc :: new ( SyntaxExtension {
633- helper_attrs,
634- ..SyntaxExtension :: default ( kind, root. edition )
635- } ) )
636- } ) . collect ( ) ;
637-
638597 // Intentionally leak the dynamic library. We can't ever unload it
639598 // since the library can make things that will live arbitrarily long.
640- mem:: forget ( lib) ;
599+ std :: mem:: forget ( lib) ;
641600
642- extensions
601+ decls
643602 }
644603
645604 /// Look for a plugin registrar. Returns library path, crate
0 commit comments