Skip to content

Commit

Permalink
Rollup merge of rust-lang#111950 - cjgillot:expn-noinline, r=oli-obk
Browse files Browse the repository at this point in the history
Remove ExpnKind::Inlined.

Suggested in rust-lang#111815 (comment)

r? ``@oli-obk``
  • Loading branch information
compiler-errors authored May 25, 2023
2 parents cb5b402 + 3a423c3 commit c2e3521
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 57 deletions.
6 changes: 1 addition & 5 deletions compiler/rustc_codegen_cranelift/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {

// Note: must be kept in sync with get_caller_location from cg_ssa
pub(crate) fn get_caller_location(&mut self, mut source_info: mir::SourceInfo) -> CValue<'tcx> {
let span_to_caller_location = |fx: &mut FunctionCx<'_, '_, 'tcx>, mut span: Span| {
// Remove `Inlined` marks as they pollute `expansion_cause`.
while span.is_inlined() {
span.remove_mark();
}
let span_to_caller_location = |fx: &mut FunctionCx<'_, '_, 'tcx>, span: Span| {
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
let caller = fx.tcx.sess.source_map().lookup_char_pos(topmost.lo());
let const_loc = fx.tcx.const_caller_location((
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_codegen_ssa/src/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1450,11 +1450,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
) -> OperandRef<'tcx, Bx::Value> {
let tcx = bx.tcx();

let mut span_to_caller_location = |mut span: Span| {
// Remove `Inlined` marks as they pollute `expansion_cause`.
while span.is_inlined() {
span.remove_mark();
}
let mut span_to_caller_location = |span: Span| {
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
let caller = tcx.sess.source_map().lookup_char_pos(topmost.lo());
let const_loc = tcx.const_caller_location((
Expand Down
15 changes: 14 additions & 1 deletion compiler/rustc_const_eval/src/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,20 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
// This deliberately does *not* honor `requires_caller_location` since it is used for much
// more than just panics.
for frame in stack.iter().rev() {
let span = frame.current_span();
let span = match frame.loc {
Left(loc) => {
// If the stacktrace passes through MIR-inlined source scopes, add them.
let mir::SourceInfo { mut span, scope } = *frame.body.source_info(loc);
let mut scope_data = &frame.body.source_scopes[scope];
while let Some((instance, call_span)) = scope_data.inlined {
frames.push(FrameInfo { span, instance });
span = call_span;
scope_data = &frame.body.source_scopes[scope_data.parent_scope.unwrap()];
}
span
}
Right(span) => span,
};
frames.push(FrameInfo { span, instance: frame.instance });
}
trace!("generate stacktrace: {:#?}", frames);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
location
}

pub(crate) fn location_triple_for_span(&self, mut span: Span) -> (Symbol, u32, u32) {
// Remove `Inlined` marks as they pollute `expansion_cause`.
while span.is_inlined() {
span.remove_mark();
}
pub(crate) fn location_triple_for_span(&self, span: Span) -> (Symbol, u32, u32) {
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
let caller = self.tcx.sess.source_map().lookup_char_pos(topmost.lo());
(
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ pub trait Emitter: Translate {

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

ExpnKind::Macro(macro_kind, name) => Some((macro_kind, name)),
}
Expand Down Expand Up @@ -403,7 +403,7 @@ pub trait Emitter: Translate {
continue;
}

if always_backtrace && !matches!(trace.kind, ExpnKind::Inlined) {
if always_backtrace {
new_labels.push((
trace.def_site,
format!(
Expand Down Expand Up @@ -442,7 +442,6 @@ pub trait Emitter: Translate {
"this derive macro expansion".into()
}
ExpnKind::Macro(MacroKind::Bang, _) => "this macro invocation".into(),
ExpnKind::Inlined => "this inlined function call".into(),
ExpnKind::Root => "the crate root".into(),
ExpnKind::AstPass(kind) => kind.descr().into(),
ExpnKind::Desugaring(kind) => {
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_middle/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,7 @@ pub fn struct_lint_level(
pub fn in_external_macro(sess: &Session, span: Span) -> bool {
let expn_data = span.ctxt().outer_expn_data();
match expn_data.kind {
ExpnKind::Inlined
| ExpnKind::Root
ExpnKind::Root
| ExpnKind::Desugaring(
DesugaringKind::ForLoop | DesugaringKind::WhileLoop | DesugaringKind::OpaqueTy,
) => false,
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2488,9 +2488,7 @@ impl<'tcx> TyCtxt<'tcx> {
&& if self.features().collapse_debuginfo {
span.in_macro_expansion_with_collapse_debuginfo()
} else {
// Inlined spans should not be collapsed as that leads to all of the
// inlined code being attributed to the inline callsite.
span.from_expansion() && !span.is_inlined()
span.from_expansion()
}
}

Expand Down
18 changes: 0 additions & 18 deletions compiler/rustc_mir_transform/src/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use rustc_middle::mir::*;
use rustc_middle::ty::TypeVisitableExt;
use rustc_middle::ty::{self, Instance, InstanceDef, ParamEnv, Ty, TyCtxt};
use rustc_session::config::OptLevel;
use rustc_span::{hygiene::ExpnKind, ExpnData, LocalExpnId, Span};
use rustc_target::abi::{FieldIdx, FIRST_VARIANT};
use rustc_target::spec::abi::Abi;

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

let mut expn_data = ExpnData::default(
ExpnKind::Inlined,
callsite.source_info.span,
self.tcx.sess.edition(),
None,
None,
);
expn_data.def_site = callee_body.span;
let expn_data =
self.tcx.with_stable_hashing_context(|hcx| LocalExpnId::fresh(expn_data, hcx));
let mut integrator = Integrator {
args: &args,
new_locals: Local::new(caller_body.local_decls.len())..,
Expand All @@ -572,7 +561,6 @@ impl<'tcx> Inliner<'tcx> {
cleanup_block: unwind,
in_cleanup_block: false,
tcx: self.tcx,
expn_data,
always_live_locals: BitSet::new_filled(callee_body.local_decls.len()),
};

Expand Down Expand Up @@ -956,7 +944,6 @@ struct Integrator<'a, 'tcx> {
cleanup_block: UnwindAction,
in_cleanup_block: bool,
tcx: TyCtxt<'tcx>,
expn_data: LocalExpnId,
always_live_locals: BitSet<Local>,
}

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

fn visit_span(&mut self, span: &mut Span) {
// Make sure that all spans track the fact that they were inlined.
*span = span.fresh_expansion(self.expn_data);
}

fn visit_basic_block_data(&mut self, block: BasicBlock, data: &mut BasicBlockData<'tcx>) {
self.in_cleanup_block = data.is_cleanup;
self.super_basic_block_data(block, data);
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_span/src/hygiene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ impl ExpnId {
// Stop going up the backtrace once include! is encountered
if expn_data.is_root()
|| expn_data.kind == ExpnKind::Macro(MacroKind::Bang, sym::include)
|| expn_data.kind == ExpnKind::Inlined
{
break;
}
Expand Down Expand Up @@ -1058,8 +1057,6 @@ pub enum ExpnKind {
AstPass(AstPass),
/// Desugaring done by the compiler during HIR lowering.
Desugaring(DesugaringKind),
/// MIR inlining
Inlined,
}

impl ExpnKind {
Expand All @@ -1073,7 +1070,6 @@ impl ExpnKind {
},
ExpnKind::AstPass(kind) => kind.descr().to_string(),
ExpnKind::Desugaring(kind) => format!("desugaring of {}", kind.descr()),
ExpnKind::Inlined => "inlined source".to_string(),
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,12 +594,6 @@ impl Span {
matches!(outer_expn.kind, ExpnKind::Macro(..)) && outer_expn.collapse_debuginfo
}

/// Returns `true` if this span comes from MIR inlining.
pub fn is_inlined(self) -> bool {
let outer_expn = self.ctxt().outer_expn_data();
matches!(outer_expn.kind, ExpnKind::Inlined)
}

/// Returns `true` if `span` originates in a derive-macro's expansion.
pub fn in_derive_expansion(self) -> bool {
matches!(self.ctxt().outer_expn_data().kind, ExpnKind::Macro(MacroKind::Derive, _))
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/tests/fail/terminate-terminator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ impl Drop for Foo {

#[inline(always)]
fn has_cleanup() {
//~^ ERROR: panic in a function that cannot unwind
let _f = Foo;
panic!();
}

extern "C" fn panic_abort() {
has_cleanup();
//~^ ERROR: panic in a function that cannot unwind
}

fn main() {
Expand Down
11 changes: 7 additions & 4 deletions src/tools/miri/tests/fail/terminate-terminator.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ error: abnormal termination: panic in a function that cannot unwind
--> $DIR/terminate-terminator.rs:LL:CC
|
LL | / fn has_cleanup() {
LL | |
LL | | let _f = Foo;
LL | | panic!();
LL | | }
| |_^ panic in a function that cannot unwind
...
LL | has_cleanup();
| ------------- in this inlined function call
|
= note: inside `panic_abort` at $DIR/terminate-terminator.rs:LL:CC
= note: inside `has_cleanup` at $DIR/terminate-terminator.rs:LL:CC
note: inside `panic_abort`
--> $DIR/terminate-terminator.rs:LL:CC
|
LL | has_cleanup();
| ^^^^^^^^^^^^^
note: inside `main`
--> $DIR/terminate-terminator.rs:LL:CC
|
Expand Down

0 comments on commit c2e3521

Please sign in to comment.