Skip to content

Commit c2e3521

Browse files
Rollup merge of #111950 - cjgillot:expn-noinline, r=oli-obk
Remove ExpnKind::Inlined. Suggested in #111815 (comment) r? ``@oli-obk``
2 parents cb5b402 + 3a423c3 commit c2e3521

File tree

12 files changed

+29
-57
lines changed

12 files changed

+29
-57
lines changed

compiler/rustc_codegen_cranelift/src/common.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -413,11 +413,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
413413

414414
// Note: must be kept in sync with get_caller_location from cg_ssa
415415
pub(crate) fn get_caller_location(&mut self, mut source_info: mir::SourceInfo) -> CValue<'tcx> {
416-
let span_to_caller_location = |fx: &mut FunctionCx<'_, '_, 'tcx>, mut span: Span| {
417-
// Remove `Inlined` marks as they pollute `expansion_cause`.
418-
while span.is_inlined() {
419-
span.remove_mark();
420-
}
416+
let span_to_caller_location = |fx: &mut FunctionCx<'_, '_, 'tcx>, span: Span| {
421417
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
422418
let caller = fx.tcx.sess.source_map().lookup_char_pos(topmost.lo());
423419
let const_loc = fx.tcx.const_caller_location((

compiler/rustc_codegen_ssa/src/mir/block.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1450,11 +1450,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
14501450
) -> OperandRef<'tcx, Bx::Value> {
14511451
let tcx = bx.tcx();
14521452

1453-
let mut span_to_caller_location = |mut span: Span| {
1454-
// Remove `Inlined` marks as they pollute `expansion_cause`.
1455-
while span.is_inlined() {
1456-
span.remove_mark();
1457-
}
1453+
let mut span_to_caller_location = |span: Span| {
14581454
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
14591455
let caller = tcx.sess.source_map().lookup_char_pos(topmost.lo());
14601456
let const_loc = tcx.const_caller_location((

compiler/rustc_const_eval/src/interpret/eval_context.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,20 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
949949
// This deliberately does *not* honor `requires_caller_location` since it is used for much
950950
// more than just panics.
951951
for frame in stack.iter().rev() {
952-
let span = frame.current_span();
952+
let span = match frame.loc {
953+
Left(loc) => {
954+
// If the stacktrace passes through MIR-inlined source scopes, add them.
955+
let mir::SourceInfo { mut span, scope } = *frame.body.source_info(loc);
956+
let mut scope_data = &frame.body.source_scopes[scope];
957+
while let Some((instance, call_span)) = scope_data.inlined {
958+
frames.push(FrameInfo { span, instance });
959+
span = call_span;
960+
scope_data = &frame.body.source_scopes[scope_data.parent_scope.unwrap()];
961+
}
962+
span
963+
}
964+
Right(span) => span,
965+
};
953966
frames.push(FrameInfo { span, instance: frame.instance });
954967
}
955968
trace!("generate stacktrace: {:#?}", frames);

compiler/rustc_const_eval/src/interpret/intrinsics/caller_location.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
111111
location
112112
}
113113

114-
pub(crate) fn location_triple_for_span(&self, mut span: Span) -> (Symbol, u32, u32) {
115-
// Remove `Inlined` marks as they pollute `expansion_cause`.
116-
while span.is_inlined() {
117-
span.remove_mark();
118-
}
114+
pub(crate) fn location_triple_for_span(&self, span: Span) -> (Symbol, u32, u32) {
119115
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
120116
let caller = self.tcx.sess.source_map().lookup_char_pos(topmost.lo());
121117
(

compiler/rustc_errors/src/emitter.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ pub trait Emitter: Translate {
332332

333333
// Skip past non-macro entries, just in case there
334334
// are some which do actually involve macros.
335-
ExpnKind::Inlined | ExpnKind::Desugaring(..) | ExpnKind::AstPass(..) => None,
335+
ExpnKind::Desugaring(..) | ExpnKind::AstPass(..) => None,
336336

337337
ExpnKind::Macro(macro_kind, name) => Some((macro_kind, name)),
338338
}
@@ -403,7 +403,7 @@ pub trait Emitter: Translate {
403403
continue;
404404
}
405405

406-
if always_backtrace && !matches!(trace.kind, ExpnKind::Inlined) {
406+
if always_backtrace {
407407
new_labels.push((
408408
trace.def_site,
409409
format!(
@@ -442,7 +442,6 @@ pub trait Emitter: Translate {
442442
"this derive macro expansion".into()
443443
}
444444
ExpnKind::Macro(MacroKind::Bang, _) => "this macro invocation".into(),
445-
ExpnKind::Inlined => "this inlined function call".into(),
446445
ExpnKind::Root => "the crate root".into(),
447446
ExpnKind::AstPass(kind) => kind.descr().into(),
448447
ExpnKind::Desugaring(kind) => {

compiler/rustc_middle/src/lint.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,7 @@ pub fn struct_lint_level(
468468
pub fn in_external_macro(sess: &Session, span: Span) -> bool {
469469
let expn_data = span.ctxt().outer_expn_data();
470470
match expn_data.kind {
471-
ExpnKind::Inlined
472-
| ExpnKind::Root
471+
ExpnKind::Root
473472
| ExpnKind::Desugaring(
474473
DesugaringKind::ForLoop | DesugaringKind::WhileLoop | DesugaringKind::OpaqueTy,
475474
) => false,

compiler/rustc_middle/src/ty/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2488,9 +2488,7 @@ impl<'tcx> TyCtxt<'tcx> {
24882488
&& if self.features().collapse_debuginfo {
24892489
span.in_macro_expansion_with_collapse_debuginfo()
24902490
} else {
2491-
// Inlined spans should not be collapsed as that leads to all of the
2492-
// inlined code being attributed to the inline callsite.
2493-
span.from_expansion() && !span.is_inlined()
2491+
span.from_expansion()
24942492
}
24952493
}
24962494

compiler/rustc_mir_transform/src/inline.rs

-18
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use rustc_middle::mir::*;
1010
use rustc_middle::ty::TypeVisitableExt;
1111
use rustc_middle::ty::{self, Instance, InstanceDef, ParamEnv, Ty, TyCtxt};
1212
use rustc_session::config::OptLevel;
13-
use rustc_span::{hygiene::ExpnKind, ExpnData, LocalExpnId, Span};
1413
use rustc_target::abi::{FieldIdx, FIRST_VARIANT};
1514
use rustc_target::spec::abi::Abi;
1615

@@ -551,16 +550,6 @@ impl<'tcx> Inliner<'tcx> {
551550
// Copy the arguments if needed.
552551
let args: Vec<_> = self.make_call_args(args, &callsite, caller_body, &callee_body);
553552

554-
let mut expn_data = ExpnData::default(
555-
ExpnKind::Inlined,
556-
callsite.source_info.span,
557-
self.tcx.sess.edition(),
558-
None,
559-
None,
560-
);
561-
expn_data.def_site = callee_body.span;
562-
let expn_data =
563-
self.tcx.with_stable_hashing_context(|hcx| LocalExpnId::fresh(expn_data, hcx));
564553
let mut integrator = Integrator {
565554
args: &args,
566555
new_locals: Local::new(caller_body.local_decls.len())..,
@@ -572,7 +561,6 @@ impl<'tcx> Inliner<'tcx> {
572561
cleanup_block: unwind,
573562
in_cleanup_block: false,
574563
tcx: self.tcx,
575-
expn_data,
576564
always_live_locals: BitSet::new_filled(callee_body.local_decls.len()),
577565
};
578566

@@ -956,7 +944,6 @@ struct Integrator<'a, 'tcx> {
956944
cleanup_block: UnwindAction,
957945
in_cleanup_block: bool,
958946
tcx: TyCtxt<'tcx>,
959-
expn_data: LocalExpnId,
960947
always_live_locals: BitSet<Local>,
961948
}
962949

@@ -1042,11 +1029,6 @@ impl<'tcx> MutVisitor<'tcx> for Integrator<'_, 'tcx> {
10421029
*scope = self.map_scope(*scope);
10431030
}
10441031

1045-
fn visit_span(&mut self, span: &mut Span) {
1046-
// Make sure that all spans track the fact that they were inlined.
1047-
*span = span.fresh_expansion(self.expn_data);
1048-
}
1049-
10501032
fn visit_basic_block_data(&mut self, block: BasicBlock, data: &mut BasicBlockData<'tcx>) {
10511033
self.in_cleanup_block = data.is_cleanup;
10521034
self.super_basic_block_data(block, data);

compiler/rustc_span/src/hygiene.rs

-4
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ impl ExpnId {
320320
// Stop going up the backtrace once include! is encountered
321321
if expn_data.is_root()
322322
|| expn_data.kind == ExpnKind::Macro(MacroKind::Bang, sym::include)
323-
|| expn_data.kind == ExpnKind::Inlined
324323
{
325324
break;
326325
}
@@ -1058,8 +1057,6 @@ pub enum ExpnKind {
10581057
AstPass(AstPass),
10591058
/// Desugaring done by the compiler during HIR lowering.
10601059
Desugaring(DesugaringKind),
1061-
/// MIR inlining
1062-
Inlined,
10631060
}
10641061

10651062
impl ExpnKind {
@@ -1073,7 +1070,6 @@ impl ExpnKind {
10731070
},
10741071
ExpnKind::AstPass(kind) => kind.descr().to_string(),
10751072
ExpnKind::Desugaring(kind) => format!("desugaring of {}", kind.descr()),
1076-
ExpnKind::Inlined => "inlined source".to_string(),
10771073
}
10781074
}
10791075
}

compiler/rustc_span/src/lib.rs

-6
Original file line numberDiff line numberDiff line change
@@ -594,12 +594,6 @@ impl Span {
594594
matches!(outer_expn.kind, ExpnKind::Macro(..)) && outer_expn.collapse_debuginfo
595595
}
596596

597-
/// Returns `true` if this span comes from MIR inlining.
598-
pub fn is_inlined(self) -> bool {
599-
let outer_expn = self.ctxt().outer_expn_data();
600-
matches!(outer_expn.kind, ExpnKind::Inlined)
601-
}
602-
603597
/// Returns `true` if `span` originates in a derive-macro's expansion.
604598
pub fn in_derive_expansion(self) -> bool {
605599
matches!(self.ctxt().outer_expn_data().kind, ExpnKind::Macro(MacroKind::Derive, _))

src/tools/miri/tests/fail/terminate-terminator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ impl Drop for Foo {
1212

1313
#[inline(always)]
1414
fn has_cleanup() {
15+
//~^ ERROR: panic in a function that cannot unwind
1516
let _f = Foo;
1617
panic!();
1718
}
1819

1920
extern "C" fn panic_abort() {
2021
has_cleanup();
21-
//~^ ERROR: panic in a function that cannot unwind
2222
}
2323

2424
fn main() {

src/tools/miri/tests/fail/terminate-terminator.stderr

+7-4
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@ error: abnormal termination: panic in a function that cannot unwind
66
--> $DIR/terminate-terminator.rs:LL:CC
77
|
88
LL | / fn has_cleanup() {
9+
LL | |
910
LL | | let _f = Foo;
1011
LL | | panic!();
1112
LL | | }
1213
| |_^ panic in a function that cannot unwind
13-
...
14-
LL | has_cleanup();
15-
| ------------- in this inlined function call
1614
|
17-
= note: inside `panic_abort` at $DIR/terminate-terminator.rs:LL:CC
15+
= note: inside `has_cleanup` at $DIR/terminate-terminator.rs:LL:CC
16+
note: inside `panic_abort`
17+
--> $DIR/terminate-terminator.rs:LL:CC
18+
|
19+
LL | has_cleanup();
20+
| ^^^^^^^^^^^^^
1821
note: inside `main`
1922
--> $DIR/terminate-terminator.rs:LL:CC
2023
|

0 commit comments

Comments
 (0)