1
1
//! Validates all used crates and extern libraries and loads their metadata
2
2
3
3
use std:: error:: Error ;
4
- use std:: ops:: Fn ;
5
4
use std:: path:: Path ;
6
5
use std:: str:: FromStr ;
7
6
use std:: time:: Duration ;
@@ -276,12 +275,6 @@ impl CStore {
276
275
. filter_map ( |( cnum, data) | data. as_deref ( ) . map ( |data| ( cnum, data) ) )
277
276
}
278
277
279
- fn iter_crate_data_mut ( & mut self ) -> impl Iterator < Item = ( CrateNum , & mut CrateMetadata ) > {
280
- self . metas
281
- . iter_enumerated_mut ( )
282
- . filter_map ( |( cnum, data) | data. as_deref_mut ( ) . map ( |data| ( cnum, data) ) )
283
- }
284
-
285
278
fn push_dependencies_in_postorder ( & self , deps : & mut IndexSet < CrateNum > , cnum : CrateNum ) {
286
279
if !deps. contains ( & cnum) {
287
280
let data = self . get_crate_data ( cnum) ;
@@ -307,13 +300,6 @@ impl CStore {
307
300
deps
308
301
}
309
302
310
- fn crate_dependencies_in_reverse_postorder (
311
- & self ,
312
- cnum : CrateNum ,
313
- ) -> impl Iterator < Item = CrateNum > {
314
- self . crate_dependencies_in_postorder ( cnum) . into_iter ( ) . rev ( )
315
- }
316
-
317
303
pub ( crate ) fn injected_panic_runtime ( & self ) -> Option < CrateNum > {
318
304
self . injected_panic_runtime
319
305
}
@@ -966,27 +952,16 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
966
952
// If we need a panic runtime, we try to find an existing one here. At
967
953
// the same time we perform some general validation of the DAG we've got
968
954
// going such as ensuring everything has a compatible panic strategy.
969
- //
970
- // The logic for finding the panic runtime here is pretty much the same
971
- // as the allocator case with the only addition that the panic strategy
972
- // compilation mode also comes into play.
973
955
let desired_strategy = self . sess . panic_strategy ( ) ;
974
956
let mut runtime_found = false ;
975
957
let mut needs_panic_runtime = attr:: contains_name ( & krate. attrs , sym:: needs_panic_runtime) ;
976
958
977
- let mut panic_runtimes = Vec :: new ( ) ;
978
- for ( cnum, data) in self . cstore . iter_crate_data ( ) {
959
+ for ( _cnum, data) in self . cstore . iter_crate_data ( ) {
979
960
needs_panic_runtime = needs_panic_runtime || data. needs_panic_runtime ( ) ;
980
961
if data. is_panic_runtime ( ) {
981
- // Inject a dependency from all #![needs_panic_runtime] to this
982
- // #![panic_runtime] crate.
983
- panic_runtimes. push ( cnum) ;
984
962
runtime_found = runtime_found || data. dep_kind ( ) == CrateDepKind :: Explicit ;
985
963
}
986
964
}
987
- for cnum in panic_runtimes {
988
- self . inject_dependency_if ( cnum, "a panic runtime" , & |data| data. needs_panic_runtime ( ) ) ;
989
- }
990
965
991
966
// If an explicitly linked and matching panic runtime was found, or if
992
967
// we just don't need one at all, then we're done here and there's
@@ -997,12 +972,10 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
997
972
998
973
// By this point we know that we (a) need a panic runtime and (b) no
999
974
// panic runtime was explicitly linked. Here we just load an appropriate
1000
- // default runtime for our panic strategy and then inject the
1001
- // dependencies.
975
+ // default runtime for our panic strategy.
1002
976
//
1003
977
// We may resolve to an already loaded crate (as the crate may not have
1004
- // been explicitly linked prior to this) and we may re-inject
1005
- // dependencies again, but both of those situations are fine.
978
+ // been explicitly linked prior to this), but this is fine.
1006
979
//
1007
980
// Also note that we have yet to perform validation of the crate graph
1008
981
// in terms of everyone has a compatible panic runtime format, that's
@@ -1031,7 +1004,6 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
1031
1004
}
1032
1005
1033
1006
self . cstore . injected_panic_runtime = Some ( cnum) ;
1034
- self . inject_dependency_if ( cnum, "a panic runtime" , & |data| data. needs_panic_runtime ( ) ) ;
1035
1007
}
1036
1008
1037
1009
fn inject_profiler_runtime ( & mut self ) {
@@ -1212,45 +1184,6 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
1212
1184
}
1213
1185
}
1214
1186
1215
- fn inject_dependency_if (
1216
- & mut self ,
1217
- krate : CrateNum ,
1218
- what : & str ,
1219
- needs_dep : & dyn Fn ( & CrateMetadata ) -> bool ,
1220
- ) {
1221
- // Don't perform this validation if the session has errors, as one of
1222
- // those errors may indicate a circular dependency which could cause
1223
- // this to stack overflow.
1224
- if self . dcx ( ) . has_errors ( ) . is_some ( ) {
1225
- return ;
1226
- }
1227
-
1228
- // Before we inject any dependencies, make sure we don't inject a
1229
- // circular dependency by validating that this crate doesn't
1230
- // transitively depend on any crates satisfying `needs_dep`.
1231
- for dep in self . cstore . crate_dependencies_in_reverse_postorder ( krate) {
1232
- let data = self . cstore . get_crate_data ( dep) ;
1233
- if needs_dep ( & data) {
1234
- self . dcx ( ) . emit_err ( errors:: NoTransitiveNeedsDep {
1235
- crate_name : self . cstore . get_crate_data ( krate) . name ( ) ,
1236
- needs_crate_name : what,
1237
- deps_crate_name : data. name ( ) ,
1238
- } ) ;
1239
- }
1240
- }
1241
-
1242
- // All crates satisfying `needs_dep` do not explicitly depend on the
1243
- // crate provided for this compile, but in order for this compilation to
1244
- // be successfully linked we need to inject a dependency (to order the
1245
- // crates on the command line correctly).
1246
- for ( cnum, data) in self . cstore . iter_crate_data_mut ( ) {
1247
- if needs_dep ( data) {
1248
- info ! ( "injecting a dep from {} to {}" , cnum, krate) ;
1249
- data. add_dependency ( krate) ;
1250
- }
1251
- }
1252
- }
1253
-
1254
1187
fn report_unused_deps ( & mut self , krate : & ast:: Crate ) {
1255
1188
// Make a point span rather than covering the whole file
1256
1189
let span = krate. spans . inner_span . shrink_to_lo ( ) ;
0 commit comments