Skip to content

Commit 723ea61

Browse files
committed
Put move source locations for parameters into Call/TailCall
Rather than store parameter moves in a separate side structure, which relies on MIR indexes not changing again, instead move the parameter move source_info into TerminatorKind::Call/TailCall itself. This keeps everything together as a parallel array of parameter move information. If we aren't annotating moves, or no parameters need annotation, then then remains as None, Otherwise it's a `Box<[Option<SourceInfo>]>` recording the source location of the annotated parameters. This ends up touching a lot of files with mostly one line changes just because of the extra field in the Call/TailCall enums. I changed a lot of the patterns to use `..` wildcard matching since in many cases most fields were being skipped.
1 parent b4962cd commit 723ea61

File tree

28 files changed

+138
-163
lines changed

28 files changed

+138
-163
lines changed

compiler/rustc_borrowck/src/lib.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -904,22 +904,14 @@ impl<'a, 'tcx> ResultsVisitor<'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<'a,
904904
state,
905905
);
906906
}
907-
TerminatorKind::Call {
908-
func,
909-
args,
910-
destination,
911-
target: _,
912-
unwind: _,
913-
call_source: _,
914-
fn_span: _,
915-
} => {
907+
TerminatorKind::Call { func, args, destination, .. } => {
916908
self.consume_operand(loc, (func, span), state);
917909
for arg in args {
918910
self.consume_operand(loc, (&arg.node, arg.span), state);
919911
}
920912
self.mutate_place(loc, (*destination, span), Deep, state);
921913
}
922-
TerminatorKind::TailCall { func, args, fn_span: _ } => {
914+
TerminatorKind::TailCall { func, args, .. } => {
923915
self.consume_operand(loc, (func, span), state);
924916
for arg in args {
925917
self.consume_operand(loc, (&arg.node, arg.span), state);

compiler/rustc_borrowck/src/polonius/legacy/loan_invalidations.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LoanInvalidationsGenerator<'a, 'tcx> {
118118
LocalMutationIsAllowed::Yes,
119119
);
120120
}
121-
TerminatorKind::Call {
122-
func,
123-
args,
124-
destination,
125-
target: _,
126-
unwind: _,
127-
call_source: _,
128-
fn_span: _,
129-
} => {
121+
TerminatorKind::Call { func, args, destination, .. } => {
130122
self.consume_operand(location, func);
131123
for arg in args {
132124
self.consume_operand(location, &arg.node);

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -478,15 +478,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
478478
switch.emit(&mut fx.bcx, discr, otherwise_block);
479479
}
480480
}
481-
TerminatorKind::Call {
482-
func,
483-
args,
484-
destination,
485-
target,
486-
fn_span,
487-
unwind,
488-
call_source: _,
489-
} => {
481+
TerminatorKind::Call { func, args, destination, target, fn_span, unwind, .. } => {
490482
fx.tcx.prof.generic_activity("codegen call").run(|| {
491483
crate::abi::codegen_terminator_call(
492484
fx,

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,13 +1152,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
11521152
}
11531153

11541154
// Look up stored SourceInfo for this argument if it exists (from annotate_moves pass)
1155-
let bb_info = self
1156-
.mir
1157-
.call_arg_move_source_info
1158-
.iter()
1159-
.find(|&&((block, idx), _)| block == helper.bb && idx == i);
1160-
if let Some((_, arg_source_info)) = bb_info {
1161-
self.set_debug_loc(bx, *arg_source_info);
1155+
let arg_source_info = match &terminator.kind {
1156+
mir::TerminatorKind::Call { arg_move_source_info, .. }
1157+
| mir::TerminatorKind::TailCall { arg_move_source_info, .. } => {
1158+
arg_move_source_info.as_ref().and_then(|infos| infos.get(i).copied().flatten())
1159+
}
1160+
_ => None,
1161+
};
1162+
1163+
if let Some(arg_source_info) = arg_source_info {
1164+
self.set_debug_loc(bx, arg_source_info);
11621165
}
11631166

11641167
self.codegen_argument(
@@ -1454,8 +1457,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
14541457
destination,
14551458
target,
14561459
unwind,
1457-
call_source: _,
14581460
fn_span,
1461+
..
14591462
} => self.codegen_call_terminator(
14601463
helper,
14611464
bx,
@@ -1469,7 +1472,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
14691472
CallKind::Normal,
14701473
mergeable_succ(),
14711474
),
1472-
mir::TerminatorKind::TailCall { ref func, ref args, fn_span } => self
1475+
mir::TerminatorKind::TailCall { ref func, ref args, fn_span, .. } => self
14731476
.codegen_call_terminator(
14741477
helper,
14751478
bx,

compiler/rustc_const_eval/src/interpret/step.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -544,15 +544,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
544544
self.go_to_block(target_block);
545545
}
546546

547-
Call {
548-
ref func,
549-
ref args,
550-
destination,
551-
target,
552-
unwind,
553-
call_source: _,
554-
fn_span: _,
555-
} => {
547+
Call { ref func, ref args, destination, target, unwind, .. } => {
556548
let old_stack = self.frame_idx();
557549
let old_loc = self.frame().loc;
558550

@@ -576,7 +568,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
576568
}
577569
}
578570

579-
TailCall { ref func, ref args, fn_span: _ } => {
571+
TailCall { ref func, ref args, .. } => {
580572
let old_frame_idx = self.frame_idx();
581573

582574
let EvaluatedCalleeAndArgs { callee, args, fn_sig, fn_abi, with_caller_location } =

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -331,13 +331,6 @@ pub struct Body<'tcx> {
331331
#[type_foldable(identity)]
332332
#[type_visitable(ignore)]
333333
pub function_coverage_info: Option<Box<coverage::FunctionCoverageInfo>>,
334-
335-
/// Debug information for argument moves/copies in Call parameters. Stores pairs of
336-
/// ((BasicBlock, argument_index), SourceInfo) for move/copy operations. Only populated when
337-
/// `-Zannotate-moves` is enabled.
338-
#[type_foldable(identity)]
339-
#[type_visitable(ignore)]
340-
pub call_arg_move_source_info: Vec<((BasicBlock, usize), SourceInfo)>,
341334
}
342335

343336
impl<'tcx> Body<'tcx> {
@@ -381,7 +374,6 @@ impl<'tcx> Body<'tcx> {
381374
tainted_by_errors,
382375
coverage_info_hi: None,
383376
function_coverage_info: None,
384-
call_arg_move_source_info: Vec::new(),
385377
};
386378
body.is_polymorphic = body.has_non_region_param();
387379
body
@@ -413,7 +405,6 @@ impl<'tcx> Body<'tcx> {
413405
tainted_by_errors: None,
414406
coverage_info_hi: None,
415407
function_coverage_info: None,
416-
call_arg_move_source_info: Vec::new(),
417408
};
418409
body.is_polymorphic = body.has_non_region_param();
419410
body
@@ -1673,11 +1664,11 @@ mod size_asserts {
16731664

16741665
use super::*;
16751666
// tidy-alphabetical-start
1676-
static_assert_size!(BasicBlockData<'_>, 128);
1667+
static_assert_size!(BasicBlockData<'_>, 144);
16771668
static_assert_size!(LocalDecl<'_>, 40);
16781669
static_assert_size!(SourceScopeData<'_>, 64);
16791670
static_assert_size!(Statement<'_>, 32);
1680-
static_assert_size!(Terminator<'_>, 96);
1671+
static_assert_size!(Terminator<'_>, 112);
16811672
static_assert_size!(VarDebugInfo<'_>, 88);
16821673
// tidy-alphabetical-end
16831674
}

compiler/rustc_middle/src/mir/syntax.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_span::{Span, Symbol};
1616
use rustc_target::asm::InlineAsmRegOrRegClass;
1717
use smallvec::SmallVec;
1818

19-
use super::{BasicBlock, Const, Local, UserTypeProjection};
19+
use super::{BasicBlock, Const, Local, SourceInfo, UserTypeProjection};
2020
use crate::mir::coverage::CoverageKind;
2121
use crate::ty::adjustment::PointerCoercion;
2222
use crate::ty::{self, GenericArgsRef, List, Region, Ty, UserTypeAnnotationIndex};
@@ -812,7 +812,7 @@ pub enum TerminatorKind<'tcx> {
812812
///
813813
/// [#71117]: https://github.com/rust-lang/rust/issues/71117
814814
Call {
815-
/// The function thats being called.
815+
/// The function that's being called.
816816
func: Operand<'tcx>,
817817
/// Arguments the function is called with.
818818
/// These are owned by the callee, which is free to modify them.
@@ -832,6 +832,13 @@ pub enum TerminatorKind<'tcx> {
832832
/// This `Span` is the span of the function, without the dot and receiver
833833
/// e.g. `foo(a, b)` in `x.foo(a, b)`
834834
fn_span: Span,
835+
/// Optional array of source info for move operations in the arguments.
836+
/// This is used to make the move operations appear in profilers as if they
837+
/// were inlined from compiler_move intrinsics.
838+
/// If None, no special source info is used.
839+
/// If Some, the array has the same length as args, with None for arguments
840+
/// that don't need special source info.
841+
arg_move_source_info: Option<Box<[Option<SourceInfo>]>>,
835842
},
836843

837844
/// Tail call.
@@ -851,7 +858,7 @@ pub enum TerminatorKind<'tcx> {
851858
/// [`Call`]: TerminatorKind::Call
852859
/// [`Return`]: TerminatorKind::Return
853860
TailCall {
854-
/// The function thats being called.
861+
/// The function that's being called.
855862
func: Operand<'tcx>,
856863
/// Arguments the function is called with.
857864
/// These are owned by the callee, which is free to modify them.
@@ -862,6 +869,13 @@ pub enum TerminatorKind<'tcx> {
862869
/// This `Span` is the span of the function, without the dot and receiver
863870
/// (e.g. `foo(a, b)` in `x.foo(a, b)`
864871
fn_span: Span,
872+
/// Optional array of source info for move operations in the arguments.
873+
/// This is used to make the move operations appear in profilers as if they
874+
/// were inlined from compiler_move intrinsics.
875+
/// If None, no special source info is used.
876+
/// If Some, the array has the same length as args, with None for arguments
877+
/// that don't need special source info.
878+
arg_move_source_info: Option<Box<[Option<SourceInfo>]>>,
865879
},
866880

867881
/// Evaluates the operand, which must have type `bool`. If it is not equal to `expected`,
@@ -1734,6 +1748,6 @@ mod size_asserts {
17341748
static_assert_size!(PlaceElem<'_>, 24);
17351749
static_assert_size!(Rvalue<'_>, 40);
17361750
static_assert_size!(StatementKind<'_>, 16);
1737-
static_assert_size!(TerminatorKind<'_>, 80);
1751+
static_assert_size!(TerminatorKind<'_>, 96);
17381752
// tidy-alphabetical-end
17391753
}

compiler/rustc_middle/src/mir/terminator.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -779,15 +779,7 @@ impl<'tcx> TerminatorKind<'tcx> {
779779
}
780780
}
781781

782-
Call {
783-
unwind,
784-
destination,
785-
ref target,
786-
func: _,
787-
args: _,
788-
fn_span: _,
789-
call_source: _,
790-
} => TerminatorEdges::AssignOnReturn {
782+
Call { unwind, destination, ref target, .. } => TerminatorEdges::AssignOnReturn {
791783
return_: target.as_ref().map(slice::from_ref).unwrap_or_default(),
792784
cleanup: unwind.cleanup_block(),
793785
place: CallReturnPlaces::Call(destination),

compiler/rustc_middle/src/mir/visit.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -551,10 +551,8 @@ macro_rules! make_mir_visitor {
551551
func,
552552
args,
553553
destination,
554-
target: _,
555-
unwind: _,
556-
call_source: _,
557554
fn_span,
555+
..
558556
} => {
559557
self.visit_span($(& $mutability)? *fn_span);
560558
self.visit_operand(func, location);
@@ -568,7 +566,7 @@ macro_rules! make_mir_visitor {
568566
);
569567
}
570568

571-
TerminatorKind::TailCall { func, args, fn_span } => {
569+
TerminatorKind::TailCall { func, args, fn_span, .. } => {
572570
self.visit_span($(& $mutability)? *fn_span);
573571
self.visit_operand(func, location);
574572
for arg in args {

compiler/rustc_mir_build/src/builder/custom/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ pub(super) fn build_custom_mir<'tcx>(
6262
pass_count: 0,
6363
coverage_info_hi: None,
6464
function_coverage_info: None,
65-
call_arg_move_source_info: Vec::new(),
6665
};
6766

6867
body.local_decls.push(LocalDecl::new(return_ty, return_ty_span));

0 commit comments

Comments
 (0)