Skip to content

Commit 0907f12

Browse files
committed
Auto merge of #120114 - Enselic:rm-fn_span, r=<try>
Make `TerminatorKind::Call::func` `Spanned` and remove `::fn_span` To get structural symmetry between `TerminatorKind::Call::func` and `TerminatorKind::Call::args`, make `func` `Spanned`, since `args` already is `Spanned`. This way we can remove the separate `fn_span` field. Doing this was briefly discussed [here](#116520 (comment)). For easier review, this PR is split into two commits. The first commit is the actual change. The second commit just makes the code build again and is very repetitive. Can someone start a perf run of this change please?
2 parents 25f8d01 + 9f62d5c commit 0907f12

File tree

45 files changed

+132
-148
lines changed

Some content is hidden

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

45 files changed

+132
-148
lines changed

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
554554
&block.terminator().kind
555555
{
556556
// Just point to the function, to reduce the chance of overlapping spans.
557-
let function_span = match func {
557+
let function_span = match &func.node {
558558
Operand::Constant(c) => c.span,
559559
Operand::Copy(place) | Operand::Move(place) => {
560560
if let Some(l) = place.as_local() {

compiler/rustc_borrowck/src/diagnostics/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
103103
let terminator = self.body[location.block].terminator();
104104
debug!("add_moved_or_invoked_closure_note: terminator={:?}", terminator);
105105
if let TerminatorKind::Call {
106-
func: Operand::Constant(box ConstOperand { const_, .. }),
106+
func: Spanned { node: Operand::Constant(box ConstOperand { const_, .. }), .. },
107107
args,
108108
..
109109
} = &terminator.kind
@@ -430,7 +430,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
430430
}) = &bbd.terminator
431431
{
432432
if let Some(source) =
433-
BorrowedContentSource::from_call(func.ty(self.body, tcx), tcx)
433+
BorrowedContentSource::from_call(func.node.ty(self.body, tcx), tcx)
434434
{
435435
return source;
436436
}
@@ -855,7 +855,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
855855
debug!("move_spans: target_temp = {:?}", target_temp);
856856

857857
if let Some(Terminator {
858-
kind: TerminatorKind::Call { fn_span, call_source, .. }, ..
858+
kind: TerminatorKind::Call { func: Spanned { span: fn_span, .. }, call_source, .. },
859+
..
859860
}) = &self.body[location.block].terminator
860861
{
861862
let Some((method_did, method_args)) = rustc_middle::util::find_self_call(

compiler/rustc_borrowck/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -699,9 +699,8 @@ impl<'cx, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx, R> for MirBorro
699699
target: _,
700700
unwind: _,
701701
call_source: _,
702-
fn_span: _,
703702
} => {
704-
self.consume_operand(loc, (func, span), flow_state);
703+
self.consume_operand(loc, (&func.node, span), flow_state);
705704
for arg in args {
706705
self.consume_operand(loc, (&arg.node, arg.span), flow_state);
707706
}

compiler/rustc_borrowck/src/polonius/loan_invalidations.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,8 @@ impl<'cx, 'tcx> Visitor<'tcx> for LoanInvalidationsGenerator<'cx, 'tcx> {
116116
target: _,
117117
unwind: _,
118118
call_source: _,
119-
fn_span: _,
120119
} => {
121-
self.consume_operand(location, func);
120+
self.consume_operand(location, &func.node);
122121
for arg in args {
123122
self.consume_operand(location, &arg.node);
124123
}

compiler/rustc_borrowck/src/type_check/mod.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -1367,12 +1367,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
13671367
// FIXME: check the values
13681368
}
13691369
TerminatorKind::Call { func, args, destination, call_source, target, .. } => {
1370-
self.check_operand(func, term_location);
1370+
self.check_operand(&func.node, term_location);
13711371
for arg in args {
13721372
self.check_operand(&arg.node, term_location);
13731373
}
13741374

1375-
let func_ty = func.ty(body, tcx);
1375+
let func_ty = func.node.ty(body, tcx);
13761376
debug!("func_ty.kind: {:?}", func_ty.kind());
13771377

13781378
let sig = match func_ty.kind() {
@@ -1441,7 +1441,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
14411441
.add_location(region_vid, term_location);
14421442
}
14431443

1444-
self.check_call_inputs(body, term, func, &sig, args, term_location, *call_source);
1444+
self.check_call_inputs(
1445+
body,
1446+
term,
1447+
&func.node,
1448+
&sig,
1449+
args,
1450+
term_location,
1451+
*call_source,
1452+
);
14451453
}
14461454
TerminatorKind::Assert { cond, msg, .. } => {
14471455
self.check_operand(cond, term_location);

compiler/rustc_codegen_cranelift/src/base.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -421,20 +421,12 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
421421
switch.emit(&mut fx.bcx, discr, otherwise_block);
422422
}
423423
}
424-
TerminatorKind::Call {
425-
func,
426-
args,
427-
destination,
428-
target,
429-
fn_span,
430-
unwind: _,
431-
call_source: _,
432-
} => {
424+
TerminatorKind::Call { func, args, destination, target, unwind: _, call_source: _ } => {
433425
fx.tcx.prof.generic_activity("codegen call").run(|| {
434426
crate::abi::codegen_terminator_call(
435427
fx,
436-
mir::SourceInfo { span: *fn_span, ..source_info },
437-
func,
428+
mir::SourceInfo { span: func.span, ..source_info },
429+
&func.node,
438430
args,
439431
*destination,
440432
*target,

compiler/rustc_codegen_ssa/src/mir/block.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -741,19 +741,18 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
741741
helper: TerminatorCodegenHelper<'tcx>,
742742
bx: &mut Bx,
743743
terminator: &mir::Terminator<'tcx>,
744-
func: &mir::Operand<'tcx>,
744+
func: &Spanned<mir::Operand<'tcx>>,
745745
args: &[Spanned<mir::Operand<'tcx>>],
746746
destination: mir::Place<'tcx>,
747747
target: Option<mir::BasicBlock>,
748748
unwind: mir::UnwindAction,
749-
fn_span: Span,
750749
mergeable_succ: bool,
751750
) -> MergingSucc {
752751
let source_info = terminator.source_info;
753752
let span = source_info.span;
754753

755754
// Create the callee. This is a fn ptr or zero-sized and hence a kind of scalar.
756-
let callee = self.codegen_operand(bx, func);
755+
let callee = self.codegen_operand(bx, &func.node);
757756

758757
let (instance, mut llfn) = match *callee.layout.ty.kind() {
759758
ty::FnDef(def_id, args) => (
@@ -829,8 +828,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
829828

830829
if intrinsic == Some(sym::caller_location) {
831830
return if let Some(target) = target {
832-
let location =
833-
self.get_caller_location(bx, mir::SourceInfo { span: fn_span, ..source_info });
831+
let location = self
832+
.get_caller_location(bx, mir::SourceInfo { span: func.span, ..source_info });
834833

835834
if let ReturnDest::IndirectOperand(tmp, _) = ret_dest {
836835
location.val.store(bx, tmp);
@@ -1019,16 +1018,17 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
10191018
} else {
10201019
args.len()
10211020
};
1021+
let fn_span = func.span;
10221022
assert_eq!(
10231023
fn_abi.args.len(),
10241024
mir_args + 1,
10251025
"#[track_caller] fn's must have 1 more argument in their ABI than in their MIR: {instance:?} {fn_span:?} {fn_abi:?}",
10261026
);
10271027
let location =
1028-
self.get_caller_location(bx, mir::SourceInfo { span: fn_span, ..source_info });
1028+
self.get_caller_location(bx, mir::SourceInfo { span: func.span, ..source_info });
10291029
debug!(
1030-
"codegen_call_terminator({:?}): location={:?} (fn_span {:?})",
1031-
terminator, location, fn_span
1030+
"codegen_call_terminator({:?}): location={:?} (func.span {:?})",
1031+
terminator, location, func.span
10321032
);
10331033

10341034
let last_arg = fn_abi.args.last().unwrap();
@@ -1256,7 +1256,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
12561256
target,
12571257
unwind,
12581258
call_source: _,
1259-
fn_span,
12601259
} => self.codegen_call_terminator(
12611260
helper,
12621261
bx,
@@ -1266,7 +1265,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
12661265
destination,
12671266
target,
12681267
unwind,
1269-
fn_span,
12701268
mergeable_succ(),
12711269
),
12721270
mir::TerminatorKind::CoroutineDrop | mir::TerminatorKind::Yield { .. } => {

compiler/rustc_const_eval/src/interpret/eval_context.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_middle::ty::layout::{
1818
use rustc_middle::ty::{self, GenericArgsRef, ParamEnv, Ty, TyCtxt, TypeFoldable, Variance};
1919
use rustc_mir_dataflow::storage::always_storage_live_locals;
2020
use rustc_session::Limit;
21-
use rustc_span::Span;
21+
use rustc_span::{source_map::Spanned, Span};
2222
use rustc_target::abi::{call::FnAbi, Align, HasDataLayout, Size, TargetDataLayout};
2323

2424
use super::{
@@ -620,8 +620,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
620620
block.terminator(),
621621
block.terminator().kind,
622622
);
623-
if let mir::TerminatorKind::Call { fn_span, .. } = block.terminator().kind {
624-
source_info.span = fn_span;
623+
if let mir::TerminatorKind::Call { func: Spanned { span, .. }, .. } =
624+
block.terminator().kind
625+
{
626+
source_info.span = span;
625627
}
626628
}
627629

compiler/rustc_const_eval/src/interpret/terminator.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
111111
self.go_to_block(target_block);
112112
}
113113

114-
Call {
115-
ref func,
116-
ref args,
117-
destination,
118-
target,
119-
unwind,
120-
call_source: _,
121-
fn_span: _,
122-
} => {
114+
Call { ref func, ref args, destination, target, unwind, call_source: _ } => {
123115
let old_stack = self.frame_idx();
124116
let old_loc = self.frame().loc;
125-
let func = self.eval_operand(func, None)?;
117+
let func = self.eval_operand(&func.node, None)?;
126118
let args = self.eval_fn_call_arguments(args)?;
127119

128120
let fn_sig_binder = func.layout.ty.fn_sig(*self.tcx);

compiler/rustc_const_eval/src/transform/check_consts/check.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -713,11 +713,11 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
713713
self.super_terminator(terminator, location);
714714

715715
match &terminator.kind {
716-
TerminatorKind::Call { func, args, fn_span, call_source, .. } => {
716+
TerminatorKind::Call { func, args, call_source, .. } => {
717717
let ConstCx { tcx, body, param_env, .. } = *self.ccx;
718718
let caller = self.def_id();
719719

720-
let fn_ty = func.ty(body, tcx);
720+
let fn_ty = func.node.ty(body, tcx);
721721

722722
let (mut callee, mut fn_args) = match *fn_ty.kind() {
723723
ty::FnDef(def_id, fn_args) => (def_id, fn_args),
@@ -784,7 +784,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
784784
caller,
785785
callee,
786786
args: fn_args,
787-
span: *fn_span,
787+
span: func.span,
788788
call_source: *call_source,
789789
feature: Some(if tcx.features().const_trait_impl {
790790
sym::effects
@@ -831,7 +831,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
831831
caller,
832832
callee,
833833
args: fn_args,
834-
span: *fn_span,
834+
span: func.span,
835835
call_source: *call_source,
836836
feature: None,
837837
});

compiler/rustc_const_eval/src/transform/validate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
12061206
}
12071207
}
12081208
TerminatorKind::Call { func, .. } => {
1209-
let func_ty = func.ty(&self.body.local_decls, self.tcx);
1209+
let func_ty = func.node.ty(&self.body.local_decls, self.tcx);
12101210
match func_ty.kind() {
12111211
ty::FnPtr(..) | ty::FnDef(..) => {}
12121212
_ => self.fail(

compiler/rustc_middle/src/mir/syntax.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -668,8 +668,10 @@ pub enum TerminatorKind<'tcx> {
668668
///
669669
/// [#71117]: https://github.com/rust-lang/rust/issues/71117
670670
Call {
671-
/// The function that’s being called.
672-
func: Operand<'tcx>,
671+
/// The function that’s being called, including the `Span` of the
672+
/// function, without the dot and receiver
673+
/// e.g. `foo(a, b)` in `x.foo(a, b)`
674+
func: Spanned<Operand<'tcx>>,
673675
/// Arguments the function is called with.
674676
/// These are owned by the callee, which is free to modify them.
675677
/// This allows the memory occupied by "by-value" arguments to be
@@ -685,9 +687,6 @@ pub enum TerminatorKind<'tcx> {
685687
unwind: UnwindAction,
686688
/// Where this call came from in HIR/THIR.
687689
call_source: CallSource,
688-
/// This `Span` is the span of the function, without the dot and receiver
689-
/// e.g. `foo(a, b)` in `x.foo(a, b)`
690-
fn_span: Span,
691690
},
692691

693692
/// Evaluates the operand, which must have type `bool`. If it is not equal to `expected`,

compiler/rustc_middle/src/mir/terminator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ impl<'tcx> TerminatorKind<'tcx> {
584584
}
585585
}
586586

587-
Call { unwind, destination, target, func: _, args: _, fn_span: _, call_source: _ } => {
587+
Call { unwind, destination, target, func: _, args: _, call_source: _ } => {
588588
TerminatorEdges::AssignOnReturn {
589589
return_: target,
590590
cleanup: unwind.cleanup_block(),

compiler/rustc_middle/src/mir/visit.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -520,9 +520,8 @@ macro_rules! make_mir_visitor {
520520
target: _,
521521
unwind: _,
522522
call_source: _,
523-
fn_span: _
524523
} => {
525-
self.visit_operand(func, location);
524+
self.visit_operand(&$($mutability)? func.node, location);
526525
for arg in args {
527526
self.visit_operand(&$($mutability)? arg.node, location);
528527
}

compiler/rustc_middle/src/util/find_self_call.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn find_self_call<'tcx>(
1818
&body[block].terminator
1919
{
2020
debug!("find_self_call: func={:?}", func);
21-
if let Operand::Constant(box ConstOperand { const_, .. }) = func {
21+
if let Operand::Constant(box ConstOperand { const_, .. }) = &func.node {
2222
if let ty::FnDef(def_id, fn_args) = *const_.ty().kind() {
2323
if let Some(ty::AssocItem { fn_has_self_parameter: true, .. }) =
2424
tcx.opt_associated_item(def_id)

compiler/rustc_mir_build/src/build/custom/parse/instruction.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,14 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
168168
)
169169
.collect::<PResult<Vec<_>>>()?;
170170
Ok(TerminatorKind::Call {
171-
func: fun,
171+
func: Spanned { node: fun, span: *fn_span },
172172
args,
173173
destination,
174174
target: Some(target),
175175
unwind,
176176
call_source: if *from_hir_call { CallSource::Normal } else {
177177
CallSource::OverloadedOperator
178178
},
179-
fn_span: *fn_span,
180179
})
181180
},
182181
)

compiler/rustc_mir_build/src/build/expr/as_rvalue.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
156156
block,
157157
synth_info,
158158
TerminatorKind::Call {
159-
func: exchange_malloc,
159+
func: Spanned { node: exchange_malloc, span: expr_span },
160160
args: vec![
161161
Spanned { node: Operand::Move(size), span: DUMMY_SP },
162162
Spanned { node: Operand::Move(align), span: DUMMY_SP },
@@ -165,7 +165,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
165165
target: Some(success),
166166
unwind: UnwindAction::Continue,
167167
call_source: CallSource::Misc,
168-
fn_span: expr_span,
169168
},
170169
);
171170
this.diverge_from(block);

compiler/rustc_mir_build/src/build/expr/into.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
265265
block,
266266
source_info,
267267
TerminatorKind::Call {
268-
func: fun,
268+
func: Spanned { node: fun, span: fn_span },
269269
args,
270270
unwind: UnwindAction::Continue,
271271
destination,
@@ -282,7 +282,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
282282
} else {
283283
CallSource::OverloadedOperator
284284
},
285-
fn_span,
286285
},
287286
);
288287
this.diverge_from(block);

0 commit comments

Comments
 (0)