Function rustc_metadata::rmeta::encoder::should_encode_mir
source · fn should_encode_mir(
tcx: TyCtxt<'_>,
reachable_set: &LocalDefIdSet,
def_id: LocalDefId,
) -> (bool, bool)
Expand description
Whether we should encode MIR. Return a pair, resp. for CTFE and for LLVM.
Computing, optimizing and encoding the MIR is a relatively expensive operation. We want to avoid this work when not required. Therefore:
- we only compute
mir_for_ctfe
on items with const-eval semantics; - we skip
optimized_mir
for check runs. - we only encode
optimized_mir
that could be generated in other crates, that is, a code that is either generic or has inline hint, and is reachable from the other crates (contained in reachable set).
Note: Reachable set describes definitions that might be generated or referenced from other
crates and it can be used to limit optimized MIR that needs to be encoded. On the other hand,
the reachable set doesn’t have much to say about which definitions might be evaluated at compile
time in other crates, so it cannot be used to omit CTFE MIR. For example, f
below is
unreachable and yet it can be evaluated in other crates:
const fn f() -> usize { 0 }
pub struct S { pub a: [usize; f()] }