11
11
//! Validates all used crates and extern libraries and loads their metadata
12
12
13
13
use cstore:: { self , CStore , CrateSource , MetadataBlob } ;
14
- use loader :: { self , CratePaths } ;
14
+ use locator :: { self , CratePaths } ;
15
15
use macro_import;
16
16
use schema:: CrateRoot ;
17
17
@@ -40,14 +40,14 @@ use syntax::parse::token::InternedString;
40
40
use syntax_pos:: { self , Span , mk_sp} ;
41
41
use log;
42
42
43
- pub struct CrateLoader < ' a > {
44
- pub sess : & ' a Session ,
45
- pub creader : CrateReader < ' a > ,
46
- cstore : & ' a CStore ,
43
+ pub struct Library {
44
+ pub dylib : Option < ( PathBuf , PathKind ) > ,
45
+ pub rlib : Option < ( PathBuf , PathKind ) > ,
46
+ pub metadata : MetadataBlob ,
47
47
}
48
48
49
- pub struct CrateReader < ' a > {
50
- sess : & ' a Session ,
49
+ pub struct CrateLoader < ' a > {
50
+ pub sess : & ' a Session ,
51
51
cstore : & ' a CStore ,
52
52
next_crate_num : CrateNum ,
53
53
foreign_item_map : FnvHashMap < String , Vec < ast:: NodeId > > ,
@@ -129,7 +129,7 @@ struct ExtensionCrate {
129
129
130
130
enum PMDSource {
131
131
Registered ( Rc < cstore:: CrateMetadata > ) ,
132
- Owned ( loader :: Library ) ,
132
+ Owned ( Library ) ,
133
133
}
134
134
135
135
impl Deref for PMDSource {
@@ -145,7 +145,7 @@ impl Deref for PMDSource {
145
145
146
146
enum LoadResult {
147
147
Previous ( CrateNum ) ,
148
- Loaded ( loader :: Library ) ,
148
+ Loaded ( Library ) ,
149
149
}
150
150
151
151
pub struct Macros {
@@ -159,13 +159,13 @@ pub struct Macros {
159
159
pub dylib : Option < PathBuf > ,
160
160
}
161
161
162
- impl < ' a > CrateReader < ' a > {
162
+ impl < ' a > CrateLoader < ' a > {
163
163
pub fn new ( sess : & ' a Session ,
164
164
cstore : & ' a CStore ,
165
165
local_crate_name : & str ,
166
166
local_crate_config : ast:: CrateConfig )
167
- -> CrateReader < ' a > {
168
- CrateReader {
167
+ -> Self {
168
+ CrateLoader {
169
169
sess : sess,
170
170
cstore : cstore,
171
171
next_crate_num : cstore. next_crate_num ( ) ,
@@ -281,7 +281,7 @@ impl<'a> CrateReader<'a> {
281
281
ident : & str ,
282
282
name : & str ,
283
283
span : Span ,
284
- lib : loader :: Library ,
284
+ lib : Library ,
285
285
explicitly_linked : bool )
286
286
-> ( CrateNum , Rc < cstore:: CrateMetadata > ,
287
287
cstore:: CrateSource ) {
@@ -306,7 +306,7 @@ impl<'a> CrateReader<'a> {
306
306
// Maintain a reference to the top most crate.
307
307
let root = if root. is_some ( ) { root } else { & crate_paths } ;
308
308
309
- let loader :: Library { dylib, rlib, metadata } = lib;
309
+ let Library { dylib, rlib, metadata } = lib;
310
310
311
311
let cnum_map = self . resolve_crate_deps ( root, & crate_root, & metadata, cnum, span) ;
312
312
@@ -352,7 +352,7 @@ impl<'a> CrateReader<'a> {
352
352
Some ( cnum) => LoadResult :: Previous ( cnum) ,
353
353
None => {
354
354
info ! ( "falling back to a load" ) ;
355
- let mut load_ctxt = loader :: Context {
355
+ let mut locate_ctxt = locator :: Context {
356
356
sess : self . sess ,
357
357
span : span,
358
358
ident : ident,
@@ -368,9 +368,9 @@ impl<'a> CrateReader<'a> {
368
368
rejected_via_version : vec ! ( ) ,
369
369
should_match_name : true ,
370
370
} ;
371
- match self . load ( & mut load_ctxt ) {
371
+ match self . load ( & mut locate_ctxt ) {
372
372
Some ( result) => result,
373
- None => load_ctxt . report_load_errs ( ) ,
373
+ None => locate_ctxt . report_errs ( ) ,
374
374
}
375
375
}
376
376
} ;
@@ -390,8 +390,8 @@ impl<'a> CrateReader<'a> {
390
390
}
391
391
}
392
392
393
- fn load ( & mut self , loader : & mut loader :: Context ) -> Option < LoadResult > {
394
- let library = match loader . maybe_load_library_crate ( ) {
393
+ fn load ( & mut self , locate_ctxt : & mut locator :: Context ) -> Option < LoadResult > {
394
+ let library = match locate_ctxt . maybe_load_library_crate ( ) {
395
395
Some ( lib) => lib,
396
396
None => return None ,
397
397
} ;
@@ -405,11 +405,11 @@ impl<'a> CrateReader<'a> {
405
405
// don't want to match a host crate against an equivalent target one
406
406
// already loaded.
407
407
let root = library. metadata . get_root ( ) ;
408
- if loader . triple == self . sess . opts . target_triple {
408
+ if locate_ctxt . triple == self . sess . opts . target_triple {
409
409
let mut result = LoadResult :: Loaded ( library) ;
410
410
self . cstore . iter_crate_data ( |cnum, data| {
411
411
if data. name ( ) == root. name && root. hash == data. hash ( ) {
412
- assert ! ( loader . hash. is_none( ) ) ;
412
+ assert ! ( locate_ctxt . hash. is_none( ) ) ;
413
413
info ! ( "load success, going to previous cnum: {}" , cnum) ;
414
414
result = LoadResult :: Previous ( cnum) ;
415
415
}
@@ -494,7 +494,7 @@ impl<'a> CrateReader<'a> {
494
494
let mut target_only = false ;
495
495
let ident = info. ident . clone ( ) ;
496
496
let name = info. name . clone ( ) ;
497
- let mut load_ctxt = loader :: Context {
497
+ let mut locate_ctxt = locator :: Context {
498
498
sess : self . sess ,
499
499
span : span,
500
500
ident : & ident[ ..] ,
@@ -510,7 +510,7 @@ impl<'a> CrateReader<'a> {
510
510
rejected_via_version : vec ! ( ) ,
511
511
should_match_name : true ,
512
512
} ;
513
- let library = self . load ( & mut load_ctxt ) . or_else ( || {
513
+ let library = self . load ( & mut locate_ctxt ) . or_else ( || {
514
514
if !is_cross {
515
515
return None
516
516
}
@@ -519,15 +519,15 @@ impl<'a> CrateReader<'a> {
519
519
target_only = true ;
520
520
should_link = info. should_link ;
521
521
522
- load_ctxt . target = & self . sess . target . target ;
523
- load_ctxt . triple = target_triple;
524
- load_ctxt . filesearch = self . sess . target_filesearch ( PathKind :: Crate ) ;
522
+ locate_ctxt . target = & self . sess . target . target ;
523
+ locate_ctxt . triple = target_triple;
524
+ locate_ctxt . filesearch = self . sess . target_filesearch ( PathKind :: Crate ) ;
525
525
526
- self . load ( & mut load_ctxt )
526
+ self . load ( & mut locate_ctxt )
527
527
} ) ;
528
528
let library = match library {
529
529
Some ( l) => l,
530
- None => load_ctxt . report_load_errs ( ) ,
530
+ None => locate_ctxt . report_errs ( ) ,
531
531
} ;
532
532
533
533
let ( dylib, metadata) = match library {
@@ -890,7 +890,7 @@ impl<'a> CrateReader<'a> {
890
890
}
891
891
892
892
impl ExtensionCrate {
893
- fn register ( self , creader : & mut CrateReader ) {
893
+ fn register ( self , loader : & mut CrateLoader ) {
894
894
if !self . should_link {
895
895
return
896
896
}
@@ -901,31 +901,17 @@ impl ExtensionCrate {
901
901
} ;
902
902
903
903
// Register crate now to avoid double-reading metadata
904
- creader. register_crate ( & None ,
905
- & self . ident ,
906
- & self . name ,
907
- self . span ,
908
- library,
909
- true ) ;
904
+ loader. register_crate ( & None , & self . ident , & self . name , self . span , library, true ) ;
910
905
}
911
906
}
912
907
913
908
impl < ' a > CrateLoader < ' a > {
914
- pub fn new ( sess : & ' a Session , cstore : & ' a CStore , krate : & ast:: Crate , crate_name : & str )
915
- -> Self {
916
- let loader = CrateLoader {
917
- sess : sess,
918
- cstore : cstore,
919
- creader : CrateReader :: new ( sess, cstore, crate_name, krate. config . clone ( ) ) ,
920
- } ;
921
-
909
+ pub fn preprocess ( & mut self , krate : & ast:: Crate ) {
922
910
for attr in krate. attrs . iter ( ) . filter ( |m| m. name ( ) == "link_args" ) {
923
911
if let Some ( ref linkarg) = attr. value_str ( ) {
924
- loader . cstore . add_used_link_args ( & linkarg) ;
912
+ self . cstore . add_used_link_args ( & linkarg) ;
925
913
}
926
914
}
927
-
928
- loader
929
915
}
930
916
931
917
fn process_foreign_mod ( & mut self , i : & ast:: Item , fm : & ast:: ForeignMod ) {
@@ -982,7 +968,7 @@ impl<'a> CrateLoader<'a> {
982
968
Some ( name) => name,
983
969
None => continue ,
984
970
} ;
985
- let list = self . creader . foreign_item_map . entry ( lib_name. to_string ( ) )
971
+ let list = self . foreign_item_map . entry ( lib_name. to_string ( ) )
986
972
. or_insert ( Vec :: new ( ) ) ;
987
973
list. extend ( fm. items . iter ( ) . map ( |it| it. id ) ) ;
988
974
}
@@ -991,8 +977,8 @@ impl<'a> CrateLoader<'a> {
991
977
992
978
impl < ' a > middle:: cstore:: CrateLoader for CrateLoader < ' a > {
993
979
fn postprocess ( & mut self , krate : & ast:: Crate ) {
994
- self . creader . inject_allocator_crate ( ) ;
995
- self . creader . inject_panic_runtime ( krate) ;
980
+ self . inject_allocator_crate ( ) ;
981
+ self . inject_panic_runtime ( krate) ;
996
982
997
983
if log_enabled ! ( log:: INFO ) {
998
984
dump_crates ( & self . cstore ) ;
@@ -1001,7 +987,7 @@ impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> {
1001
987
for & ( ref name, kind) in & self . sess . opts . libs {
1002
988
register_native_lib ( self . sess , self . cstore , None , name. clone ( ) , kind) ;
1003
989
}
1004
- self . creader . register_statically_included_foreign_items ( ) ;
990
+ self . register_statically_included_foreign_items ( ) ;
1005
991
}
1006
992
1007
993
fn process_item ( & mut self , item : & ast:: Item , definitions : & hir_map:: Definitions ) {
@@ -1024,12 +1010,12 @@ impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> {
1024
1010
}
1025
1011
}
1026
1012
1027
- if let Some ( info) = self . creader . extract_crate_info ( item) {
1013
+ if let Some ( info) = self . extract_crate_info ( item) {
1028
1014
if !info. should_link {
1029
1015
return ;
1030
1016
}
1031
1017
1032
- let ( cnum, ..) = self . creader . resolve_crate (
1018
+ let ( cnum, ..) = self . resolve_crate (
1033
1019
& None , & info. ident , & info. name , None , item. span , PathKind :: Crate , true ,
1034
1020
) ;
1035
1021
@@ -1038,7 +1024,7 @@ impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> {
1038
1024
1039
1025
let extern_crate =
1040
1026
ExternCrate { def_id : def_id, span : item. span , direct : true , path_len : len } ;
1041
- self . creader . update_extern_crate ( cnum, extern_crate, & mut FnvHashSet ( ) ) ;
1027
+ self . update_extern_crate ( cnum, extern_crate, & mut FnvHashSet ( ) ) ;
1042
1028
1043
1029
self . cstore . add_extern_mod_stmt_cnum ( info. id , cnum) ;
1044
1030
}
0 commit comments