about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-04-09 07:41:34 +0000
committerbors <bors@rust-lang.org>2024-04-09 07:41:34 +0000
commitbb78dba64ca4158ef2f3488d0d41a82c75a504f2 (patch)
tree69c4ce19c766dd5dba1e7af57aa342d9a7d973f1 /compiler/rustc_codegen_ssa/src
parent86b603cd792b3f6172ba4f676d7b586c1af7630a (diff)
parentb5b49289e1e67a1b333da3ba6cf374ca11b9d326 (diff)
downloadrust-bb78dba64ca4158ef2f3488d0d41a82c75a504f2.tar.gz
rust-bb78dba64ca4158ef2f3488d0d41a82c75a504f2.zip
Auto merge of #123272 - saethlin:reachable-mono-cleanup, r=cjgillot
Only collect mono items from reachable blocks

Fixes the wrong comment pointed out in: https://github.com/rust-lang/rust/pull/121421#discussion_r1537378431
Moves the analysis to use the worklist strategy: https://github.com/rust-lang/rust/pull/121421#discussion_r1501840823
Also fixes https://github.com/rust-lang/rust/issues/85836, using the same reachability analysis
Diffstat (limited to 'compiler/rustc_codegen_ssa/src')
-rw-r--r--compiler/rustc_codegen_ssa/src/mir/mod.rs9
1 files changed, 4 insertions, 5 deletions
diff --git a/compiler/rustc_codegen_ssa/src/mir/mod.rs b/compiler/rustc_codegen_ssa/src/mir/mod.rs
index 387a5366b20..1f4473d2ec4 100644
--- a/compiler/rustc_codegen_ssa/src/mir/mod.rs
+++ b/compiler/rustc_codegen_ssa/src/mir/mod.rs
@@ -257,20 +257,19 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
     // Apply debuginfo to the newly allocated locals.
     fx.debug_introduce_locals(&mut start_bx);
 
-    let reachable_blocks = mir.reachable_blocks_in_mono(cx.tcx(), instance);
-
     // The builders will be created separately for each basic block at `codegen_block`.
     // So drop the builder of `start_llbb` to avoid having two at the same time.
     drop(start_bx);
 
+    let reachable_blocks = traversal::mono_reachable_as_bitset(mir, cx.tcx(), instance);
+
     // Codegen the body of each block using reverse postorder
     for (bb, _) in traversal::reverse_postorder(mir) {
         if reachable_blocks.contains(bb) {
             fx.codegen_block(bb);
         } else {
-            // This may have references to things we didn't monomorphize, so we
-            // don't actually codegen the body. We still create the block so
-            // terminators in other blocks can reference it without worry.
+            // We want to skip this block, because it's not reachable. But we still create
+            // the block so terminators in other blocks can reference it.
             fx.codegen_block_as_unreachable(bb);
         }
     }