Skip to content

Commit 5abb1fe

Browse files
committed
Auto merge of #146625 - Zalathar:rollup-hrqdohi, r=Zalathar
Rollup of 4 pull requests Successful merges: - #143613 (Fix backtraces with `-C panic=abort` on linux; emit unwind tables by default) - #145181 (remove FIXME block from `has_significant_drop`, it never encounters inference variables) - #146552 (StateTransform: Do not renumber resume local.) - #146588 (tests/run-make: Update list of statically linked musl targets) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8a1b399 + e2b2c14 commit 5abb1fe

23 files changed

+700
-226
lines changed

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ impl<'tcx> Body<'tcx> {
471471

472472
/// Returns an iterator over all function arguments.
473473
#[inline]
474-
pub fn args_iter(&self) -> impl Iterator<Item = Local> + ExactSizeIterator {
474+
pub fn args_iter(&self) -> impl Iterator<Item = Local> + ExactSizeIterator + use<> {
475475
(1..self.arg_count + 1).map(Local::new)
476476
}
477477

compiler/rustc_middle/src/mir/query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::ty::{self, CoroutineArgsExt, OpaqueHiddenType, Ty};
1717
rustc_index::newtype_index! {
1818
#[derive(HashStable)]
1919
#[encodable]
20-
#[debug_format = "_{}"]
20+
#[debug_format = "_s{}"]
2121
pub struct CoroutineSavedLocal {}
2222
}
2323

compiler/rustc_middle/src/ty/util.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,7 @@ impl<'tcx> Ty<'tcx> {
13591359
/// 2229 drop reorder migration analysis.
13601360
#[inline]
13611361
pub fn has_significant_drop(self, tcx: TyCtxt<'tcx>, typing_env: ty::TypingEnv<'tcx>) -> bool {
1362+
assert!(!self.has_non_region_infer());
13621363
// Avoid querying in simple cases.
13631364
match needs_drop_components(tcx, self) {
13641365
Err(AlwaysRequiresDrop) => true,
@@ -1371,14 +1372,6 @@ impl<'tcx> Ty<'tcx> {
13711372
_ => self,
13721373
};
13731374

1374-
// FIXME(#86868): We should be canonicalizing, or else moving this to a method of inference
1375-
// context, or *something* like that, but for now just avoid passing inference
1376-
// variables to queries that can't cope with them. Instead, conservatively
1377-
// return "true" (may change drop order).
1378-
if query_ty.has_infer() {
1379-
return true;
1380-
}
1381-
13821375
// This doesn't depend on regions, so try to minimize distinct
13831376
// query keys used.
13841377
let erased = tcx.normalize_erasing_regions(typing_env, query_ty);

compiler/rustc_mir_transform/src/coroutine.rs

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,14 +1340,13 @@ fn create_cases<'tcx>(
13401340
}
13411341
}
13421342

1343-
if operation == Operation::Resume {
1343+
if operation == Operation::Resume && point.resume_arg != CTX_ARG.into() {
13441344
// Move the resume argument to the destination place of the `Yield` terminator
1345-
let resume_arg = CTX_ARG;
13461345
statements.push(Statement::new(
13471346
source_info,
13481347
StatementKind::Assign(Box::new((
13491348
point.resume_arg,
1350-
Rvalue::Use(Operand::Move(resume_arg.into())),
1349+
Rvalue::Use(Operand::Move(CTX_ARG.into())),
13511350
))),
13521351
));
13531352
}
@@ -1439,7 +1438,10 @@ fn check_field_tys_sized<'tcx>(
14391438
}
14401439

14411440
impl<'tcx> crate::MirPass<'tcx> for StateTransform {
1441+
#[instrument(level = "debug", skip(self, tcx, body), ret)]
14421442
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
1443+
debug!(def_id = ?body.source.def_id());
1444+
14431445
let Some(old_yield_ty) = body.yield_ty() else {
14441446
// This only applies to coroutines
14451447
return;
@@ -1518,31 +1520,7 @@ impl<'tcx> crate::MirPass<'tcx> for StateTransform {
15181520
cleanup_async_drops(body);
15191521
}
15201522

1521-
// We also replace the resume argument and insert an `Assign`.
1522-
// This is needed because the resume argument `_2` might be live across a `yield`, in which
1523-
// case there is no `Assign` to it that the transform can turn into a store to the coroutine
1524-
// state. After the yield the slot in the coroutine state would then be uninitialized.
1525-
let resume_local = CTX_ARG;
1526-
let resume_ty = body.local_decls[resume_local].ty;
1527-
let old_resume_local = replace_local(resume_local, resume_ty, body, tcx);
1528-
1529-
// When first entering the coroutine, move the resume argument into its old local
1530-
// (which is now a generator interior).
1531-
let source_info = SourceInfo::outermost(body.span);
1532-
let stmts = &mut body.basic_blocks_mut()[START_BLOCK].statements;
1533-
stmts.insert(
1534-
0,
1535-
Statement::new(
1536-
source_info,
1537-
StatementKind::Assign(Box::new((
1538-
old_resume_local.into(),
1539-
Rvalue::Use(Operand::Move(resume_local.into())),
1540-
))),
1541-
),
1542-
);
1543-
15441523
let always_live_locals = always_storage_live_locals(body);
1545-
15461524
let movable = coroutine_kind.movability() == hir::Movability::Movable;
15471525
let liveness_info =
15481526
locals_live_across_suspend_points(tcx, body, &always_live_locals, movable);
@@ -1583,6 +1561,21 @@ impl<'tcx> crate::MirPass<'tcx> for StateTransform {
15831561
};
15841562
transform.visit_body(body);
15851563

1564+
// MIR parameters are not explicitly assigned-to when entering the MIR body.
1565+
// If we want to save their values inside the coroutine state, we need to do so explicitly.
1566+
let source_info = SourceInfo::outermost(body.span);
1567+
let args_iter = body.args_iter();
1568+
body.basic_blocks.as_mut()[START_BLOCK].statements.splice(
1569+
0..0,
1570+
args_iter.filter_map(|local| {
1571+
let (ty, variant_index, idx) = transform.remap[local]?;
1572+
let lhs = transform.make_field(variant_index, idx, ty);
1573+
let rhs = Rvalue::Use(Operand::Move(local.into()));
1574+
let assign = StatementKind::Assign(Box::new((lhs, rhs)));
1575+
Some(Statement::new(source_info, assign))
1576+
}),
1577+
);
1578+
15861579
// Update our MIR struct to reflect the changes we've made
15871580
body.arg_count = 2; // self, resume arg
15881581
body.spread_arg = None;

compiler/rustc_session/src/session.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,8 @@ impl Session {
751751
// ELF x86-64 abi, but it can be disabled for some compilation units.
752752
//
753753
// Typically when we're compiling with `-C panic=abort` we don't need
754-
// `uwtable` because we can't generate any exceptions!
754+
// `uwtable` because we can't generate any exceptions! But note that
755+
// some targets require unwind tables to generate backtraces.
755756
// Unwind tables are needed when compiling with `-C panic=unwind`, but
756757
// LLVM won't omit unwind tables unless the function is also marked as
757758
// `nounwind`, so users are allowed to disable `uwtable` emission.

compiler/rustc_target/src/spec/base/android.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ pub(crate) fn opts() -> TargetOptions {
88
base.tls_model = TlsModel::Emulated;
99
base.has_thread_local = false;
1010
base.supported_sanitizers = SanitizerSet::ADDRESS;
11-
// This is for backward compatibility, see https://github.com/rust-lang/rust/issues/49867
12-
// for context. (At that time, there was no `-C force-unwind-tables`, so the only solution
13-
// was to always emit `uwtable`).
14-
base.default_uwtable = true;
1511
base.crt_static_respected = true;
1612
base
1713
}

compiler/rustc_target/src/spec/base/linux.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ pub(crate) fn opts() -> TargetOptions {
1212
relro_level: RelroLevel::Full,
1313
has_thread_local: true,
1414
crt_static_respected: true,
15+
// We want backtraces to work by default and they rely on unwind tables
16+
// (regardless of `-C panic` strategy).
17+
default_uwtable: true,
1518
supported_split_debuginfo: Cow::Borrowed(&[
1619
SplitDebuginfo::Packed,
1720
SplitDebuginfo::Unpacked,

tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-abort.mir

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// MIR for `a::{closure#0}` 0 coroutine_drop_async
22

33
fn a::{closure#0}(_1: Pin<&mut {async fn body of a<T>()}>, _2: &mut Context<'_>) -> Poll<()> {
4-
debug _task_context => _19;
4+
debug _task_context => _2;
55
debug x => ((*(_1.0: &mut {async fn body of a<T>()})).0: T);
66
let mut _0: std::task::Poll<()>;
77
let _3: T;
@@ -20,15 +20,14 @@ fn a::{closure#0}(_1: Pin<&mut {async fn body of a<T>()}>, _2: &mut Context<'_>)
2020
let mut _16: &mut impl std::future::Future<Output = ()>;
2121
let mut _17: std::pin::Pin<&mut impl std::future::Future<Output = ()>>;
2222
let mut _18: isize;
23-
let mut _19: &mut std::task::Context<'_>;
24-
let mut _20: u32;
23+
let mut _19: u32;
2524
scope 1 {
2625
debug x => (((*(_1.0: &mut {async fn body of a<T>()})) as variant#4).0: T);
2726
}
2827

2928
bb0: {
30-
_20 = discriminant((*(_1.0: &mut {async fn body of a<T>()})));
31-
switchInt(move _20) -> [0: bb9, 3: bb12, 4: bb13, otherwise: bb14];
29+
_19 = discriminant((*(_1.0: &mut {async fn body of a<T>()})));
30+
switchInt(move _19) -> [0: bb9, 3: bb12, 4: bb13, otherwise: bb14];
3231
}
3332

3433
bb1: {

tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-unwind.mir

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// MIR for `a::{closure#0}` 0 coroutine_drop_async
22

33
fn a::{closure#0}(_1: Pin<&mut {async fn body of a<T>()}>, _2: &mut Context<'_>) -> Poll<()> {
4-
debug _task_context => _19;
4+
debug _task_context => _2;
55
debug x => ((*(_1.0: &mut {async fn body of a<T>()})).0: T);
66
let mut _0: std::task::Poll<()>;
77
let _3: T;
@@ -20,15 +20,14 @@ fn a::{closure#0}(_1: Pin<&mut {async fn body of a<T>()}>, _2: &mut Context<'_>)
2020
let mut _16: &mut impl std::future::Future<Output = ()>;
2121
let mut _17: std::pin::Pin<&mut impl std::future::Future<Output = ()>>;
2222
let mut _18: isize;
23-
let mut _19: &mut std::task::Context<'_>;
24-
let mut _20: u32;
23+
let mut _19: u32;
2524
scope 1 {
2625
debug x => (((*(_1.0: &mut {async fn body of a<T>()})) as variant#4).0: T);
2726
}
2827

2928
bb0: {
30-
_20 = discriminant((*(_1.0: &mut {async fn body of a<T>()})));
31-
switchInt(move _20) -> [0: bb12, 2: bb18, 3: bb16, 4: bb17, otherwise: bb19];
29+
_19 = discriminant((*(_1.0: &mut {async fn body of a<T>()})));
30+
switchInt(move _19) -> [0: bb12, 2: bb18, 3: bb16, 4: bb17, otherwise: bb19];
3231
}
3332

3433
bb1: {

tests/mir-opt/building/async_await.a-{closure#0}.coroutine_resume.0.mir

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,17 @@
1010
} */
1111

1212
fn a::{closure#0}(_1: Pin<&mut {async fn body of a()}>, _2: &mut Context<'_>) -> Poll<()> {
13-
debug _task_context => _4;
13+
debug _task_context => _2;
1414
let mut _0: std::task::Poll<()>;
1515
let mut _3: ();
16-
let mut _4: &mut std::task::Context<'_>;
17-
let mut _5: u32;
16+
let mut _4: u32;
1817

1918
bb0: {
20-
_5 = discriminant((*(_1.0: &mut {async fn body of a()})));
21-
switchInt(move _5) -> [0: bb1, 1: bb4, otherwise: bb5];
19+
_4 = discriminant((*(_1.0: &mut {async fn body of a()})));
20+
switchInt(move _4) -> [0: bb1, 1: bb4, otherwise: bb5];
2221
}
2322

2423
bb1: {
25-
_4 = move _2;
2624
_3 = const ();
2725
goto -> bb3;
2826
}

0 commit comments

Comments
 (0)