Skip to content

Commit 3e7d027

Browse files
committed
Auto merge of #128761 - matthiaskrgr:rollup-5p1mlqq, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #124944 (On trait bound mismatch, detect multiple crate versions in dep tree) - #125048 (PinCoerceUnsized trait into core) - #128406 (implement BufReader::peek) - #128539 (Forbid unused unsafe in vxworks-specific std modules) - #128687 (interpret: refactor function call handling to be better-abstracted) - #128692 (Add a triagebot mention for `library/Cargo.lock`) - #128710 (Don't ICE when getting an input file name's stem fails) - #128718 (Consider `cfg_attr` checked by `CheckAttrVisitor`) - #128751 (std::thread: set_name implementation proposal for vxWorks.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c4352e9 + 28fe48d commit 3e7d027

15 files changed

+85
-100
lines changed

Diff for: src/concurrency/thread.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ pub struct Thread<'tcx> {
256256
/// which then forwards it to 'Resume'. However this argument is implicit in MIR,
257257
/// so we have to store it out-of-band. When there are multiple active unwinds,
258258
/// the innermost one is always caught first, so we can store them as a stack.
259-
pub(crate) panic_payloads: Vec<Scalar>,
259+
pub(crate) panic_payloads: Vec<ImmTy<'tcx>>,
260260

261261
/// Last OS error location in memory. It is a 32-bit integer.
262262
pub(crate) last_error: Option<MPlaceTy<'tcx>>,
@@ -377,10 +377,6 @@ impl VisitProvenance for Frame<'_, Provenance, FrameExtra<'_>> {
377377
return_place,
378378
locals,
379379
extra,
380-
body: _,
381-
instance: _,
382-
return_to_block: _,
383-
loc: _,
384380
// There are some private fields we cannot access; they contain no tags.
385381
..
386382
} = self;
@@ -952,7 +948,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
952948
this.call_function(
953949
instance,
954950
start_abi,
955-
&[*func_arg],
951+
&[func_arg],
956952
Some(&ret_place),
957953
StackPopCleanup::Root { cleanup: true },
958954
)?;

Diff for: src/eval.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ pub fn create_ecx<'tcx>(
307307
// First argument is constructed later, because it's skipped if the entry function uses #[start].
308308

309309
// Second argument (argc): length of `config.args`.
310-
let argc = Scalar::from_target_usize(u64::try_from(config.args.len()).unwrap(), &ecx);
310+
let argc =
311+
ImmTy::from_int(i64::try_from(config.args.len()).unwrap(), ecx.machine.layouts.isize);
311312
// Third argument (`argv`): created from `config.args`.
312313
let argv = {
313314
// Put each argument in memory, collect pointers.
@@ -334,21 +335,19 @@ pub fn create_ecx<'tcx>(
334335
ecx.write_immediate(arg, &place)?;
335336
}
336337
ecx.mark_immutable(&argvs_place);
337-
// A pointer to that place is the 3rd argument for main.
338-
let argv = argvs_place.to_ref(&ecx);
339338
// Store `argc` and `argv` for macOS `_NSGetArg{c,v}`.
340339
{
341340
let argc_place =
342341
ecx.allocate(ecx.machine.layouts.isize, MiriMemoryKind::Machine.into())?;
343-
ecx.write_scalar(argc, &argc_place)?;
342+
ecx.write_immediate(*argc, &argc_place)?;
344343
ecx.mark_immutable(&argc_place);
345344
ecx.machine.argc = Some(argc_place.ptr());
346345

347346
let argv_place = ecx.allocate(
348347
ecx.layout_of(Ty::new_imm_ptr(tcx, tcx.types.unit))?,
349348
MiriMemoryKind::Machine.into(),
350349
)?;
351-
ecx.write_immediate(argv, &argv_place)?;
350+
ecx.write_pointer(argvs_place.ptr(), &argv_place)?;
352351
ecx.mark_immutable(&argv_place);
353352
ecx.machine.argv = Some(argv_place.ptr());
354353
}
@@ -369,7 +368,7 @@ pub fn create_ecx<'tcx>(
369368
}
370369
ecx.mark_immutable(&cmd_place);
371370
}
372-
argv
371+
ecx.mplace_to_ref(&argvs_place)?
373372
};
374373

375374
// Return place (in static memory so that it does not count as leak).
@@ -405,10 +404,14 @@ pub fn create_ecx<'tcx>(
405404
start_instance,
406405
Abi::Rust,
407406
&[
408-
Scalar::from_pointer(main_ptr, &ecx).into(),
409-
argc.into(),
407+
ImmTy::from_scalar(
408+
Scalar::from_pointer(main_ptr, &ecx),
409+
// FIXME use a proper fn ptr type
410+
ecx.machine.layouts.const_raw_ptr,
411+
),
412+
argc,
410413
argv,
411-
Scalar::from_u8(sigpipe).into(),
414+
ImmTy::from_uint(sigpipe, ecx.machine.layouts.u8),
412415
],
413416
Some(&ret_place),
414417
StackPopCleanup::Root { cleanup: true },
@@ -418,7 +421,7 @@ pub fn create_ecx<'tcx>(
418421
ecx.call_function(
419422
entry_instance,
420423
Abi::Rust,
421-
&[argc.into(), argv],
424+
&[argc, argv],
422425
Some(&ret_place),
423426
StackPopCleanup::Root { cleanup: true },
424427
)?;

Diff for: src/helpers.rs

+28-37
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ use rustc_apfloat::Float;
1212
use rustc_hir::{
1313
def::{DefKind, Namespace},
1414
def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE},
15+
Safety,
1516
};
1617
use rustc_index::IndexVec;
1718
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
1819
use rustc_middle::middle::dependency_format::Linkage;
1920
use rustc_middle::middle::exported_symbols::ExportedSymbol;
2021
use rustc_middle::mir;
21-
use rustc_middle::ty::layout::MaybeResult;
22+
use rustc_middle::ty::layout::{FnAbiOf, MaybeResult};
2223
use rustc_middle::ty::{
2324
self,
2425
layout::{LayoutOf, TyAndLayout},
@@ -492,48 +493,38 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
492493
&mut self,
493494
f: ty::Instance<'tcx>,
494495
caller_abi: Abi,
495-
args: &[Immediate<Provenance>],
496+
args: &[ImmTy<'tcx>],
496497
dest: Option<&MPlaceTy<'tcx>>,
497498
stack_pop: StackPopCleanup,
498499
) -> InterpResult<'tcx> {
499500
let this = self.eval_context_mut();
500-
let param_env = ty::ParamEnv::reveal_all(); // in Miri this is always the param_env we use... and this.param_env is private.
501-
let callee_abi = f.ty(*this.tcx, param_env).fn_sig(*this.tcx).abi();
502-
if callee_abi != caller_abi {
503-
throw_ub_format!(
504-
"calling a function with ABI {} using caller ABI {}",
505-
callee_abi.name(),
506-
caller_abi.name()
507-
)
508-
}
509501

510-
// Push frame.
502+
// Get MIR.
511503
let mir = this.load_mir(f.def, None)?;
512504
let dest = match dest {
513505
Some(dest) => dest.clone(),
514506
None => MPlaceTy::fake_alloc_zst(this.layout_of(mir.return_ty())?),
515507
};
516-
this.push_stack_frame(f, mir, &dest, stack_pop)?;
517-
518-
// Initialize arguments.
519-
let mut callee_args = this.frame().body.args_iter();
520-
for arg in args {
521-
let local = callee_args
522-
.next()
523-
.ok_or_else(|| err_ub_format!("callee has fewer arguments than expected"))?;
524-
// Make the local live, and insert the initial value.
525-
this.storage_live(local)?;
526-
let callee_arg = this.local_to_place(local)?;
527-
this.write_immediate(*arg, &callee_arg)?;
528-
}
529-
if callee_args.next().is_some() {
530-
throw_ub_format!("callee has more arguments than expected");
531-
}
532-
533-
// Initialize remaining locals.
534-
this.storage_live_for_always_live_locals()?;
535508

536-
Ok(())
509+
// Construct a function pointer type representing the caller perspective.
510+
let sig = this.tcx.mk_fn_sig(
511+
args.iter().map(|a| a.layout.ty),
512+
dest.layout.ty,
513+
/*c_variadic*/ false,
514+
Safety::Safe,
515+
caller_abi,
516+
);
517+
let caller_fn_abi = this.fn_abi_of_fn_ptr(ty::Binder::dummy(sig), ty::List::empty())?;
518+
519+
this.init_stack_frame(
520+
f,
521+
mir,
522+
caller_fn_abi,
523+
&args.iter().map(|a| FnArg::Copy(a.clone().into())).collect::<Vec<_>>(),
524+
/*with_caller_location*/ false,
525+
&dest,
526+
stack_pop,
527+
)
537528
}
538529

539530
/// Visits the memory covered by `place`, sensitive to freezing: the 2nd parameter
@@ -1114,12 +1105,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
11141105
// Make an attempt to get at the instance of the function this is inlined from.
11151106
let instance: Option<_> = try {
11161107
let scope = frame.current_source_info()?.scope;
1117-
let inlined_parent = frame.body.source_scopes[scope].inlined_parent_scope?;
1118-
let source = &frame.body.source_scopes[inlined_parent];
1108+
let inlined_parent = frame.body().source_scopes[scope].inlined_parent_scope?;
1109+
let source = &frame.body().source_scopes[inlined_parent];
11191110
source.inlined.expect("inlined_parent_scope points to scope without inline info").0
11201111
};
11211112
// Fall back to the instance of the function itself.
1122-
let instance = instance.unwrap_or(frame.instance);
1113+
let instance = instance.unwrap_or(frame.instance());
11231114
// Now check the crate it is in. We could try to be clever here and e.g. check if this is
11241115
// the same crate as `start_fn`, but that would not work for running std tests in Miri, so
11251116
// we'd need some more hacks anyway. So we just check the name of the crate. If someone
@@ -1359,9 +1350,9 @@ impl<'tcx> MiriMachine<'tcx> {
13591350

13601351
/// This is the source of truth for the `is_user_relevant` flag in our `FrameExtra`.
13611352
pub fn is_user_relevant(&self, frame: &Frame<'tcx, Provenance>) -> bool {
1362-
let def_id = frame.instance.def_id();
1353+
let def_id = frame.instance().def_id();
13631354
(def_id.is_local() || self.local_crates.contains(&def_id.krate))
1364-
&& !frame.instance.def.requires_caller_location(self.tcx)
1355+
&& !frame.instance().def.requires_caller_location(self.tcx)
13651356
}
13661357
}
13671358

Diff for: src/machine.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
13521352
) -> InterpResult<'tcx, Frame<'tcx, Provenance, FrameExtra<'tcx>>> {
13531353
// Start recording our event before doing anything else
13541354
let timing = if let Some(profiler) = ecx.machine.profiler.as_ref() {
1355-
let fn_name = frame.instance.to_string();
1355+
let fn_name = frame.instance().to_string();
13561356
let entry = ecx.machine.string_cache.entry(fn_name.clone());
13571357
let name = entry.or_insert_with(|| profiler.alloc_string(&*fn_name));
13581358

@@ -1443,7 +1443,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
14431443
// tracing-tree can autoamtically annotate scope changes, but it gets very confused by our
14441444
// concurrency and what it prints is just plain wrong. So we print our own information
14451445
// instead. (Cc https://github.com/rust-lang/miri/issues/2266)
1446-
info!("Leaving {}", ecx.frame().instance);
1446+
info!("Leaving {}", ecx.frame().instance());
14471447
Ok(())
14481448
}
14491449

@@ -1473,7 +1473,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
14731473
// Needs to be done after dropping frame to show up on the right nesting level.
14741474
// (Cc https://github.com/rust-lang/miri/issues/2266)
14751475
if !ecx.active_thread_stack().is_empty() {
1476-
info!("Continuing in {}", ecx.frame().instance);
1476+
info!("Continuing in {}", ecx.frame().instance());
14771477
}
14781478
res
14791479
}
@@ -1486,7 +1486,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
14861486
let Some(Provenance::Concrete { alloc_id, .. }) = mplace.ptr().provenance else {
14871487
panic!("after_local_allocated should only be called on fresh allocations");
14881488
};
1489-
let local_decl = &ecx.frame().body.local_decls[local];
1489+
let local_decl = &ecx.frame().body().local_decls[local];
14901490
let span = local_decl.source_info.span;
14911491
ecx.machine.allocation_spans.borrow_mut().insert(alloc_id, (span, None));
14921492
Ok(())

Diff for: src/shims/backtrace.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
4646
let mut data = Vec::new();
4747
for frame in this.active_thread_stack().iter().rev() {
4848
// Match behavior of debuginfo (`FunctionCx::adjusted_span_and_dbg_scope`).
49-
let span = hygiene::walk_chain_collapsed(frame.current_span(), frame.body.span);
50-
data.push((frame.instance, span.lo()));
49+
let span = hygiene::walk_chain_collapsed(frame.current_span(), frame.body().span);
50+
data.push((frame.instance(), span.lo()));
5151
}
5252

5353
let ptrs: Vec<_> = data

Diff for: src/shims/panic.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub struct CatchUnwindData<'tcx> {
2525
/// The `catch_fn` callback to call in case of a panic.
2626
catch_fn: Pointer,
2727
/// The `data` argument for that callback.
28-
data: Scalar,
28+
data: ImmTy<'tcx>,
2929
/// The return place from the original call to `try`.
3030
dest: MPlaceTy<'tcx>,
3131
/// The return block from the original call to `try`.
@@ -48,9 +48,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
4848
fn handle_miri_start_unwind(&mut self, payload: &OpTy<'tcx>) -> InterpResult<'tcx> {
4949
let this = self.eval_context_mut();
5050

51-
trace!("miri_start_unwind: {:?}", this.frame().instance);
51+
trace!("miri_start_unwind: {:?}", this.frame().instance());
5252

53-
let payload = this.read_scalar(payload)?;
53+
let payload = this.read_immediate(payload)?;
5454
let thread = this.active_thread_mut();
5555
thread.panic_payloads.push(payload);
5656

@@ -80,7 +80,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
8080
// Get all the arguments.
8181
let [try_fn, data, catch_fn] = check_arg_count(args)?;
8282
let try_fn = this.read_pointer(try_fn)?;
83-
let data = this.read_scalar(data)?;
83+
let data = this.read_immediate(data)?;
8484
let catch_fn = this.read_pointer(catch_fn)?;
8585

8686
// Now we make a function call, and pass `data` as first and only argument.
@@ -89,7 +89,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
8989
this.call_function(
9090
f_instance,
9191
Abi::Rust,
92-
&[data.into()],
92+
&[data.clone()],
9393
None,
9494
// Directly return to caller.
9595
StackPopCleanup::Goto { ret, unwind: mir::UnwindAction::Continue },
@@ -124,7 +124,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
124124
// and we are unwinding, so we should catch that.
125125
trace!(
126126
"unwinding: found catch_panic frame during unwinding: {:?}",
127-
this.frame().instance
127+
this.frame().instance()
128128
);
129129

130130
// We set the return value of `try` to 1, since there was a panic.
@@ -140,7 +140,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
140140
this.call_function(
141141
f_instance,
142142
Abi::Rust,
143-
&[catch_unwind.data.into(), payload.into()],
143+
&[catch_unwind.data, payload],
144144
None,
145145
// Directly return to caller of `try`.
146146
StackPopCleanup::Goto {
@@ -169,7 +169,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
169169
this.call_function(
170170
panic,
171171
Abi::Rust,
172-
&[msg.to_ref(this)],
172+
&[this.mplace_to_ref(&msg)?],
173173
None,
174174
StackPopCleanup::Goto { ret: None, unwind },
175175
)
@@ -188,7 +188,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
188188
this.call_function(
189189
panic,
190190
Abi::Rust,
191-
&[msg.to_ref(this)],
191+
&[this.mplace_to_ref(&msg)?],
192192
None,
193193
StackPopCleanup::Goto { ret: None, unwind: mir::UnwindAction::Unreachable },
194194
)
@@ -207,17 +207,17 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
207207
// Forward to `panic_bounds_check` lang item.
208208

209209
// First arg: index.
210-
let index = this.read_scalar(&this.eval_operand(index, None)?)?;
210+
let index = this.read_immediate(&this.eval_operand(index, None)?)?;
211211
// Second arg: len.
212-
let len = this.read_scalar(&this.eval_operand(len, None)?)?;
212+
let len = this.read_immediate(&this.eval_operand(len, None)?)?;
213213

214214
// Call the lang item.
215215
let panic_bounds_check = this.tcx.lang_items().panic_bounds_check_fn().unwrap();
216216
let panic_bounds_check = ty::Instance::mono(this.tcx.tcx, panic_bounds_check);
217217
this.call_function(
218218
panic_bounds_check,
219219
Abi::Rust,
220-
&[index.into(), len.into()],
220+
&[index, len],
221221
None,
222222
StackPopCleanup::Goto { ret: None, unwind },
223223
)?;
@@ -226,9 +226,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
226226
// Forward to `panic_misaligned_pointer_dereference` lang item.
227227

228228
// First arg: required.
229-
let required = this.read_scalar(&this.eval_operand(required, None)?)?;
229+
let required = this.read_immediate(&this.eval_operand(required, None)?)?;
230230
// Second arg: found.
231-
let found = this.read_scalar(&this.eval_operand(found, None)?)?;
231+
let found = this.read_immediate(&this.eval_operand(found, None)?)?;
232232

233233
// Call the lang item.
234234
let panic_misaligned_pointer_dereference =
@@ -238,7 +238,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
238238
this.call_function(
239239
panic_misaligned_pointer_dereference,
240240
Abi::Rust,
241-
&[required.into(), found.into()],
241+
&[required, found],
242242
None,
243243
StackPopCleanup::Goto { ret: None, unwind },
244244
)?;

0 commit comments

Comments
 (0)