compiler: Lower fn call arg spans down to MIR

To enable improved accuracy of diagnostics in upcoming commits.
This commit is contained in:
Martin Nordholts 2024-01-12 08:21:42 +01:00
parent 924ea05103
commit 16ba56c242
47 changed files with 221 additions and 170 deletions

View File

@ -1257,7 +1257,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
return None;
};
debug!("checking call args for uses of inner_param: {:?}", args);
args.contains(&Operand::Move(inner_param)).then_some((loc, term))
args.iter()
.map(|a| &a.node)
.any(|a| a == &Operand::Move(inner_param))
.then_some((loc, term))
})
else {
debug!("no uses of inner_param found as a by-move call arg");
@ -3242,7 +3245,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
assigned_to, args
);
for operand in args {
let (Operand::Copy(assigned_from) | Operand::Move(assigned_from)) = operand
let (Operand::Copy(assigned_from) | Operand::Move(assigned_from)) =
&operand.node
else {
continue;
};

View File

@ -691,7 +691,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
);
// Check if one of the arguments to this function is the target place.
let found_target = args.iter().any(|arg| {
if let Operand::Move(place) = arg {
if let Operand::Move(place) = arg.node {
if let Some(potential) = place.as_local() {
potential == target
} else {

View File

@ -23,6 +23,7 @@ use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
use rustc_middle::util::{call_kind, CallDesugaringKind};
use rustc_mir_dataflow::move_paths::{InitLocation, LookupResult};
use rustc_span::def_id::LocalDefId;
use rustc_span::source_map::Spanned;
use rustc_span::{symbol::sym, Span, Symbol, DUMMY_SP};
use rustc_target::abi::{FieldIdx, VariantIdx};
use rustc_trait_selection::infer::InferCtxtExt;
@ -111,9 +112,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
debug!("add_moved_or_invoked_closure_note: id={:?}", id);
if Some(self.infcx.tcx.parent(id)) == self.infcx.tcx.lang_items().fn_once_trait() {
let closure = match args.first() {
Some(Operand::Copy(place) | Operand::Move(place))
if target == place.local_or_deref_local() =>
{
Some(Spanned {
node: Operand::Copy(place) | Operand::Move(place), ..
}) if target == place.local_or_deref_local() => {
place.local_or_deref_local().unwrap()
}
_ => return false,

View File

@ -703,7 +703,7 @@ impl<'cx, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx, R> for MirBorro
} => {
self.consume_operand(loc, (func, span), flow_state);
for arg in args {
self.consume_operand(loc, (arg, span), flow_state);
self.consume_operand(loc, (&arg.node, arg.span), flow_state);
}
self.mutate_place(loc, (*destination, span), Deep, flow_state);
}

View File

@ -120,7 +120,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for LoanInvalidationsGenerator<'cx, 'tcx> {
} => {
self.consume_operand(location, func);
for arg in args {
self.consume_operand(location, arg);
self.consume_operand(location, &arg.node);
}
self.mutate_place(location, *destination, Deep);
}

View File

@ -36,6 +36,7 @@ use rustc_middle::ty::{
};
use rustc_middle::ty::{GenericArgsRef, UserArgs};
use rustc_span::def_id::CRATE_DEF_ID;
use rustc_span::source_map::Spanned;
use rustc_span::symbol::sym;
use rustc_span::{Span, DUMMY_SP};
use rustc_target::abi::{FieldIdx, FIRST_VARIANT};
@ -1359,7 +1360,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
TerminatorKind::Call { func, args, destination, call_source, target, .. } => {
self.check_operand(func, term_location);
for arg in args {
self.check_operand(arg, term_location);
self.check_operand(&arg.node, term_location);
}
let func_ty = func.ty(body, tcx);
@ -1580,7 +1581,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
term: &Terminator<'tcx>,
func: &Operand<'tcx>,
sig: &ty::FnSig<'tcx>,
args: &[Operand<'tcx>],
args: &[Spanned<Operand<'tcx>>],
term_location: Location,
call_source: CallSource,
) {
@ -1593,7 +1594,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
if self.tcx().is_intrinsic(def_id) {
match self.tcx().item_name(def_id) {
sym::simd_shuffle => {
if !matches!(args[2], Operand::Constant(_)) {
if !matches!(args[2], Spanned { node: Operand::Constant(_), .. }) {
self.tcx()
.dcx()
.emit_err(SimdShuffleLastConst { span: term.source_info.span });
@ -1606,7 +1607,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
debug!(?func_ty);
for (n, (fn_arg, op_arg)) in iter::zip(sig.inputs(), args).enumerate() {
let op_arg_ty = op_arg.ty(body, self.tcx());
let op_arg_ty = op_arg.node.ty(body, self.tcx());
let op_arg_ty = self.normalize(op_arg_ty, term_location);
let category = if call_source.from_hir_call() {

View File

@ -11,6 +11,7 @@ use cranelift_module::ModuleError;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::ty::layout::FnAbiOf;
use rustc_session::Session;
use rustc_span::source_map::Spanned;
use rustc_target::abi::call::{Conv, FnAbi};
use rustc_target::spec::abi::Abi;
@ -360,7 +361,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
fx: &mut FunctionCx<'_, '_, 'tcx>,
source_info: mir::SourceInfo,
func: &Operand<'tcx>,
args: &[Operand<'tcx>],
args: &[Spanned<Operand<'tcx>>],
destination: Place<'tcx>,
target: Option<BasicBlock>,
) {
@ -415,7 +416,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
let extra_args = &args[fn_sig.inputs().skip_binder().len()..];
let extra_args = fx.tcx.mk_type_list_from_iter(
extra_args.iter().map(|op_arg| fx.monomorphize(op_arg.ty(fx.mir, fx.tcx))),
extra_args.iter().map(|op_arg| fx.monomorphize(op_arg.node.ty(fx.mir, fx.tcx))),
);
let fn_abi = if let Some(instance) = instance {
RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(instance, extra_args)
@ -440,10 +441,10 @@ pub(crate) fn codegen_terminator_call<'tcx>(
// Unpack arguments tuple for closures
let mut args = if fn_sig.abi() == Abi::RustCall {
let (self_arg, pack_arg) = match args {
[pack_arg] => (None, codegen_call_argument_operand(fx, pack_arg)),
[pack_arg] => (None, codegen_call_argument_operand(fx, &pack_arg.node)),
[self_arg, pack_arg] => (
Some(codegen_call_argument_operand(fx, self_arg)),
codegen_call_argument_operand(fx, pack_arg),
Some(codegen_call_argument_operand(fx, &self_arg.node)),
codegen_call_argument_operand(fx, &pack_arg.node),
),
_ => panic!("rust-call abi requires one or two arguments"),
};
@ -463,7 +464,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
}
args
} else {
args.iter().map(|arg| codegen_call_argument_operand(fx, arg)).collect::<Vec<_>>()
args.iter().map(|arg| codegen_call_argument_operand(fx, &arg.node)).collect::<Vec<_>>()
};
// Pass the caller location for `#[track_caller]`.

View File

@ -7,7 +7,7 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>(
fx: &mut FunctionCx<'_, '_, 'tcx>,
intrinsic: &str,
generic_args: GenericArgsRef<'tcx>,
args: &[mir::Operand<'tcx>],
args: &[Spanned<mir::Operand<'tcx>>],
ret: CPlace<'tcx>,
target: Option<BasicBlock>,
span: Span,

View File

@ -7,7 +7,7 @@ pub(crate) fn codegen_aarch64_llvm_intrinsic_call<'tcx>(
fx: &mut FunctionCx<'_, '_, 'tcx>,
intrinsic: &str,
_args: GenericArgsRef<'tcx>,
args: &[mir::Operand<'tcx>],
args: &[Spanned<mir::Operand<'tcx>>],
ret: CPlace<'tcx>,
target: Option<BasicBlock>,
) {

View File

@ -11,7 +11,7 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
fx: &mut FunctionCx<'_, '_, 'tcx>,
intrinsic: &str,
_args: GenericArgsRef<'tcx>,
args: &[mir::Operand<'tcx>],
args: &[Spanned<mir::Operand<'tcx>>],
ret: CPlace<'tcx>,
target: Option<BasicBlock>,
span: Span,
@ -175,9 +175,9 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
[x, y, kind] => (x, y, kind),
_ => bug!("wrong number of args for intrinsic {intrinsic}"),
};
let x = codegen_operand(fx, x);
let y = codegen_operand(fx, y);
let kind = match kind {
let x = codegen_operand(fx, &x.node);
let y = codegen_operand(fx, &y.node);
let kind = match &kind.node {
Operand::Constant(const_) => crate::constant::eval_mir_constant(fx, const_).0,
Operand::Copy(_) | Operand::Move(_) => unreachable!("{kind:?}"),
};
@ -287,8 +287,8 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
[a, b] => (a, b),
_ => bug!("wrong number of args for intrinsic {intrinsic}"),
};
let a = codegen_operand(fx, a);
let b = codegen_operand(fx, b);
let a = codegen_operand(fx, &a.node);
let b = codegen_operand(fx, &b.node);
// Based on the pseudocode at https://github.com/rust-lang/stdarch/blob/1cfbca8b38fd9b4282b2f054f61c6ca69fc7ce29/crates/core_arch/src/x86/avx2.rs#L2319-L2332
let zero = fx.bcx.ins().iconst(types::I8, 0);
@ -325,9 +325,9 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
[a, b, imm8] => (a, b, imm8),
_ => bug!("wrong number of args for intrinsic {intrinsic}"),
};
let a = codegen_operand(fx, a);
let b = codegen_operand(fx, b);
let imm8 = codegen_operand(fx, imm8).load_scalar(fx);
let a = codegen_operand(fx, &a.node);
let b = codegen_operand(fx, &b.node);
let imm8 = codegen_operand(fx, &imm8.node).load_scalar(fx);
let a_low = a.value_typed_lane(fx, fx.tcx.types.u128, 0).load_scalar(fx);
let a_high = a.value_typed_lane(fx, fx.tcx.types.u128, 1).load_scalar(fx);
@ -956,8 +956,8 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
let b = b.load_scalar(fx);
let lb = lb.load_scalar(fx);
let imm8 = if let Some(imm8) = crate::constant::mir_operand_get_const_val(fx, &args[4])
{
let imm8 =
if let Some(imm8) = crate::constant::mir_operand_get_const_val(fx, &args[4].node) {
imm8
} else {
fx.tcx
@ -1009,8 +1009,8 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
let b = b.load_scalar(fx);
let lb = lb.load_scalar(fx);
let imm8 = if let Some(imm8) = crate::constant::mir_operand_get_const_val(fx, &args[4])
{
let imm8 =
if let Some(imm8) = crate::constant::mir_operand_get_const_val(fx, &args[4].node) {
imm8
} else {
fx.tcx
@ -1056,8 +1056,8 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
let a = a.load_scalar(fx);
let b = b.load_scalar(fx);
let imm8 = if let Some(imm8) = crate::constant::mir_operand_get_const_val(fx, &args[2])
{
let imm8 =
if let Some(imm8) = crate::constant::mir_operand_get_const_val(fx, &args[2].node) {
imm8
} else {
fx.tcx.dcx().span_fatal(
@ -1093,8 +1093,8 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
let a = a.load_scalar(fx);
let imm8 = if let Some(imm8) = crate::constant::mir_operand_get_const_val(fx, &args[1])
{
let imm8 =
if let Some(imm8) = crate::constant::mir_operand_get_const_val(fx, &args[1].node) {
imm8
} else {
fx.tcx.dcx().span_fatal(

View File

@ -5,7 +5,7 @@ macro_rules! intrinsic_args {
($fx:expr, $args:expr => ($($arg:tt),*); $intrinsic:expr) => {
#[allow(unused_parens)]
let ($($arg),*) = if let [$($arg),*] = $args {
($(codegen_operand($fx, $arg)),*)
($(codegen_operand($fx, &($arg).node)),*)
} else {
$crate::intrinsics::bug_on_incorrect_arg_count($intrinsic);
};
@ -22,6 +22,7 @@ use rustc_middle::ty;
use rustc_middle::ty::layout::{HasParamEnv, ValidityRequirement};
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
use rustc_middle::ty::GenericArgsRef;
use rustc_span::source_map::Spanned;
use rustc_span::symbol::{kw, sym, Symbol};
pub(crate) use self::llvm::codegen_llvm_intrinsic_call;
@ -263,7 +264,7 @@ fn bool_to_zero_or_max_uint<'tcx>(
pub(crate) fn codegen_intrinsic_call<'tcx>(
fx: &mut FunctionCx<'_, '_, 'tcx>,
instance: Instance<'tcx>,
args: &[mir::Operand<'tcx>],
args: &[Spanned<mir::Operand<'tcx>>],
destination: CPlace<'tcx>,
target: Option<BasicBlock>,
source_info: mir::SourceInfo,
@ -301,7 +302,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
fn codegen_float_intrinsic_call<'tcx>(
fx: &mut FunctionCx<'_, '_, 'tcx>,
intrinsic: Symbol,
args: &[mir::Operand<'tcx>],
args: &[Spanned<mir::Operand<'tcx>>],
ret: CPlace<'tcx>,
) -> bool {
let (name, arg_count, ty, clif_ty) = match intrinsic {
@ -353,18 +354,21 @@ fn codegen_float_intrinsic_call<'tcx>(
let (a, b, c);
let args = match args {
[x] => {
a = [codegen_operand(fx, x).load_scalar(fx)];
a = [codegen_operand(fx, &x.node).load_scalar(fx)];
&a as &[_]
}
[x, y] => {
b = [codegen_operand(fx, x).load_scalar(fx), codegen_operand(fx, y).load_scalar(fx)];
b = [
codegen_operand(fx, &x.node).load_scalar(fx),
codegen_operand(fx, &y.node).load_scalar(fx),
];
&b
}
[x, y, z] => {
c = [
codegen_operand(fx, x).load_scalar(fx),
codegen_operand(fx, y).load_scalar(fx),
codegen_operand(fx, z).load_scalar(fx),
codegen_operand(fx, &x.node).load_scalar(fx),
codegen_operand(fx, &y.node).load_scalar(fx),
codegen_operand(fx, &z.node).load_scalar(fx),
];
&c
}
@ -422,7 +426,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
instance: Instance<'tcx>,
intrinsic: Symbol,
generic_args: GenericArgsRef<'tcx>,
args: &[mir::Operand<'tcx>],
args: &[Spanned<mir::Operand<'tcx>>],
ret: CPlace<'tcx>,
destination: Option<BasicBlock>,
source_info: mir::SourceInfo,

View File

@ -21,7 +21,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
fx: &mut FunctionCx<'_, '_, 'tcx>,
intrinsic: Symbol,
generic_args: GenericArgsRef<'tcx>,
args: &[mir::Operand<'tcx>],
args: &[Spanned<mir::Operand<'tcx>>],
ret: CPlace<'tcx>,
target: BasicBlock,
span: Span,
@ -121,8 +121,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
let [x, y] = args else {
bug!("wrong number of args for intrinsic {intrinsic}");
};
let x = codegen_operand(fx, x);
let y = codegen_operand(fx, y);
let x = codegen_operand(fx, &x.node);
let y = codegen_operand(fx, &y.node);
if !x.layout().ty.is_simd() {
report_simd_type_validation_error(fx, intrinsic, span, x.layout().ty);
@ -172,8 +172,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
bug!("wrong number of args for intrinsic {intrinsic}");
}
};
let x = codegen_operand(fx, x);
let y = codegen_operand(fx, y);
let x = codegen_operand(fx, &x.node);
let y = codegen_operand(fx, &y.node);
if !x.layout().ty.is_simd() {
report_simd_type_validation_error(fx, intrinsic, span, x.layout().ty);
@ -182,7 +182,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
// Make sure this is actually an array, since typeck only checks the length-suffixed
// version of this intrinsic.
let idx_ty = fx.monomorphize(idx.ty(fx.mir, fx.tcx));
let idx_ty = fx.monomorphize(idx.node.ty(fx.mir, fx.tcx));
let n: u16 = match idx_ty.kind() {
ty::Array(ty, len) if matches!(ty.kind(), ty::Uint(ty::UintTy::U32)) => len
.try_eval_target_usize(fx.tcx, ty::ParamEnv::reveal_all())
@ -215,7 +215,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
let indexes = {
use rustc_middle::mir::interpret::*;
let idx_const = match idx {
let idx_const = match &idx.node {
Operand::Constant(const_) => crate::constant::eval_mir_constant(fx, const_).0,
Operand::Copy(_) | Operand::Move(_) => unreachable!("{idx:?}"),
};
@ -269,12 +269,12 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
bug!("wrong number of args for intrinsic {intrinsic}");
}
};
let base = codegen_operand(fx, base);
let val = codegen_operand(fx, val);
let base = codegen_operand(fx, &base.node);
let val = codegen_operand(fx, &val.node);
// FIXME validate
let idx_const = if let Some(idx_const) =
crate::constant::mir_operand_get_const_val(fx, idx)
crate::constant::mir_operand_get_const_val(fx, &idx.node)
{
idx_const
} else {
@ -304,7 +304,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
bug!("wrong number of args for intrinsic {intrinsic}");
}
};
let v = codegen_operand(fx, v);
let v = codegen_operand(fx, &v.node);
if !v.layout().ty.is_simd() {
report_simd_type_validation_error(fx, intrinsic, span, v.layout().ty);
@ -312,7 +312,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
}
let idx_const = if let Some(idx_const) =
crate::constant::mir_operand_get_const_val(fx, idx)
crate::constant::mir_operand_get_const_val(fx, &idx.node)
{
idx_const
} else {

View File

@ -17,7 +17,7 @@ use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, ValidityRequirement};
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
use rustc_middle::ty::{self, Instance, Ty};
use rustc_session::config::OptLevel;
use rustc_span::{sym, Span, Symbol};
use rustc_span::{source_map::Spanned, sym, Span, Symbol};
use rustc_target::abi::call::{ArgAbi, FnAbi, PassMode, Reg};
use rustc_target::abi::{self, HasDataLayout, WrappingRange};
use rustc_target::spec::abi::Abi;
@ -742,7 +742,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
bx: &mut Bx,
terminator: &mir::Terminator<'tcx>,
func: &mir::Operand<'tcx>,
args: &[mir::Operand<'tcx>],
args: &[Spanned<mir::Operand<'tcx>>],
destination: mir::Place<'tcx>,
target: Option<mir::BasicBlock>,
unwind: mir::UnwindAction,
@ -793,7 +793,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let extra_args = &args[sig.inputs().skip_binder().len()..];
let extra_args = bx.tcx().mk_type_list_from_iter(extra_args.iter().map(|op_arg| {
let op_ty = op_arg.ty(self.mir, bx.tcx());
let op_ty = op_arg.node.ty(self.mir, bx.tcx());
self.monomorphize(op_ty)
}));
@ -863,7 +863,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
// checked by const-qualification, which also
// promotes any complex rvalues to constants.
if i == 2 && intrinsic == sym::simd_shuffle {
if let mir::Operand::Constant(constant) = arg {
if let mir::Operand::Constant(constant) = &arg.node {
let (llval, ty) = self.simd_shuffle_indices(bx, constant);
return OperandRef {
val: Immediate(llval),
@ -874,7 +874,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
}
}
self.codegen_operand(bx, arg)
self.codegen_operand(bx, &arg.node)
})
.collect();
@ -910,7 +910,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let mut copied_constant_arguments = vec![];
'make_args: for (i, arg) in first_args.iter().enumerate() {
let mut op = self.codegen_operand(bx, arg);
let mut op = self.codegen_operand(bx, &arg.node);
if let (0, Some(ty::InstanceDef::Virtual(_, idx))) = (i, def) {
match op.val {
@ -988,7 +988,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
// The callee needs to own the argument memory if we pass it
// by-ref, so make a local copy of non-immediate constants.
match (arg, op.val) {
match (&arg.node, op.val) {
(&mir::Operand::Copy(_), Ref(_, None, _))
| (&mir::Operand::Constant(_), Ref(_, None, _)) => {
let tmp = PlaceRef::alloca(bx, op.layout);
@ -1003,7 +1003,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
self.codegen_argument(bx, op, &mut llargs, &fn_abi.args[i]);
}
let num_untupled = untuple.map(|tup| {
self.codegen_arguments_untupled(bx, tup, &mut llargs, &fn_abi.args[first_args.len()..])
self.codegen_arguments_untupled(
bx,
&tup.node,
&mut llargs,
&fn_abi.args[first_args.len()..],
)
});
let needs_location =

View File

@ -9,7 +9,7 @@ use rustc_middle::{
AdtDef, Instance, Ty,
},
};
use rustc_span::sym;
use rustc_span::{source_map::Spanned, sym};
use rustc_target::abi::{self, FieldIdx};
use rustc_target::abi::{
call::{ArgAbi, FnAbi, PassMode},
@ -242,13 +242,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
/// Evaluate the arguments of a function call
pub(super) fn eval_fn_call_arguments(
&self,
ops: &[mir::Operand<'tcx>],
ops: &[Spanned<mir::Operand<'tcx>>],
) -> InterpResult<'tcx, Vec<FnArg<'tcx, M::Provenance>>> {
ops.iter()
.map(|op| {
Ok(match op {
Ok(match &op.node {
mir::Operand::Move(place) => FnArg::InPlace(self.eval_place(*place)?),
_ => FnArg::Copy(self.eval_operand(op, None)?),
_ => FnArg::Copy(self.eval_operand(&op.node, None)?),
})
})
.collect()

View File

@ -804,7 +804,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
// const-eval of the `begin_panic` fn assumes the argument is `&str`
if Some(callee) == tcx.lang_items().begin_panic_fn() {
match args[0].ty(&self.ccx.body.local_decls, tcx).kind() {
match args[0].node.ty(&self.ccx.body.local_decls, tcx).kind() {
ty::Ref(_, ty, _) if ty.is_str() => return,
_ => self.check_op(ops::PanicNonStr),
}
@ -812,7 +812,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
// const-eval of `#[rustc_const_panic_str]` functions assumes the argument is `&&str`
if tcx.has_attr(callee, sym::rustc_const_panic_str) {
match args[0].ty(&self.ccx.body.local_decls, tcx).kind() {
match args[0].node.ty(&self.ccx.body.local_decls, tcx).kind() {
ty::Ref(_, ty, _) if matches!(ty.kind(), ty::Ref(_, ty, _) if ty.is_str()) =>
{
return;

View File

@ -402,7 +402,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> {
);
}
for arg in args {
if let Operand::Move(place) = arg {
if let Operand::Move(place) = &arg.node {
if is_within_packed(self.tcx, &self.body.local_decls, *place).is_some() {
// This is bad! The callee will expect the memory to be aligned.
self.fail(

View File

@ -785,7 +785,7 @@ impl<'tcx> TerminatorKind<'tcx> {
Call { func, args, destination, .. } => {
write!(fmt, "{destination:?} = ")?;
write!(fmt, "{func:?}(")?;
for (index, arg) in args.iter().enumerate() {
for (index, arg) in args.iter().map(|a| &a.node).enumerate() {
if index > 0 {
write!(fmt, ", ")?;
}

View File

@ -16,6 +16,7 @@ use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
use rustc_hir::def_id::DefId;
use rustc_hir::{self, CoroutineKind};
use rustc_index::IndexVec;
use rustc_span::source_map::Spanned;
use rustc_target::abi::{FieldIdx, VariantIdx};
use rustc_ast::Mutability;
@ -673,7 +674,9 @@ pub enum TerminatorKind<'tcx> {
/// These are owned by the callee, which is free to modify them.
/// This allows the memory occupied by "by-value" arguments to be
/// reused across function calls without duplicating the contents.
args: Vec<Operand<'tcx>>,
/// The span for each arg is also included
/// (e.g. `a` and `b` in `x.foo(a, b)`).
args: Vec<Spanned<Operand<'tcx>>>,
/// Where the returned value will be written
destination: Place<'tcx>,
/// Where to go after this call returns. If none, the call necessarily diverges.

View File

@ -524,7 +524,7 @@ macro_rules! make_mir_visitor {
} => {
self.visit_operand(func, location);
for arg in args {
self.visit_operand(arg, location);
self.visit_operand(&$($mutability)? arg.node, location);
}
self.visit_place(
destination,

View File

@ -2,6 +2,7 @@ use crate::mir::*;
use crate::ty::GenericArgsRef;
use crate::ty::{self, TyCtxt};
use rustc_span::def_id::DefId;
use rustc_span::source_map::Spanned;
/// Checks if the specified `local` is used as the `self` parameter of a method call
/// in the provided `BasicBlock`. If it is, then the `DefId` of the called method is
@ -23,7 +24,13 @@ pub fn find_self_call<'tcx>(
tcx.opt_associated_item(def_id)
{
debug!("find_self_call: args={:?}", fn_args);
if let [Operand::Move(self_place) | Operand::Copy(self_place), ..] = **args {
if let [
Spanned {
node: Operand::Move(self_place) | Operand::Copy(self_place), ..
},
..,
] = **args
{
if self_place.as_local() == Some(local) {
return Some((def_id, fn_args));
}

View File

@ -2,6 +2,7 @@ use rustc_middle::mir::interpret::Scalar;
use rustc_middle::mir::tcx::PlaceTy;
use rustc_middle::ty::cast::mir_cast_kind;
use rustc_middle::{mir::*, thir::*, ty};
use rustc_span::source_map::Spanned;
use rustc_span::Span;
use rustc_target::abi::{FieldIdx, VariantIdx};
@ -162,7 +163,9 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
let fun = self.parse_operand(*fun)?;
let args = args
.iter()
.map(|arg| self.parse_operand(*arg))
.map(|arg|
Ok(Spanned { node: self.parse_operand(*arg)?, span: self.thir.exprs[*arg].span } )
)
.collect::<PResult<Vec<_>>>()?;
Ok(TerminatorKind::Call {
func: fun,

View File

@ -2,6 +2,7 @@
use rustc_index::{Idx, IndexVec};
use rustc_middle::ty::util::IntTypeExt;
use rustc_span::source_map::Spanned;
use rustc_target::abi::{Abi, FieldIdx, Primitive};
use crate::build::expr::as_place::PlaceBase;
@ -15,7 +16,7 @@ use rustc_middle::thir::*;
use rustc_middle::ty::cast::{mir_cast_kind, CastTy};
use rustc_middle::ty::layout::IntegerExt;
use rustc_middle::ty::{self, Ty, UpvarArgs};
use rustc_span::Span;
use rustc_span::{Span, DUMMY_SP};
impl<'a, 'tcx> Builder<'a, 'tcx> {
/// Returns an rvalue suitable for use until the end of the current
@ -156,7 +157,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
synth_info,
TerminatorKind::Call {
func: exchange_malloc,
args: vec![Operand::Move(size), Operand::Move(align)],
args: vec![
Spanned { node: Operand::Move(size), span: DUMMY_SP },
Spanned { node: Operand::Move(align), span: DUMMY_SP },
],
destination: storage,
target: Some(success),
unwind: UnwindAction::Continue,
@ -733,7 +737,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
this.diverge_from(block);
block = success;
}
this.record_operands_moved(&[value_operand]);
this.record_operands_moved(&[Spanned { node: value_operand, span: DUMMY_SP }]);
}
block.and(Rvalue::Aggregate(Box::new(AggregateKind::Array(elem_ty)), IndexVec::new()))
}

View File

@ -9,6 +9,7 @@ use rustc_hir as hir;
use rustc_middle::mir::*;
use rustc_middle::thir::*;
use rustc_middle::ty::CanonicalUserTypeAnnotation;
use rustc_span::source_map::Spanned;
use std::iter;
impl<'a, 'tcx> Builder<'a, 'tcx> {
@ -248,7 +249,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let args: Vec<_> = args
.into_iter()
.copied()
.map(|arg| unpack!(block = this.as_local_call_operand(block, arg)))
.map(|arg| Spanned {
node: unpack!(block = this.as_local_call_operand(block, arg)),
span: this.thir.exprs[arg].span,
})
.collect();
let success = this.cfg.start_new_block();

View File

@ -17,8 +17,9 @@ use rustc_middle::ty::util::IntTypeExt;
use rustc_middle::ty::GenericArg;
use rustc_middle::ty::{self, adjustment::PointerCoercion, Ty, TyCtxt};
use rustc_span::def_id::DefId;
use rustc_span::source_map::Spanned;
use rustc_span::symbol::{sym, Symbol};
use rustc_span::Span;
use rustc_span::{Span, DUMMY_SP};
use rustc_target::abi::VariantIdx;
use std::cmp::Ordering;
@ -271,7 +272,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
user_ty: None,
const_: method,
})),
args: vec![Operand::Move(ref_string)],
args: vec![Spanned { node: Operand::Move(ref_string), span: DUMMY_SP }],
destination: ref_str,
target: Some(eq_block),
unwind: UnwindAction::Continue,
@ -526,7 +527,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
const_: method,
})),
args: vec![Operand::Copy(val), expect],
args: vec![
Spanned { node: Operand::Copy(val), span: DUMMY_SP },
Spanned { node: expect, span: DUMMY_SP },
],
destination: eq_result,
target: Some(eq_block),
unwind: UnwindAction::Continue,

View File

@ -91,6 +91,7 @@ use rustc_middle::middle::region;
use rustc_middle::mir::*;
use rustc_middle::thir::{ExprId, LintLevel};
use rustc_session::lint::Level;
use rustc_span::source_map::Spanned;
use rustc_span::{Span, DUMMY_SP};
#[derive(Debug)]
@ -1020,14 +1021,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// spurious borrow-check errors -- the problem, ironically, is
/// not the `DROP(_X)` itself, but the (spurious) unwind pathways
/// that it creates. See #64391 for an example.
pub(crate) fn record_operands_moved(&mut self, operands: &[Operand<'tcx>]) {
pub(crate) fn record_operands_moved(&mut self, operands: &[Spanned<Operand<'tcx>>]) {
let local_scope = self.local_scope();
let scope = self.scopes.scopes.last_mut().unwrap();
assert_eq!(scope.region_scope, local_scope, "local scope is not the topmost scope!",);
// look for moves of a local variable, like `MOVE(_X)`
let locals_moved = operands.iter().flat_map(|operand| match operand {
let locals_moved = operands.iter().flat_map(|operand| match operand.node {
Operand::Copy(_) | Operand::Constant(_) => None,
Operand::Move(place) => place.as_local(),
});

View File

@ -7,6 +7,8 @@ use rustc_middle::traits::Reveal;
use rustc_middle::ty::util::IntTypeExt;
use rustc_middle::ty::GenericArgsRef;
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_span::source_map::Spanned;
use rustc_span::DUMMY_SP;
use rustc_target::abi::{FieldIdx, VariantIdx, FIRST_VARIANT};
use std::{fmt, iter};
@ -652,7 +654,10 @@ where
[ty.into()],
self.source_info.span,
),
args: vec![Operand::Move(Place::from(ref_place))],
args: vec![Spanned {
node: Operand::Move(Place::from(ref_place)),
span: DUMMY_SP,
}],
destination: unit_temp,
target: Some(succ),
unwind: unwind.into_action(),

View File

@ -469,7 +469,7 @@ impl<'b, 'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> Gatherer<'b, 'a, 'tcx, F> {
} => {
self.gather_operand(func);
for arg in args {
self.gather_operand(arg);
self.gather_operand(&arg.node);
}
if let Some(_bb) = target {
self.create_move_path(destination);

View File

@ -209,7 +209,7 @@ impl PeekCall {
assert_eq!(fn_args.len(), 1);
let kind = PeekCallKind::from_arg_ty(fn_args.type_at(0));
let arg = match &args[0] {
let arg = match &args[0].node {
Operand::Copy(place) | Operand::Move(place) => {
if let Some(local) = place.as_local() {
local

View File

@ -675,9 +675,9 @@ fn eliminate_get_context_call<'tcx>(bb_data: &mut BasicBlockData<'tcx>) -> Local
let terminator = bb_data.terminator.take().unwrap();
if let TerminatorKind::Call { mut args, destination, target, .. } = terminator.kind {
let arg = args.pop().unwrap();
let local = arg.place().unwrap().local;
let local = arg.node.place().unwrap().local;
let arg = Rvalue::Use(arg);
let arg = Rvalue::Use(arg.node);
let assign = Statement {
source_info: terminator.source_info,
kind: StatementKind::Assign(Box::new((destination, arg))),
@ -1865,7 +1865,7 @@ impl<'tcx> Visitor<'tcx> for EnsureCoroutineFieldAssignmentsNeverAlias<'_> {
self.check_assigned_place(*destination, |this| {
this.visit_operand(func, location);
for arg in args {
this.visit_operand(arg, location);
this.visit_operand(&arg.node, location);
}
});
}

View File

@ -52,7 +52,7 @@ pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
live.seek_to_block_end(bb);
let mut state = live.get().clone();
for (index, arg) in args.iter().enumerate().rev() {
for (index, arg) in args.iter().map(|a| &a.node).enumerate().rev() {
if let Operand::Copy(place) = *arg
&& !place.is_indirect()
// Do not skip the transformation if the local is in debuginfo, as we do
@ -119,7 +119,7 @@ pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
let TerminatorKind::Call { ref mut args, .. } = bbs[block].terminator_mut().kind else {
bug!()
};
let arg = &mut args[argument_index];
let arg = &mut args[argument_index].node;
let Operand::Copy(place) = *arg else { bug!() };
*arg = Operand::Move(place);
}

View File

@ -111,7 +111,7 @@ impl<'tcx> Visitor<'tcx> for DeduceReadOnly {
if let TerminatorKind::Call { ref args, .. } = terminator.kind {
for arg in args {
if let Operand::Move(place) = *arg {
if let Operand::Move(place) = arg.node {
let local = place.local;
if place.is_indirect()
|| local == RETURN_PLACE

View File

@ -609,7 +609,7 @@ impl WriteInfo {
self.add_place(*destination);
self.add_operand(func);
for arg in args {
self.add_operand(arg);
self.add_operand(&arg.node);
}
}
TerminatorKind::InlineAsm { operands, .. } => {

View File

@ -4,6 +4,7 @@ use rustc_middle::mir::visit::Visitor;
use rustc_middle::mir::*;
use rustc_middle::ty::{self, EarlyBinder, GenericArgsRef, Ty, TyCtxt};
use rustc_session::lint::builtin::FUNCTION_ITEM_REFERENCES;
use rustc_span::source_map::Spanned;
use rustc_span::{symbol::sym, Span};
use rustc_target::spec::abi::Abi;
@ -43,7 +44,7 @@ impl<'tcx> Visitor<'tcx> for FunctionItemRefChecker<'_, 'tcx> {
if let ty::FnDef(def_id, args_ref) = *func_ty.kind() {
// Handle calls to `transmute`
if self.tcx.is_diagnostic_item(sym::transmute, def_id) {
let arg_ty = args[0].ty(self.body, self.tcx);
let arg_ty = args[0].node.ty(self.body, self.tcx);
for inner_ty in arg_ty.walk().filter_map(|arg| arg.as_type()) {
if let Some((fn_id, fn_args)) = FunctionItemRefChecker::is_fn_ref(inner_ty)
{
@ -67,7 +68,7 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> {
&self,
def_id: DefId,
args_ref: GenericArgsRef<'tcx>,
args: &[Operand<'tcx>],
args: &[Spanned<Operand<'tcx>>],
source_info: SourceInfo,
) {
let param_env = self.tcx.param_env(def_id);
@ -134,8 +135,8 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> {
.unwrap_or(None)
}
fn nth_arg_span(&self, args: &[Operand<'tcx>], n: usize) -> Span {
match &args[n] {
fn nth_arg_span(&self, args: &[Spanned<Operand<'tcx>>], n: usize) -> Span {
match &args[n].node {
Operand::Copy(place) | Operand::Move(place) => {
self.body.local_decls[place.local].source_info.span
}

View File

@ -11,6 +11,7 @@ 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::source_map::Spanned;
use rustc_target::abi::FieldIdx;
use rustc_target::spec::abi::Abi;
@ -172,7 +173,7 @@ impl<'tcx> Inliner<'tcx> {
let TerminatorKind::Call { args, destination, .. } = &terminator.kind else { bug!() };
let destination_ty = destination.ty(&caller_body.local_decls, self.tcx).ty;
for arg in args {
if !arg.ty(&caller_body.local_decls, self.tcx).is_sized(self.tcx, self.param_env) {
if !arg.node.ty(&caller_body.local_decls, self.tcx).is_sized(self.tcx, self.param_env) {
// We do not allow inlining functions with unsized params. Inlining these functions
// could create unsized locals, which are unsound and being phased out.
return Err("Call has unsized argument");
@ -238,9 +239,9 @@ impl<'tcx> Inliner<'tcx> {
};
let self_arg_ty =
self_arg.map(|self_arg| self_arg.ty(&caller_body.local_decls, self.tcx));
self_arg.map(|self_arg| self_arg.node.ty(&caller_body.local_decls, self.tcx));
let arg_tuple_ty = arg_tuple.ty(&caller_body.local_decls, self.tcx);
let arg_tuple_ty = arg_tuple.node.ty(&caller_body.local_decls, self.tcx);
let ty::Tuple(arg_tuple_tys) = *arg_tuple_ty.kind() else {
bug!("Closure arguments are not passed as a tuple");
};
@ -263,7 +264,7 @@ impl<'tcx> Inliner<'tcx> {
} else {
for (arg, input) in args.iter().zip(callee_body.args_iter()) {
let input_type = callee_body.local_decls[input].ty;
let arg_ty = arg.ty(&caller_body.local_decls, self.tcx);
let arg_ty = arg.node.ty(&caller_body.local_decls, self.tcx);
if !util::relate_types(
self.tcx,
self.param_env,
@ -694,7 +695,7 @@ impl<'tcx> Inliner<'tcx> {
fn make_call_args(
&self,
args: Vec<Operand<'tcx>>,
args: Vec<Spanned<Operand<'tcx>>>,
callsite: &CallSite<'tcx>,
caller_body: &mut Body<'tcx>,
callee_body: &Body<'tcx>,
@ -728,13 +729,13 @@ impl<'tcx> Inliner<'tcx> {
if callsite.fn_sig.abi() == Abi::RustCall && callee_body.spread_arg.is_none() {
let mut args = args.into_iter();
let self_ = self.create_temp_if_necessary(
args.next().unwrap(),
args.next().unwrap().node,
callsite,
caller_body,
return_block,
);
let tuple = self.create_temp_if_necessary(
args.next().unwrap(),
args.next().unwrap().node,
callsite,
caller_body,
return_block,
@ -761,7 +762,7 @@ impl<'tcx> Inliner<'tcx> {
closure_ref_arg.chain(tuple_tmp_args).collect()
} else {
args.into_iter()
.map(|a| self.create_temp_if_necessary(a, callsite, caller_body, return_block))
.map(|a| self.create_temp_if_necessary(a.node, callsite, caller_body, return_block))
.collect()
}
}

View File

@ -215,7 +215,7 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
// These types are easily available from locals, so check that before
// doing DefId lookups to figure out what we're actually calling.
let arg_ty = args[0].ty(self.local_decls, self.tcx);
let arg_ty = args[0].node.ty(self.local_decls, self.tcx);
let ty::Ref(_region, inner_ty, Mutability::Not) = *arg_ty.kind() else { return };
@ -238,7 +238,7 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
return;
}
let Some(arg_place) = args.pop().unwrap().place() else { return };
let Some(arg_place) = args.pop().unwrap().node.place() else { return };
statements.push(Statement {
source_info: terminator.source_info,

View File

@ -41,7 +41,7 @@ use rustc_middle::mir::{
};
use rustc_middle::query::Providers;
use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt};
use rustc_span::sym;
use rustc_span::{source_map::Spanned, sym, DUMMY_SP};
use rustc_trait_selection::traits;
#[macro_use]
@ -170,13 +170,13 @@ fn remap_mir_for_const_eval_select<'tcx>(
{
let [tupled_args, called_in_const, called_at_rt]: [_; 3] =
std::mem::take(args).try_into().unwrap();
let ty = tupled_args.ty(&body.local_decls, tcx);
let ty = tupled_args.node.ty(&body.local_decls, tcx);
let fields = ty.tuple_fields();
let num_args = fields.len();
let func =
if context == hir::Constness::Const { called_in_const } else { called_at_rt };
let (method, place): (fn(Place<'tcx>) -> Operand<'tcx>, Place<'tcx>) =
match tupled_args {
match tupled_args.node {
Operand::Constant(_) => {
// there is no good way of extracting a tuple arg from a constant (const generic stuff)
// so we just create a temporary and deconstruct that.
@ -185,7 +185,7 @@ fn remap_mir_for_const_eval_select<'tcx>(
source_info: SourceInfo::outermost(fn_span),
kind: StatementKind::Assign(Box::new((
local.into(),
Rvalue::Use(tupled_args.clone()),
Rvalue::Use(tupled_args.node.clone()),
))),
});
(Operand::Move, local.into())
@ -200,11 +200,11 @@ fn remap_mir_for_const_eval_select<'tcx>(
place_elems.push(ProjectionElem::Field(x.into(), fields[x]));
let projection = tcx.mk_place_elems(&place_elems);
let place = Place { local: place.local, projection };
method(place)
Spanned { node: method(place), span: DUMMY_SP }
})
.collect();
terminator.kind = TerminatorKind::Call {
func,
func: func.node,
args: arguments,
destination,
target,

View File

@ -131,7 +131,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Lint<'a, 'tcx> {
self.places.insert(destination.as_ref());
let mut has_duplicates = false;
for arg in args {
if let Operand::Move(place) = arg {
if let Operand::Move(place) = &arg.node {
has_duplicates |= !self.places.insert(place.as_ref());
}
}

View File

@ -45,9 +45,9 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics {
kind: StatementKind::Intrinsic(Box::new(
NonDivergingIntrinsic::CopyNonOverlapping(
rustc_middle::mir::CopyNonOverlapping {
src: args.next().unwrap(),
dst: args.next().unwrap(),
count: args.next().unwrap(),
src: args.next().unwrap().node,
dst: args.next().unwrap().node,
count: args.next().unwrap().node,
},
),
)),
@ -66,7 +66,7 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics {
block.statements.push(Statement {
source_info: terminator.source_info,
kind: StatementKind::Intrinsic(Box::new(
NonDivergingIntrinsic::Assume(args.next().unwrap()),
NonDivergingIntrinsic::Assume(args.next().unwrap().node),
)),
});
assert_eq!(
@ -112,7 +112,7 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics {
source_info: terminator.source_info,
kind: StatementKind::Assign(Box::new((
*destination,
Rvalue::BinaryOp(bin_op, Box::new((lhs, rhs))),
Rvalue::BinaryOp(bin_op, Box::new((lhs.node, rhs.node))),
))),
});
terminator.kind = TerminatorKind::Goto { target };
@ -136,7 +136,7 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics {
source_info: terminator.source_info,
kind: StatementKind::Assign(Box::new((
*destination,
Rvalue::CheckedBinaryOp(bin_op, Box::new((lhs, rhs))),
Rvalue::CheckedBinaryOp(bin_op, Box::new((lhs.node, rhs.node))),
))),
});
terminator.kind = TerminatorKind::Goto { target };
@ -164,7 +164,7 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics {
let [arg] = args.as_slice() else {
span_bug!(terminator.source_info.span, "Wrong number of arguments");
};
let derefed_place = if let Some(place) = arg.place()
let derefed_place = if let Some(place) = arg.node.place()
&& let Some(local) = place.as_local()
{
tcx.mk_place_deref(local.into())
@ -200,7 +200,7 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics {
"Wrong number of arguments for write_via_move intrinsic",
);
};
let derefed_place = if let Some(place) = ptr.place()
let derefed_place = if let Some(place) = ptr.node.place()
&& let Some(local) = place.as_local()
{
tcx.mk_place_deref(local.into())
@ -214,13 +214,13 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics {
source_info: terminator.source_info,
kind: StatementKind::Assign(Box::new((
derefed_place,
Rvalue::Use(val),
Rvalue::Use(val.node),
))),
});
terminator.kind = TerminatorKind::Goto { target };
}
sym::discriminant_value => {
if let (Some(target), Some(arg)) = (*target, args[0].place()) {
if let (Some(target), Some(arg)) = (*target, args[0].node.place()) {
let arg = tcx.mk_place_deref(arg);
block.statements.push(Statement {
source_info: terminator.source_info,
@ -244,7 +244,7 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics {
source_info: terminator.source_info,
kind: StatementKind::Assign(Box::new((
*destination,
Rvalue::BinaryOp(BinOp::Offset, Box::new((ptr, delta))),
Rvalue::BinaryOp(BinOp::Offset, Box::new((ptr.node, delta.node))),
))),
});
terminator.kind = TerminatorKind::Goto { target };
@ -265,7 +265,7 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics {
source_info: terminator.source_info,
kind: StatementKind::Assign(Box::new((
*destination,
Rvalue::Cast(CastKind::Transmute, arg, dst_ty),
Rvalue::Cast(CastKind::Transmute, arg.node, dst_ty),
))),
});

View File

@ -50,7 +50,7 @@ fn lower_slice_len_call<'tcx>(
} = &terminator.kind
// some heuristics for fast rejection
&& let [arg] = &args[..]
&& let Some(arg) = arg.place()
&& let Some(arg) = arg.node.place()
&& let ty::FnDef(fn_def_id, _) = func.ty(local_decls, tcx).kind()
&& *fn_def_id == slice_len_fn_item_def_id
{

View File

@ -22,6 +22,7 @@ use rustc_middle::ty::{self, List, Ty, TyCtxt, TypeVisitableExt};
use rustc_span::Span;
use rustc_index::{Idx, IndexSlice, IndexVec};
use rustc_span::source_map::Spanned;
use std::assert_matches::assert_matches;
use std::cell::Cell;
@ -565,7 +566,7 @@ impl<'tcx> Validator<'_, 'tcx> {
fn validate_call(
&mut self,
callee: &Operand<'tcx>,
args: &[Operand<'tcx>],
args: &[Spanned<Operand<'tcx>>],
) -> Result<(), Unpromotable> {
let fn_ty = callee.ty(self.body, self.tcx);
@ -595,7 +596,7 @@ impl<'tcx> Validator<'_, 'tcx> {
self.validate_operand(callee)?;
for arg in args {
self.validate_operand(arg)?;
self.validate_operand(&arg.node)?;
}
Ok(())
@ -731,7 +732,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
} => {
self.visit_operand(&mut func, loc);
for arg in &mut args {
self.visit_operand(arg, loc);
self.visit_operand(&mut arg.node, loc);
}
let last = self.promoted.basic_blocks.last_index().unwrap();

View File

@ -9,7 +9,7 @@ use rustc_target::abi::{FieldIdx, VariantIdx, FIRST_VARIANT};
use rustc_index::{Idx, IndexVec};
use rustc_span::Span;
use rustc_span::{source_map::Spanned, Span, DUMMY_SP};
use rustc_target::spec::abi::Abi;
use std::fmt;
@ -526,7 +526,7 @@ impl<'tcx> CloneShimBuilder<'tcx> {
vec![statement],
TerminatorKind::Call {
func,
args: vec![Operand::Move(ref_loc)],
args: vec![Spanned { node: Operand::Move(ref_loc), span: DUMMY_SP }],
destination: dest,
target: Some(next),
unwind: UnwindAction::Cleanup(cleanup),
@ -811,6 +811,7 @@ fn build_call_shim<'tcx>(
};
// BB #0
let args = args.into_iter().map(|a| Spanned { node: a, span: DUMMY_SP }).collect::<Vec<_>>();
block(
&mut blocks,
statements,

View File

@ -668,7 +668,7 @@ impl<'a, 'tcx> MirUsedCollector<'a, 'tcx> {
fn check_fn_args_move_size(
&mut self,
callee_ty: Ty<'tcx>,
args: &[mir::Operand<'tcx>],
args: &[Spanned<mir::Operand<'tcx>>],
location: Location,
) {
let limit = self.tcx.move_size_limit();
@ -693,7 +693,7 @@ impl<'a, 'tcx> MirUsedCollector<'a, 'tcx> {
}
for arg in args {
self.check_operand_move_size(arg, location);
self.check_operand_move_size(&arg.node, location);
}
}
}

View File

@ -609,7 +609,7 @@ impl<'tcx> Stable<'tcx> for mir::TerminatorKind<'tcx> {
fn_span: _,
} => TerminatorKind::Call {
func: func.stable(tables),
args: args.iter().map(|arg| arg.stable(tables)).collect(),
args: args.iter().map(|arg| arg.node.stable(tables)).collect(),
destination: destination.stable(tables),
target: target.map(|t| t.as_usize()),
unwind: unwind.stable(tables),

View File

@ -70,7 +70,7 @@ mod monotonic {
impl<T> !DerefMut for MonotonicVec<T> {}
}
#[derive(Clone, Encodable, Decodable, Debug, Copy, HashStable_Generic)]
#[derive(Clone, Encodable, Decodable, Debug, Copy, PartialEq, Hash, HashStable_Generic)]
pub struct Spanned<T> {
pub node: T,
pub span: Span,

View File

@ -257,9 +257,9 @@ fn is_call_with_ref_arg<'tcx>(
..
} = kind
&& args.len() == 1
&& let mir::Operand::Move(mir::Place { local, .. }) = &args[0]
&& let mir::Operand::Move(mir::Place { local, .. }) = &args[0].node
&& let ty::FnDef(def_id, _) = *func.ty(mir, cx.tcx).kind()
&& let (inner_ty, 1) = walk_ptrs_ty_depth(args[0].ty(mir, cx.tcx))
&& let (inner_ty, 1) = walk_ptrs_ty_depth(args[0].node.ty(mir, cx.tcx))
&& !is_copy(cx, inner_ty)
{
Some((def_id, *local, inner_ty, destination.as_local()?))

View File

@ -104,7 +104,7 @@ impl<'a, 'b, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'b,
let mut mutable_borrowers = vec![];
for op in args {
match op {
match &op.node {
mir::Operand::Copy(p) | mir::Operand::Move(p) => {
if let ty::Ref(_, _, Mutability::Mut) = self.body.local_decls[p.local].ty.kind() {
mutable_borrowers.push(p.local);

View File

@ -345,7 +345,7 @@ fn check_terminator<'tcx>(
check_operand(tcx, func, span, body)?;
for arg in args {
check_operand(tcx, arg, span, body)?;
check_operand(tcx, &arg.node, span, body)?;
}
Ok(())
} else {