2
2
3
3
use crate :: cstore:: { self , CStore , CrateSource , MetadataBlob } ;
4
4
use crate :: locator:: { self , CratePaths } ;
5
- use crate :: decoder:: proc_macro_def_path_table;
6
- use crate :: schema:: CrateRoot ;
5
+ use crate :: schema:: { CrateRoot } ;
7
6
use rustc_data_structures:: sync:: { Lrc , RwLock , Lock } ;
8
7
9
8
use rustc:: hir:: def_id:: CrateNum ;
@@ -26,11 +25,11 @@ use std::{cmp, fs};
26
25
use syntax:: ast;
27
26
use syntax:: attr;
28
27
use syntax:: ext:: allocator:: { global_allocator_spans, AllocatorKind } ;
29
- use syntax:: ext:: base:: { SyntaxExtension , SyntaxExtensionKind } ;
30
28
use syntax:: symbol:: { Symbol , sym} ;
31
29
use syntax:: { span_err, span_fatal} ;
32
30
use syntax_pos:: { Span , DUMMY_SP } ;
33
31
use log:: { debug, info, log_enabled} ;
32
+ use proc_macro:: bridge:: client:: ProcMacro ;
34
33
35
34
pub struct Library {
36
35
pub dylib : Option < ( PathBuf , PathKind ) > ,
@@ -230,24 +229,13 @@ impl<'a> CrateLoader<'a> {
230
229
231
230
let dependencies: Vec < CrateNum > = cnum_map. iter ( ) . cloned ( ) . collect ( ) ;
232
231
233
- let proc_macros = crate_root. proc_macro_decls_static . map ( |_| {
232
+ let raw_proc_macros = crate_root. proc_macro_data . map ( |_| {
234
233
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)
241
237
} 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)
251
239
}
252
240
} ) ;
253
241
@@ -260,13 +248,16 @@ impl<'a> CrateLoader<'a> {
260
248
. map ( |trait_impls| ( trait_impls. trait_id , trait_impls. impls ) )
261
249
. collect ( ) ;
262
250
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
+
263
255
let cmeta = cstore:: CrateMetadata {
264
256
name : crate_root. name ,
265
257
imported_name : ident,
266
258
extern_crate : Lock :: new ( None ) ,
267
259
def_path_table : Lrc :: new ( def_path_table) ,
268
260
trait_impls,
269
- proc_macros,
270
261
root : crate_root,
271
262
blob : metadata,
272
263
cnum_map,
@@ -280,7 +271,10 @@ impl<'a> CrateLoader<'a> {
280
271
rlib,
281
272
rmeta,
282
273
} ,
283
- private_dep
274
+ private_dep,
275
+ span,
276
+ host_lib,
277
+ raw_proc_macros
284
278
} ;
285
279
286
280
let cmeta = Lrc :: new ( cmeta) ;
@@ -300,8 +294,6 @@ impl<'a> CrateLoader<'a> {
300
294
// message we emit
301
295
let mut proc_macro_locator = locate_ctxt. clone ( ) ;
302
296
303
- // Try to load a proc macro
304
- proc_macro_locator. is_proc_macro = Some ( true ) ;
305
297
306
298
// Load the proc macro crate for the target
307
299
let ( locator, target_result) = if self . sess . opts . debugging_opts . dual_proc_macros {
@@ -389,7 +381,7 @@ impl<'a> CrateLoader<'a> {
389
381
match result {
390
382
( LoadResult :: Previous ( cnum) , None ) => {
391
383
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 ( ) {
393
385
dep_kind = DepKind :: UnexportedMacrosOnly ;
394
386
}
395
387
data. dep_kind . with_lock ( |data_dep_kind| {
@@ -482,7 +474,7 @@ impl<'a> CrateLoader<'a> {
482
474
dep_kind : DepKind )
483
475
-> cstore:: CrateNumMap {
484
476
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 ( ) {
486
478
return cstore:: CrateNumMap :: new ( ) ;
487
479
}
488
480
@@ -574,19 +566,13 @@ impl<'a> CrateLoader<'a> {
574
566
}
575
567
}
576
568
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;
587
575
use crate :: dynamic_lib:: DynamicLibrary ;
588
- use proc_macro:: bridge:: client:: ProcMacro ;
589
- use syntax:: ext:: proc_macro:: { BangProcMacro , AttrProcMacro , ProcMacroDerive } ;
590
576
591
577
let path = match dylib {
592
578
Some ( dylib) => dylib,
@@ -608,38 +594,11 @@ impl<'a> CrateLoader<'a> {
608
594
* ( sym as * const & [ ProcMacro ] )
609
595
} ;
610
596
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
-
638
597
// Intentionally leak the dynamic library. We can't ever unload it
639
598
// since the library can make things that will live arbitrarily long.
640
- mem:: forget ( lib) ;
599
+ std :: mem:: forget ( lib) ;
641
600
642
- extensions
601
+ decls
643
602
}
644
603
645
604
/// Look for a plugin registrar. Returns library path, crate
0 commit comments