Skip to content

Commit 42b533d

Browse files
authored
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 #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.
2 parents e3a514c + 3c455fe commit 42b533d

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/librustc_mir/transform/inline.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,15 @@ impl Inliner<'tcx> {
9494
continue;
9595
}
9696

97-
let self_node_id = self.tcx.hir().as_local_node_id(self.source.def_id()).unwrap();
98-
let callee_node_id = self.tcx.hir().as_local_node_id(callsite.callee);
97+
let callee_hir_id = self.tcx.hir().as_local_hir_id(callsite.callee);
9998

100-
let callee_body = if let Some(callee_node_id) = callee_node_id {
99+
let callee_body = if let Some(callee_hir_id) = callee_hir_id {
100+
let self_hir_id = self.tcx.hir().as_local_hir_id(self.source.def_id()).unwrap();
101101
// Avoid a cycle here by only using `optimized_mir` only if we have
102-
// a lower node id than the callee. This ensures that the callee will
102+
// a lower `HirId` than the callee. This ensures that the callee will
103103
// not inline us. This trick only works without incremental compilation.
104104
// So don't do it if that is enabled.
105-
if !self.tcx.dep_graph.is_fully_enabled()
106-
&& self_node_id.as_u32() < callee_node_id.as_u32()
107-
{
105+
if !self.tcx.dep_graph.is_fully_enabled() && self_hir_id < callee_hir_id {
108106
self.tcx.optimized_mir(callsite.callee)
109107
} else {
110108
continue;

0 commit comments

Comments
 (0)