@@ -43,12 +43,14 @@ use log;
43
43
44
44
pub struct LocalCrateReader < ' a , ' b : ' a > {
45
45
sess : & ' a Session ,
46
+ cstore : & ' a CStore ,
46
47
creader : CrateReader < ' a > ,
47
48
ast_map : & ' a hir_map:: Map < ' b > ,
48
49
}
49
50
50
51
pub struct CrateReader < ' a > {
51
52
sess : & ' a Session ,
53
+ cstore : & ' a CStore ,
52
54
next_crate_num : ast:: CrateNum ,
53
55
foreign_item_map : FnvHashMap < String , Vec < ast:: NodeId > > ,
54
56
}
@@ -113,6 +115,7 @@ pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
113
115
114
116
115
117
fn register_native_lib ( sess : & Session ,
118
+ cstore : & CStore ,
116
119
span : Option < Span > ,
117
120
name : String ,
118
121
kind : cstore:: NativeLibraryKind ) {
@@ -139,7 +142,7 @@ fn register_native_lib(sess: &Session,
139
142
None => sess. err ( msg) ,
140
143
}
141
144
}
142
- sess . cstore . add_used_library ( name, kind) ;
145
+ cstore. add_used_library ( name, kind) ;
143
146
}
144
147
145
148
// Extra info about a crate loaded for plugins or exported macros.
@@ -164,10 +167,11 @@ impl PMDSource {
164
167
}
165
168
166
169
impl < ' a > CrateReader < ' a > {
167
- pub fn new ( sess : & ' a Session ) -> CrateReader < ' a > {
170
+ pub fn new ( sess : & ' a Session , cstore : & ' a CStore ) -> CrateReader < ' a > {
168
171
CrateReader {
169
172
sess : sess,
170
- next_crate_num : sess. cstore . next_crate_num ( ) ,
173
+ cstore : cstore,
174
+ next_crate_num : cstore. next_crate_num ( ) ,
171
175
foreign_item_map : FnvHashMap ( ) ,
172
176
}
173
177
}
@@ -224,7 +228,7 @@ impl<'a> CrateReader<'a> {
224
228
fn existing_match ( & self , name : & str , hash : Option < & Svh > , kind : PathKind )
225
229
-> Option < ast:: CrateNum > {
226
230
let mut ret = None ;
227
- self . sess . cstore . iter_crate_data ( |cnum, data| {
231
+ self . cstore . iter_crate_data ( |cnum, data| {
228
232
if data. name != name { return }
229
233
230
234
match hash {
@@ -242,7 +246,7 @@ impl<'a> CrateReader<'a> {
242
246
// We're also sure to compare *paths*, not actual byte slices. The
243
247
// `source` stores paths which are normalized which may be different
244
248
// from the strings on the command line.
245
- let source = self . sess . cstore . do_get_used_crate_source ( cnum) . unwrap ( ) ;
249
+ let source = self . cstore . do_get_used_crate_source ( cnum) . unwrap ( ) ;
246
250
if let Some ( locs) = self . sess . opts . externs . get ( name) {
247
251
let found = locs. iter ( ) . any ( |l| {
248
252
let l = fs:: canonicalize ( l) . ok ( ) ;
@@ -342,8 +346,8 @@ impl<'a> CrateReader<'a> {
342
346
cnum : cnum,
343
347
} ;
344
348
345
- self . sess . cstore . set_crate_data ( cnum, cmeta. clone ( ) ) ;
346
- self . sess . cstore . add_used_crate_source ( source. clone ( ) ) ;
349
+ self . cstore . set_crate_data ( cnum, cmeta. clone ( ) ) ;
350
+ self . cstore . add_used_crate_source ( source. clone ( ) ) ;
347
351
( cnum, cmeta, source)
348
352
}
349
353
@@ -398,7 +402,7 @@ impl<'a> CrateReader<'a> {
398
402
let meta_hash = decoder:: get_crate_hash ( library. metadata
399
403
. as_slice ( ) ) ;
400
404
let mut result = LookupResult :: Loaded ( library) ;
401
- self . sess . cstore . iter_crate_data ( |cnum, data| {
405
+ self . cstore . iter_crate_data ( |cnum, data| {
402
406
if data. name ( ) == name && meta_hash == data. hash ( ) {
403
407
assert ! ( hash. is_none( ) ) ;
404
408
result = LookupResult :: Previous ( cnum) ;
@@ -410,11 +414,11 @@ impl<'a> CrateReader<'a> {
410
414
411
415
match result {
412
416
LookupResult :: Previous ( cnum) => {
413
- let data = self . sess . cstore . get_crate_data ( cnum) ;
417
+ let data = self . cstore . get_crate_data ( cnum) ;
414
418
if explicitly_linked && !data. explicitly_linked . get ( ) {
415
419
data. explicitly_linked . set ( explicitly_linked) ;
416
420
}
417
- ( cnum, data, self . sess . cstore . do_get_used_crate_source ( cnum) . unwrap ( ) )
421
+ ( cnum, data, self . cstore . do_get_used_crate_source ( cnum) . unwrap ( ) )
418
422
}
419
423
LookupResult :: Loaded ( library) => {
420
424
self . register_crate ( root, ident, name, span, library,
@@ -512,7 +516,7 @@ impl<'a> CrateReader<'a> {
512
516
let source_name = format ! ( "<{} macros>" , item. ident) ;
513
517
let mut macros = vec ! [ ] ;
514
518
decoder:: each_exported_macro ( ekrate. metadata . as_slice ( ) ,
515
- & * self . sess . cstore . intr ,
519
+ & * self . cstore . intr ,
516
520
|name, attrs, body| {
517
521
// NB: Don't use parse::parse_tts_from_source_str because it parses with
518
522
// quote_depth > 0.
@@ -593,14 +597,14 @@ impl<'a> CrateReader<'a> {
593
597
}
594
598
595
599
fn register_statically_included_foreign_items ( & mut self ) {
596
- let libs = self . sess . cstore . get_used_libraries ( ) ;
600
+ let libs = self . cstore . get_used_libraries ( ) ;
597
601
for ( lib, list) in self . foreign_item_map . iter ( ) {
598
602
let is_static = libs. borrow ( ) . iter ( ) . any ( |& ( ref name, kind) | {
599
603
lib == name && kind == cstore:: NativeStatic
600
604
} ) ;
601
605
if is_static {
602
606
for id in list {
603
- self . sess . cstore . add_statically_included_foreign_item ( * id) ;
607
+ self . cstore . add_statically_included_foreign_item ( * id) ;
604
608
}
605
609
}
606
610
}
@@ -614,7 +618,7 @@ impl<'a> CrateReader<'a> {
614
618
// also bail out as we don't need to implicitly inject one.
615
619
let mut needs_allocator = false ;
616
620
let mut found_required_allocator = false ;
617
- self . sess . cstore . iter_crate_data ( |cnum, data| {
621
+ self . cstore . iter_crate_data ( |cnum, data| {
618
622
needs_allocator = needs_allocator || data. needs_allocator ( ) ;
619
623
if data. is_allocator ( ) {
620
624
debug ! ( "{} required by rlib and is an allocator" , data. name( ) ) ;
@@ -693,7 +697,7 @@ impl<'a> CrateReader<'a> {
693
697
//
694
698
// Here we inject a dependency from all crates with #![needs_allocator]
695
699
// to the crate tagged with #![allocator] for this compilation unit.
696
- self . sess . cstore . iter_crate_data ( |cnum, data| {
700
+ self . cstore . iter_crate_data ( |cnum, data| {
697
701
if !data. needs_allocator ( ) {
698
702
return
699
703
}
@@ -707,10 +711,10 @@ impl<'a> CrateReader<'a> {
707
711
708
712
fn validate ( me : & CrateReader , krate : ast:: CrateNum ,
709
713
allocator : ast:: CrateNum ) {
710
- let data = me. sess . cstore . get_crate_data ( krate) ;
714
+ let data = me. cstore . get_crate_data ( krate) ;
711
715
if data. needs_allocator ( ) {
712
716
let krate_name = data. name ( ) ;
713
- let data = me. sess . cstore . get_crate_data ( allocator) ;
717
+ let data = me. cstore . get_crate_data ( allocator) ;
714
718
let alloc_name = data. name ( ) ;
715
719
me. sess . err ( & format ! ( "the allocator crate `{}` cannot depend \
716
720
on a crate that needs an allocator, but \
@@ -726,10 +730,11 @@ impl<'a> CrateReader<'a> {
726
730
}
727
731
728
732
impl < ' a , ' b > LocalCrateReader < ' a , ' b > {
729
- pub fn new ( sess : & ' a Session , map : & ' a hir_map:: Map < ' b > ) -> LocalCrateReader < ' a , ' b > {
733
+ pub fn new ( sess : & ' a Session , cstore : & ' a CStore , map : & ' a hir_map:: Map < ' b > ) -> LocalCrateReader < ' a , ' b > {
730
734
LocalCrateReader {
731
735
sess : sess,
732
- creader : CrateReader :: new ( sess) ,
736
+ cstore : cstore,
737
+ creader : CrateReader :: new ( sess, cstore) ,
733
738
ast_map : map,
734
739
}
735
740
}
@@ -743,19 +748,19 @@ impl<'a, 'b> LocalCrateReader<'a, 'b> {
743
748
self . creader . inject_allocator_crate ( ) ;
744
749
745
750
if log_enabled ! ( log:: INFO ) {
746
- dump_crates ( & self . sess . cstore ) ;
751
+ dump_crates ( & self . cstore ) ;
747
752
}
748
753
749
754
for & ( ref name, kind) in & self . sess . opts . libs {
750
- register_native_lib ( self . sess , None , name. clone ( ) , kind) ;
755
+ register_native_lib ( self . sess , self . cstore , None , name. clone ( ) , kind) ;
751
756
}
752
757
self . creader . register_statically_included_foreign_items ( ) ;
753
758
}
754
759
755
760
fn process_crate ( & self , c : & hir:: Crate ) {
756
761
for a in c. attrs . iter ( ) . filter ( |m| m. name ( ) == "link_args" ) {
757
762
match a. value_str ( ) {
758
- Some ( ref linkarg) => self . sess . cstore . add_used_link_args ( & linkarg) ,
763
+ Some ( ref linkarg) => self . cstore . add_used_link_args ( & linkarg) ,
759
764
None => { /* fallthrough */ }
760
765
}
761
766
}
@@ -783,7 +788,7 @@ impl<'a, 'b> LocalCrateReader<'a, 'b> {
783
788
self . ast_map . with_path ( i. id , |path| {
784
789
cmeta. update_local_path ( path)
785
790
} ) ;
786
- self . sess . cstore . add_extern_mod_stmt_cnum ( info. id , cnum) ;
791
+ self . cstore . add_extern_mod_stmt_cnum ( info. id , cnum) ;
787
792
}
788
793
None => ( )
789
794
}
@@ -801,7 +806,7 @@ impl<'a, 'b> LocalCrateReader<'a, 'b> {
801
806
// First, add all of the custom #[link_args] attributes
802
807
for m in i. attrs . iter ( ) . filter ( |a| a. check_name ( "link_args" ) ) {
803
808
if let Some ( linkarg) = m. value_str ( ) {
804
- self . sess . cstore . add_used_link_args ( & linkarg) ;
809
+ self . cstore . add_used_link_args ( & linkarg) ;
805
810
}
806
811
}
807
812
@@ -836,7 +841,7 @@ impl<'a, 'b> LocalCrateReader<'a, 'b> {
836
841
InternedString :: new ( "foo" )
837
842
}
838
843
} ;
839
- register_native_lib ( self . sess , Some ( m. span ) , n. to_string ( ) , kind) ;
844
+ register_native_lib ( self . sess , self . cstore , Some ( m. span ) , n. to_string ( ) , kind) ;
840
845
}
841
846
842
847
// Finally, process the #[linked_from = "..."] attribute
0 commit comments