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