Skip to content

Commit

Permalink
reachable computation: clarify comments around consts
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Jun 11, 2024
1 parent aec67e2 commit bea33cd
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions compiler/rustc_passes/src/reachable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,20 @@ impl<'tcx> ReachableContext<'tcx> {
}

hir::ItemKind::Const(_, _, init) => {
// Only things actually ending up in the final constant need to be reachable.
// Everything else is either already available as `mir_for_ctfe`, or can't be used
// by codegen anyway.
// Only things actually ending up in the final constant value need to be
// reachable. Everything else is only needed during const-eval and hence
// already available as `mir_for_ctfe`.
match self.tcx.const_eval_poly_to_alloc(item.owner_id.def_id.into()) {
Ok(alloc) => {
let alloc = self.tcx.global_alloc(alloc.alloc_id).unwrap_memory();
self.propagate_from_alloc(alloc);
}
// Reachable generic constants will be inlined into other crates
// unconditionally, so we need to make sure that their
// contents are also reachable.
// We can't figure out which value the constant will evaluate to. In
// lieu of that, we have to consider everything mentioned in the const
// initializer reachable, since it *may* end up in the final value.
Err(ErrorHandled::TooGeneric(_)) => self.visit_nested_body(init),
// If there was an error evaluating the const, nothing can be reachable
// via it, and anyway compilation will fail.
Err(ErrorHandled::Reported(..)) => {}
}
}
Expand Down

0 comments on commit bea33cd

Please sign in to comment.