Skip to content

Commit

Permalink
Make TerminatorKind::Call::func Spanned build
Browse files Browse the repository at this point in the history
To make review easier, this commit does not make any semantic changes.
It only makes the previous commit build.
  • Loading branch information
Enselic committed Jan 18, 2024
1 parent 0d353cd commit 9f62d5c
Show file tree
Hide file tree
Showing 44 changed files with 128 additions and 143 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&block.terminator().kind
{
// Just point to the function, to reduce the chance of overlapping spans.
let function_span = match func {
let function_span = match &func.node {
Operand::Constant(c) => c.span,
Operand::Copy(place) | Operand::Move(place) => {
if let Some(l) = place.as_local() {
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_borrowck/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let terminator = self.body[location.block].terminator();
debug!("add_moved_or_invoked_closure_note: terminator={:?}", terminator);
if let TerminatorKind::Call {
func: Operand::Constant(box ConstOperand { const_, .. }),
func: Spanned { node: Operand::Constant(box ConstOperand { const_, .. }), .. },
args,
..
} = &terminator.kind
Expand Down Expand Up @@ -430,7 +430,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
}) = &bbd.terminator
{
if let Some(source) =
BorrowedContentSource::from_call(func.ty(self.body, tcx), tcx)
BorrowedContentSource::from_call(func.node.ty(self.body, tcx), tcx)
{
return source;
}
Expand Down Expand Up @@ -855,7 +855,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
debug!("move_spans: target_temp = {:?}", target_temp);

if let Some(Terminator {
kind: TerminatorKind::Call { fn_span, call_source, .. }, ..
kind: TerminatorKind::Call { func: Spanned { span: fn_span, .. }, call_source, .. },
..
}) = &self.body[location.block].terminator
{
let Some((method_did, method_args)) = rustc_middle::util::find_self_call(
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,9 +699,8 @@ impl<'cx, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx, R> for MirBorro
target: _,
unwind: _,
call_source: _,
fn_span: _,
} => {
self.consume_operand(loc, (func, span), flow_state);
self.consume_operand(loc, (&func.node, span), flow_state);
for arg in args {
self.consume_operand(loc, (&arg.node, arg.span), flow_state);
}
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_borrowck/src/polonius/loan_invalidations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,8 @@ impl<'cx, 'tcx> Visitor<'tcx> for LoanInvalidationsGenerator<'cx, 'tcx> {
target: _,
unwind: _,
call_source: _,
fn_span: _,
} => {
self.consume_operand(location, func);
self.consume_operand(location, &func.node);
for arg in args {
self.consume_operand(location, &arg.node);
}
Expand Down
14 changes: 11 additions & 3 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1367,12 +1367,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
// FIXME: check the values
}
TerminatorKind::Call { func, args, destination, call_source, target, .. } => {
self.check_operand(func, term_location);
self.check_operand(&func.node, term_location);
for arg in args {
self.check_operand(&arg.node, term_location);
}

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

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

self.check_call_inputs(body, term, func, &sig, args, term_location, *call_source);
self.check_call_inputs(
body,
term,
&func.node,
&sig,
args,
term_location,
*call_source,
);
}
TerminatorKind::Assert { cond, msg, .. } => {
self.check_operand(cond, term_location);
Expand Down
14 changes: 3 additions & 11 deletions compiler/rustc_codegen_cranelift/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,20 +421,12 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
switch.emit(&mut fx.bcx, discr, otherwise_block);
}
}
TerminatorKind::Call {
func,
args,
destination,
target,
fn_span,
unwind: _,
call_source: _,
} => {
TerminatorKind::Call { func, args, destination, target, unwind: _, call_source: _ } => {
fx.tcx.prof.generic_activity("codegen call").run(|| {
crate::abi::codegen_terminator_call(
fx,
mir::SourceInfo { span: *fn_span, ..source_info },
func,
mir::SourceInfo { span: func.span, ..source_info },
&func.node,
args,
*destination,
*target,
Expand Down
18 changes: 8 additions & 10 deletions compiler/rustc_codegen_ssa/src/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,19 +741,18 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
helper: TerminatorCodegenHelper<'tcx>,
bx: &mut Bx,
terminator: &mir::Terminator<'tcx>,
func: &mir::Operand<'tcx>,
func: &Spanned<mir::Operand<'tcx>>,
args: &[Spanned<mir::Operand<'tcx>>],
destination: mir::Place<'tcx>,
target: Option<mir::BasicBlock>,
unwind: mir::UnwindAction,
fn_span: Span,
mergeable_succ: bool,
) -> MergingSucc {
let source_info = terminator.source_info;
let span = source_info.span;

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

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

if intrinsic == Some(sym::caller_location) {
return if let Some(target) = target {
let location =
self.get_caller_location(bx, mir::SourceInfo { span: fn_span, ..source_info });
let location = self
.get_caller_location(bx, mir::SourceInfo { span: func.span, ..source_info });

if let ReturnDest::IndirectOperand(tmp, _) = ret_dest {
location.val.store(bx, tmp);
Expand Down Expand Up @@ -1019,16 +1018,17 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
} else {
args.len()
};
let fn_span = func.span;
assert_eq!(
fn_abi.args.len(),
mir_args + 1,
"#[track_caller] fn's must have 1 more argument in their ABI than in their MIR: {instance:?} {fn_span:?} {fn_abi:?}",
);
let location =
self.get_caller_location(bx, mir::SourceInfo { span: fn_span, ..source_info });
self.get_caller_location(bx, mir::SourceInfo { span: func.span, ..source_info });
debug!(
"codegen_call_terminator({:?}): location={:?} (fn_span {:?})",
terminator, location, fn_span
"codegen_call_terminator({:?}): location={:?} (func.span {:?})",
terminator, location, func.span
);

let last_arg = fn_abi.args.last().unwrap();
Expand Down Expand Up @@ -1256,7 +1256,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
target,
unwind,
call_source: _,
fn_span,
} => self.codegen_call_terminator(
helper,
bx,
Expand All @@ -1266,7 +1265,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
destination,
target,
unwind,
fn_span,
mergeable_succ(),
),
mir::TerminatorKind::CoroutineDrop | mir::TerminatorKind::Yield { .. } => {
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_const_eval/src/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use rustc_middle::ty::layout::{
use rustc_middle::ty::{self, GenericArgsRef, ParamEnv, Ty, TyCtxt, TypeFoldable, Variance};
use rustc_mir_dataflow::storage::always_storage_live_locals;
use rustc_session::Limit;
use rustc_span::Span;
use rustc_span::{source_map::Spanned, Span};
use rustc_target::abi::{call::FnAbi, Align, HasDataLayout, Size, TargetDataLayout};

use super::{
Expand Down Expand Up @@ -620,8 +620,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
block.terminator(),
block.terminator().kind,
);
if let mir::TerminatorKind::Call { fn_span, .. } = block.terminator().kind {
source_info.span = fn_span;
if let mir::TerminatorKind::Call { func: Spanned { span, .. }, .. } =
block.terminator().kind
{
source_info.span = span;
}
}

Expand Down
12 changes: 2 additions & 10 deletions compiler/rustc_const_eval/src/interpret/terminator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
self.go_to_block(target_block);
}

Call {
ref func,
ref args,
destination,
target,
unwind,
call_source: _,
fn_span: _,
} => {
Call { ref func, ref args, destination, target, unwind, call_source: _ } => {
let old_stack = self.frame_idx();
let old_loc = self.frame().loc;
let func = self.eval_operand(func, None)?;
let func = self.eval_operand(&func.node, None)?;
let args = self.eval_fn_call_arguments(args)?;

let fn_sig_binder = func.layout.ty.fn_sig(*self.tcx);
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_const_eval/src/transform/check_consts/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,11 +713,11 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
self.super_terminator(terminator, location);

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

let fn_ty = func.ty(body, tcx);
let fn_ty = func.node.ty(body, tcx);

let (mut callee, mut fn_args) = match *fn_ty.kind() {
ty::FnDef(def_id, fn_args) => (def_id, fn_args),
Expand Down Expand Up @@ -784,7 +784,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
caller,
callee,
args: fn_args,
span: *fn_span,
span: func.span,
call_source: *call_source,
feature: Some(if tcx.features().const_trait_impl {
sym::effects
Expand Down Expand Up @@ -831,7 +831,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
caller,
callee,
args: fn_args,
span: *fn_span,
span: func.span,
call_source: *call_source,
feature: None,
});
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/transform/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
}
}
TerminatorKind::Call { func, .. } => {
let func_ty = func.ty(&self.body.local_decls, self.tcx);
let func_ty = func.node.ty(&self.body.local_decls, self.tcx);
match func_ty.kind() {
ty::FnPtr(..) | ty::FnDef(..) => {}
_ => self.fail(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/terminator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ impl<'tcx> TerminatorKind<'tcx> {
}
}

Call { unwind, destination, target, func: _, args: _, fn_span: _, call_source: _ } => {
Call { unwind, destination, target, func: _, args: _, call_source: _ } => {
TerminatorEdges::AssignOnReturn {
return_: target,
cleanup: unwind.cleanup_block(),
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_middle/src/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,8 @@ macro_rules! make_mir_visitor {
target: _,
unwind: _,
call_source: _,
fn_span: _
} => {
self.visit_operand(func, location);
self.visit_operand(&$($mutability)? func.node, location);
for arg in args {
self.visit_operand(&$($mutability)? arg.node, location);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/util/find_self_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn find_self_call<'tcx>(
&body[block].terminator
{
debug!("find_self_call: func={:?}", func);
if let Operand::Constant(box ConstOperand { const_, .. }) = func {
if let Operand::Constant(box ConstOperand { const_, .. }) = &func.node {
if let ty::FnDef(def_id, fn_args) = *const_.ty().kind() {
if let Some(ty::AssocItem { fn_has_self_parameter: true, .. }) =
tcx.opt_associated_item(def_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,14 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
)
.collect::<PResult<Vec<_>>>()?;
Ok(TerminatorKind::Call {
func: fun,
func: Spanned { node: fun, span: *fn_span },
args,
destination,
target: Some(target),
unwind,
call_source: if *from_hir_call { CallSource::Normal } else {
CallSource::OverloadedOperator
},
fn_span: *fn_span,
})
},
)
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_mir_build/src/build/expr/as_rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
block,
synth_info,
TerminatorKind::Call {
func: exchange_malloc,
func: Spanned { node: exchange_malloc, span: expr_span },
args: vec![
Spanned { node: Operand::Move(size), span: DUMMY_SP },
Spanned { node: Operand::Move(align), span: DUMMY_SP },
Expand All @@ -165,7 +165,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
target: Some(success),
unwind: UnwindAction::Continue,
call_source: CallSource::Misc,
fn_span: expr_span,
},
);
this.diverge_from(block);
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_mir_build/src/build/expr/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
block,
source_info,
TerminatorKind::Call {
func: fun,
func: Spanned { node: fun, span: fn_span },
args,
unwind: UnwindAction::Continue,
destination,
Expand All @@ -282,7 +282,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
} else {
CallSource::OverloadedOperator
},
fn_span,
},
);
this.diverge_from(block);
Expand Down
Loading

0 comments on commit 9f62d5c

Please sign in to comment.