Skip to content
Open
307 changes: 235 additions & 72 deletions compiler/rustc_mir_build/src/builder/scope.rs

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions compiler/rustc_mir_transform/src/cleanup_post_borrowck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
//! - [`FakeRead`]
//! - [`Assign`] statements with a [`Fake`] borrow
//! - [`Coverage`] statements of kind [`BlockMarker`] or [`SpanMarker`]
//! - [`StorageDead`] statements in cleanup blocks (unwind paths) - these are only needed
//! for borrow-checking and are removed from cleanup blocks after borrowck completes.
//! StorageDead on normal paths may be needed by later passes (e.g., coroutine transforms)
//! and will be conditionally removed by RemoveStorageMarkers during optimization if enabled.
//!
//! [`AscribeUserType`]: rustc_middle::mir::StatementKind::AscribeUserType
//! [`Assign`]: rustc_middle::mir::StatementKind::Assign
Expand All @@ -15,6 +19,7 @@
//! [`Coverage`]: rustc_middle::mir::StatementKind::Coverage
//! [`BlockMarker`]: rustc_middle::mir::coverage::CoverageKind::BlockMarker
//! [`SpanMarker`]: rustc_middle::mir::coverage::CoverageKind::SpanMarker
//! [`StorageDead`]: rustc_middle::mir::StatementKind::StorageDead

use rustc_middle::mir::coverage::CoverageKind;
use rustc_middle::mir::*;
Expand All @@ -28,6 +33,11 @@ impl<'tcx> crate::MirPass<'tcx> for CleanupPostBorrowck {
// Manually invalidate CFG caches if we actually change a terminator's edges.
let mut invalidate_cfg = false;
for basic_block in body.basic_blocks.as_mut_preserves_cfg().iter_mut() {
// Only remove StorageDead from cleanup blocks (unwind paths).
// StorageDead on normal paths may be needed by later passes (e.g., coroutine
// transforms) and may be used by codegen backends. RemoveStorageMarkers will
// conditionally remove them during optimization if enabled (when mir_opt_level > 0
// and lifetime markers are not being emitted).
for statement in basic_block.statements.iter_mut() {
match statement.kind {
StatementKind::AscribeUserType(..)
Expand All @@ -41,6 +51,11 @@ impl<'tcx> crate::MirPass<'tcx> for CleanupPostBorrowck {
| StatementKind::BackwardIncompatibleDropHint { .. } => {
statement.make_nop(true)
}
StatementKind::StorageDead(..)
if basic_block.is_cleanup && body.coroutine.is_none() =>
{
statement.make_nop(true)
}
StatementKind::Assign(box (
_,
Rvalue::Cast(
Expand Down
5 changes: 3 additions & 2 deletions src/tools/rust-analyzer/crates/hir-def/src/import_map.rs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From your commit message:

This fixes compilation errors that are blocking CI, though these are
pre-existing issues unrelated to the StorageDead changes.

I guess this breakage comes from this PR rather than pre-existing, as this isn't failing in other PRs?

Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,10 @@ pub fn search_dependencies(
let import_maps: Vec<_> =
krate.data(db).dependencies.iter().map(|dep| db.import_map(dep.crate_id)).collect();

let mut op = fst::map::OpBuilder::new();

match query.search_mode {
SearchMode::Exact => {
let automaton = fst::automaton::Str::new(&query.lowercased);
let mut op = fst::map::OpBuilder::new();

for map in &import_maps {
op = op.add(map.fst.search(&automaton));
Expand All @@ -439,6 +438,7 @@ pub fn search_dependencies(
}
SearchMode::Fuzzy => {
let automaton = fst::automaton::Subsequence::new(&query.lowercased);
let mut op = fst::map::OpBuilder::new();

for map in &import_maps {
op = op.add(map.fst.search(&automaton));
Expand All @@ -447,6 +447,7 @@ pub fn search_dependencies(
}
SearchMode::Prefix => {
let automaton = fst::automaton::Str::new(&query.lowercased).starts_with();
let mut op = fst::map::OpBuilder::new();

for map in &import_maps {
op = op.add(map.fst.search(&automaton));
Expand Down
5 changes: 3 additions & 2 deletions src/tools/rust-analyzer/crates/ide-db/src/symbol_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,11 +569,10 @@ impl Query {
cb: impl FnMut(&'db FileSymbol<'db>) -> ControlFlow<T>,
) -> Option<T> {
let _p = tracing::info_span!("symbol_index::Query::search").entered();

let mut op = fst::map::OpBuilder::new();
match self.mode {
SearchMode::Exact => {
let automaton = fst::automaton::Str::new(&self.lowercased);
let mut op = fst::map::OpBuilder::new();

for index in indices.iter() {
op = op.add(index.map.search(&automaton));
Expand All @@ -582,6 +581,7 @@ impl Query {
}
SearchMode::Fuzzy => {
let automaton = fst::automaton::Subsequence::new(&self.lowercased);
let mut op = fst::map::OpBuilder::new();

for index in indices.iter() {
op = op.add(index.map.search(&automaton));
Expand All @@ -590,6 +590,7 @@ impl Query {
}
SearchMode::Prefix => {
let automaton = fst::automaton::Str::new(&self.lowercased).starts_with();
let mut op = fst::map::OpBuilder::new();

for index in indices.iter() {
op = op.add(index.map.search(&automaton));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ fn a::{closure#0}(_1: Pin<&mut {async fn body of a<T>()}>, _2: &mut Context<'_>)
}

bb3 (cleanup): {
nop;
nop;
goto -> bb5;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,19 @@ fn main() -> () {
}

bb6 (cleanup): {
StorageDead(_6);
drop(_5) -> [return: bb7, unwind terminate(cleanup)];
}

bb7 (cleanup): {
StorageDead(_5);
drop(_4) -> [return: bb8, unwind terminate(cleanup)];
}

bb8 (cleanup): {
StorageDead(_4);
StorageDead(_2);
StorageDead(_1);
resume;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn test_complex() -> () {
bb0: {
StorageLive(_1);
StorageLive(_2);
_2 = E::f() -> [return: bb1, unwind: bb35];
_2 = E::f() -> [return: bb1, unwind: bb38];
}

bb1: {
Expand All @@ -42,7 +42,7 @@ fn test_complex() -> () {

bb5: {
StorageLive(_4);
_4 = always_true() -> [return: bb6, unwind: bb35];
_4 = always_true() -> [return: bb6, unwind: bb38];
}

bb6: {
Expand All @@ -64,7 +64,7 @@ fn test_complex() -> () {
}

bb9: {
drop(_7) -> [return: bb11, unwind: bb35];
drop(_7) -> [return: bb11, unwind: bb37];
}

bb10: {
Expand All @@ -78,7 +78,7 @@ fn test_complex() -> () {
}

bb12: {
drop(_7) -> [return: bb13, unwind: bb35];
drop(_7) -> [return: bb13, unwind: bb37];
}

bb13: {
Expand All @@ -98,7 +98,7 @@ fn test_complex() -> () {
}

bb15: {
drop(_10) -> [return: bb17, unwind: bb35];
drop(_10) -> [return: bb17, unwind: bb36];
}

bb16: {
Expand Down Expand Up @@ -139,7 +139,7 @@ fn test_complex() -> () {
StorageDead(_4);
StorageDead(_1);
StorageLive(_11);
_11 = always_true() -> [return: bb23, unwind: bb35];
_11 = always_true() -> [return: bb23, unwind: bb38];
}

bb23: {
Expand All @@ -156,7 +156,7 @@ fn test_complex() -> () {

bb26: {
StorageLive(_12);
_12 = E::f() -> [return: bb27, unwind: bb35];
_12 = E::f() -> [return: bb27, unwind: bb38];
}

bb27: {
Expand Down Expand Up @@ -199,6 +199,25 @@ fn test_complex() -> () {
}

bb35 (cleanup): {
StorageDead(_10);
StorageDead(_9);
StorageDead(_2);
goto -> bb38;
}

bb36 (cleanup): {
StorageDead(_10);
StorageDead(_9);
goto -> bb38;
}

bb37 (cleanup): {
StorageDead(_7);
StorageDead(_6);
goto -> bb38;
}

bb38 (cleanup): {
resume;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn test_or() -> () {
}

bb1: {
drop(_3) -> [return: bb3, unwind: bb13];
drop(_3) -> [return: bb3, unwind: bb14];
}

bb2: {
Expand All @@ -34,7 +34,7 @@ fn test_or() -> () {
}

bb4: {
drop(_3) -> [return: bb5, unwind: bb13];
drop(_3) -> [return: bb5, unwind: bb14];
}

bb5: {
Expand Down Expand Up @@ -86,6 +86,19 @@ fn test_or() -> () {
}

bb13 (cleanup): {
StorageDead(_6);
StorageDead(_5);
goto -> bb15;
}

bb14 (cleanup): {
StorageDead(_3);
StorageDead(_2);
goto -> bb15;
}

bb15 (cleanup): {
StorageDead(_1);
resume;
}
}
Loading
Loading