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
}
@@ -943,27 +930,16 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
943
930
// If we need a panic runtime, we try to find an existing one here. At
944
931
// the same time we perform some general validation of the DAG we've got
945
932
// going such as ensuring everything has a compatible panic strategy.
946
- //
947
- // The logic for finding the panic runtime here is pretty much the same
948
- // as the allocator case with the only addition that the panic strategy
949
- // compilation mode also comes into play.
950
933
let desired_strategy = self . sess . panic_strategy ( ) ;
951
934
let mut runtime_found = false ;
952
935
let mut needs_panic_runtime = attr:: contains_name ( & krate. attrs , sym:: needs_panic_runtime) ;
953
936
954
- let mut panic_runtimes = Vec :: new ( ) ;
955
- for ( cnum, data) in self . cstore . iter_crate_data ( ) {
937
+ for ( _cnum, data) in self . cstore . iter_crate_data ( ) {
956
938
needs_panic_runtime = needs_panic_runtime || data. needs_panic_runtime ( ) ;
957
939
if data. is_panic_runtime ( ) {
958
- // Inject a dependency from all #![needs_panic_runtime] to this
959
- // #![panic_runtime] crate.
960
- panic_runtimes. push ( cnum) ;
961
940
runtime_found = runtime_found || data. dep_kind ( ) == CrateDepKind :: Explicit ;
962
941
}
963
942
}
964
- for cnum in panic_runtimes {
965
- self . inject_dependency_if ( cnum, "a panic runtime" , & |data| data. needs_panic_runtime ( ) ) ;
966
- }
967
943
968
944
// If an explicitly linked and matching panic runtime was found, or if
969
945
// we just don't need one at all, then we're done here and there's
@@ -974,12 +950,10 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
974
950
975
951
// By this point we know that we (a) need a panic runtime and (b) no
976
952
// panic runtime was explicitly linked. Here we just load an appropriate
977
- // default runtime for our panic strategy and then inject the
978
- // dependencies.
953
+ // default runtime for our panic strategy.
979
954
//
980
955
// We may resolve to an already loaded crate (as the crate may not have
981
- // been explicitly linked prior to this) and we may re-inject
982
- // dependencies again, but both of those situations are fine.
956
+ // been explicitly linked prior to this), but this is fine.
983
957
//
984
958
// Also note that we have yet to perform validation of the crate graph
985
959
// in terms of everyone has a compatible panic runtime format, that's
@@ -1008,7 +982,6 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
1008
982
}
1009
983
1010
984
self . cstore . injected_panic_runtime = Some ( cnum) ;
1011
- self . inject_dependency_if ( cnum, "a panic runtime" , & |data| data. needs_panic_runtime ( ) ) ;
1012
985
}
1013
986
1014
987
fn inject_profiler_runtime ( & mut self ) {
@@ -1189,45 +1162,6 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
1189
1162
}
1190
1163
}
1191
1164
1192
- fn inject_dependency_if (
1193
- & mut self ,
1194
- krate : CrateNum ,
1195
- what : & str ,
1196
- needs_dep : & dyn Fn ( & CrateMetadata ) -> bool ,
1197
- ) {
1198
- // Don't perform this validation if the session has errors, as one of
1199
- // those errors may indicate a circular dependency which could cause
1200
- // this to stack overflow.
1201
- if self . dcx ( ) . has_errors ( ) . is_some ( ) {
1202
- return ;
1203
- }
1204
-
1205
- // Before we inject any dependencies, make sure we don't inject a
1206
- // circular dependency by validating that this crate doesn't
1207
- // transitively depend on any crates satisfying `needs_dep`.
1208
- for dep in self . cstore . crate_dependencies_in_reverse_postorder ( krate) {
1209
- let data = self . cstore . get_crate_data ( dep) ;
1210
- if needs_dep ( & data) {
1211
- self . dcx ( ) . emit_err ( errors:: NoTransitiveNeedsDep {
1212
- crate_name : self . cstore . get_crate_data ( krate) . name ( ) ,
1213
- needs_crate_name : what,
1214
- deps_crate_name : data. name ( ) ,
1215
- } ) ;
1216
- }
1217
- }
1218
-
1219
- // All crates satisfying `needs_dep` do not explicitly depend on the
1220
- // crate provided for this compile, but in order for this compilation to
1221
- // be successfully linked we need to inject a dependency (to order the
1222
- // crates on the command line correctly).
1223
- for ( cnum, data) in self . cstore . iter_crate_data_mut ( ) {
1224
- if needs_dep ( data) {
1225
- info ! ( "injecting a dep from {} to {}" , cnum, krate) ;
1226
- data. add_dependency ( krate) ;
1227
- }
1228
- }
1229
- }
1230
-
1231
1165
fn report_unused_deps ( & mut self , krate : & ast:: Crate ) {
1232
1166
// Make a point span rather than covering the whole file
1233
1167
let span = krate. spans . inner_span . shrink_to_lo ( ) ;
0 commit comments