mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 23:34:48 +00:00
Rollup merge of #71285 - ljedrz:mir_inline_span_for_optimized_mir, r=ecstatic-morse
MIR: use HirId instead of NodeId to avoid cycles while inlining I wanted to see if I could limit the number of uses of `NodeId` when `HirId` is available and I saw that some of the MIR `Inliner` code could use `Span` instead of `NodeId`, not unlike in https://github.com/rust-lang/rust/pull/71197. ~If I'm understanding the reason for not calling `optimized_mir` in incremental builds here correctly, this change could also allow us to do so.~ This change could affect performance, so if this approach makes sense, a perf run is probably a good idea.
This commit is contained in:
commit
42b533d7ba
@ -94,17 +94,15 @@ impl Inliner<'tcx> {
|
||||
continue;
|
||||
}
|
||||
|
||||
let self_node_id = self.tcx.hir().as_local_node_id(self.source.def_id()).unwrap();
|
||||
let callee_node_id = self.tcx.hir().as_local_node_id(callsite.callee);
|
||||
let callee_hir_id = self.tcx.hir().as_local_hir_id(callsite.callee);
|
||||
|
||||
let callee_body = if let Some(callee_node_id) = callee_node_id {
|
||||
let callee_body = if let Some(callee_hir_id) = callee_hir_id {
|
||||
let self_hir_id = self.tcx.hir().as_local_hir_id(self.source.def_id()).unwrap();
|
||||
// Avoid a cycle here by only using `optimized_mir` only if we have
|
||||
// a lower node id than the callee. This ensures that the callee will
|
||||
// a lower `HirId` than the callee. This ensures that the callee will
|
||||
// not inline us. This trick only works without incremental compilation.
|
||||
// So don't do it if that is enabled.
|
||||
if !self.tcx.dep_graph.is_fully_enabled()
|
||||
&& self_node_id.as_u32() < callee_node_id.as_u32()
|
||||
{
|
||||
if !self.tcx.dep_graph.is_fully_enabled() && self_hir_id < callee_hir_id {
|
||||
self.tcx.optimized_mir(callsite.callee)
|
||||
} else {
|
||||
continue;
|
||||
|
Loading…
Reference in New Issue
Block a user