Skip to content

Commit e77e4fc

Browse files
committedFeb 27, 2022
Only create a single expansion for each inline integration.
·
1.88.01.61.0
1 parent 6cbc6c3 commit e77e4fc

File tree

51 files changed

+502
-497
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+502
-497
lines changed
 

‎compiler/rustc_errors/src/emitter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,8 @@ pub trait Emitter {
408408
"this derive macro expansion".into()
409409
}
410410
ExpnKind::Macro(MacroKind::Bang, _) => "this macro invocation".into(),
411-
ExpnKind::Inlined => "the inlined copy of this code".into(),
412-
ExpnKind::Root => "in the crate root".into(),
411+
ExpnKind::Inlined => "this inlined function call".into(),
412+
ExpnKind::Root => "the crate root".into(),
413413
ExpnKind::AstPass(kind) => kind.descr().into(),
414414
ExpnKind::Desugaring(kind) => {
415415
format!("this {} desugaring", kind.descr()).into()

‎compiler/rustc_mir_transform/src/inline.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_middle::mir::*;
1010
use rustc_middle::traits::ObligationCause;
1111
use rustc_middle::ty::subst::Subst;
1212
use rustc_middle::ty::{self, ConstKind, Instance, InstanceDef, ParamEnv, Ty, TyCtxt};
13-
use rustc_span::{hygiene::ExpnKind, ExpnData, Span};
13+
use rustc_span::{hygiene::ExpnKind, ExpnData, LocalExpnId, Span};
1414
use rustc_target::spec::abi::Abi;
1515

1616
use super::simplify::{remove_dead_blocks, CfgSimplifier};
@@ -543,6 +543,16 @@ impl<'tcx> Inliner<'tcx> {
543543
// Copy the arguments if needed.
544544
let args: Vec<_> = self.make_call_args(args, &callsite, caller_body, &callee_body);
545545

546+
let mut expn_data = ExpnData::default(
547+
ExpnKind::Inlined,
548+
callsite.source_info.span,
549+
self.tcx.sess.edition(),
550+
None,
551+
None,
552+
);
553+
expn_data.def_site = callee_body.span;
554+
let expn_data =
555+
LocalExpnId::fresh(expn_data, self.tcx.create_stable_hashing_context());
546556
let mut integrator = Integrator {
547557
args: &args,
548558
new_locals: Local::new(caller_body.local_decls.len())..,
@@ -553,8 +563,7 @@ impl<'tcx> Inliner<'tcx> {
553563
cleanup_block: cleanup,
554564
in_cleanup_block: false,
555565
tcx: self.tcx,
556-
callsite_span: callsite.source_info.span,
557-
body_span: callee_body.span,
566+
expn_data,
558567
always_live_locals: BitSet::new_filled(callee_body.local_decls.len()),
559568
};
560569

@@ -787,8 +796,7 @@ struct Integrator<'a, 'tcx> {
787796
cleanup_block: Option<BasicBlock>,
788797
in_cleanup_block: bool,
789798
tcx: TyCtxt<'tcx>,
790-
callsite_span: Span,
791-
body_span: Span,
799+
expn_data: LocalExpnId,
792800
always_live_locals: BitSet<Local>,
793801
}
794802

@@ -835,12 +843,8 @@ impl<'tcx> MutVisitor<'tcx> for Integrator<'_, 'tcx> {
835843
}
836844

837845
fn visit_span(&mut self, span: &mut Span) {
838-
let mut expn_data =
839-
ExpnData::default(ExpnKind::Inlined, *span, self.tcx.sess.edition(), None, None);
840-
expn_data.def_site = self.body_span;
841846
// Make sure that all spans track the fact that they were inlined.
842-
*span =
843-
self.callsite_span.fresh_expansion(expn_data, self.tcx.create_stable_hashing_context());
847+
*span = span.fresh_expansion(self.expn_data);
844848
}
845849

846850
fn visit_place(&mut self, place: &mut Place<'tcx>, context: PlaceContext, location: Location) {

0 commit comments

Comments
 (0)
Please sign in to comment.