@@ -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
@@ -399,7 +403,7 @@ impl<'a> CrateReader<'a> {
399
403
let meta_hash = decoder:: get_crate_hash ( library. metadata
400
404
. as_slice ( ) ) ;
401
405
let mut result = LookupResult :: Loaded ( library) ;
402
- self . sess . cstore . iter_crate_data ( |cnum, data| {
406
+ self . cstore . iter_crate_data ( |cnum, data| {
403
407
if data. name ( ) == name && meta_hash == data. hash ( ) {
404
408
assert ! ( hash. is_none( ) ) ;
405
409
result = LookupResult :: Previous ( cnum) ;
@@ -411,11 +415,11 @@ impl<'a> CrateReader<'a> {
411
415
412
416
match result {
413
417
LookupResult :: Previous ( cnum) => {
414
- let data = self . sess . cstore . get_crate_data ( cnum) ;
418
+ let data = self . cstore . get_crate_data ( cnum) ;
415
419
if explicitly_linked && !data. explicitly_linked . get ( ) {
416
420
data. explicitly_linked . set ( explicitly_linked) ;
417
421
}
418
- ( cnum, data, self . sess . cstore . do_get_used_crate_source ( cnum) . unwrap ( ) )
422
+ ( cnum, data, self . cstore . do_get_used_crate_source ( cnum) . unwrap ( ) )
419
423
}
420
424
LookupResult :: Loaded ( library) => {
421
425
self . register_crate ( root, ident, name, span, library,
@@ -513,7 +517,7 @@ impl<'a> CrateReader<'a> {
513
517
let source_name = format ! ( "<{} macros>" , item. ident) ;
514
518
let mut macros = vec ! [ ] ;
515
519
decoder:: each_exported_macro ( ekrate. metadata . as_slice ( ) ,
516
- & * self . sess . cstore . intr ,
520
+ & * self . cstore . intr ,
517
521
|name, attrs, body| {
518
522
// NB: Don't use parse::parse_tts_from_source_str because it parses with
519
523
// quote_depth > 0.
@@ -594,14 +598,14 @@ impl<'a> CrateReader<'a> {
594
598
}
595
599
596
600
fn register_statically_included_foreign_items ( & mut self ) {
597
- let libs = self . sess . cstore . get_used_libraries ( ) ;
601
+ let libs = self . cstore . get_used_libraries ( ) ;
598
602
for ( lib, list) in self . foreign_item_map . iter ( ) {
599
603
let is_static = libs. borrow ( ) . iter ( ) . any ( |& ( ref name, kind) | {
600
604
lib == name && kind == cstore:: NativeStatic
601
605
} ) ;
602
606
if is_static {
603
607
for id in list {
604
- self . sess . cstore . add_statically_included_foreign_item ( * id) ;
608
+ self . cstore . add_statically_included_foreign_item ( * id) ;
605
609
}
606
610
}
607
611
}
@@ -615,7 +619,7 @@ impl<'a> CrateReader<'a> {
615
619
// also bail out as we don't need to implicitly inject one.
616
620
let mut needs_allocator = false ;
617
621
let mut found_required_allocator = false ;
618
- self . sess . cstore . iter_crate_data ( |cnum, data| {
622
+ self . cstore . iter_crate_data ( |cnum, data| {
619
623
needs_allocator = needs_allocator || data. needs_allocator ( ) ;
620
624
if data. is_allocator ( ) {
621
625
debug ! ( "{} required by rlib and is an allocator" , data. name( ) ) ;
@@ -694,7 +698,7 @@ impl<'a> CrateReader<'a> {
694
698
//
695
699
// Here we inject a dependency from all crates with #![needs_allocator]
696
700
// to the crate tagged with #![allocator] for this compilation unit.
697
- self . sess . cstore . iter_crate_data ( |cnum, data| {
701
+ self . cstore . iter_crate_data ( |cnum, data| {
698
702
if !data. needs_allocator ( ) {
699
703
return
700
704
}
@@ -708,10 +712,10 @@ impl<'a> CrateReader<'a> {
708
712
709
713
fn validate ( me : & CrateReader , krate : ast:: CrateNum ,
710
714
allocator : ast:: CrateNum ) {
711
- let data = me. sess . cstore . get_crate_data ( krate) ;
715
+ let data = me. cstore . get_crate_data ( krate) ;
712
716
if data. needs_allocator ( ) {
713
717
let krate_name = data. name ( ) ;
714
- let data = me. sess . cstore . get_crate_data ( allocator) ;
718
+ let data = me. cstore . get_crate_data ( allocator) ;
715
719
let alloc_name = data. name ( ) ;
716
720
me. sess . err ( & format ! ( "the allocator crate `{}` cannot depend \
717
721
on a crate that needs an allocator, but \
@@ -727,10 +731,11 @@ impl<'a> CrateReader<'a> {
727
731
}
728
732
729
733
impl < ' a , ' b > LocalCrateReader < ' a , ' b > {
730
- pub fn new ( sess : & ' a Session , map : & ' a hir_map:: Map < ' b > ) -> LocalCrateReader < ' a , ' b > {
734
+ pub fn new ( sess : & ' a Session , cstore : & ' a CStore , map : & ' a hir_map:: Map < ' b > ) -> LocalCrateReader < ' a , ' b > {
731
735
LocalCrateReader {
732
736
sess : sess,
733
- creader : CrateReader :: new ( sess) ,
737
+ cstore : cstore,
738
+ creader : CrateReader :: new ( sess, cstore) ,
734
739
ast_map : map,
735
740
}
736
741
}
@@ -744,19 +749,19 @@ impl<'a, 'b> LocalCrateReader<'a, 'b> {
744
749
self . creader . inject_allocator_crate ( ) ;
745
750
746
751
if log_enabled ! ( log:: INFO ) {
747
- dump_crates ( & self . sess . cstore ) ;
752
+ dump_crates ( & self . cstore ) ;
748
753
}
749
754
750
755
for & ( ref name, kind) in & self . sess . opts . libs {
751
- register_native_lib ( self . sess , None , name. clone ( ) , kind) ;
756
+ register_native_lib ( self . sess , self . cstore , None , name. clone ( ) , kind) ;
752
757
}
753
758
self . creader . register_statically_included_foreign_items ( ) ;
754
759
}
755
760
756
761
fn process_crate ( & self , c : & hir:: Crate ) {
757
762
for a in c. attrs . iter ( ) . filter ( |m| m. name ( ) == "link_args" ) {
758
763
match a. value_str ( ) {
759
- Some ( ref linkarg) => self . sess . cstore . add_used_link_args ( & linkarg) ,
764
+ Some ( ref linkarg) => self . cstore . add_used_link_args ( & linkarg) ,
760
765
None => { /* fallthrough */ }
761
766
}
762
767
}
@@ -784,7 +789,7 @@ impl<'a, 'b> LocalCrateReader<'a, 'b> {
784
789
self . ast_map . with_path ( i. id , |path| {
785
790
cmeta. update_local_path ( path)
786
791
} ) ;
787
- self . sess . cstore . add_extern_mod_stmt_cnum ( info. id , cnum) ;
792
+ self . cstore . add_extern_mod_stmt_cnum ( info. id , cnum) ;
788
793
}
789
794
None => ( )
790
795
}
@@ -802,7 +807,7 @@ impl<'a, 'b> LocalCrateReader<'a, 'b> {
802
807
// First, add all of the custom #[link_args] attributes
803
808
for m in i. attrs . iter ( ) . filter ( |a| a. check_name ( "link_args" ) ) {
804
809
if let Some ( linkarg) = m. value_str ( ) {
805
- self . sess . cstore . add_used_link_args ( & linkarg) ;
810
+ self . cstore . add_used_link_args ( & linkarg) ;
806
811
}
807
812
}
808
813
@@ -837,7 +842,7 @@ impl<'a, 'b> LocalCrateReader<'a, 'b> {
837
842
InternedString :: new ( "foo" )
838
843
}
839
844
} ;
840
- register_native_lib ( self . sess , Some ( m. span ) , n. to_string ( ) , kind) ;
845
+ register_native_lib ( self . sess , self . cstore , Some ( m. span ) , n. to_string ( ) , kind) ;
841
846
}
842
847
843
848
// Finally, process the #[linked_from = "..."] attribute
0 commit comments