11
11
use front:: map as ast_map;
12
12
use metadata:: cstore;
13
13
use metadata:: decoder;
14
+ use metadata:: encoder;
15
+ use metadata:: loader;
14
16
use middle:: astencode;
17
+ use middle:: def;
15
18
use middle:: lang_items;
16
- use middle:: ty;
19
+ use middle:: ty:: { self , Ty } ;
17
20
use middle:: def_id:: { DefId , DefIndex } ;
21
+ use util:: nodemap:: { NodeMap , NodeSet } ;
18
22
19
23
use std:: any:: Any ;
24
+ use std:: cell:: RefCell ;
20
25
use std:: rc:: Rc ;
26
+ use std:: path:: PathBuf ;
21
27
use syntax:: ast;
22
28
use syntax:: attr;
29
+ use rustc_back:: target:: Target ;
23
30
use rustc_front:: hir;
24
31
32
+ pub use metadata:: common:: LinkMeta ;
33
+ pub use metadata:: creader:: validate_crate_name;
25
34
pub use metadata:: csearch:: FoundAst ;
35
+ pub use metadata:: cstore:: CrateSource ;
26
36
pub use metadata:: cstore:: LinkagePreference ;
37
+ pub use metadata:: cstore:: NativeLibraryKind ;
27
38
pub use metadata:: decoder:: DecodeInlinedItem ;
28
39
pub use metadata:: decoder:: DefLike ;
29
40
pub use metadata:: inline:: InlinedItem ;
30
41
31
42
pub use self :: DefLike :: { DlDef , DlField , DlImpl } ;
43
+ pub use self :: NativeLibraryKind :: { NativeStatic , NativeFramework , NativeUnknown } ;
32
44
33
45
pub struct ChildItem {
34
46
pub def : DefLike ,
@@ -54,6 +66,7 @@ pub trait CrateStore<'tcx> : Any {
54
66
fn item_super_predicates ( & self , tcx : & ty:: ctxt < ' tcx > , def : DefId )
55
67
-> ty:: GenericPredicates < ' tcx > ;
56
68
fn item_attrs ( & self , def_id : DefId ) -> Vec < ast:: Attribute > ;
69
+ fn item_symbol ( & self , def : DefId ) -> String ;
57
70
fn trait_def ( & self , tcx : & ty:: ctxt < ' tcx > , def : DefId ) -> ty:: TraitDef < ' tcx > ;
58
71
fn adt_def ( & self , tcx : & ty:: ctxt < ' tcx > , def : DefId ) -> ty:: AdtDefMaster < ' tcx > ;
59
72
fn inherent_implementations_for_type ( & self , def_id : DefId ) -> Vec < DefId > ;
@@ -86,14 +99,21 @@ pub trait CrateStore<'tcx> : Any {
86
99
fn is_defaulted_trait ( & self , did : DefId ) -> bool ;
87
100
fn is_impl ( & self , did : DefId ) -> bool ;
88
101
fn is_static_method ( & self , did : DefId ) -> bool ;
102
+ fn is_extern_fn ( & self , tcx : & ty:: ctxt < ' tcx > , did : DefId ) -> bool ;
103
+ fn is_static ( & self , did : DefId ) -> bool ;
89
104
90
- // metadata
105
+ // crate metadata
91
106
fn dylib_dependency_formats ( & self , cnum : ast:: CrateNum )
92
107
-> Vec < ( ast:: CrateNum , LinkagePreference ) > ;
93
108
fn lang_items ( & self , cnum : ast:: CrateNum ) -> Vec < ( DefIndex , usize ) > ;
94
109
fn missing_lang_items ( & self , cnum : ast:: CrateNum ) -> Vec < lang_items:: LangItem > ;
95
110
fn is_staged_api ( & self , cnum : ast:: CrateNum ) -> bool ;
111
+ fn is_explicitly_linked ( & self , cnum : ast:: CrateNum ) -> bool ;
112
+ fn is_allocator ( & self , cnum : ast:: CrateNum ) -> bool ;
113
+ fn crate_name ( & self , cnum : ast:: CrateNum ) -> String ;
96
114
fn plugin_registrar_fn ( & self , cnum : ast:: CrateNum ) -> Option < DefId > ;
115
+ fn native_libraries ( & self , cnum : ast:: CrateNum ) -> Vec < ( NativeLibraryKind , String ) > ;
116
+ fn reachable_ids ( & self , cnum : ast:: CrateNum ) -> Vec < DefId > ;
97
117
98
118
// resolve
99
119
fn def_path ( & self , def : DefId ) -> ast_map:: DefPath ;
@@ -102,9 +122,24 @@ pub trait CrateStore<'tcx> : Any {
102
122
fn item_children ( & self , did : DefId ) -> Vec < ChildItem > ;
103
123
fn crate_top_level_items ( & self , cnum : ast:: CrateNum ) -> Vec < ChildItem > ;
104
124
105
- // misc.
125
+ // misc. metadata
106
126
fn maybe_get_item_ast ( & ' tcx self , tcx : & ty:: ctxt < ' tcx > , def : DefId )
107
127
-> FoundAst < ' tcx > ;
128
+
129
+ // utility functions
130
+ fn metadata_filename ( & self ) -> & str ;
131
+ fn metadata_section_name ( & self , target : & Target ) -> & str ;
132
+ fn encode_type ( & self , tcx : & ty:: ctxt < ' tcx > , ty : Ty < ' tcx > ) -> Vec < u8 > ;
133
+ fn used_crates ( & self , prefer : LinkagePreference ) -> Vec < ( ast:: CrateNum , Option < PathBuf > ) > ;
134
+ fn used_crate_source ( & self , cnum : ast:: CrateNum ) -> CrateSource ;
135
+ fn encode_metadata ( & self ,
136
+ tcx : & ty:: ctxt < ' tcx > ,
137
+ reexports : & def:: ExportMap ,
138
+ item_symbols : & RefCell < NodeMap < String > > ,
139
+ link_meta : & LinkMeta ,
140
+ reachable : & NodeSet ,
141
+ krate : & hir:: Crate ) -> Vec < u8 > ;
142
+ fn metadata_encoding_version ( & self ) -> & [ u8 ] ;
108
143
}
109
144
110
145
impl < ' tcx > CrateStore < ' tcx > for cstore:: CStore {
@@ -165,6 +200,12 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
165
200
decoder:: get_item_attrs ( & * cdata, def_id. index )
166
201
}
167
202
203
+ fn item_symbol ( & self , def : DefId ) -> String
204
+ {
205
+ let cdata = self . get_crate_data ( def. krate ) ;
206
+ decoder:: get_symbol ( & cdata, def. index )
207
+ }
208
+
168
209
fn trait_def ( & self , tcx : & ty:: ctxt < ' tcx > , def : DefId ) -> ty:: TraitDef < ' tcx >
169
210
{
170
211
let cdata = self . get_crate_data ( def. krate ) ;
@@ -285,21 +326,36 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
285
326
decoder:: is_const_fn ( & cdata, did. index )
286
327
}
287
328
288
- fn is_defaulted_trait ( & self , trait_def_id : DefId ) -> bool {
329
+ fn is_defaulted_trait ( & self , trait_def_id : DefId ) -> bool
330
+ {
289
331
let cdata = self . get_crate_data ( trait_def_id. krate ) ;
290
332
decoder:: is_defaulted_trait ( & * cdata, trait_def_id. index )
291
333
}
292
334
293
- fn is_impl ( & self , did : DefId ) -> bool {
335
+ fn is_impl ( & self , did : DefId ) -> bool
336
+ {
294
337
let cdata = self . get_crate_data ( did. krate ) ;
295
338
decoder:: is_impl ( & * cdata, did. index )
296
339
}
297
340
298
- fn is_static_method ( & self , def : DefId ) -> bool {
341
+ fn is_static_method ( & self , def : DefId ) -> bool
342
+ {
299
343
let cdata = self . get_crate_data ( def. krate ) ;
300
344
decoder:: is_static_method ( & * cdata, def. index )
301
345
}
302
346
347
+ fn is_extern_fn ( & self , tcx : & ty:: ctxt < ' tcx > , did : DefId ) -> bool
348
+ {
349
+ let cdata = self . get_crate_data ( did. krate ) ;
350
+ decoder:: is_extern_fn ( & * cdata, did. index , tcx)
351
+ }
352
+
353
+ fn is_static ( & self , did : DefId ) -> bool
354
+ {
355
+ let cdata = self . get_crate_data ( did. krate ) ;
356
+ decoder:: is_static ( & * cdata, did. index )
357
+ }
358
+
303
359
fn dylib_dependency_formats ( & self , cnum : ast:: CrateNum )
304
360
-> Vec < ( ast:: CrateNum , LinkagePreference ) >
305
361
{
@@ -329,6 +385,21 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
329
385
self . get_crate_data ( cnum) . staged_api
330
386
}
331
387
388
+ fn is_explicitly_linked ( & self , cnum : ast:: CrateNum ) -> bool
389
+ {
390
+ self . get_crate_data ( cnum) . explicitly_linked . get ( )
391
+ }
392
+
393
+ fn is_allocator ( & self , cnum : ast:: CrateNum ) -> bool
394
+ {
395
+ self . get_crate_data ( cnum) . is_allocator ( )
396
+ }
397
+
398
+ fn crate_name ( & self , cnum : ast:: CrateNum ) -> String
399
+ {
400
+ self . get_crate_data ( cnum) . name . clone ( )
401
+ }
402
+
332
403
fn plugin_registrar_fn ( & self , cnum : ast:: CrateNum ) -> Option < DefId >
333
404
{
334
405
let cdata = self . get_crate_data ( cnum) ;
@@ -338,6 +409,18 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
338
409
} )
339
410
}
340
411
412
+ fn native_libraries ( & self , cnum : ast:: CrateNum ) -> Vec < ( NativeLibraryKind , String ) >
413
+ {
414
+ let cdata = self . get_crate_data ( cnum) ;
415
+ decoder:: get_native_libraries ( & * cdata)
416
+ }
417
+
418
+ fn reachable_ids ( & self , cnum : ast:: CrateNum ) -> Vec < DefId >
419
+ {
420
+ let cdata = self . get_crate_data ( cnum) ;
421
+ decoder:: get_reachable_ids ( & * cdata)
422
+ }
423
+
341
424
fn def_path ( & self , def : DefId ) -> ast_map:: DefPath
342
425
{
343
426
let cdata = self . get_crate_data ( def. krate ) ;
@@ -396,4 +479,58 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
396
479
let decode_inlined_item = Box :: new ( astencode:: decode_inlined_item) ;
397
480
decoder:: maybe_get_item_ast ( & * cdata, tcx, def. index , decode_inlined_item)
398
481
}
482
+
483
+ fn metadata_filename ( & self ) -> & str
484
+ {
485
+ loader:: METADATA_FILENAME
486
+ }
487
+
488
+ fn metadata_section_name ( & self , target : & Target ) -> & str
489
+ {
490
+ loader:: meta_section_name ( target)
491
+ }
492
+ fn encode_type ( & self , tcx : & ty:: ctxt < ' tcx > , ty : Ty < ' tcx > ) -> Vec < u8 >
493
+ {
494
+ encoder:: encoded_ty ( tcx, ty)
495
+ }
496
+
497
+ fn used_crates ( & self , prefer : LinkagePreference ) -> Vec < ( ast:: CrateNum , Option < PathBuf > ) >
498
+ {
499
+ self . do_get_used_crates ( prefer)
500
+ }
501
+
502
+ fn used_crate_source ( & self , cnum : ast:: CrateNum ) -> CrateSource
503
+ {
504
+ self . do_get_used_crate_source ( cnum) . unwrap ( )
505
+ }
506
+
507
+ fn encode_metadata ( & self ,
508
+ tcx : & ty:: ctxt < ' tcx > ,
509
+ reexports : & def:: ExportMap ,
510
+ item_symbols : & RefCell < NodeMap < String > > ,
511
+ link_meta : & LinkMeta ,
512
+ reachable : & NodeSet ,
513
+ krate : & hir:: Crate ) -> Vec < u8 >
514
+ {
515
+ let encode_inlined_item: encoder:: EncodeInlinedItem =
516
+ Box :: new ( |ecx, rbml_w, ii| astencode:: encode_inlined_item ( ecx, rbml_w, ii) ) ;
517
+
518
+ let encode_params = encoder:: EncodeParams {
519
+ diag : tcx. sess . diagnostic ( ) ,
520
+ tcx : tcx,
521
+ reexports : reexports,
522
+ item_symbols : item_symbols,
523
+ link_meta : link_meta,
524
+ cstore : self ,
525
+ encode_inlined_item : encode_inlined_item,
526
+ reachable : reachable
527
+ } ;
528
+ encoder:: encode_metadata ( encode_params, krate)
529
+
530
+ }
531
+
532
+ fn metadata_encoding_version ( & self ) -> & [ u8 ]
533
+ {
534
+ encoder:: metadata_encoding_version
535
+ }
399
536
}
0 commit comments