mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Rollup merge of #111950 - cjgillot:expn-noinline, r=oli-obk
Remove ExpnKind::Inlined. Suggested in https://github.com/rust-lang/rust/pull/111815#issuecomment-1561903339 r? ``@oli-obk``
This commit is contained in:
commit
c2e3521bfb
@ -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((
|
||||
|
@ -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((
|
||||
|
@ -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);
|
||||
|
@ -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());
|
||||
(
|
||||
|
@ -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)),
|
||||
}
|
||||
@ -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!(
|
||||
@ -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) => {
|
||||
|
@ -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,
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
@ -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())..,
|
||||
@ -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()),
|
||||
};
|
||||
|
||||
@ -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>,
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
@ -1058,8 +1057,6 @@ pub enum ExpnKind {
|
||||
AstPass(AstPass),
|
||||
/// Desugaring done by the compiler during HIR lowering.
|
||||
Desugaring(DesugaringKind),
|
||||
/// MIR inlining
|
||||
Inlined,
|
||||
}
|
||||
|
||||
impl ExpnKind {
|
||||
@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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, _))
|
||||
|
@ -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() {
|
||||
|
@ -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
|
||||
|
|
||||
|
Loading…
Reference in New Issue
Block a user