4
4
//! An item is "externally reachable" if it is relevant for other crates. This obviously includes
5
5
//! all public items. However, some of these items cannot be compiled to machine code (because they
6
6
//! are generic), and for some the machine code is not sufficient (because we want to cross-crate
7
- //! inline them, or run them in the compile-time MIR interpreter ). These items "need cross-crate
8
- //! MIR". When a reachable function `f` needs cross-crate MIR, then all the functions it calls also
9
- //! become reachable, as they will be necessary to use the MIR of `f` from another crate.
7
+ //! inline them). These items "need cross-crate MIR". When a reachable function `f` needs
8
+ //! cross-crate MIR, then all the functions it calls also become reachable, as they will be
9
+ //! necessary to use the MIR of `f` from another crate.
10
10
11
11
use hir:: def_id:: LocalDefIdSet ;
12
12
use rustc_data_structures:: stack:: ensure_sufficient_stack;
@@ -26,6 +26,12 @@ use rustc_target::spec::abi::Abi;
26
26
27
27
/// Determines whether this (assumed to be reachable) item "needs cross-crate MIR", i.e. whether
28
28
/// another crate needs to be able to access this items' MIR.
29
+ ///
30
+ /// On top of what was explained above, `const fn` also "need cross-crate MIR". This is *not*
31
+ /// because we need the MIR to interpret them (MIR for const-eval and MIR for codegen is separate,
32
+ /// and MIR for const-eval is always encoded). Instead, it is because `const fn` can create `fn()`
33
+ /// pointers to other items which end up in the evaluated result of the constant and can then be
34
+ /// called from other crates. Those items must be considered reachable.
29
35
fn needs_cross_crate_mir ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> bool {
30
36
tcx. generics_of ( def_id) . requires_monomorphization ( tcx)
31
37
|| tcx. cross_crate_inlinable ( def_id)
@@ -449,6 +455,8 @@ fn reachable_set(tcx: TyCtxt<'_>, (): ()) -> LocalDefIdSet {
449
455
// items of non-exported traits (or maybe all local traits?) unless their respective
450
456
// trait items are used from inlinable code through method call syntax or UFCS, or their
451
457
// trait is a lang item.
458
+ // (But if you implement this, don't forget to take into account that vtables and also
459
+ // make trait methods reachable!)
452
460
let crate_items = tcx. hir_crate_items ( ( ) ) ;
453
461
454
462
for id in crate_items. items ( ) {
0 commit comments