From 887c130863126d814fd00fe5eca2235708065add Mon Sep 17 00:00:00 2001 From: David Carlier Date: Fri, 24 May 2024 21:56:00 +0000 Subject: [PATCH 01/41] solarish platform add supports for available-parallelism. --- src/tools/miri/ci/ci.sh | 4 +-- .../src/shims/unix/solarish/foreign_items.rs | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/tools/miri/ci/ci.sh b/src/tools/miri/ci/ci.sh index f97a611b36407..67985f9b7d6e9 100755 --- a/src/tools/miri/ci/ci.sh +++ b/src/tools/miri/ci/ci.sh @@ -148,8 +148,8 @@ case $HOST_TARGET in UNIX="panic/panic panic/unwind concurrency/simple atomic libc-mem libc-misc libc-random env num_cpus" # the things that are very similar across all Unixes, and hence easily supported there TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal $BASIC $UNIX threadname libc-time fs TEST_TARGET=i686-unknown-freebsd run_tests_minimal $BASIC $UNIX threadname libc-time fs - TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $BASIC $UNIX threadname pthread-sync libc-time - TEST_TARGET=x86_64-pc-solaris run_tests_minimal $BASIC $UNIX threadname pthread-sync libc-time + TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $BASIC $UNIX threadname pthread-sync available-parallelism libc-time + TEST_TARGET=x86_64-pc-solaris run_tests_minimal $BASIC $UNIX threadname pthread-sync available-parallelism libc-time TEST_TARGET=aarch64-linux-android run_tests_minimal $BASIC $UNIX TEST_TARGET=wasm32-wasip2 run_tests_minimal empty_main wasm heap_alloc libc-mem TEST_TARGET=wasm32-unknown-unknown run_tests_minimal empty_main wasm diff --git a/src/tools/miri/src/shims/unix/solarish/foreign_items.rs b/src/tools/miri/src/shims/unix/solarish/foreign_items.rs index c4dfb147ed981..83ccbee495335 100644 --- a/src/tools/miri/src/shims/unix/solarish/foreign_items.rs +++ b/src/tools/miri/src/shims/unix/solarish/foreign_items.rs @@ -69,6 +69,36 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { this.write_null(dest)?; } + "pset_info" => { + let [pset, tpe, cpus, list] = + this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; + // We do not need to handle the current process cpu mask, available_parallelism + // implementation pass null anyway. We only care for the number of + // cpus. + // https://docs.oracle.com/cd/E88353_01/html/E37841/pset-info-2.html + + let ps_myid = this.eval_libc_i32("PS_MYID"); + let pset = this.read_scalar(pset)?.to_i32()?; + let tpe = this.read_pointer(tpe)?; + let list = this.read_pointer(list)?; + + if ps_myid != pset { + throw_unsup_format!("pset_info is only supported with pset==PS_MYID"); + } + + if !this.ptr_is_null(tpe)? { + throw_unsup_format!("pset_info is only supported with type==NULL"); + } + + if !this.ptr_is_null(list)? { + throw_unsup_format!("pset_info is only supported with list==NULL"); + } + + let cpus = this.deref_pointer(cpus)?; + this.write_scalar(Scalar::from_u32(this.machine.num_cpus), &cpus)?; + this.write_null(dest)?; + } + _ => return Ok(EmulateItemResult::NotSupported), } Ok(EmulateItemResult::NeedsReturn) From d3974fabfdfb58314d57ab96530b2e47b5eb110e Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 26 May 2024 22:43:58 +0200 Subject: [PATCH 02/41] reorder code --- src/tools/miri/src/shims/unix/solarish/foreign_items.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/miri/src/shims/unix/solarish/foreign_items.rs b/src/tools/miri/src/shims/unix/solarish/foreign_items.rs index 83ccbee495335..d852b3537aa27 100644 --- a/src/tools/miri/src/shims/unix/solarish/foreign_items.rs +++ b/src/tools/miri/src/shims/unix/solarish/foreign_items.rs @@ -77,11 +77,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { // cpus. // https://docs.oracle.com/cd/E88353_01/html/E37841/pset-info-2.html - let ps_myid = this.eval_libc_i32("PS_MYID"); let pset = this.read_scalar(pset)?.to_i32()?; let tpe = this.read_pointer(tpe)?; let list = this.read_pointer(list)?; + let ps_myid = this.eval_libc_i32("PS_MYID"); if ps_myid != pset { throw_unsup_format!("pset_info is only supported with pset==PS_MYID"); } From 38870cf09c3afcb288bca132f8b51da3b97eb1ca Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 26 May 2024 22:53:45 +0200 Subject: [PATCH 03/41] avoid using macro_use --- src/tools/miri/cargo-miri/src/main.rs | 5 ++--- src/tools/miri/cargo-miri/src/util.rs | 5 +++-- src/tools/miri/src/bin/miri.rs | 3 ++- src/tools/miri/src/borrow_tracker/stacked_borrows/stack.rs | 1 + src/tools/miri/src/concurrency/init_once.rs | 2 +- src/tools/miri/src/concurrency/mod.rs | 3 +-- src/tools/miri/src/concurrency/sync.rs | 1 + src/tools/miri/src/lib.rs | 4 ++-- 8 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/tools/miri/cargo-miri/src/main.rs b/src/tools/miri/cargo-miri/src/main.rs index 9fdd4c3e47043..7d9f77f3752d9 100644 --- a/src/tools/miri/cargo-miri/src/main.rs +++ b/src/tools/miri/cargo-miri/src/main.rs @@ -1,15 +1,14 @@ #![allow(clippy::useless_format, clippy::derive_partial_eq_without_eq, rustc::internal)] -#[macro_use] -mod util; - mod arg; mod phases; mod setup; +mod util; use std::{env, iter}; use crate::phases::*; +use crate::util::show_error; /// Returns `true` if our flags look like they may be for rustdoc, i.e., this is cargo calling us to /// be rustdoc. It's hard to be sure as cargo does not have a RUSTDOC_WRAPPER or an env var that diff --git a/src/tools/miri/cargo-miri/src/util.rs b/src/tools/miri/cargo-miri/src/util.rs index 28a824e54f65c..5b6a391aabcda 100644 --- a/src/tools/miri/cargo-miri/src/util.rs +++ b/src/tools/miri/cargo-miri/src/util.rs @@ -11,14 +11,15 @@ use serde::{Deserialize, Serialize}; pub use crate::arg::*; -pub fn show_error(msg: &impl std::fmt::Display) -> ! { +pub fn show_error_(msg: &impl std::fmt::Display) -> ! { eprintln!("fatal error: {msg}"); std::process::exit(1) } macro_rules! show_error { - ($($tt:tt)*) => { crate::util::show_error(&format_args!($($tt)*)) }; + ($($tt:tt)*) => { crate::util::show_error_(&format_args!($($tt)*)) }; } +pub(crate) use show_error; /// The information to run a crate with the given environment. #[derive(Clone, Serialize, Deserialize)] diff --git a/src/tools/miri/src/bin/miri.rs b/src/tools/miri/src/bin/miri.rs index d748febeed4b1..829bfa7cd7086 100644 --- a/src/tools/miri/src/bin/miri.rs +++ b/src/tools/miri/src/bin/miri.rs @@ -8,7 +8,6 @@ )] // Some "regular" crates we want to share with rustc -#[macro_use] extern crate tracing; // The rustc crates we need @@ -26,6 +25,8 @@ use std::num::NonZero; use std::path::PathBuf; use std::str::FromStr; +use tracing::debug; + use rustc_data_structures::sync::Lrc; use rustc_driver::Compilation; use rustc_hir::{self as hir, Node}; diff --git a/src/tools/miri/src/borrow_tracker/stacked_borrows/stack.rs b/src/tools/miri/src/borrow_tracker/stacked_borrows/stack.rs index 3b6c29b5eb154..f65f49a75ddd9 100644 --- a/src/tools/miri/src/borrow_tracker/stacked_borrows/stack.rs +++ b/src/tools/miri/src/borrow_tracker/stacked_borrows/stack.rs @@ -2,6 +2,7 @@ use std::ops::Range; use rustc_data_structures::fx::FxHashSet; +use tracing::trace; use crate::borrow_tracker::{ stacked_borrows::{Item, Permission}, diff --git a/src/tools/miri/src/concurrency/init_once.rs b/src/tools/miri/src/concurrency/init_once.rs index 3d6cf7ecca67b..f1534d3745f95 100644 --- a/src/tools/miri/src/concurrency/init_once.rs +++ b/src/tools/miri/src/concurrency/init_once.rs @@ -7,7 +7,7 @@ use super::sync::EvalContextExtPriv as _; use super::vector_clock::VClock; use crate::*; -declare_id!(InitOnceId); +super::sync::declare_id!(InitOnceId); #[derive(Default, Debug, Copy, Clone, PartialEq, Eq)] /// The current status of a one time initialization. diff --git a/src/tools/miri/src/concurrency/mod.rs b/src/tools/miri/src/concurrency/mod.rs index 15e1a94d6db0e..822d173ac06a7 100644 --- a/src/tools/miri/src/concurrency/mod.rs +++ b/src/tools/miri/src/concurrency/mod.rs @@ -1,8 +1,7 @@ pub mod data_race; +pub mod init_once; mod range_object_map; -#[macro_use] pub mod sync; -pub mod init_once; pub mod thread; mod vector_clock; pub mod weak_memory; diff --git a/src/tools/miri/src/concurrency/sync.rs b/src/tools/miri/src/concurrency/sync.rs index 8925409ecc244..2ea89050ecd90 100644 --- a/src/tools/miri/src/concurrency/sync.rs +++ b/src/tools/miri/src/concurrency/sync.rs @@ -61,6 +61,7 @@ macro_rules! declare_id { } }; } +pub(super) use declare_id; declare_id!(MutexId); diff --git a/src/tools/miri/src/lib.rs b/src/tools/miri/src/lib.rs index 2fa88b6a24619..fa7c46f2a0158 100644 --- a/src/tools/miri/src/lib.rs +++ b/src/tools/miri/src/lib.rs @@ -53,7 +53,6 @@ // Some "regular" crates we want to share with rustc extern crate either; -#[macro_use] extern crate tracing; // The rustc crates we need @@ -64,7 +63,6 @@ extern crate rustc_data_structures; extern crate rustc_errors; extern crate rustc_hir; extern crate rustc_index; -#[macro_use] extern crate rustc_middle; extern crate rustc_session; extern crate rustc_span; @@ -91,6 +89,8 @@ mod range_map; mod shims; // Establish a "crate-wide prelude": we often import `crate::*`. +use rustc_middle::{bug, span_bug}; +use tracing::{info, trace}; // Make all those symbols available in the same place as our own. #[doc(no_inline)] From d562cec048cb5da46b2351549beffbad8248de1c Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 27 May 2024 16:41:53 +0200 Subject: [PATCH 04/41] Preparing for merge from rustc --- src/tools/miri/rust-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/miri/rust-version b/src/tools/miri/rust-version index aa06a0dbcdc5b..3b24a903d3af7 100644 --- a/src/tools/miri/rust-version +++ b/src/tools/miri/rust-version @@ -1 +1 @@ -21e6de7eb64c09102de3f100420a09edc1a2a8d7 +a59072ec4fb6824213df5e9de8cae4812fd4fe97 From 84f70abacb2a9a0d6d90435b44ba69c71147e34c Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 27 May 2024 16:43:30 +0200 Subject: [PATCH 05/41] fmt --- .../stacked_borrows/diagnostics.rs | 6 +----- src/tools/miri/src/concurrency/init_once.rs | 5 +---- src/tools/miri/src/concurrency/sync.rs | 9 ++------- src/tools/miri/src/shims/unix/sync.rs | 18 ++++-------------- src/tools/miri/src/shims/x86/aesni.rs | 4 +--- src/tools/miri/src/shims/x86/avx.rs | 4 +--- src/tools/miri/src/shims/x86/avx2.rs | 4 +--- src/tools/miri/src/shims/x86/sse.rs | 4 +--- src/tools/miri/src/shims/x86/sse2.rs | 4 +--- src/tools/miri/src/shims/x86/sse3.rs | 4 +--- src/tools/miri/src/shims/x86/sse41.rs | 4 +--- src/tools/miri/src/shims/x86/ssse3.rs | 4 +--- 12 files changed, 16 insertions(+), 54 deletions(-) diff --git a/src/tools/miri/src/borrow_tracker/stacked_borrows/diagnostics.rs b/src/tools/miri/src/borrow_tracker/stacked_borrows/diagnostics.rs index 8270a8c321ce1..87d9057cb89dc 100644 --- a/src/tools/miri/src/borrow_tracker/stacked_borrows/diagnostics.rs +++ b/src/tools/miri/src/borrow_tracker/stacked_borrows/diagnostics.rs @@ -149,11 +149,7 @@ impl<'ecx, 'tcx> DiagnosticCxBuilder<'ecx, 'tcx> { DiagnosticCxBuilder { machine, operation } } - pub fn read( - machine: &'ecx MiriMachine<'tcx>, - tag: ProvenanceExtra, - range: AllocRange, - ) -> Self { + pub fn read(machine: &'ecx MiriMachine<'tcx>, tag: ProvenanceExtra, range: AllocRange) -> Self { let operation = Operation::Access(AccessOp { kind: AccessKind::Read, tag, range }); DiagnosticCxBuilder { machine, operation } } diff --git a/src/tools/miri/src/concurrency/init_once.rs b/src/tools/miri/src/concurrency/init_once.rs index ab58b27cd2b11..7f8500159c14c 100644 --- a/src/tools/miri/src/concurrency/init_once.rs +++ b/src/tools/miri/src/concurrency/init_once.rs @@ -33,10 +33,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> { #[inline] fn init_once_get_or_create(&mut self, existing: F) -> InterpResult<'tcx, InitOnceId> where - F: FnOnce( - &mut MiriInterpCx<'tcx>, - InitOnceId, - ) -> InterpResult<'tcx, Option>, + F: FnOnce(&mut MiriInterpCx<'tcx>, InitOnceId) -> InterpResult<'tcx, Option>, { let this = self.eval_context_mut(); let next_index = this.machine.sync.init_onces.next_index(); diff --git a/src/tools/miri/src/concurrency/sync.rs b/src/tools/miri/src/concurrency/sync.rs index cff50bdb64c8c..dfe4d0d4c2f9b 100644 --- a/src/tools/miri/src/concurrency/sync.rs +++ b/src/tools/miri/src/concurrency/sync.rs @@ -161,9 +161,7 @@ pub struct SynchronizationObjects { // Private extension trait for local helper methods impl<'tcx> EvalContextExtPriv<'tcx> for crate::MiriInterpCx<'tcx> {} -pub(super) trait EvalContextExtPriv<'tcx>: - crate::MiriInterpCxExt<'tcx> -{ +pub(super) trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> { /// Lazily initialize the ID of this Miri sync structure. /// ('0' indicates uninit.) #[inline] @@ -245,10 +243,7 @@ pub(super) trait EvalContextExtPriv<'tcx>: #[inline] fn condvar_get_or_create(&mut self, existing: F) -> InterpResult<'tcx, CondvarId> where - F: FnOnce( - &mut MiriInterpCx<'tcx>, - CondvarId, - ) -> InterpResult<'tcx, Option>, + F: FnOnce(&mut MiriInterpCx<'tcx>, CondvarId) -> InterpResult<'tcx, Option>, { let this = self.eval_context_mut(); let next_index = this.machine.sync.condvars.next_index(); diff --git a/src/tools/miri/src/shims/unix/sync.rs b/src/tools/miri/src/shims/unix/sync.rs index 0743ad14495d4..304c1386370c5 100644 --- a/src/tools/miri/src/shims/unix/sync.rs +++ b/src/tools/miri/src/shims/unix/sync.rs @@ -10,9 +10,7 @@ use crate::*; // - kind: i32 #[inline] -fn mutexattr_kind_offset<'tcx>( - ecx: &MiriInterpCx<'tcx>, -) -> InterpResult<'tcx, u64> { +fn mutexattr_kind_offset<'tcx>(ecx: &MiriInterpCx<'tcx>) -> InterpResult<'tcx, u64> { Ok(match &*ecx.tcx.sess.target.os { "linux" | "illumos" | "solaris" | "macos" => 0, os => throw_unsup_format!("`pthread_mutexattr` is not supported on {os}"), @@ -53,17 +51,11 @@ fn mutexattr_set_kind<'tcx>( /// in `pthread_mutexattr_settype` function. const PTHREAD_MUTEX_NORMAL_FLAG: i32 = 0x8000000; -fn is_mutex_kind_default<'tcx>( - ecx: &MiriInterpCx<'tcx>, - kind: i32, -) -> InterpResult<'tcx, bool> { +fn is_mutex_kind_default<'tcx>(ecx: &MiriInterpCx<'tcx>, kind: i32) -> InterpResult<'tcx, bool> { Ok(kind == ecx.eval_libc_i32("PTHREAD_MUTEX_DEFAULT")) } -fn is_mutex_kind_normal<'tcx>( - ecx: &MiriInterpCx<'tcx>, - kind: i32, -) -> InterpResult<'tcx, bool> { +fn is_mutex_kind_normal<'tcx>(ecx: &MiriInterpCx<'tcx>, kind: i32) -> InterpResult<'tcx, bool> { let mutex_normal_kind = ecx.eval_libc_i32("PTHREAD_MUTEX_NORMAL"); Ok(kind == (mutex_normal_kind | PTHREAD_MUTEX_NORMAL_FLAG)) } @@ -220,9 +212,7 @@ fn rwlock_get_id<'tcx>( // - clock: i32 #[inline] -fn condattr_clock_offset<'tcx>( - ecx: &MiriInterpCx<'tcx>, -) -> InterpResult<'tcx, u64> { +fn condattr_clock_offset<'tcx>(ecx: &MiriInterpCx<'tcx>) -> InterpResult<'tcx, u64> { Ok(match &*ecx.tcx.sess.target.os { "linux" | "illumos" | "solaris" => 0, // macOS does not have a clock attribute. diff --git a/src/tools/miri/src/shims/x86/aesni.rs b/src/tools/miri/src/shims/x86/aesni.rs index c1be1d4582a7a..e7164d6651137 100644 --- a/src/tools/miri/src/shims/x86/aesni.rs +++ b/src/tools/miri/src/shims/x86/aesni.rs @@ -6,9 +6,7 @@ use rustc_target::spec::abi::Abi; use crate::*; impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {} -pub(super) trait EvalContextExt<'tcx>: - crate::MiriInterpCxExt<'tcx> -{ +pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_x86_aesni_intrinsic( &mut self, link_name: Symbol, diff --git a/src/tools/miri/src/shims/x86/avx.rs b/src/tools/miri/src/shims/x86/avx.rs index f782fbfff4e74..1a912f6ff5d73 100644 --- a/src/tools/miri/src/shims/x86/avx.rs +++ b/src/tools/miri/src/shims/x86/avx.rs @@ -13,9 +13,7 @@ use super::{ use crate::*; impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {} -pub(super) trait EvalContextExt<'tcx>: - crate::MiriInterpCxExt<'tcx> -{ +pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_x86_avx_intrinsic( &mut self, link_name: Symbol, diff --git a/src/tools/miri/src/shims/x86/avx2.rs b/src/tools/miri/src/shims/x86/avx2.rs index 91764a20572a6..9b50da79edd2f 100644 --- a/src/tools/miri/src/shims/x86/avx2.rs +++ b/src/tools/miri/src/shims/x86/avx2.rs @@ -11,9 +11,7 @@ use super::{ use crate::*; impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {} -pub(super) trait EvalContextExt<'tcx>: - crate::MiriInterpCxExt<'tcx> -{ +pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_x86_avx2_intrinsic( &mut self, link_name: Symbol, diff --git a/src/tools/miri/src/shims/x86/sse.rs b/src/tools/miri/src/shims/x86/sse.rs index 0afb2090cad63..16c0708182005 100644 --- a/src/tools/miri/src/shims/x86/sse.rs +++ b/src/tools/miri/src/shims/x86/sse.rs @@ -10,9 +10,7 @@ use super::{ use crate::*; impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {} -pub(super) trait EvalContextExt<'tcx>: - crate::MiriInterpCxExt<'tcx> -{ +pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_x86_sse_intrinsic( &mut self, link_name: Symbol, diff --git a/src/tools/miri/src/shims/x86/sse2.rs b/src/tools/miri/src/shims/x86/sse2.rs index bdff22cfa95b2..f8b512e7981c5 100644 --- a/src/tools/miri/src/shims/x86/sse2.rs +++ b/src/tools/miri/src/shims/x86/sse2.rs @@ -9,9 +9,7 @@ use super::{ use crate::*; impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {} -pub(super) trait EvalContextExt<'tcx>: - crate::MiriInterpCxExt<'tcx> -{ +pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_x86_sse2_intrinsic( &mut self, link_name: Symbol, diff --git a/src/tools/miri/src/shims/x86/sse3.rs b/src/tools/miri/src/shims/x86/sse3.rs index 7dbe5163199b8..58d27ef8f7213 100644 --- a/src/tools/miri/src/shims/x86/sse3.rs +++ b/src/tools/miri/src/shims/x86/sse3.rs @@ -6,9 +6,7 @@ use super::horizontal_bin_op; use crate::*; impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {} -pub(super) trait EvalContextExt<'tcx>: - crate::MiriInterpCxExt<'tcx> -{ +pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_x86_sse3_intrinsic( &mut self, link_name: Symbol, diff --git a/src/tools/miri/src/shims/x86/sse41.rs b/src/tools/miri/src/shims/x86/sse41.rs index b3880fec3e034..79f885ed09482 100644 --- a/src/tools/miri/src/shims/x86/sse41.rs +++ b/src/tools/miri/src/shims/x86/sse41.rs @@ -5,9 +5,7 @@ use super::{conditional_dot_product, mpsadbw, packusdw, round_all, round_first, use crate::*; impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {} -pub(super) trait EvalContextExt<'tcx>: - crate::MiriInterpCxExt<'tcx> -{ +pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_x86_sse41_intrinsic( &mut self, link_name: Symbol, diff --git a/src/tools/miri/src/shims/x86/ssse3.rs b/src/tools/miri/src/shims/x86/ssse3.rs index 1f7870f8ca03b..2bb9a8dec6906 100644 --- a/src/tools/miri/src/shims/x86/ssse3.rs +++ b/src/tools/miri/src/shims/x86/ssse3.rs @@ -6,9 +6,7 @@ use super::{horizontal_bin_op, int_abs, pmulhrsw, psign}; use crate::*; impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {} -pub(super) trait EvalContextExt<'tcx>: - crate::MiriInterpCxExt<'tcx> -{ +pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_x86_ssse3_intrinsic( &mut self, link_name: Symbol, From fcb4cf52d8111d781d3b9a7b25dd26cddf7338e8 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 27 May 2024 17:29:52 +0200 Subject: [PATCH 06/41] avoid repeating the Provenance parameter everywhere --- src/tools/miri/src/borrow_tracker/mod.rs | 11 +- .../src/borrow_tracker/stacked_borrows/mod.rs | 33 ++-- .../src/borrow_tracker/tree_borrows/mod.rs | 37 ++--- src/tools/miri/src/concurrency/data_race.rs | 42 ++--- src/tools/miri/src/concurrency/init_once.rs | 2 +- src/tools/miri/src/concurrency/sync.rs | 69 ++++---- src/tools/miri/src/concurrency/thread.rs | 8 +- src/tools/miri/src/concurrency/weak_memory.rs | 43 +++-- src/tools/miri/src/helpers.rs | 79 ++++----- src/tools/miri/src/intrinsics/atomic.rs | 38 ++--- src/tools/miri/src/intrinsics/mod.rs | 10 +- src/tools/miri/src/intrinsics/simd.rs | 10 +- src/tools/miri/src/lib.rs | 9 +- src/tools/miri/src/machine.rs | 34 ++-- src/tools/miri/src/operator.rs | 6 +- src/tools/miri/src/provenance_gc.rs | 10 +- src/tools/miri/src/shims/alloc.rs | 12 +- src/tools/miri/src/shims/backtrace.rs | 16 +- src/tools/miri/src/shims/extern_static.rs | 2 +- src/tools/miri/src/shims/foreign_items.rs | 22 +-- src/tools/miri/src/shims/native_lib.rs | 13 +- src/tools/miri/src/shims/panic.rs | 10 +- src/tools/miri/src/shims/time.rs | 39 ++--- src/tools/miri/src/shims/tls.rs | 18 +- .../src/shims/unix/android/foreign_items.rs | 4 +- src/tools/miri/src/shims/unix/env.rs | 21 +-- src/tools/miri/src/shims/unix/fd.rs | 4 +- .../miri/src/shims/unix/foreign_items.rs | 6 +- .../src/shims/unix/freebsd/foreign_items.rs | 4 +- src/tools/miri/src/shims/unix/fs.rs | 114 ++++++------- src/tools/miri/src/shims/unix/linux/epoll.rs | 29 ++-- .../miri/src/shims/unix/linux/eventfd.rs | 6 +- .../src/shims/unix/linux/foreign_items.rs | 4 +- src/tools/miri/src/shims/unix/linux/mem.rs | 10 +- src/tools/miri/src/shims/unix/linux/sync.rs | 4 +- .../src/shims/unix/macos/foreign_items.rs | 4 +- src/tools/miri/src/shims/unix/mem.rs | 18 +- src/tools/miri/src/shims/unix/socket.rs | 10 +- .../src/shims/unix/solarish/foreign_items.rs | 4 +- src/tools/miri/src/shims/unix/sync.rs | 143 ++++++---------- src/tools/miri/src/shims/unix/thread.rs | 30 ++-- .../miri/src/shims/wasi/foreign_items.rs | 4 +- src/tools/miri/src/shims/windows/env.rs | 37 ++--- .../miri/src/shims/windows/foreign_items.rs | 4 +- src/tools/miri/src/shims/windows/handle.rs | 6 +- src/tools/miri/src/shims/windows/sync.rs | 45 +++-- src/tools/miri/src/shims/windows/thread.rs | 16 +- src/tools/miri/src/shims/x86/aesni.rs | 10 +- src/tools/miri/src/shims/x86/avx.rs | 4 +- src/tools/miri/src/shims/x86/avx2.rs | 4 +- src/tools/miri/src/shims/x86/mod.rs | 156 +++++++++--------- src/tools/miri/src/shims/x86/sse.rs | 4 +- src/tools/miri/src/shims/x86/sse2.rs | 4 +- src/tools/miri/src/shims/x86/sse3.rs | 4 +- src/tools/miri/src/shims/x86/sse41.rs | 4 +- src/tools/miri/src/shims/x86/ssse3.rs | 4 +- 56 files changed, 585 insertions(+), 709 deletions(-) diff --git a/src/tools/miri/src/borrow_tracker/mod.rs b/src/tools/miri/src/borrow_tracker/mod.rs index a55ec427d5f08..1b84ecc768608 100644 --- a/src/tools/miri/src/borrow_tracker/mod.rs +++ b/src/tools/miri/src/borrow_tracker/mod.rs @@ -281,8 +281,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn retag_ptr_value( &mut self, kind: RetagKind, - val: &ImmTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, ImmTy<'tcx, Provenance>> { + val: &ImmTy<'tcx>, + ) -> InterpResult<'tcx, ImmTy<'tcx>> { let this = self.eval_context_mut(); let method = this.machine.borrow_tracker.as_ref().unwrap().borrow().borrow_tracker_method; match method { @@ -294,7 +294,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn retag_place_contents( &mut self, kind: RetagKind, - place: &PlaceTy<'tcx, Provenance>, + place: &PlaceTy<'tcx>, ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); let method = this.machine.borrow_tracker.as_ref().unwrap().borrow().borrow_tracker_method; @@ -304,10 +304,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } } - fn protect_place( - &mut self, - place: &MPlaceTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, MPlaceTy<'tcx, Provenance>> { + fn protect_place(&mut self, place: &MPlaceTy<'tcx>) -> InterpResult<'tcx, MPlaceTy<'tcx>> { let this = self.eval_context_mut(); let method = this.machine.borrow_tracker.as_ref().unwrap().borrow().borrow_tracker_method; match method { diff --git a/src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs b/src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs index 2786668695e27..5af2eeeec06ea 100644 --- a/src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs +++ b/src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs @@ -587,7 +587,7 @@ trait EvalContextPrivExt<'tcx, 'ecx>: crate::MiriInterpCxExt<'tcx> { /// Returns the provenance that should be used henceforth. fn sb_reborrow( &mut self, - place: &MPlaceTy<'tcx, Provenance>, + place: &MPlaceTy<'tcx>, size: Size, new_perm: NewPermission, new_tag: BorTag, @@ -809,10 +809,10 @@ trait EvalContextPrivExt<'tcx, 'ecx>: crate::MiriInterpCxExt<'tcx> { fn sb_retag_place( &mut self, - place: &MPlaceTy<'tcx, Provenance>, + place: &MPlaceTy<'tcx>, new_perm: NewPermission, info: RetagInfo, // diagnostics info about this retag - ) -> InterpResult<'tcx, MPlaceTy<'tcx, Provenance>> { + ) -> InterpResult<'tcx, MPlaceTy<'tcx>> { let this = self.eval_context_mut(); let size = this.size_and_align_of_mplace(place)?.map(|(size, _)| size); // FIXME: If we cannot determine the size (because the unsized tail is an `extern type`), @@ -839,10 +839,10 @@ trait EvalContextPrivExt<'tcx, 'ecx>: crate::MiriInterpCxExt<'tcx> { /// `kind` indicates what kind of reference is being created. fn sb_retag_reference( &mut self, - val: &ImmTy<'tcx, Provenance>, + val: &ImmTy<'tcx>, new_perm: NewPermission, info: RetagInfo, // diagnostics info about this retag - ) -> InterpResult<'tcx, ImmTy<'tcx, Provenance>> { + ) -> InterpResult<'tcx, ImmTy<'tcx>> { let this = self.eval_context_mut(); let place = this.ref_to_mplace(val)?; let new_place = this.sb_retag_place(&place, new_perm, info)?; @@ -855,8 +855,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn sb_retag_ptr_value( &mut self, kind: RetagKind, - val: &ImmTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, ImmTy<'tcx, Provenance>> { + val: &ImmTy<'tcx>, + ) -> InterpResult<'tcx, ImmTy<'tcx>> { let this = self.eval_context_mut(); let new_perm = NewPermission::from_ref_ty(val.layout.ty, kind, this); let cause = match kind { @@ -870,7 +870,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn sb_retag_place_contents( &mut self, kind: RetagKind, - place: &PlaceTy<'tcx, Provenance>, + place: &PlaceTy<'tcx>, ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); let retag_fields = this.machine.borrow_tracker.as_mut().unwrap().get_mut().retag_fields; @@ -895,7 +895,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { #[inline(always)] // yes this helps in our benchmarks fn retag_ptr_inplace( &mut self, - place: &PlaceTy<'tcx, Provenance>, + place: &PlaceTy<'tcx>, new_perm: NewPermission, ) -> InterpResult<'tcx> { let val = self.ecx.read_immediate(&self.ecx.place_to_op(place)?)?; @@ -909,18 +909,14 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } } impl<'ecx, 'tcx> ValueVisitor<'tcx, MiriMachine<'tcx>> for RetagVisitor<'ecx, 'tcx> { - type V = PlaceTy<'tcx, Provenance>; + type V = PlaceTy<'tcx>; #[inline(always)] fn ecx(&self) -> &MiriInterpCx<'tcx> { self.ecx } - fn visit_box( - &mut self, - box_ty: Ty<'tcx>, - place: &PlaceTy<'tcx, Provenance>, - ) -> InterpResult<'tcx> { + fn visit_box(&mut self, box_ty: Ty<'tcx>, place: &PlaceTy<'tcx>) -> InterpResult<'tcx> { // Only boxes for the global allocator get any special treatment. if box_ty.is_box_global(*self.ecx.tcx) { // Boxes get a weak protectors, since they may be deallocated. @@ -930,7 +926,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { Ok(()) } - fn visit_value(&mut self, place: &PlaceTy<'tcx, Provenance>) -> InterpResult<'tcx> { + fn visit_value(&mut self, place: &PlaceTy<'tcx>) -> InterpResult<'tcx> { // If this place is smaller than a pointer, we know that it can't contain any // pointers we need to retag, so we can stop recursion early. // This optimization is crucial for ZSTs, because they can contain way more fields @@ -984,10 +980,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// call. /// /// This is used to ensure soundness of in-place function argument/return passing. - fn sb_protect_place( - &mut self, - place: &MPlaceTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, MPlaceTy<'tcx, Provenance>> { + fn sb_protect_place(&mut self, place: &MPlaceTy<'tcx>) -> InterpResult<'tcx, MPlaceTy<'tcx>> { let this = self.eval_context_mut(); // Retag it. With protection! That is the entire point. diff --git a/src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs b/src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs index e1c06b2bd98e5..a5867ff24a0cf 100644 --- a/src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs +++ b/src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs @@ -195,7 +195,7 @@ trait EvalContextPrivExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// Returns the provenance that should be used henceforth. fn tb_reborrow( &mut self, - place: &MPlaceTy<'tcx, Provenance>, // parent tag extracted from here + place: &MPlaceTy<'tcx>, // parent tag extracted from here ptr_size: Size, new_perm: NewPermission, new_tag: BorTag, @@ -327,9 +327,9 @@ trait EvalContextPrivExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn tb_retag_place( &mut self, - place: &MPlaceTy<'tcx, Provenance>, + place: &MPlaceTy<'tcx>, new_perm: NewPermission, - ) -> InterpResult<'tcx, MPlaceTy<'tcx, Provenance>> { + ) -> InterpResult<'tcx, MPlaceTy<'tcx>> { let this = self.eval_context_mut(); // Determine the size of the reborrow. @@ -366,9 +366,9 @@ trait EvalContextPrivExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// Retags an individual pointer, returning the retagged version. fn tb_retag_reference( &mut self, - val: &ImmTy<'tcx, Provenance>, + val: &ImmTy<'tcx>, new_perm: NewPermission, - ) -> InterpResult<'tcx, ImmTy<'tcx, Provenance>> { + ) -> InterpResult<'tcx, ImmTy<'tcx>> { let this = self.eval_context_mut(); let place = this.ref_to_mplace(val)?; let new_place = this.tb_retag_place(&place, new_perm)?; @@ -383,8 +383,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn tb_retag_ptr_value( &mut self, kind: RetagKind, - val: &ImmTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, ImmTy<'tcx, Provenance>> { + val: &ImmTy<'tcx>, + ) -> InterpResult<'tcx, ImmTy<'tcx>> { let this = self.eval_context_mut(); let new_perm = match val.layout.ty.kind() { &ty::Ref(_, pointee, mutability) => @@ -402,7 +402,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn tb_retag_place_contents( &mut self, kind: RetagKind, - place: &PlaceTy<'tcx, Provenance>, + place: &PlaceTy<'tcx>, ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); let options = this.machine.borrow_tracker.as_mut().unwrap().get_mut(); @@ -423,7 +423,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { #[inline(always)] // yes this helps in our benchmarks fn retag_ptr_inplace( &mut self, - place: &PlaceTy<'tcx, Provenance>, + place: &PlaceTy<'tcx>, new_perm: Option, ) -> InterpResult<'tcx> { if let Some(new_perm) = new_perm { @@ -435,7 +435,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } } impl<'ecx, 'tcx> ValueVisitor<'tcx, MiriMachine<'tcx>> for RetagVisitor<'ecx, 'tcx> { - type V = PlaceTy<'tcx, Provenance>; + type V = PlaceTy<'tcx>; #[inline(always)] fn ecx(&self) -> &MiriInterpCx<'tcx> { @@ -445,11 +445,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// Regardless of how `Unique` is handled, Boxes are always reborrowed. /// When `Unique` is also reborrowed, then it behaves exactly like `Box` /// except for the fact that `Box` has a non-zero-sized reborrow. - fn visit_box( - &mut self, - box_ty: Ty<'tcx>, - place: &PlaceTy<'tcx, Provenance>, - ) -> InterpResult<'tcx> { + fn visit_box(&mut self, box_ty: Ty<'tcx>, place: &PlaceTy<'tcx>) -> InterpResult<'tcx> { // Only boxes for the global allocator get any special treatment. if box_ty.is_box_global(*self.ecx.tcx) { let new_perm = NewPermission::from_unique_ty( @@ -463,7 +459,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { Ok(()) } - fn visit_value(&mut self, place: &PlaceTy<'tcx, Provenance>) -> InterpResult<'tcx> { + fn visit_value(&mut self, place: &PlaceTy<'tcx>) -> InterpResult<'tcx> { // If this place is smaller than a pointer, we know that it can't contain any // pointers we need to retag, so we can stop recursion early. // This optimization is crucial for ZSTs, because they can contain way more fields @@ -526,10 +522,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// call. /// /// This is used to ensure soundness of in-place function argument/return passing. - fn tb_protect_place( - &mut self, - place: &MPlaceTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, MPlaceTy<'tcx, Provenance>> { + fn tb_protect_place(&mut self, place: &MPlaceTy<'tcx>) -> InterpResult<'tcx, MPlaceTy<'tcx>> { let this = self.eval_context_mut(); // Retag it. With protection! That is the entire point. @@ -604,8 +597,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// and output can be used by `retag_ptr_inplace`. fn inner_ptr_of_unique<'tcx>( ecx: &MiriInterpCx<'tcx>, - place: &PlaceTy<'tcx, Provenance>, -) -> InterpResult<'tcx, PlaceTy<'tcx, Provenance>> { + place: &PlaceTy<'tcx>, +) -> InterpResult<'tcx, PlaceTy<'tcx>> { // Follows the same layout as `interpret/visitor.rs:walk_value` for `Box` in // `rustc_const_eval`, just with one fewer layer. // Here we have a `Unique(NonNull(*mut), PhantomData)` diff --git a/src/tools/miri/src/concurrency/data_race.rs b/src/tools/miri/src/concurrency/data_race.rs index 719c262290ef2..caf74bc70e4ad 100644 --- a/src/tools/miri/src/concurrency/data_race.rs +++ b/src/tools/miri/src/concurrency/data_race.rs @@ -606,9 +606,9 @@ pub trait EvalContextExt<'tcx>: MiriInterpCxExt<'tcx> { /// Perform an atomic read operation at the memory location. fn read_scalar_atomic( &self, - place: &MPlaceTy<'tcx, Provenance>, + place: &MPlaceTy<'tcx>, atomic: AtomicReadOrd, - ) -> InterpResult<'tcx, Scalar> { + ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_ref(); this.atomic_access_check(place, AtomicAccessType::Load(atomic))?; // This will read from the last store in the modification order of this location. In case @@ -625,8 +625,8 @@ pub trait EvalContextExt<'tcx>: MiriInterpCxExt<'tcx> { /// Perform an atomic write operation at the memory location. fn write_scalar_atomic( &mut self, - val: Scalar, - dest: &MPlaceTy<'tcx, Provenance>, + val: Scalar, + dest: &MPlaceTy<'tcx>, atomic: AtomicWriteOrd, ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); @@ -645,12 +645,12 @@ pub trait EvalContextExt<'tcx>: MiriInterpCxExt<'tcx> { /// Perform an atomic RMW operation on a memory location. fn atomic_rmw_op_immediate( &mut self, - place: &MPlaceTy<'tcx, Provenance>, - rhs: &ImmTy<'tcx, Provenance>, + place: &MPlaceTy<'tcx>, + rhs: &ImmTy<'tcx>, op: mir::BinOp, not: bool, atomic: AtomicRwOrd, - ) -> InterpResult<'tcx, ImmTy<'tcx, Provenance>> { + ) -> InterpResult<'tcx, ImmTy<'tcx>> { let this = self.eval_context_mut(); this.atomic_access_check(place, AtomicAccessType::Rmw)?; @@ -670,10 +670,10 @@ pub trait EvalContextExt<'tcx>: MiriInterpCxExt<'tcx> { /// scalar value, the old value is returned. fn atomic_exchange_scalar( &mut self, - place: &MPlaceTy<'tcx, Provenance>, - new: Scalar, + place: &MPlaceTy<'tcx>, + new: Scalar, atomic: AtomicRwOrd, - ) -> InterpResult<'tcx, Scalar> { + ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); this.atomic_access_check(place, AtomicAccessType::Rmw)?; @@ -690,11 +690,11 @@ pub trait EvalContextExt<'tcx>: MiriInterpCxExt<'tcx> { /// scalar value, the old value is returned. fn atomic_min_max_scalar( &mut self, - place: &MPlaceTy<'tcx, Provenance>, - rhs: ImmTy<'tcx, Provenance>, + place: &MPlaceTy<'tcx>, + rhs: ImmTy<'tcx>, min: bool, atomic: AtomicRwOrd, - ) -> InterpResult<'tcx, ImmTy<'tcx, Provenance>> { + ) -> InterpResult<'tcx, ImmTy<'tcx>> { let this = self.eval_context_mut(); this.atomic_access_check(place, AtomicAccessType::Rmw)?; @@ -726,9 +726,9 @@ pub trait EvalContextExt<'tcx>: MiriInterpCxExt<'tcx> { /// identical. fn atomic_compare_exchange_scalar( &mut self, - place: &MPlaceTy<'tcx, Provenance>, - expect_old: &ImmTy<'tcx, Provenance>, - new: Scalar, + place: &MPlaceTy<'tcx>, + expect_old: &ImmTy<'tcx>, + new: Scalar, success: AtomicRwOrd, fail: AtomicReadOrd, can_fail_spuriously: bool, @@ -1163,7 +1163,7 @@ trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> { /// Checks that an atomic access is legal at the given place. fn atomic_access_check( &self, - place: &MPlaceTy<'tcx, Provenance>, + place: &MPlaceTy<'tcx>, access_type: AtomicAccessType, ) -> InterpResult<'tcx> { let this = self.eval_context_ref(); @@ -1219,7 +1219,7 @@ trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> { /// associated memory-place and on the current thread. fn validate_atomic_load( &self, - place: &MPlaceTy<'tcx, Provenance>, + place: &MPlaceTy<'tcx>, atomic: AtomicReadOrd, ) -> InterpResult<'tcx> { let this = self.eval_context_ref(); @@ -1241,7 +1241,7 @@ trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> { /// associated memory-place and on the current thread. fn validate_atomic_store( &mut self, - place: &MPlaceTy<'tcx, Provenance>, + place: &MPlaceTy<'tcx>, atomic: AtomicWriteOrd, ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); @@ -1263,7 +1263,7 @@ trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> { /// at the associated memory place and on the current thread. fn validate_atomic_rmw( &mut self, - place: &MPlaceTy<'tcx, Provenance>, + place: &MPlaceTy<'tcx>, atomic: AtomicRwOrd, ) -> InterpResult<'tcx> { use AtomicRwOrd::*; @@ -1292,7 +1292,7 @@ trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> { /// Generic atomic operation implementation fn validate_atomic_op( &self, - place: &MPlaceTy<'tcx, Provenance>, + place: &MPlaceTy<'tcx>, atomic: A, access: AccessType, mut op: impl FnMut( diff --git a/src/tools/miri/src/concurrency/init_once.rs b/src/tools/miri/src/concurrency/init_once.rs index 7f8500159c14c..9145ef32c525b 100644 --- a/src/tools/miri/src/concurrency/init_once.rs +++ b/src/tools/miri/src/concurrency/init_once.rs @@ -51,7 +51,7 @@ impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {} pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn init_once_get_or_create_id( &mut self, - lock_op: &OpTy<'tcx, Provenance>, + lock_op: &OpTy<'tcx>, lock_layout: TyAndLayout<'tcx>, offset: u64, ) -> InterpResult<'tcx, InitOnceId> { diff --git a/src/tools/miri/src/concurrency/sync.rs b/src/tools/miri/src/concurrency/sync.rs index dfe4d0d4c2f9b..030546b7cb518 100644 --- a/src/tools/miri/src/concurrency/sync.rs +++ b/src/tools/miri/src/concurrency/sync.rs @@ -55,7 +55,7 @@ macro_rules! declare_id { } impl $name { - pub fn to_u32_scalar(&self) -> Scalar { + pub fn to_u32_scalar(&self) -> Scalar { Scalar::from_u32(self.0.get()) } } @@ -168,7 +168,7 @@ pub(super) trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> { fn get_or_create_id( &mut self, next_id: Id, - lock_op: &OpTy<'tcx, Provenance>, + lock_op: &OpTy<'tcx>, lock_layout: TyAndLayout<'tcx>, offset: u64, ) -> InterpResult<'tcx, Option> { @@ -262,8 +262,8 @@ pub(super) trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> { fn condvar_reacquire_mutex( &mut self, mutex: MutexId, - retval: Scalar, - dest: MPlaceTy<'tcx, Provenance>, + retval: Scalar, + dest: MPlaceTy<'tcx>, ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); if this.mutex_is_locked(mutex) { @@ -287,7 +287,7 @@ impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {} pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn mutex_get_or_create_id( &mut self, - lock_op: &OpTy<'tcx, Provenance>, + lock_op: &OpTy<'tcx>, lock_layout: TyAndLayout<'tcx>, offset: u64, ) -> InterpResult<'tcx, MutexId> { @@ -299,7 +299,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn rwlock_get_or_create_id( &mut self, - lock_op: &OpTy<'tcx, Provenance>, + lock_op: &OpTy<'tcx>, lock_layout: TyAndLayout<'tcx>, offset: u64, ) -> InterpResult<'tcx, RwLockId> { @@ -311,7 +311,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn condvar_get_or_create_id( &mut self, - lock_op: &OpTy<'tcx, Provenance>, + lock_op: &OpTy<'tcx>, lock_layout: TyAndLayout<'tcx>, offset: u64, ) -> InterpResult<'tcx, CondvarId> { @@ -393,12 +393,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// Put the thread into the queue waiting for the mutex. /// Once the Mutex becomes available, `retval` will be written to `dest`. #[inline] - fn mutex_enqueue_and_block( - &mut self, - id: MutexId, - retval: Scalar, - dest: MPlaceTy<'tcx, Provenance>, - ) { + fn mutex_enqueue_and_block(&mut self, id: MutexId, retval: Scalar, dest: MPlaceTy<'tcx>) { let this = self.eval_context_mut(); assert!(this.mutex_is_locked(id), "queing on unlocked mutex"); let thread = this.active_thread(); @@ -409,8 +404,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { callback!( @capture<'tcx> { id: MutexId, - retval: Scalar, - dest: MPlaceTy<'tcx, Provenance>, + retval: Scalar, + dest: MPlaceTy<'tcx>, } @unblock = |this| { assert!(!this.mutex_is_locked(id)); @@ -506,8 +501,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn rwlock_enqueue_and_block_reader( &mut self, id: RwLockId, - retval: Scalar, - dest: MPlaceTy<'tcx, Provenance>, + retval: Scalar, + dest: MPlaceTy<'tcx>, ) { let this = self.eval_context_mut(); let thread = this.active_thread(); @@ -519,8 +514,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { callback!( @capture<'tcx> { id: RwLockId, - retval: Scalar, - dest: MPlaceTy<'tcx, Provenance>, + retval: Scalar, + dest: MPlaceTy<'tcx>, } @unblock = |this| { this.rwlock_reader_lock(id); @@ -589,8 +584,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn rwlock_enqueue_and_block_writer( &mut self, id: RwLockId, - retval: Scalar, - dest: MPlaceTy<'tcx, Provenance>, + retval: Scalar, + dest: MPlaceTy<'tcx>, ) { let this = self.eval_context_mut(); assert!(this.rwlock_is_locked(id), "write-queueing on unlocked rwlock"); @@ -602,8 +597,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { callback!( @capture<'tcx> { id: RwLockId, - retval: Scalar, - dest: MPlaceTy<'tcx, Provenance>, + retval: Scalar, + dest: MPlaceTy<'tcx>, } @unblock = |this| { this.rwlock_writer_lock(id); @@ -629,9 +624,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { condvar: CondvarId, mutex: MutexId, timeout: Option, - retval_succ: Scalar, - retval_timeout: Scalar, - dest: MPlaceTy<'tcx, Provenance>, + retval_succ: Scalar, + retval_timeout: Scalar, + dest: MPlaceTy<'tcx>, ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); if let Some(old_locked_count) = this.mutex_unlock(mutex)? { @@ -655,9 +650,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { @capture<'tcx> { condvar: CondvarId, mutex: MutexId, - retval_succ: Scalar, - retval_timeout: Scalar, - dest: MPlaceTy<'tcx, Provenance>, + retval_succ: Scalar, + retval_timeout: Scalar, + dest: MPlaceTy<'tcx>, } @unblock = |this| { // The condvar was signaled. Make sure we get the clock for that. @@ -710,10 +705,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { addr: u64, bitset: u32, timeout: Option, - retval_succ: Scalar, - retval_timeout: Scalar, - dest: MPlaceTy<'tcx, Provenance>, - errno_timeout: Scalar, + retval_succ: Scalar, + retval_timeout: Scalar, + dest: MPlaceTy<'tcx>, + errno_timeout: Scalar, ) { let this = self.eval_context_mut(); let thread = this.active_thread(); @@ -727,10 +722,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { callback!( @capture<'tcx> { addr: u64, - retval_succ: Scalar, - retval_timeout: Scalar, - dest: MPlaceTy<'tcx, Provenance>, - errno_timeout: Scalar, + retval_succ: Scalar, + retval_timeout: Scalar, + dest: MPlaceTy<'tcx>, + errno_timeout: Scalar, } @unblock = |this| { let futex = this.machine.sync.futexes.get(&addr).unwrap(); diff --git a/src/tools/miri/src/concurrency/thread.rs b/src/tools/miri/src/concurrency/thread.rs index 8e8e1182bfffe..16fb69f3c5f2c 100644 --- a/src/tools/miri/src/concurrency/thread.rs +++ b/src/tools/miri/src/concurrency/thread.rs @@ -256,10 +256,10 @@ pub struct Thread<'tcx> { /// which then forwards it to 'Resume'. However this argument is implicit in MIR, /// so we have to store it out-of-band. When there are multiple active unwinds, /// the innermost one is always caught first, so we can store them as a stack. - pub(crate) panic_payloads: Vec>, + pub(crate) panic_payloads: Vec, /// Last OS error location in memory. It is a 32-bit integer. - pub(crate) last_error: Option>, + pub(crate) last_error: Option>, } pub type StackEmptyCallback<'tcx> = @@ -877,10 +877,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { #[inline] fn start_regular_thread( &mut self, - thread: Option>, + thread: Option>, start_routine: Pointer>, start_abi: Abi, - func_arg: ImmTy<'tcx, Provenance>, + func_arg: ImmTy<'tcx>, ret_layout: TyAndLayout<'tcx>, ) -> InterpResult<'tcx, ThreadId> { let this = self.eval_context_mut(); diff --git a/src/tools/miri/src/concurrency/weak_memory.rs b/src/tools/miri/src/concurrency/weak_memory.rs index 7a49f6d34707b..e92eaa8f91f75 100644 --- a/src/tools/miri/src/concurrency/weak_memory.rs +++ b/src/tools/miri/src/concurrency/weak_memory.rs @@ -148,7 +148,7 @@ struct StoreElement { // FIXME: this means the store must be fully initialized; // we will have to change this if we want to support atomics on // (partially) uninitialized data. - val: Scalar, + val: Scalar, /// Metadata about loads from this store element, /// behind a RefCell to keep load op take &self @@ -197,7 +197,7 @@ impl StoreBufferAlloc { fn get_or_create_store_buffer<'tcx>( &self, range: AllocRange, - init: Scalar, + init: Scalar, ) -> InterpResult<'tcx, Ref<'_, StoreBuffer>> { let access_type = self.store_buffers.borrow().access_type(range); let pos = match access_type { @@ -222,7 +222,7 @@ impl StoreBufferAlloc { fn get_or_create_store_buffer_mut<'tcx>( &mut self, range: AllocRange, - init: Scalar, + init: Scalar, ) -> InterpResult<'tcx, &mut StoreBuffer> { let buffers = self.store_buffers.get_mut(); let access_type = buffers.access_type(range); @@ -244,7 +244,7 @@ impl StoreBufferAlloc { } impl<'tcx> StoreBuffer { - fn new(init: Scalar) -> Self { + fn new(init: Scalar) -> Self { let mut buffer = VecDeque::new(); buffer.reserve(STORE_BUFFER_LIMIT); let mut ret = Self { buffer }; @@ -282,7 +282,7 @@ impl<'tcx> StoreBuffer { is_seqcst: bool, rng: &mut (impl rand::Rng + ?Sized), validate: impl FnOnce() -> InterpResult<'tcx>, - ) -> InterpResult<'tcx, (Scalar, LoadRecency)> { + ) -> InterpResult<'tcx, (Scalar, LoadRecency)> { // Having a live borrow to store_buffer while calling validate_atomic_load is fine // because the race detector doesn't touch store_buffer @@ -307,7 +307,7 @@ impl<'tcx> StoreBuffer { fn buffered_write( &mut self, - val: Scalar, + val: Scalar, global: &DataRaceState, thread_mgr: &ThreadManager<'_>, is_seqcst: bool, @@ -408,7 +408,7 @@ impl<'tcx> StoreBuffer { /// ATOMIC STORE IMPL in the paper (except we don't need the location's vector clock) fn store_impl( &mut self, - val: Scalar, + val: Scalar, index: VectorIdx, thread_clock: &VClock, is_seqcst: bool, @@ -450,12 +450,7 @@ impl StoreElement { /// buffer regardless of subsequent loads by the same thread; if the earliest load of another /// thread doesn't happen before the current one, then no subsequent load by the other thread /// can happen before the current one. - fn load_impl( - &self, - index: VectorIdx, - clocks: &ThreadClockSet, - is_seqcst: bool, - ) -> Scalar { + fn load_impl(&self, index: VectorIdx, clocks: &ThreadClockSet, is_seqcst: bool) -> Scalar { let mut load_info = self.load_info.borrow_mut(); load_info.sc_loaded |= is_seqcst; let _ = load_info.timestamps.try_insert(index, clocks.clock[index]); @@ -467,10 +462,10 @@ impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {} pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn buffered_atomic_rmw( &mut self, - new_val: Scalar, - place: &MPlaceTy<'tcx, Provenance>, + new_val: Scalar, + place: &MPlaceTy<'tcx>, atomic: AtomicRwOrd, - init: Scalar, + init: Scalar, ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); let (alloc_id, base_offset, ..) = this.ptr_get_alloc_id(place.ptr())?; @@ -493,11 +488,11 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn buffered_atomic_read( &self, - place: &MPlaceTy<'tcx, Provenance>, + place: &MPlaceTy<'tcx>, atomic: AtomicReadOrd, - latest_in_mo: Scalar, + latest_in_mo: Scalar, validate: impl FnOnce() -> InterpResult<'tcx>, - ) -> InterpResult<'tcx, Scalar> { + ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_ref(); if let Some(global) = &this.machine.data_race { let (alloc_id, base_offset, ..) = this.ptr_get_alloc_id(place.ptr())?; @@ -534,10 +529,10 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn buffered_atomic_write( &mut self, - val: Scalar, - dest: &MPlaceTy<'tcx, Provenance>, + val: Scalar, + dest: &MPlaceTy<'tcx>, atomic: AtomicWriteOrd, - init: Scalar, + init: Scalar, ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); let (alloc_id, base_offset, ..) = this.ptr_get_alloc_id(dest.ptr())?; @@ -579,9 +574,9 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// to perform load_impl on the latest store element fn perform_read_on_buffered_latest( &self, - place: &MPlaceTy<'tcx, Provenance>, + place: &MPlaceTy<'tcx>, atomic: AtomicReadOrd, - init: Scalar, + init: Scalar, ) -> InterpResult<'tcx> { let this = self.eval_context_ref(); diff --git a/src/tools/miri/src/helpers.rs b/src/tools/miri/src/helpers.rs index 5c3b8f2d2a052..6d860f6661a33 100644 --- a/src/tools/miri/src/helpers.rs +++ b/src/tools/miri/src/helpers.rs @@ -255,7 +255,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } /// Evaluates the scalar at the specified path. - fn eval_path(&self, path: &[&str]) -> OpTy<'tcx, Provenance> { + fn eval_path(&self, path: &[&str]) -> OpTy<'tcx> { let this = self.eval_context_ref(); let instance = this.resolve_path(path, Namespace::ValueNS); // We don't give a span -- this isn't actually used directly by the program anyway. @@ -264,7 +264,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { }); const_val.into() } - fn eval_path_scalar(&self, path: &[&str]) -> Scalar { + fn eval_path_scalar(&self, path: &[&str]) -> Scalar { let this = self.eval_context_ref(); let val = this.eval_path(path); this.read_scalar(&val) @@ -272,7 +272,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } /// Helper function to get a `libc` constant as a `Scalar`. - fn eval_libc(&self, name: &str) -> Scalar { + fn eval_libc(&self, name: &str) -> Scalar { self.eval_path_scalar(&["libc", name]) } @@ -293,7 +293,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } /// Helper function to get a `windows` constant as a `Scalar`. - fn eval_windows(&self, module: &str, name: &str) -> Scalar { + fn eval_windows(&self, module: &str, name: &str) -> Scalar { self.eval_context_ref().eval_path_scalar(&["std", "sys", "pal", "windows", module, name]) } @@ -453,7 +453,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { f: ty::Instance<'tcx>, caller_abi: Abi, args: &[Immediate], - dest: Option<&MPlaceTy<'tcx, Provenance>>, + dest: Option<&MPlaceTy<'tcx>>, stack_pop: StackPopCleanup, ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); @@ -501,7 +501,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// The range is relative to `place`. fn visit_freeze_sensitive( &self, - place: &MPlaceTy<'tcx, Provenance>, + place: &MPlaceTy<'tcx>, size: Size, mut action: impl FnMut(AllocRange, bool) -> InterpResult<'tcx>, ) -> InterpResult<'tcx> { @@ -575,7 +575,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// whether we are inside an `UnsafeCell` or not. struct UnsafeCellVisitor<'ecx, 'tcx, F> where - F: FnMut(&MPlaceTy<'tcx, Provenance>) -> InterpResult<'tcx>, + F: FnMut(&MPlaceTy<'tcx>) -> InterpResult<'tcx>, { ecx: &'ecx MiriInterpCx<'tcx>, unsafe_cell_action: F, @@ -583,9 +583,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { impl<'ecx, 'tcx, F> ValueVisitor<'tcx, MiriMachine<'tcx>> for UnsafeCellVisitor<'ecx, 'tcx, F> where - F: FnMut(&MPlaceTy<'tcx, Provenance>) -> InterpResult<'tcx>, + F: FnMut(&MPlaceTy<'tcx>) -> InterpResult<'tcx>, { - type V = MPlaceTy<'tcx, Provenance>; + type V = MPlaceTy<'tcx>; #[inline(always)] fn ecx(&self) -> &MiriInterpCx<'tcx> { @@ -603,7 +603,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } // Hook to detect `UnsafeCell`. - fn visit_value(&mut self, v: &MPlaceTy<'tcx, Provenance>) -> InterpResult<'tcx> { + fn visit_value(&mut self, v: &MPlaceTy<'tcx>) -> InterpResult<'tcx> { trace!("UnsafeCellVisitor: {:?} {:?}", *v, v.layout.ty); let is_unsafe_cell = match v.layout.ty.kind() { ty::Adt(adt, _) => @@ -649,7 +649,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn visit_union( &mut self, - _v: &MPlaceTy<'tcx, Provenance>, + _v: &MPlaceTy<'tcx>, _fields: NonZero, ) -> InterpResult<'tcx> { bug!("we should have already handled unions in `visit_value`") @@ -720,7 +720,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// Get last error variable as a place, lazily allocating thread-local storage for it if /// necessary. - fn last_error_place(&mut self) -> InterpResult<'tcx, MPlaceTy<'tcx, Provenance>> { + fn last_error_place(&mut self) -> InterpResult<'tcx, MPlaceTy<'tcx>> { let this = self.eval_context_mut(); if let Some(errno_place) = this.active_thread_ref().last_error.as_ref() { Ok(errno_place.clone()) @@ -735,14 +735,14 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } /// Sets the last error variable. - fn set_last_error(&mut self, scalar: Scalar) -> InterpResult<'tcx> { + fn set_last_error(&mut self, scalar: Scalar) -> InterpResult<'tcx> { let this = self.eval_context_mut(); let errno_place = this.last_error_place()?; this.write_scalar(scalar, &errno_place) } /// Gets the last error variable. - fn get_last_error(&mut self) -> InterpResult<'tcx, Scalar> { + fn get_last_error(&mut self) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); let errno_place = this.last_error_place()?; this.read_scalar(&errno_place) @@ -750,7 +750,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// This function tries to produce the most similar OS error from the `std::io::ErrorKind` /// as a platform-specific errnum. - fn io_error_to_errnum(&self, err: std::io::Error) -> InterpResult<'tcx, Scalar> { + fn io_error_to_errnum(&self, err: std::io::Error) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_ref(); let target = &this.tcx.sess.target; if target.families.iter().any(|f| f == "unix") { @@ -779,7 +779,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { #[allow(clippy::needless_return)] fn try_errnum_to_io_error( &self, - errnum: Scalar, + errnum: Scalar, ) -> InterpResult<'tcx, Option> { let this = self.eval_context_ref(); let target = &this.tcx.sess.target; @@ -836,7 +836,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &self, op: &impl Readable<'tcx, Provenance>, layout: TyAndLayout<'tcx>, - ) -> InterpResult<'tcx, MPlaceTy<'tcx, Provenance>> { + ) -> InterpResult<'tcx, MPlaceTy<'tcx>> { let this = self.eval_context_ref(); let ptr = this.read_pointer(op)?; Ok(this.ptr_to_mplace(ptr, layout)) @@ -849,7 +849,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { offset: u64, base_layout: TyAndLayout<'tcx>, value_layout: TyAndLayout<'tcx>, - ) -> InterpResult<'tcx, MPlaceTy<'tcx, Provenance>> { + ) -> InterpResult<'tcx, MPlaceTy<'tcx>> { let this = self.eval_context_ref(); let op_place = this.deref_pointer_as(op, base_layout)?; let offset = Size::from_bytes(offset); @@ -866,7 +866,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { offset: u64, base_layout: TyAndLayout<'tcx>, value_layout: TyAndLayout<'tcx>, - ) -> InterpResult<'tcx, Scalar> { + ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_ref(); let value_place = this.deref_pointer_and_offset(op, offset, base_layout, value_layout)?; this.read_scalar(&value_place) @@ -876,7 +876,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, op: &impl Readable<'tcx, Provenance>, offset: u64, - value: impl Into>, + value: impl Into, base_layout: TyAndLayout<'tcx>, value_layout: TyAndLayout<'tcx>, ) -> InterpResult<'tcx, ()> { @@ -888,10 +888,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// Parse a `timespec` struct and return it as a `std::time::Duration`. It returns `None` /// if the value in the `timespec` struct is invalid. Some libc functions will return /// `EINVAL` in this case. - fn read_timespec( - &mut self, - tp: &MPlaceTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, Option> { + fn read_timespec(&mut self, tp: &MPlaceTy<'tcx>) -> InterpResult<'tcx, Option> { let this = self.eval_context_mut(); let seconds_place = this.project_field(tp, 0)?; let seconds_scalar = this.read_scalar(&seconds_place)?; @@ -914,10 +911,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } /// Read bytes from a byte slice. - fn read_byte_slice<'a>( - &'a self, - slice: &ImmTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, &'a [u8]> + fn read_byte_slice<'a>(&'a self, slice: &ImmTy<'tcx>) -> InterpResult<'tcx, &'a [u8]> where 'tcx: 'a, { @@ -1138,17 +1132,17 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { abi: Abi, exp_abi: Abi, link_name: Symbol, - args: &'a [OpTy<'tcx, Provenance>], - ) -> InterpResult<'tcx, &'a [OpTy<'tcx, Provenance>; N]> + args: &'a [OpTy<'tcx>], + ) -> InterpResult<'tcx, &'a [OpTy<'tcx>; N]> where - &'a [OpTy<'tcx, Provenance>; N]: TryFrom<&'a [OpTy<'tcx, Provenance>]>, + &'a [OpTy<'tcx>; N]: TryFrom<&'a [OpTy<'tcx>]>, { self.check_abi_and_shim_symbol_clash(abi, exp_abi, link_name)?; check_arg_count(args) } /// Mark a machine allocation that was just created as immutable. - fn mark_immutable(&mut self, mplace: &MPlaceTy<'tcx, Provenance>) { + fn mark_immutable(&mut self, mplace: &MPlaceTy<'tcx>) { let this = self.eval_context_mut(); // This got just allocated, so there definitely is a pointer here. let provenance = mplace.ptr().into_pointer_or_addr().unwrap().provenance; @@ -1168,10 +1162,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// Returns `None` if `f` is NaN or out of range. fn float_to_int_checked( &self, - src: &ImmTy<'tcx, Provenance>, + src: &ImmTy<'tcx>, cast_to: TyAndLayout<'tcx>, round: rustc_apfloat::Round, - ) -> InterpResult<'tcx, Option>> { + ) -> InterpResult<'tcx, Option>> { let this = self.eval_context_ref(); fn float_to_int_inner<'tcx, F: rustc_apfloat::Float>( @@ -1179,7 +1173,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { src: F, cast_to: TyAndLayout<'tcx>, round: rustc_apfloat::Round, - ) -> (Scalar, rustc_apfloat::Status) { + ) -> (Scalar, rustc_apfloat::Status) { let int_size = cast_to.layout.size; match cast_to.ty.kind() { // Unsigned @@ -1267,10 +1261,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } /// Lookup an array of immediates stored as a linker section of name `name`. - fn lookup_link_section( - &mut self, - name: &str, - ) -> InterpResult<'tcx, Vec>> { + fn lookup_link_section(&mut self, name: &str) -> InterpResult<'tcx, Vec>> { let this = self.eval_context_mut(); let tcx = this.tcx.tcx; @@ -1338,10 +1329,10 @@ impl<'tcx> MiriMachine<'tcx> { /// Check that the number of args is what we expect. pub fn check_arg_count<'a, 'tcx, const N: usize>( - args: &'a [OpTy<'tcx, Provenance>], -) -> InterpResult<'tcx, &'a [OpTy<'tcx, Provenance>; N]> + args: &'a [OpTy<'tcx>], +) -> InterpResult<'tcx, &'a [OpTy<'tcx>; N]> where - &'a [OpTy<'tcx, Provenance>; N]: TryFrom<&'a [OpTy<'tcx, Provenance>]>, + &'a [OpTy<'tcx>; N]: TryFrom<&'a [OpTy<'tcx>]>, { if let Ok(ops) = args.try_into() { return Ok(ops); @@ -1374,7 +1365,7 @@ pub fn get_local_crates(tcx: TyCtxt<'_>) -> Vec { local_crates } -pub(crate) fn bool_to_simd_element(b: bool, size: Size) -> Scalar { +pub(crate) fn bool_to_simd_element(b: bool, size: Size) -> Scalar { // SIMD uses all-1 as pattern for "true". In two's complement, // -1 has all its bits set to one and `from_int` will truncate or // sign-extend it to `size` as required. @@ -1382,7 +1373,7 @@ pub(crate) fn bool_to_simd_element(b: bool, size: Size) -> Scalar { Scalar::from_int(val, size) } -pub(crate) fn simd_element_to_bool(elem: ImmTy<'_, Provenance>) -> InterpResult<'_, bool> { +pub(crate) fn simd_element_to_bool(elem: ImmTy<'_>) -> InterpResult<'_, bool> { let val = elem.to_scalar().to_int(elem.layout.size)?; Ok(match val { 0 => false, diff --git a/src/tools/miri/src/intrinsics/atomic.rs b/src/tools/miri/src/intrinsics/atomic.rs index 17f95df9aa150..d76f622e84baf 100644 --- a/src/tools/miri/src/intrinsics/atomic.rs +++ b/src/tools/miri/src/intrinsics/atomic.rs @@ -18,8 +18,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn emulate_atomic_intrinsic( &mut self, intrinsic_name: &str, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { let this = self.eval_context_mut(); @@ -124,8 +124,8 @@ impl<'tcx> EvalContextPrivExt<'tcx> for MiriInterpCx<'tcx> {} trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> { fn atomic_load( &mut self, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, atomic: AtomicReadOrd, ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); @@ -140,11 +140,7 @@ trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> { Ok(()) } - fn atomic_store( - &mut self, - args: &[OpTy<'tcx, Provenance>], - atomic: AtomicWriteOrd, - ) -> InterpResult<'tcx> { + fn atomic_store(&mut self, args: &[OpTy<'tcx>], atomic: AtomicWriteOrd) -> InterpResult<'tcx> { let this = self.eval_context_mut(); let [place, val] = check_arg_count(args)?; @@ -159,7 +155,7 @@ trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> { fn compiler_fence_intrinsic( &mut self, - args: &[OpTy<'tcx, Provenance>], + args: &[OpTy<'tcx>], atomic: AtomicFenceOrd, ) -> InterpResult<'tcx> { let [] = check_arg_count(args)?; @@ -170,7 +166,7 @@ trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> { fn atomic_fence_intrinsic( &mut self, - args: &[OpTy<'tcx, Provenance>], + args: &[OpTy<'tcx>], atomic: AtomicFenceOrd, ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); @@ -181,8 +177,8 @@ trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> { fn atomic_rmw_op( &mut self, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, atomic_op: AtomicOp, atomic: AtomicRwOrd, ) -> InterpResult<'tcx> { @@ -223,8 +219,8 @@ trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> { fn atomic_exchange( &mut self, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, atomic: AtomicRwOrd, ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); @@ -240,8 +236,8 @@ trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> { fn atomic_compare_exchange_impl( &mut self, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, success: AtomicRwOrd, fail: AtomicReadOrd, can_fail_spuriously: bool, @@ -269,8 +265,8 @@ trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> { fn atomic_compare_exchange( &mut self, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, success: AtomicRwOrd, fail: AtomicReadOrd, ) -> InterpResult<'tcx> { @@ -279,8 +275,8 @@ trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> { fn atomic_compare_exchange_weak( &mut self, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, success: AtomicRwOrd, fail: AtomicReadOrd, ) -> InterpResult<'tcx> { diff --git a/src/tools/miri/src/intrinsics/mod.rs b/src/tools/miri/src/intrinsics/mod.rs index e39b78d3816f7..9f7e2baaaf972 100644 --- a/src/tools/miri/src/intrinsics/mod.rs +++ b/src/tools/miri/src/intrinsics/mod.rs @@ -23,8 +23,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn call_intrinsic( &mut self, instance: ty::Instance<'tcx>, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, ret: Option, unwind: mir::UnwindAction, ) -> InterpResult<'tcx, Option>> { @@ -79,8 +79,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, intrinsic_name: &str, generic_args: ty::GenericArgsRef<'tcx>, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, ret: Option, ) -> InterpResult<'tcx, EmulateItemResult> { let this = self.eval_context_mut(); @@ -385,7 +385,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { "frem_fast" => mir::BinOp::Rem, _ => bug!(), }; - let float_finite = |x: &ImmTy<'tcx, _>| -> InterpResult<'tcx, bool> { + let float_finite = |x: &ImmTy<'tcx>| -> InterpResult<'tcx, bool> { let ty::Float(fty) = x.layout.ty.kind() else { bug!("float_finite: non-float input type {}", x.layout.ty) }; diff --git a/src/tools/miri/src/intrinsics/simd.rs b/src/tools/miri/src/intrinsics/simd.rs index ed0c30e2a11a0..6d0682cd11088 100644 --- a/src/tools/miri/src/intrinsics/simd.rs +++ b/src/tools/miri/src/intrinsics/simd.rs @@ -23,8 +23,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, intrinsic_name: &str, generic_args: ty::GenericArgsRef<'tcx>, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { let this = self.eval_context_mut(); match intrinsic_name { @@ -760,9 +760,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn fminmax_op( &self, op: MinMax, - left: &ImmTy<'tcx, Provenance>, - right: &ImmTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, Scalar> { + left: &ImmTy<'tcx>, + right: &ImmTy<'tcx>, + ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_ref(); assert_eq!(left.layout.ty, right.layout.ty); let ty::Float(float_ty) = left.layout.ty.kind() else { diff --git a/src/tools/miri/src/lib.rs b/src/tools/miri/src/lib.rs index fa7c46f2a0158..0e79fef564eef 100644 --- a/src/tools/miri/src/lib.rs +++ b/src/tools/miri/src/lib.rs @@ -97,7 +97,14 @@ use tracing::{info, trace}; pub use rustc_const_eval::interpret::*; // Resolve ambiguity. #[doc(no_inline)] -pub use rustc_const_eval::interpret::{self, AllocMap, PlaceTy, Provenance as _}; +pub use rustc_const_eval::interpret::{self, AllocMap, Provenance as _}; + +// Type aliases that set the provenance parameter. +pub type Scalar = interpret::Scalar; +pub type ImmTy<'tcx> = interpret::ImmTy<'tcx, machine::Provenance>; +pub type OpTy<'tcx> = interpret::OpTy<'tcx, machine::Provenance>; +pub type PlaceTy<'tcx> = interpret::PlaceTy<'tcx, machine::Provenance>; +pub type MPlaceTy<'tcx> = interpret::MPlaceTy<'tcx, machine::Provenance>; pub use crate::intrinsics::EvalContextExt as _; pub use crate::shims::env::{EnvVars, EvalContextExt as _}; diff --git a/src/tools/miri/src/machine.rs b/src/tools/miri/src/machine.rs index fc1a655c1232f..1dc11054935f3 100644 --- a/src/tools/miri/src/machine.rs +++ b/src/tools/miri/src/machine.rs @@ -246,7 +246,7 @@ static_assert_size!(Pointer, 24); // #[cfg(target_pointer_width = "64")] //static_assert_size!(Pointer>, 24); #[cfg(target_pointer_width = "64")] -static_assert_size!(Scalar, 32); +static_assert_size!(Scalar, 32); impl fmt::Debug for Provenance { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { @@ -442,7 +442,7 @@ pub struct MiriMachine<'tcx> { pub(crate) env_vars: EnvVars<'tcx>, /// Return place of the main function. - pub(crate) main_fn_ret_place: Option>, + pub(crate) main_fn_ret_place: Option>, /// Program arguments (`Option` because we can only initialize them after creating the ecx). /// These are *pointers* to argc/argv because macOS. @@ -565,7 +565,7 @@ pub struct MiriMachine<'tcx> { /// Maps MIR consts to their evaluated result. We combine the const with a "salt" (`usize`) /// that is fixed per stack frame; this lets us have sometimes different results for the /// same const while ensuring consistent results within a single call. - const_cache: RefCell, usize), OpTy<'tcx, Provenance>>>, + const_cache: RefCell, usize), OpTy<'tcx>>>, /// For each allocation, an offset inside that allocation that was deemed aligned even for /// symbolic alignment checks. This cannot be stored in `AllocExtra` since it needs to be @@ -946,7 +946,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> { instance: ty::Instance<'tcx>, abi: Abi, args: &[FnArg<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + dest: &MPlaceTy<'tcx>, ret: Option, unwind: mir::UnwindAction, ) -> InterpResult<'tcx, Option<(&'tcx mir::Body<'tcx>, ty::Instance<'tcx>)>> { @@ -973,7 +973,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> { fn_val: DynSym, abi: Abi, args: &[FnArg<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + dest: &MPlaceTy<'tcx>, ret: Option, unwind: mir::UnwindAction, ) -> InterpResult<'tcx> { @@ -985,8 +985,8 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> { fn call_intrinsic( ecx: &mut MiriInterpCx<'tcx>, instance: ty::Instance<'tcx>, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, ret: Option, unwind: mir::UnwindAction, ) -> InterpResult<'tcx, Option>> { @@ -1027,9 +1027,9 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> { fn binary_ptr_op( ecx: &MiriInterpCx<'tcx>, bin_op: mir::BinOp, - left: &ImmTy<'tcx, Provenance>, - right: &ImmTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, ImmTy<'tcx, Provenance>> { + left: &ImmTy<'tcx>, + right: &ImmTy<'tcx>, + ) -> InterpResult<'tcx, ImmTy<'tcx>> { ecx.binary_ptr_op(bin_op, left, right) } @@ -1314,8 +1314,8 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> { fn retag_ptr_value( ecx: &mut InterpCx<'tcx, Self>, kind: mir::RetagKind, - val: &ImmTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, ImmTy<'tcx, Provenance>> { + val: &ImmTy<'tcx>, + ) -> InterpResult<'tcx, ImmTy<'tcx>> { if ecx.machine.borrow_tracker.is_some() { ecx.retag_ptr_value(kind, val) } else { @@ -1327,7 +1327,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> { fn retag_place_contents( ecx: &mut InterpCx<'tcx, Self>, kind: mir::RetagKind, - place: &PlaceTy<'tcx, Provenance>, + place: &PlaceTy<'tcx>, ) -> InterpResult<'tcx> { if ecx.machine.borrow_tracker.is_some() { ecx.retag_place_contents(kind, place)?; @@ -1337,7 +1337,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> { fn protect_in_place_function_argument( ecx: &mut InterpCx<'tcx, Self>, - place: &MPlaceTy<'tcx, Provenance>, + place: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx> { // If we have a borrow tracker, we also have it set up protection so that all reads *and // writes* during this call are insta-UB. @@ -1492,7 +1492,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> { fn after_local_allocated( ecx: &mut InterpCx<'tcx, Self>, local: mir::Local, - mplace: &MPlaceTy<'tcx, Provenance>, + mplace: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx> { let Some(Provenance::Concrete { alloc_id, .. }) = mplace.ptr().provenance else { panic!("after_local_allocated should only be called on fresh allocations"); @@ -1509,14 +1509,14 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> { span: Span, layout: Option>, eval: F, - ) -> InterpResult<'tcx, OpTy<'tcx, Self::Provenance>> + ) -> InterpResult<'tcx, OpTy<'tcx>> where F: Fn( &InterpCx<'tcx, Self>, mir::Const<'tcx>, Span, Option>, - ) -> InterpResult<'tcx, OpTy<'tcx, Self::Provenance>>, + ) -> InterpResult<'tcx, OpTy<'tcx>>, { let frame = ecx.active_thread_stack().last().unwrap(); let mut cache = ecx.machine.const_cache.borrow_mut(); diff --git a/src/tools/miri/src/operator.rs b/src/tools/miri/src/operator.rs index c04f12c339e0c..bc44e672bd85e 100644 --- a/src/tools/miri/src/operator.rs +++ b/src/tools/miri/src/operator.rs @@ -12,9 +12,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn binary_ptr_op( &self, bin_op: mir::BinOp, - left: &ImmTy<'tcx, Provenance>, - right: &ImmTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, ImmTy<'tcx, Provenance>> { + left: &ImmTy<'tcx>, + right: &ImmTy<'tcx>, + ) -> InterpResult<'tcx, ImmTy<'tcx>> { use rustc_middle::mir::BinOp::*; let this = self.eval_context_ref(); diff --git a/src/tools/miri/src/provenance_gc.rs b/src/tools/miri/src/provenance_gc.rs index 03b6cfdce7bc0..67190d3849bfe 100644 --- a/src/tools/miri/src/provenance_gc.rs +++ b/src/tools/miri/src/provenance_gc.rs @@ -70,7 +70,7 @@ impl VisitProvenance for Pointer> { } } -impl VisitProvenance for Scalar { +impl VisitProvenance for Scalar { fn visit_provenance(&self, visit: &mut VisitWith<'_>) { match self { Scalar::Ptr(ptr, _) => ptr.visit_provenance(visit), @@ -103,20 +103,20 @@ impl VisitProvenance for MemPlaceMeta { } } -impl VisitProvenance for ImmTy<'_, Provenance> { +impl VisitProvenance for ImmTy<'_> { fn visit_provenance(&self, visit: &mut VisitWith<'_>) { (**self).visit_provenance(visit) } } -impl VisitProvenance for MPlaceTy<'_, Provenance> { +impl VisitProvenance for MPlaceTy<'_> { fn visit_provenance(&self, visit: &mut VisitWith<'_>) { self.ptr().visit_provenance(visit); self.meta().visit_provenance(visit); } } -impl VisitProvenance for PlaceTy<'_, Provenance> { +impl VisitProvenance for PlaceTy<'_> { fn visit_provenance(&self, visit: &mut VisitWith<'_>) { match self.as_mplace_or_local() { Either::Left(mplace) => mplace.visit_provenance(visit), @@ -125,7 +125,7 @@ impl VisitProvenance for PlaceTy<'_, Provenance> { } } -impl VisitProvenance for OpTy<'_, Provenance> { +impl VisitProvenance for OpTy<'_> { fn visit_provenance(&self, visit: &mut VisitWith<'_>) { match self.as_mplace_or_imm() { Either::Left(mplace) => mplace.visit_provenance(visit), diff --git a/src/tools/miri/src/shims/alloc.rs b/src/tools/miri/src/shims/alloc.rs index bbe4bdd8450ca..d1e5dca0bef05 100644 --- a/src/tools/miri/src/shims/alloc.rs +++ b/src/tools/miri/src/shims/alloc.rs @@ -113,10 +113,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn posix_memalign( &mut self, - memptr: &OpTy<'tcx, Provenance>, - align: &OpTy<'tcx, Provenance>, - size: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, Scalar> { + memptr: &OpTy<'tcx>, + align: &OpTy<'tcx>, + size: &OpTy<'tcx>, + ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); let memptr = this.deref_pointer(memptr)?; let align = this.read_target_usize(align)?; @@ -175,8 +175,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn aligned_alloc( &mut self, - align: &OpTy<'tcx, Provenance>, - size: &OpTy<'tcx, Provenance>, + align: &OpTy<'tcx>, + size: &OpTy<'tcx>, ) -> InterpResult<'tcx, Pointer>> { let this = self.eval_context_mut(); let align = this.read_target_usize(align)?; diff --git a/src/tools/miri/src/shims/backtrace.rs b/src/tools/miri/src/shims/backtrace.rs index 6ec65a16b8a45..06be9c1e63e06 100644 --- a/src/tools/miri/src/shims/backtrace.rs +++ b/src/tools/miri/src/shims/backtrace.rs @@ -11,8 +11,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, abi: Abi, link_name: Symbol, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); let [flags] = this.check_shim(abi, Abi::Rust, link_name, args)?; @@ -31,8 +31,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, abi: Abi, link_name: Symbol, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); let tcx = this.tcx; @@ -110,7 +110,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn resolve_frame_pointer( &mut self, - ptr: &OpTy<'tcx, Provenance>, + ptr: &OpTy<'tcx>, ) -> InterpResult<'tcx, (Instance<'tcx>, Loc, String, String)> { let this = self.eval_context_mut(); @@ -140,8 +140,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, abi: Abi, link_name: Symbol, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); let [ptr, flags] = this.check_shim(abi, Abi::Rust, link_name, args)?; @@ -218,7 +218,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, abi: Abi, link_name: Symbol, - args: &[OpTy<'tcx, Provenance>], + args: &[OpTy<'tcx>], ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); diff --git a/src/tools/miri/src/shims/extern_static.rs b/src/tools/miri/src/shims/extern_static.rs index 9330ac0b4dd8d..17ac2638a69f4 100644 --- a/src/tools/miri/src/shims/extern_static.rs +++ b/src/tools/miri/src/shims/extern_static.rs @@ -6,7 +6,7 @@ impl<'tcx> MiriMachine<'tcx> { fn alloc_extern_static( this: &mut MiriInterpCx<'tcx>, name: &str, - val: ImmTy<'tcx, Provenance>, + val: ImmTy<'tcx>, ) -> InterpResult<'tcx> { let place = this.allocate(val.layout, MiriMemoryKind::ExternStatic.into())?; this.write_immediate(*val, &place)?; diff --git a/src/tools/miri/src/shims/foreign_items.rs b/src/tools/miri/src/shims/foreign_items.rs index 6dfd9866cae97..898fc111fd43f 100644 --- a/src/tools/miri/src/shims/foreign_items.rs +++ b/src/tools/miri/src/shims/foreign_items.rs @@ -40,8 +40,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, link_name: Symbol, abi: Abi, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, ret: Option, unwind: mir::UnwindAction, ) -> InterpResult<'tcx, Option<(&'tcx mir::Body<'tcx>, ty::Instance<'tcx>)>> { @@ -123,8 +123,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, sym: DynSym, abi: Abi, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, ret: Option, unwind: mir::UnwindAction, ) -> InterpResult<'tcx> { @@ -208,8 +208,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, link_name: Symbol, abi: Abi, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { let this = self.eval_context_mut(); @@ -238,11 +238,11 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> { // ``` // fn shim_name( // &mut self, - // arg1: &OpTy<'tcx, Provenance>, - // arg2: &OpTy<'tcx, Provenance>, - // arg3: &OpTy<'tcx, Provenance>, - // arg4: &OpTy<'tcx, Provenance>) - // -> InterpResult<'tcx, Scalar> { + // arg1: &OpTy<'tcx>, + // arg2: &OpTy<'tcx>, + // arg3: &OpTy<'tcx>, + // arg4: &OpTy<'tcx>) + // -> InterpResult<'tcx, Scalar> { // let this = self.eval_context_mut(); // // // First thing: load all the arguments. Details depend on the shim. diff --git a/src/tools/miri/src/shims/native_lib.rs b/src/tools/miri/src/shims/native_lib.rs index cc5cc75332aa6..40697e17ba193 100644 --- a/src/tools/miri/src/shims/native_lib.rs +++ b/src/tools/miri/src/shims/native_lib.rs @@ -14,10 +14,10 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> { fn call_native_with_args<'a>( &mut self, link_name: Symbol, - dest: &MPlaceTy<'tcx, Provenance>, + dest: &MPlaceTy<'tcx>, ptr: CodePtr, libffi_args: Vec>, - ) -> InterpResult<'tcx, ImmTy<'tcx, Provenance>> { + ) -> InterpResult<'tcx, ImmTy<'tcx>> { let this = self.eval_context_mut(); // Call the function (`ptr`) with arguments `libffi_args`, and obtain the return value @@ -132,8 +132,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn call_native_fn( &mut self, link_name: Symbol, - dest: &MPlaceTy<'tcx, Provenance>, - args: &[OpTy<'tcx, Provenance>], + dest: &MPlaceTy<'tcx>, + args: &[OpTy<'tcx>], ) -> InterpResult<'tcx, bool> { let this = self.eval_context_mut(); // Get the pointer to the function in the shared object file if it exists. @@ -216,10 +216,7 @@ impl<'a> CArg { /// Extract the scalar value from the result of reading a scalar from the machine, /// and convert it to a `CArg`. -fn imm_to_carg<'tcx>( - v: ImmTy<'tcx, Provenance>, - cx: &impl HasDataLayout, -) -> InterpResult<'tcx, CArg> { +fn imm_to_carg<'tcx>(v: ImmTy<'tcx>, cx: &impl HasDataLayout) -> InterpResult<'tcx, CArg> { Ok(match v.layout.ty.kind() { // If the primitive provided can be converted to a type matching the type pattern // then create a `CArg` of this primitive value with the corresponding `CArg` constructor. diff --git a/src/tools/miri/src/shims/panic.rs b/src/tools/miri/src/shims/panic.rs index 8aed6d4f463fa..3c9c0eb5c60d8 100644 --- a/src/tools/miri/src/shims/panic.rs +++ b/src/tools/miri/src/shims/panic.rs @@ -25,9 +25,9 @@ pub struct CatchUnwindData<'tcx> { /// The `catch_fn` callback to call in case of a panic. catch_fn: Pointer>, /// The `data` argument for that callback. - data: Scalar, + data: Scalar, /// The return place from the original call to `try`. - dest: MPlaceTy<'tcx, Provenance>, + dest: MPlaceTy<'tcx>, /// The return block from the original call to `try`. ret: Option, } @@ -45,7 +45,7 @@ impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {} pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// Handles the special `miri_start_unwind` intrinsic, which is called /// by libpanic_unwind to delegate the actual unwinding process to Miri. - fn handle_miri_start_unwind(&mut self, payload: &OpTy<'tcx, Provenance>) -> InterpResult<'tcx> { + fn handle_miri_start_unwind(&mut self, payload: &OpTy<'tcx>) -> InterpResult<'tcx> { let this = self.eval_context_mut(); trace!("miri_start_unwind: {:?}", this.frame().instance); @@ -60,8 +60,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// Handles the `try` intrinsic, the underlying implementation of `std::panicking::try`. fn handle_catch_unwind( &mut self, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, ret: Option, ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); diff --git a/src/tools/miri/src/shims/time.rs b/src/tools/miri/src/shims/time.rs index 9fb7a735c30b3..963ee1c3e627f 100644 --- a/src/tools/miri/src/shims/time.rs +++ b/src/tools/miri/src/shims/time.rs @@ -18,9 +18,9 @@ impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {} pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn clock_gettime( &mut self, - clk_id_op: &OpTy<'tcx, Provenance>, - tp_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, Scalar> { + clk_id_op: &OpTy<'tcx>, + tp_op: &OpTy<'tcx>, + ) -> InterpResult<'tcx, Scalar> { // This clock support is deliberately minimal because a lot of clock types have fiddly // properties (is it possible for Miri to be suspended independently of the host?). If you // have a use for another clock type, please open an issue. @@ -93,11 +93,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { Ok(Scalar::from_i32(0)) } - fn gettimeofday( - &mut self, - tv_op: &OpTy<'tcx, Provenance>, - tz_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, i32> { + fn gettimeofday(&mut self, tv_op: &OpTy<'tcx>, tz_op: &OpTy<'tcx>) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); this.assert_target_os_is_unix("gettimeofday"); @@ -127,8 +123,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { // https://linux.die.net/man/3/localtime_r fn localtime_r( &mut self, - timep: &OpTy<'tcx, Provenance>, - result_op: &OpTy<'tcx, Provenance>, + timep: &OpTy<'tcx>, + result_op: &OpTy<'tcx>, ) -> InterpResult<'tcx, Pointer>> { let this = self.eval_context_mut(); @@ -212,7 +208,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn GetSystemTimeAsFileTime( &mut self, shim_name: &str, - LPFILETIME_op: &OpTy<'tcx, Provenance>, + LPFILETIME_op: &OpTy<'tcx>, ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); @@ -242,8 +238,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { #[allow(non_snake_case)] fn QueryPerformanceCounter( &mut self, - lpPerformanceCount_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, Scalar> { + lpPerformanceCount_op: &OpTy<'tcx>, + ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); this.assert_target_os("windows", "QueryPerformanceCounter"); @@ -261,8 +257,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { #[allow(non_snake_case)] fn QueryPerformanceFrequency( &mut self, - lpFrequency_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, Scalar> { + lpFrequency_op: &OpTy<'tcx>, + ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); this.assert_target_os("windows", "QueryPerformanceFrequency"); @@ -279,7 +275,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { Ok(Scalar::from_i32(-1)) // Return non-zero on success } - fn mach_absolute_time(&self) -> InterpResult<'tcx, Scalar> { + fn mach_absolute_time(&self) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_ref(); this.assert_target_os("macos", "mach_absolute_time"); @@ -293,10 +289,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { Ok(Scalar::from_u64(res)) } - fn mach_timebase_info( - &mut self, - info_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, Scalar> { + fn mach_timebase_info(&mut self, info_op: &OpTy<'tcx>) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); this.assert_target_os("macos", "mach_timebase_info"); @@ -313,8 +306,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn nanosleep( &mut self, - req_op: &OpTy<'tcx, Provenance>, - _rem: &OpTy<'tcx, Provenance>, // Signal handlers are not supported, so rem will never be written to. + req_op: &OpTy<'tcx>, + _rem: &OpTy<'tcx>, // Signal handlers are not supported, so rem will never be written to. ) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); @@ -350,7 +343,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } #[allow(non_snake_case)] - fn Sleep(&mut self, timeout: &OpTy<'tcx, Provenance>) -> InterpResult<'tcx> { + fn Sleep(&mut self, timeout: &OpTy<'tcx>) -> InterpResult<'tcx> { let this = self.eval_context_mut(); this.assert_target_os("windows", "Sleep"); diff --git a/src/tools/miri/src/shims/tls.rs b/src/tools/miri/src/shims/tls.rs index fa52b036ce948..c91386fa877fb 100644 --- a/src/tools/miri/src/shims/tls.rs +++ b/src/tools/miri/src/shims/tls.rs @@ -16,7 +16,7 @@ pub type TlsKey = u128; pub struct TlsEntry<'tcx> { /// The data for this key. None is used to represent NULL. /// (We normalize this early to avoid having to do a NULL-ptr-test each time we access the data.) - data: BTreeMap>, + data: BTreeMap, dtor: Option>, } @@ -38,7 +38,7 @@ pub struct TlsData<'tcx> { /// A single per thread destructor of the thread local storage (that's how /// things work on macOS) with a data argument. - macos_thread_dtors: BTreeMap, Scalar)>, + macos_thread_dtors: BTreeMap, Scalar)>, } impl<'tcx> Default for TlsData<'tcx> { @@ -86,7 +86,7 @@ impl<'tcx> TlsData<'tcx> { key: TlsKey, thread_id: ThreadId, cx: &impl HasDataLayout, - ) -> InterpResult<'tcx, Scalar> { + ) -> InterpResult<'tcx, Scalar> { match self.keys.get(&key) { Some(TlsEntry { data, .. }) => { let value = data.get(&thread_id).copied(); @@ -101,7 +101,7 @@ impl<'tcx> TlsData<'tcx> { &mut self, key: TlsKey, thread_id: ThreadId, - new_data: Scalar, + new_data: Scalar, cx: &impl HasDataLayout, ) -> InterpResult<'tcx> { match self.keys.get_mut(&key) { @@ -132,7 +132,7 @@ impl<'tcx> TlsData<'tcx> { &mut self, thread: ThreadId, dtor: ty::Instance<'tcx>, - data: Scalar, + data: Scalar, ) -> InterpResult<'tcx> { if self.macos_thread_dtors.insert(thread, (dtor, data)).is_some() { throw_unsup_format!( @@ -165,7 +165,7 @@ impl<'tcx> TlsData<'tcx> { &mut self, key: Option, thread_id: ThreadId, - ) -> Option<(ty::Instance<'tcx>, Scalar, TlsKey)> { + ) -> Option<(ty::Instance<'tcx>, Scalar, TlsKey)> { use std::ops::Bound::*; let thread_local = &mut self.keys; @@ -228,7 +228,7 @@ enum TlsDtorsStatePriv<'tcx> { PthreadDtors(RunningDtorState), /// For Windows Dtors, we store the list of functions that we still have to call. /// These are functions from the magic `.CRT$XLB` linker section. - WindowsDtors(Vec>), + WindowsDtors(Vec>), Done, } @@ -297,7 +297,7 @@ impl<'tcx> EvalContextPrivExt<'tcx> for crate::MiriInterpCx<'tcx> {} trait EvalContextPrivExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// Schedule TLS destructors for Windows. /// On windows, TLS destructors are managed by std. - fn lookup_windows_tls_dtors(&mut self) -> InterpResult<'tcx, Vec>> { + fn lookup_windows_tls_dtors(&mut self) -> InterpResult<'tcx, Vec>> { let this = self.eval_context_mut(); // Windows has a special magic linker section that is run on certain events. @@ -305,7 +305,7 @@ trait EvalContextPrivExt<'tcx>: crate::MiriInterpCxExt<'tcx> { Ok(this.lookup_link_section(".CRT$XLB")?) } - fn schedule_windows_tls_dtor(&mut self, dtor: ImmTy<'tcx, Provenance>) -> InterpResult<'tcx> { + fn schedule_windows_tls_dtor(&mut self, dtor: ImmTy<'tcx>) -> InterpResult<'tcx> { let this = self.eval_context_mut(); let dtor = dtor.to_scalar().to_pointer(this)?; diff --git a/src/tools/miri/src/shims/unix/android/foreign_items.rs b/src/tools/miri/src/shims/unix/android/foreign_items.rs index 8a6e025ee18f9..42552a51edae3 100644 --- a/src/tools/miri/src/shims/unix/android/foreign_items.rs +++ b/src/tools/miri/src/shims/unix/android/foreign_items.rs @@ -13,8 +13,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, link_name: Symbol, abi: Abi, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { let this = self.eval_context_mut(); match link_name.as_str() { diff --git a/src/tools/miri/src/shims/unix/env.rs b/src/tools/miri/src/shims/unix/env.rs index 26096910aa196..f21207c52f55b 100644 --- a/src/tools/miri/src/shims/unix/env.rs +++ b/src/tools/miri/src/shims/unix/env.rs @@ -16,7 +16,7 @@ pub struct UnixEnvVars<'tcx> { map: FxHashMap>>, /// Place where the `environ` static is stored. Lazily initialized, but then never changes. - environ: MPlaceTy<'tcx, Provenance>, + environ: MPlaceTy<'tcx>, } impl VisitProvenance for UnixEnvVars<'_> { @@ -139,10 +139,7 @@ fn alloc_environ_block<'tcx>( impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {} pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { - fn getenv( - &mut self, - name_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, Pointer>> { + fn getenv(&mut self, name_op: &OpTy<'tcx>) -> InterpResult<'tcx, Pointer>> { let this = self.eval_context_mut(); this.assert_target_os_is_unix("getenv"); @@ -153,11 +150,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { Ok(var_ptr.unwrap_or_else(Pointer::null)) } - fn setenv( - &mut self, - name_op: &OpTy<'tcx, Provenance>, - value_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, i32> { + fn setenv(&mut self, name_op: &OpTy<'tcx>, value_op: &OpTy<'tcx>) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); this.assert_target_os_is_unix("setenv"); @@ -187,7 +180,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } } - fn unsetenv(&mut self, name_op: &OpTy<'tcx, Provenance>) -> InterpResult<'tcx, i32> { + fn unsetenv(&mut self, name_op: &OpTy<'tcx>) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); this.assert_target_os_is_unix("unsetenv"); @@ -215,8 +208,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn getcwd( &mut self, - buf_op: &OpTy<'tcx, Provenance>, - size_op: &OpTy<'tcx, Provenance>, + buf_op: &OpTy<'tcx>, + size_op: &OpTy<'tcx>, ) -> InterpResult<'tcx, Pointer>> { let this = self.eval_context_mut(); this.assert_target_os_is_unix("getcwd"); @@ -245,7 +238,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { Ok(Pointer::null()) } - fn chdir(&mut self, path_op: &OpTy<'tcx, Provenance>) -> InterpResult<'tcx, i32> { + fn chdir(&mut self, path_op: &OpTy<'tcx>) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); this.assert_target_os_is_unix("chdir"); diff --git a/src/tools/miri/src/shims/unix/fd.rs b/src/tools/miri/src/shims/unix/fd.rs index 5fdd77a0cbdb0..4a1a4466ddbde 100644 --- a/src/tools/miri/src/shims/unix/fd.rs +++ b/src/tools/miri/src/shims/unix/fd.rs @@ -273,7 +273,7 @@ impl FdTable { impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {} pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { - fn fcntl(&mut self, args: &[OpTy<'tcx, Provenance>]) -> InterpResult<'tcx, i32> { + fn fcntl(&mut self, args: &[OpTy<'tcx>]) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); if args.len() < 2 { @@ -329,7 +329,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } } - fn close(&mut self, fd_op: &OpTy<'tcx, Provenance>) -> InterpResult<'tcx, Scalar> { + fn close(&mut self, fd_op: &OpTy<'tcx>) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); let fd = this.read_scalar(fd_op)?.to_i32()?; diff --git a/src/tools/miri/src/shims/unix/foreign_items.rs b/src/tools/miri/src/shims/unix/foreign_items.rs index 052715e239f23..2282099fa0d23 100644 --- a/src/tools/miri/src/shims/unix/foreign_items.rs +++ b/src/tools/miri/src/shims/unix/foreign_items.rs @@ -43,8 +43,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, link_name: Symbol, abi: Abi, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { let this = self.eval_context_mut(); @@ -326,7 +326,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { let name = this.read_scalar(name)?.to_i32()?; // FIXME: Which of these are POSIX, and which are GNU/Linux? // At least the names seem to all also exist on macOS. - let sysconfs: &[(&str, fn(&MiriInterpCx<'_>) -> Scalar)] = &[ + let sysconfs: &[(&str, fn(&MiriInterpCx<'_>) -> Scalar)] = &[ ("_SC_PAGESIZE", |this| Scalar::from_int(this.machine.page_size, this.pointer_size())), ("_SC_NPROCESSORS_CONF", |this| Scalar::from_int(this.machine.num_cpus, this.pointer_size())), ("_SC_NPROCESSORS_ONLN", |this| Scalar::from_int(this.machine.num_cpus, this.pointer_size())), diff --git a/src/tools/miri/src/shims/unix/freebsd/foreign_items.rs b/src/tools/miri/src/shims/unix/freebsd/foreign_items.rs index 30eb88151e4b7..36f25767a8ea0 100644 --- a/src/tools/miri/src/shims/unix/freebsd/foreign_items.rs +++ b/src/tools/miri/src/shims/unix/freebsd/foreign_items.rs @@ -14,8 +14,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, link_name: Symbol, abi: Abi, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { let this = self.eval_context_mut(); match link_name.as_str() { diff --git a/src/tools/miri/src/shims/unix/fs.rs b/src/tools/miri/src/shims/unix/fs.rs index 8e3d547b0750c..438f8b2c7e652 100644 --- a/src/tools/miri/src/shims/unix/fs.rs +++ b/src/tools/miri/src/shims/unix/fs.rs @@ -91,7 +91,7 @@ trait EvalContextExtPrivate<'tcx>: crate::MiriInterpCxExt<'tcx> { fn macos_stat_write_buf( &mut self, metadata: FileMetadata, - buf_op: &OpTy<'tcx, Provenance>, + buf_op: &OpTy<'tcx>, ) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); @@ -256,7 +256,7 @@ fn maybe_sync_file( impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {} pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { - fn open(&mut self, args: &[OpTy<'tcx, Provenance>]) -> InterpResult<'tcx, i32> { + fn open(&mut self, args: &[OpTy<'tcx>]) -> InterpResult<'tcx, i32> { if args.len() < 2 { throw_ub_format!( "incorrect number of arguments for `open`: got {}, expected at least 2", @@ -389,12 +389,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { this.try_unwrap_io_result(fd) } - fn lseek64( - &mut self, - fd: i32, - offset: i128, - whence: i32, - ) -> InterpResult<'tcx, Scalar> { + fn lseek64(&mut self, fd: i32, offset: i128, whence: i32) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); // Isolation check is done via `FileDescriptor` trait. @@ -425,7 +420,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { Ok(Scalar::from_i64(result)) } - fn unlink(&mut self, path_op: &OpTy<'tcx, Provenance>) -> InterpResult<'tcx, i32> { + fn unlink(&mut self, path_op: &OpTy<'tcx>) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); let path = this.read_path_from_c_str(this.read_pointer(path_op)?)?; @@ -443,8 +438,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn symlink( &mut self, - target_op: &OpTy<'tcx, Provenance>, - linkpath_op: &OpTy<'tcx, Provenance>, + target_op: &OpTy<'tcx>, + linkpath_op: &OpTy<'tcx>, ) -> InterpResult<'tcx, i32> { #[cfg(unix)] fn create_link(src: &Path, dst: &Path) -> std::io::Result<()> { @@ -474,9 +469,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn macos_fbsd_stat( &mut self, - path_op: &OpTy<'tcx, Provenance>, - buf_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, Scalar> { + path_op: &OpTy<'tcx>, + buf_op: &OpTy<'tcx>, + ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); if !matches!(&*this.tcx.sess.target.os, "macos" | "freebsd") { @@ -506,9 +501,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { // `lstat` is used to get symlink metadata. fn macos_fbsd_lstat( &mut self, - path_op: &OpTy<'tcx, Provenance>, - buf_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, Scalar> { + path_op: &OpTy<'tcx>, + buf_op: &OpTy<'tcx>, + ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); if !matches!(&*this.tcx.sess.target.os, "macos" | "freebsd") { @@ -536,9 +531,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn macos_fbsd_fstat( &mut self, - fd_op: &OpTy<'tcx, Provenance>, - buf_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, Scalar> { + fd_op: &OpTy<'tcx>, + buf_op: &OpTy<'tcx>, + ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); if !matches!(&*this.tcx.sess.target.os, "macos" | "freebsd") { @@ -563,11 +558,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn linux_statx( &mut self, - dirfd_op: &OpTy<'tcx, Provenance>, // Should be an `int` - pathname_op: &OpTy<'tcx, Provenance>, // Should be a `const char *` - flags_op: &OpTy<'tcx, Provenance>, // Should be an `int` - mask_op: &OpTy<'tcx, Provenance>, // Should be an `unsigned int` - statxbuf_op: &OpTy<'tcx, Provenance>, // Should be a `struct statx *` + dirfd_op: &OpTy<'tcx>, // Should be an `int` + pathname_op: &OpTy<'tcx>, // Should be a `const char *` + flags_op: &OpTy<'tcx>, // Should be an `int` + mask_op: &OpTy<'tcx>, // Should be an `unsigned int` + statxbuf_op: &OpTy<'tcx>, // Should be a `struct statx *` ) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); @@ -745,8 +740,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn rename( &mut self, - oldpath_op: &OpTy<'tcx, Provenance>, - newpath_op: &OpTy<'tcx, Provenance>, + oldpath_op: &OpTy<'tcx>, + newpath_op: &OpTy<'tcx>, ) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); @@ -774,11 +769,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { this.try_unwrap_io_result(result) } - fn mkdir( - &mut self, - path_op: &OpTy<'tcx, Provenance>, - mode_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, i32> { + fn mkdir(&mut self, path_op: &OpTy<'tcx>, mode_op: &OpTy<'tcx>) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); #[cfg_attr(not(unix), allow(unused_variables))] @@ -813,7 +804,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { this.try_unwrap_io_result(result) } - fn rmdir(&mut self, path_op: &OpTy<'tcx, Provenance>) -> InterpResult<'tcx, i32> { + fn rmdir(&mut self, path_op: &OpTy<'tcx>) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); let path = this.read_path_from_c_str(this.read_pointer(path_op)?)?; @@ -830,10 +821,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { this.try_unwrap_io_result(result) } - fn opendir( - &mut self, - name_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, Scalar> { + fn opendir(&mut self, name_op: &OpTy<'tcx>) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); let name = this.read_path_from_c_str(this.read_pointer(name_op)?)?; @@ -864,10 +852,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } } - fn linux_readdir64( - &mut self, - dirp_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, Scalar> { + fn linux_readdir64(&mut self, dirp_op: &OpTy<'tcx>) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); this.assert_target_os("linux", "readdir64"); @@ -962,10 +947,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn macos_fbsd_readdir_r( &mut self, - dirp_op: &OpTy<'tcx, Provenance>, - entry_op: &OpTy<'tcx, Provenance>, - result_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, Scalar> { + dirp_op: &OpTy<'tcx>, + entry_op: &OpTy<'tcx>, + result_op: &OpTy<'tcx>, + ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); if !matches!(&*this.tcx.sess.target.os, "macos" | "freebsd") { @@ -1083,7 +1068,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { })) } - fn closedir(&mut self, dirp_op: &OpTy<'tcx, Provenance>) -> InterpResult<'tcx, i32> { + fn closedir(&mut self, dirp_op: &OpTy<'tcx>) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); let dirp = this.read_target_usize(dirp_op)?; @@ -1106,7 +1091,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } } - fn ftruncate64(&mut self, fd: i32, length: i128) -> InterpResult<'tcx, Scalar> { + fn ftruncate64(&mut self, fd: i32, length: i128) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); // Reject if isolation is enabled. @@ -1147,7 +1132,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } } - fn fsync(&mut self, fd_op: &OpTy<'tcx, Provenance>) -> InterpResult<'tcx, i32> { + fn fsync(&mut self, fd_op: &OpTy<'tcx>) -> InterpResult<'tcx, i32> { // On macOS, `fsync` (unlike `fcntl(F_FULLFSYNC)`) does not wait for the // underlying disk to finish writing. In the interest of host compatibility, // we conservatively implement this with `sync_all`, which @@ -1182,7 +1167,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { this.try_unwrap_io_result(io_result) } - fn fdatasync(&mut self, fd_op: &OpTy<'tcx, Provenance>) -> InterpResult<'tcx, i32> { + fn fdatasync(&mut self, fd_op: &OpTy<'tcx>) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); let fd = this.read_scalar(fd_op)?.to_i32()?; @@ -1209,11 +1194,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn sync_file_range( &mut self, - fd_op: &OpTy<'tcx, Provenance>, - offset_op: &OpTy<'tcx, Provenance>, - nbytes_op: &OpTy<'tcx, Provenance>, - flags_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, Scalar> { + fd_op: &OpTy<'tcx>, + offset_op: &OpTy<'tcx>, + nbytes_op: &OpTy<'tcx>, + flags_op: &OpTy<'tcx>, + ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); let fd = this.read_scalar(fd_op)?.to_i32()?; @@ -1259,9 +1244,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn readlink( &mut self, - pathname_op: &OpTy<'tcx, Provenance>, - buf_op: &OpTy<'tcx, Provenance>, - bufsize_op: &OpTy<'tcx, Provenance>, + pathname_op: &OpTy<'tcx>, + buf_op: &OpTy<'tcx>, + bufsize_op: &OpTy<'tcx>, ) -> InterpResult<'tcx, i64> { let this = self.eval_context_mut(); @@ -1302,10 +1287,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } } - fn isatty( - &mut self, - miri_fd: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, Scalar> { + fn isatty(&mut self, miri_fd: &OpTy<'tcx>) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); // "returns 1 if fd is an open file descriptor referring to a terminal; // otherwise 0 is returned, and errno is set to indicate the error" @@ -1326,9 +1308,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn realpath( &mut self, - path_op: &OpTy<'tcx, Provenance>, - processed_path_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, Scalar> { + path_op: &OpTy<'tcx>, + processed_path_op: &OpTy<'tcx>, + ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); this.assert_target_os_is_unix("realpath"); @@ -1384,7 +1366,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } } } - fn mkstemp(&mut self, template_op: &OpTy<'tcx, Provenance>) -> InterpResult<'tcx, i32> { + fn mkstemp(&mut self, template_op: &OpTy<'tcx>) -> InterpResult<'tcx, i32> { use rand::seq::SliceRandom; // POSIX defines the template string. @@ -1531,7 +1513,7 @@ fn extract_sec_and_nsec<'tcx>( /// Stores a file's metadata in order to avoid code duplication in the different metadata related /// shims. struct FileMetadata { - mode: Scalar, + mode: Scalar, size: u64, created: Option<(u64, u32)>, accessed: Option<(u64, u32)>, diff --git a/src/tools/miri/src/shims/unix/linux/epoll.rs b/src/tools/miri/src/shims/unix/linux/epoll.rs index 50868e60e9510..aa4dc98287016 100644 --- a/src/tools/miri/src/shims/unix/linux/epoll.rs +++ b/src/tools/miri/src/shims/unix/linux/epoll.rs @@ -25,10 +25,10 @@ struct Epoll { struct EpollEvent { #[allow(dead_code)] events: u32, - /// `Scalar` is used to represent the + /// `Scalar` is used to represent the /// `epoll_data` type union. #[allow(dead_code)] - data: Scalar, + data: Scalar, } impl FileDescription for Epoll { @@ -51,10 +51,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// is 0, then this function is the same as `epoll_create()`. /// /// - fn epoll_create1( - &mut self, - flags: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, Scalar> { + fn epoll_create1(&mut self, flags: &OpTy<'tcx>) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); let flags = this.read_scalar(flags)?.to_i32()?; @@ -85,11 +82,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// fn epoll_ctl( &mut self, - epfd: &OpTy<'tcx, Provenance>, - op: &OpTy<'tcx, Provenance>, - fd: &OpTy<'tcx, Provenance>, - event: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, Scalar> { + epfd: &OpTy<'tcx>, + op: &OpTy<'tcx>, + fd: &OpTy<'tcx>, + event: &OpTy<'tcx>, + ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); let epfd = this.read_scalar(epfd)?.to_i32()?; @@ -167,11 +164,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// fn epoll_wait( &mut self, - epfd: &OpTy<'tcx, Provenance>, - events: &OpTy<'tcx, Provenance>, - maxevents: &OpTy<'tcx, Provenance>, - timeout: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, Scalar> { + epfd: &OpTy<'tcx>, + events: &OpTy<'tcx>, + maxevents: &OpTy<'tcx>, + timeout: &OpTy<'tcx>, + ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); let epfd = this.read_scalar(epfd)?.to_i32()?; diff --git a/src/tools/miri/src/shims/unix/linux/eventfd.rs b/src/tools/miri/src/shims/unix/linux/eventfd.rs index 1447e498fd7d1..777142b25c47b 100644 --- a/src/tools/miri/src/shims/unix/linux/eventfd.rs +++ b/src/tools/miri/src/shims/unix/linux/eventfd.rs @@ -84,11 +84,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// `EFD_SEMAPHORE` - miri does not support semaphore-like semantics. /// /// - fn eventfd( - &mut self, - val: &OpTy<'tcx, Provenance>, - flags: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, Scalar> { + fn eventfd(&mut self, val: &OpTy<'tcx>, flags: &OpTy<'tcx>) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); let val = this.read_scalar(val)?.to_u32()?; diff --git a/src/tools/miri/src/shims/unix/linux/foreign_items.rs b/src/tools/miri/src/shims/unix/linux/foreign_items.rs index 7d0c8be1eaa08..e31d43d9190a0 100644 --- a/src/tools/miri/src/shims/unix/linux/foreign_items.rs +++ b/src/tools/miri/src/shims/unix/linux/foreign_items.rs @@ -20,8 +20,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, link_name: Symbol, abi: Abi, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { let this = self.eval_context_mut(); diff --git a/src/tools/miri/src/shims/unix/linux/mem.rs b/src/tools/miri/src/shims/unix/linux/mem.rs index 5f5d2b0c739de..c430eff0180ea 100644 --- a/src/tools/miri/src/shims/unix/linux/mem.rs +++ b/src/tools/miri/src/shims/unix/linux/mem.rs @@ -8,11 +8,11 @@ impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {} pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn mremap( &mut self, - old_address: &OpTy<'tcx, Provenance>, - old_size: &OpTy<'tcx, Provenance>, - new_size: &OpTy<'tcx, Provenance>, - flags: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, Scalar> { + old_address: &OpTy<'tcx>, + old_size: &OpTy<'tcx>, + new_size: &OpTy<'tcx>, + flags: &OpTy<'tcx>, + ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); let old_address = this.read_pointer(old_address)?; diff --git a/src/tools/miri/src/shims/unix/linux/sync.rs b/src/tools/miri/src/shims/unix/linux/sync.rs index de83a358db92d..3e0d5e58d4cda 100644 --- a/src/tools/miri/src/shims/unix/linux/sync.rs +++ b/src/tools/miri/src/shims/unix/linux/sync.rs @@ -6,8 +6,8 @@ use crate::*; /// `args` is the arguments *after* the syscall number. pub fn futex<'tcx>( this: &mut MiriInterpCx<'tcx>, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx> { // The amount of arguments used depends on the type of futex operation. // The full futex syscall takes six arguments (excluding the syscall diff --git a/src/tools/miri/src/shims/unix/macos/foreign_items.rs b/src/tools/miri/src/shims/unix/macos/foreign_items.rs index a1e9ccec676ec..25002f0a611c7 100644 --- a/src/tools/miri/src/shims/unix/macos/foreign_items.rs +++ b/src/tools/miri/src/shims/unix/macos/foreign_items.rs @@ -14,8 +14,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, link_name: Symbol, abi: Abi, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { let this = self.eval_context_mut(); diff --git a/src/tools/miri/src/shims/unix/mem.rs b/src/tools/miri/src/shims/unix/mem.rs index 4d727c0b1804f..de5a5d0759c4b 100644 --- a/src/tools/miri/src/shims/unix/mem.rs +++ b/src/tools/miri/src/shims/unix/mem.rs @@ -21,13 +21,13 @@ impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {} pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn mmap( &mut self, - addr: &OpTy<'tcx, Provenance>, - length: &OpTy<'tcx, Provenance>, - prot: &OpTy<'tcx, Provenance>, - flags: &OpTy<'tcx, Provenance>, - fd: &OpTy<'tcx, Provenance>, + addr: &OpTy<'tcx>, + length: &OpTy<'tcx>, + prot: &OpTy<'tcx>, + flags: &OpTy<'tcx>, + fd: &OpTy<'tcx>, offset: i128, - ) -> InterpResult<'tcx, Scalar> { + ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); // We do not support MAP_FIXED, so the addr argument is always ignored (except for the MacOS hack) @@ -123,11 +123,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { Ok(Scalar::from_pointer(ptr, this)) } - fn munmap( - &mut self, - addr: &OpTy<'tcx, Provenance>, - length: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, Scalar> { + fn munmap(&mut self, addr: &OpTy<'tcx>, length: &OpTy<'tcx>) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); let addr = this.read_pointer(addr)?; diff --git a/src/tools/miri/src/shims/unix/socket.rs b/src/tools/miri/src/shims/unix/socket.rs index a0fa3bcee3427..7eb7e28ea367d 100644 --- a/src/tools/miri/src/shims/unix/socket.rs +++ b/src/tools/miri/src/shims/unix/socket.rs @@ -35,11 +35,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// fn socketpair( &mut self, - domain: &OpTy<'tcx, Provenance>, - type_: &OpTy<'tcx, Provenance>, - protocol: &OpTy<'tcx, Provenance>, - sv: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, Scalar> { + domain: &OpTy<'tcx>, + type_: &OpTy<'tcx>, + protocol: &OpTy<'tcx>, + sv: &OpTy<'tcx>, + ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); let _domain = this.read_scalar(domain)?.to_i32()?; diff --git a/src/tools/miri/src/shims/unix/solarish/foreign_items.rs b/src/tools/miri/src/shims/unix/solarish/foreign_items.rs index 93427b05d2d85..a0cc4a62bfd2b 100644 --- a/src/tools/miri/src/shims/unix/solarish/foreign_items.rs +++ b/src/tools/miri/src/shims/unix/solarish/foreign_items.rs @@ -14,8 +14,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, link_name: Symbol, abi: Abi, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { let this = self.eval_context_mut(); match link_name.as_str() { diff --git a/src/tools/miri/src/shims/unix/sync.rs b/src/tools/miri/src/shims/unix/sync.rs index 304c1386370c5..7d4c32bc87e91 100644 --- a/src/tools/miri/src/shims/unix/sync.rs +++ b/src/tools/miri/src/shims/unix/sync.rs @@ -19,7 +19,7 @@ fn mutexattr_kind_offset<'tcx>(ecx: &MiriInterpCx<'tcx>) -> InterpResult<'tcx, u fn mutexattr_get_kind<'tcx>( ecx: &MiriInterpCx<'tcx>, - attr_op: &OpTy<'tcx, Provenance>, + attr_op: &OpTy<'tcx>, ) -> InterpResult<'tcx, i32> { ecx.deref_pointer_and_read( attr_op, @@ -32,7 +32,7 @@ fn mutexattr_get_kind<'tcx>( fn mutexattr_set_kind<'tcx>( ecx: &mut MiriInterpCx<'tcx>, - attr_op: &OpTy<'tcx, Provenance>, + attr_op: &OpTy<'tcx>, kind: i32, ) -> InterpResult<'tcx, ()> { ecx.deref_pointer_and_write( @@ -117,7 +117,7 @@ fn mutex_kind_offset<'tcx>(ecx: &MiriInterpCx<'tcx>) -> u64 { fn mutex_get_id<'tcx>( ecx: &mut MiriInterpCx<'tcx>, - mutex_op: &OpTy<'tcx, Provenance>, + mutex_op: &OpTy<'tcx>, ) -> InterpResult<'tcx, MutexId> { ecx.mutex_get_or_create_id( mutex_op, @@ -128,7 +128,7 @@ fn mutex_get_id<'tcx>( fn mutex_reset_id<'tcx>( ecx: &mut MiriInterpCx<'tcx>, - mutex_op: &OpTy<'tcx, Provenance>, + mutex_op: &OpTy<'tcx>, ) -> InterpResult<'tcx, ()> { ecx.deref_pointer_and_write( mutex_op, @@ -141,7 +141,7 @@ fn mutex_reset_id<'tcx>( fn mutex_get_kind<'tcx>( ecx: &MiriInterpCx<'tcx>, - mutex_op: &OpTy<'tcx, Provenance>, + mutex_op: &OpTy<'tcx>, ) -> InterpResult<'tcx, i32> { ecx.deref_pointer_and_read( mutex_op, @@ -154,7 +154,7 @@ fn mutex_get_kind<'tcx>( fn mutex_set_kind<'tcx>( ecx: &mut MiriInterpCx<'tcx>, - mutex_op: &OpTy<'tcx, Provenance>, + mutex_op: &OpTy<'tcx>, kind: i32, ) -> InterpResult<'tcx, ()> { ecx.deref_pointer_and_write( @@ -198,7 +198,7 @@ fn rwlock_id_offset<'tcx>(ecx: &MiriInterpCx<'tcx>) -> InterpResult<'tcx, u64> { fn rwlock_get_id<'tcx>( ecx: &mut MiriInterpCx<'tcx>, - rwlock_op: &OpTy<'tcx, Provenance>, + rwlock_op: &OpTy<'tcx>, ) -> InterpResult<'tcx, RwLockId> { ecx.rwlock_get_or_create_id( rwlock_op, @@ -222,7 +222,7 @@ fn condattr_clock_offset<'tcx>(ecx: &MiriInterpCx<'tcx>) -> InterpResult<'tcx, u fn condattr_get_clock_id<'tcx>( ecx: &MiriInterpCx<'tcx>, - attr_op: &OpTy<'tcx, Provenance>, + attr_op: &OpTy<'tcx>, ) -> InterpResult<'tcx, i32> { ecx.deref_pointer_and_read( attr_op, @@ -235,7 +235,7 @@ fn condattr_get_clock_id<'tcx>( fn condattr_set_clock_id<'tcx>( ecx: &mut MiriInterpCx<'tcx>, - attr_op: &OpTy<'tcx, Provenance>, + attr_op: &OpTy<'tcx>, clock_id: i32, ) -> InterpResult<'tcx, ()> { ecx.deref_pointer_and_write( @@ -313,7 +313,7 @@ fn cond_clock_offset<'tcx>(ecx: &MiriInterpCx<'tcx>) -> u64 { fn cond_get_id<'tcx>( ecx: &mut MiriInterpCx<'tcx>, - cond_op: &OpTy<'tcx, Provenance>, + cond_op: &OpTy<'tcx>, ) -> InterpResult<'tcx, CondvarId> { ecx.condvar_get_or_create_id( cond_op, @@ -324,7 +324,7 @@ fn cond_get_id<'tcx>( fn cond_reset_id<'tcx>( ecx: &mut MiriInterpCx<'tcx>, - cond_op: &OpTy<'tcx, Provenance>, + cond_op: &OpTy<'tcx>, ) -> InterpResult<'tcx, ()> { ecx.deref_pointer_and_write( cond_op, @@ -337,7 +337,7 @@ fn cond_reset_id<'tcx>( fn cond_get_clock_id<'tcx>( ecx: &MiriInterpCx<'tcx>, - cond_op: &OpTy<'tcx, Provenance>, + cond_op: &OpTy<'tcx>, ) -> InterpResult<'tcx, i32> { ecx.deref_pointer_and_read( cond_op, @@ -350,7 +350,7 @@ fn cond_get_clock_id<'tcx>( fn cond_set_clock_id<'tcx>( ecx: &mut MiriInterpCx<'tcx>, - cond_op: &OpTy<'tcx, Provenance>, + cond_op: &OpTy<'tcx>, clock_id: i32, ) -> InterpResult<'tcx, ()> { ecx.deref_pointer_and_write( @@ -364,10 +364,7 @@ fn cond_set_clock_id<'tcx>( impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {} pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { - fn pthread_mutexattr_init( - &mut self, - attr_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, i32> { + fn pthread_mutexattr_init(&mut self, attr_op: &OpTy<'tcx>) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); let default_kind = this.eval_libc_i32("PTHREAD_MUTEX_DEFAULT"); @@ -378,8 +375,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn pthread_mutexattr_settype( &mut self, - attr_op: &OpTy<'tcx, Provenance>, - kind_op: &OpTy<'tcx, Provenance>, + attr_op: &OpTy<'tcx>, + kind_op: &OpTy<'tcx>, ) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); @@ -417,10 +414,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { Ok(0) } - fn pthread_mutexattr_destroy( - &mut self, - attr_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, i32> { + fn pthread_mutexattr_destroy(&mut self, attr_op: &OpTy<'tcx>) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); // Destroying an uninit pthread_mutexattr is UB, so check to make sure it's not uninit. @@ -447,8 +441,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn pthread_mutex_init( &mut self, - mutex_op: &OpTy<'tcx, Provenance>, - attr_op: &OpTy<'tcx, Provenance>, + mutex_op: &OpTy<'tcx>, + attr_op: &OpTy<'tcx>, ) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); @@ -469,8 +463,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn pthread_mutex_lock( &mut self, - mutex_op: &OpTy<'tcx, Provenance>, - dest: &MPlaceTy<'tcx, Provenance>, + mutex_op: &OpTy<'tcx>, + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); @@ -508,10 +502,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { Ok(()) } - fn pthread_mutex_trylock( - &mut self, - mutex_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, i32> { + fn pthread_mutex_trylock(&mut self, mutex_op: &OpTy<'tcx>) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); let kind = mutex_get_kind(this, mutex_op)?; @@ -543,10 +534,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } } - fn pthread_mutex_unlock( - &mut self, - mutex_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, i32> { + fn pthread_mutex_unlock(&mut self, mutex_op: &OpTy<'tcx>) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); let kind = mutex_get_kind(this, mutex_op)?; @@ -577,10 +565,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } } - fn pthread_mutex_destroy( - &mut self, - mutex_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, i32> { + fn pthread_mutex_destroy(&mut self, mutex_op: &OpTy<'tcx>) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); let id = mutex_get_id(this, mutex_op)?; @@ -604,8 +589,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn pthread_rwlock_rdlock( &mut self, - rwlock_op: &OpTy<'tcx, Provenance>, - dest: &MPlaceTy<'tcx, Provenance>, + rwlock_op: &OpTy<'tcx>, + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); @@ -621,10 +606,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { Ok(()) } - fn pthread_rwlock_tryrdlock( - &mut self, - rwlock_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, i32> { + fn pthread_rwlock_tryrdlock(&mut self, rwlock_op: &OpTy<'tcx>) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); let id = rwlock_get_id(this, rwlock_op)?; @@ -639,8 +621,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn pthread_rwlock_wrlock( &mut self, - rwlock_op: &OpTy<'tcx, Provenance>, - dest: &MPlaceTy<'tcx, Provenance>, + rwlock_op: &OpTy<'tcx>, + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); @@ -668,10 +650,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { Ok(()) } - fn pthread_rwlock_trywrlock( - &mut self, - rwlock_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, i32> { + fn pthread_rwlock_trywrlock(&mut self, rwlock_op: &OpTy<'tcx>) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); let id = rwlock_get_id(this, rwlock_op)?; @@ -684,10 +663,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } } - fn pthread_rwlock_unlock( - &mut self, - rwlock_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, i32> { + fn pthread_rwlock_unlock(&mut self, rwlock_op: &OpTy<'tcx>) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); let id = rwlock_get_id(this, rwlock_op)?; @@ -702,10 +678,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } } - fn pthread_rwlock_destroy( - &mut self, - rwlock_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, i32> { + fn pthread_rwlock_destroy(&mut self, rwlock_op: &OpTy<'tcx>) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); let id = rwlock_get_id(this, rwlock_op)?; @@ -726,10 +699,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { Ok(0) } - fn pthread_condattr_init( - &mut self, - attr_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, i32> { + fn pthread_condattr_init(&mut self, attr_op: &OpTy<'tcx>) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); // no clock attribute on macOS @@ -746,9 +716,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn pthread_condattr_setclock( &mut self, - attr_op: &OpTy<'tcx, Provenance>, - clock_id_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, Scalar> { + attr_op: &OpTy<'tcx>, + clock_id_op: &OpTy<'tcx>, + ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); let clock_id = this.read_scalar(clock_id_op)?.to_i32()?; @@ -766,9 +736,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn pthread_condattr_getclock( &mut self, - attr_op: &OpTy<'tcx, Provenance>, - clk_id_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, Scalar> { + attr_op: &OpTy<'tcx>, + clk_id_op: &OpTy<'tcx>, + ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); let clock_id = condattr_get_clock_id(this, attr_op)?; @@ -777,10 +747,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { Ok(Scalar::from_i32(0)) } - fn pthread_condattr_destroy( - &mut self, - attr_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, i32> { + fn pthread_condattr_destroy(&mut self, attr_op: &OpTy<'tcx>) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); // Destroying an uninit pthread_condattr is UB, so check to make sure it's not uninit. @@ -800,8 +767,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn pthread_cond_init( &mut self, - cond_op: &OpTy<'tcx, Provenance>, - attr_op: &OpTy<'tcx, Provenance>, + cond_op: &OpTy<'tcx>, + attr_op: &OpTy<'tcx>, ) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); @@ -821,17 +788,14 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { Ok(0) } - fn pthread_cond_signal(&mut self, cond_op: &OpTy<'tcx, Provenance>) -> InterpResult<'tcx, i32> { + fn pthread_cond_signal(&mut self, cond_op: &OpTy<'tcx>) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); let id = cond_get_id(this, cond_op)?; this.condvar_signal(id)?; Ok(0) } - fn pthread_cond_broadcast( - &mut self, - cond_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, i32> { + fn pthread_cond_broadcast(&mut self, cond_op: &OpTy<'tcx>) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); let id = cond_get_id(this, cond_op)?; while this.condvar_signal(id)? {} @@ -840,9 +804,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn pthread_cond_wait( &mut self, - cond_op: &OpTy<'tcx, Provenance>, - mutex_op: &OpTy<'tcx, Provenance>, - dest: &MPlaceTy<'tcx, Provenance>, + cond_op: &OpTy<'tcx>, + mutex_op: &OpTy<'tcx>, + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); @@ -863,10 +827,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn pthread_cond_timedwait( &mut self, - cond_op: &OpTy<'tcx, Provenance>, - mutex_op: &OpTy<'tcx, Provenance>, - abstime_op: &OpTy<'tcx, Provenance>, - dest: &MPlaceTy<'tcx, Provenance>, + cond_op: &OpTy<'tcx>, + mutex_op: &OpTy<'tcx>, + abstime_op: &OpTy<'tcx>, + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); @@ -906,10 +870,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { Ok(()) } - fn pthread_cond_destroy( - &mut self, - cond_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, i32> { + fn pthread_cond_destroy(&mut self, cond_op: &OpTy<'tcx>) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); let id = cond_get_id(this, cond_op)?; diff --git a/src/tools/miri/src/shims/unix/thread.rs b/src/tools/miri/src/shims/unix/thread.rs index 323b5c1992ebb..6fe331ba623a1 100644 --- a/src/tools/miri/src/shims/unix/thread.rs +++ b/src/tools/miri/src/shims/unix/thread.rs @@ -6,10 +6,10 @@ impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {} pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn pthread_create( &mut self, - thread: &OpTy<'tcx, Provenance>, - _attr: &OpTy<'tcx, Provenance>, - start_routine: &OpTy<'tcx, Provenance>, - arg: &OpTy<'tcx, Provenance>, + thread: &OpTy<'tcx>, + _attr: &OpTy<'tcx>, + start_routine: &OpTy<'tcx>, + arg: &OpTy<'tcx>, ) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); @@ -32,8 +32,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn pthread_join( &mut self, - thread: &OpTy<'tcx, Provenance>, - retval: &OpTy<'tcx, Provenance>, + thread: &OpTy<'tcx>, + retval: &OpTy<'tcx>, ) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); @@ -48,7 +48,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { Ok(0) } - fn pthread_detach(&mut self, thread: &OpTy<'tcx, Provenance>) -> InterpResult<'tcx, i32> { + fn pthread_detach(&mut self, thread: &OpTy<'tcx>) -> InterpResult<'tcx, i32> { let this = self.eval_context_mut(); let thread_id = this.read_scalar(thread)?.to_int(this.libc_ty_layout("pthread_t").size)?; @@ -60,7 +60,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { Ok(0) } - fn pthread_self(&mut self) -> InterpResult<'tcx, Scalar> { + fn pthread_self(&mut self) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); let thread_id = this.active_thread(); @@ -71,10 +71,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// including the null terminator. fn pthread_setname_np( &mut self, - thread: Scalar, - name: Scalar, + thread: Scalar, + name: Scalar, max_name_len: usize, - ) -> InterpResult<'tcx, Scalar> { + ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); let thread = thread.to_int(this.libc_ty_layout("pthread_t").size)?; @@ -95,10 +95,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn pthread_getname_np( &mut self, - thread: Scalar, - name_out: Scalar, - len: Scalar, - ) -> InterpResult<'tcx, Scalar> { + thread: Scalar, + name_out: Scalar, + len: Scalar, + ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); let thread = thread.to_int(this.libc_ty_layout("pthread_t").size)?; diff --git a/src/tools/miri/src/shims/wasi/foreign_items.rs b/src/tools/miri/src/shims/wasi/foreign_items.rs index b81b35bd963ef..e9fe90081d09c 100644 --- a/src/tools/miri/src/shims/wasi/foreign_items.rs +++ b/src/tools/miri/src/shims/wasi/foreign_items.rs @@ -14,8 +14,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, link_name: Symbol, abi: Abi, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { let this = self.eval_context_mut(); match link_name.as_str() { diff --git a/src/tools/miri/src/shims/windows/env.rs b/src/tools/miri/src/shims/windows/env.rs index 488a05366d238..f90e5644d027f 100644 --- a/src/tools/miri/src/shims/windows/env.rs +++ b/src/tools/miri/src/shims/windows/env.rs @@ -38,10 +38,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { #[allow(non_snake_case)] fn GetEnvironmentVariableW( &mut self, - name_op: &OpTy<'tcx, Provenance>, // LPCWSTR - buf_op: &OpTy<'tcx, Provenance>, // LPWSTR - size_op: &OpTy<'tcx, Provenance>, // DWORD - ) -> InterpResult<'tcx, Scalar> { + name_op: &OpTy<'tcx>, // LPCWSTR + buf_op: &OpTy<'tcx>, // LPWSTR + size_op: &OpTy<'tcx>, // DWORD + ) -> InterpResult<'tcx, Scalar> { // ^ Returns DWORD (u32 on Windows) let this = self.eval_context_mut(); @@ -93,10 +93,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } #[allow(non_snake_case)] - fn FreeEnvironmentStringsW( - &mut self, - env_block_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, Scalar> { + fn FreeEnvironmentStringsW(&mut self, env_block_op: &OpTy<'tcx>) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); this.assert_target_os("windows", "FreeEnvironmentStringsW"); @@ -109,9 +106,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { #[allow(non_snake_case)] fn SetEnvironmentVariableW( &mut self, - name_op: &OpTy<'tcx, Provenance>, // LPCWSTR - value_op: &OpTy<'tcx, Provenance>, // LPCWSTR - ) -> InterpResult<'tcx, Scalar> { + name_op: &OpTy<'tcx>, // LPCWSTR + value_op: &OpTy<'tcx>, // LPCWSTR + ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); this.assert_target_os("windows", "SetEnvironmentVariableW"); @@ -142,9 +139,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { #[allow(non_snake_case)] fn GetCurrentDirectoryW( &mut self, - size_op: &OpTy<'tcx, Provenance>, // DWORD - buf_op: &OpTy<'tcx, Provenance>, // LPTSTR - ) -> InterpResult<'tcx, Scalar> { + size_op: &OpTy<'tcx>, // DWORD + buf_op: &OpTy<'tcx>, // LPTSTR + ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); this.assert_target_os("windows", "GetCurrentDirectoryW"); @@ -174,8 +171,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { #[allow(non_snake_case)] fn SetCurrentDirectoryW( &mut self, - path_op: &OpTy<'tcx, Provenance>, // LPCTSTR - ) -> InterpResult<'tcx, Scalar> { + path_op: &OpTy<'tcx>, // LPCTSTR + ) -> InterpResult<'tcx, Scalar> { // ^ Returns BOOL (i32 on Windows) let this = self.eval_context_mut(); @@ -211,10 +208,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { #[allow(non_snake_case)] fn GetUserProfileDirectoryW( &mut self, - token: &OpTy<'tcx, Provenance>, // HANDLE - buf: &OpTy<'tcx, Provenance>, // LPWSTR - size: &OpTy<'tcx, Provenance>, // LPDWORD - ) -> InterpResult<'tcx, Scalar> // returns BOOL + token: &OpTy<'tcx>, // HANDLE + buf: &OpTy<'tcx>, // LPWSTR + size: &OpTy<'tcx>, // LPDWORD + ) -> InterpResult<'tcx, Scalar> // returns BOOL { let this = self.eval_context_mut(); this.assert_target_os("windows", "GetUserProfileDirectoryW"); diff --git a/src/tools/miri/src/shims/windows/foreign_items.rs b/src/tools/miri/src/shims/windows/foreign_items.rs index a60c2a337cfc5..bfa14bcb5fad4 100644 --- a/src/tools/miri/src/shims/windows/foreign_items.rs +++ b/src/tools/miri/src/shims/windows/foreign_items.rs @@ -82,8 +82,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, link_name: Symbol, abi: Abi, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { let this = self.eval_context_mut(); diff --git a/src/tools/miri/src/shims/windows/handle.rs b/src/tools/miri/src/shims/windows/handle.rs index 3e274a5b80285..58c8683ff2777 100644 --- a/src/tools/miri/src/shims/windows/handle.rs +++ b/src/tools/miri/src/shims/windows/handle.rs @@ -119,7 +119,7 @@ impl Handle { Self::new(discriminant, data) } - pub fn to_scalar(self, cx: &impl HasDataLayout) -> Scalar { + pub fn to_scalar(self, cx: &impl HasDataLayout) -> Scalar { // 64-bit handles are sign extended 32-bit handles // see https://docs.microsoft.com/en-us/windows/win32/winprog64/interprocess-communication #[allow(clippy::cast_possible_wrap)] // we want it to wrap @@ -128,7 +128,7 @@ impl Handle { } pub fn from_scalar<'tcx>( - handle: Scalar, + handle: Scalar, cx: &impl HasDataLayout, ) -> InterpResult<'tcx, Option> { let sign_extended_handle = handle.to_target_isize(cx)?; @@ -155,7 +155,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { ))) } - fn CloseHandle(&mut self, handle_op: &OpTy<'tcx, Provenance>) -> InterpResult<'tcx> { + fn CloseHandle(&mut self, handle_op: &OpTy<'tcx>) -> InterpResult<'tcx> { let this = self.eval_context_mut(); let handle = this.read_scalar(handle_op)?; diff --git a/src/tools/miri/src/shims/windows/sync.rs b/src/tools/miri/src/shims/windows/sync.rs index d5fe15b401bc7..e77986dd5fe02 100644 --- a/src/tools/miri/src/shims/windows/sync.rs +++ b/src/tools/miri/src/shims/windows/sync.rs @@ -10,10 +10,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> { // Windows sync primitives are pointer sized. // We only use the first 4 bytes for the id. - fn init_once_get_id( - &mut self, - init_once_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, InitOnceId> { + fn init_once_get_id(&mut self, init_once_op: &OpTy<'tcx>) -> InterpResult<'tcx, InitOnceId> { let this = self.eval_context_mut(); this.init_once_get_or_create_id(init_once_op, this.windows_ty_layout("INIT_ONCE"), 0) } @@ -22,8 +19,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> { fn init_once_try_begin( &mut self, id: InitOnceId, - pending_place: &MPlaceTy<'tcx, Provenance>, - dest: &MPlaceTy<'tcx, Provenance>, + pending_place: &MPlaceTy<'tcx>, + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, bool> { let this = self.eval_context_mut(); Ok(match this.init_once_status(id) { @@ -49,11 +46,11 @@ impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {} pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn InitOnceBeginInitialize( &mut self, - init_once_op: &OpTy<'tcx, Provenance>, - flags_op: &OpTy<'tcx, Provenance>, - pending_op: &OpTy<'tcx, Provenance>, - context_op: &OpTy<'tcx, Provenance>, - dest: &MPlaceTy<'tcx, Provenance>, + init_once_op: &OpTy<'tcx>, + flags_op: &OpTy<'tcx>, + pending_op: &OpTy<'tcx>, + context_op: &OpTy<'tcx>, + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); @@ -82,8 +79,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { callback!( @capture<'tcx> { id: InitOnceId, - pending_place: MPlaceTy<'tcx, Provenance>, - dest: MPlaceTy<'tcx, Provenance>, + pending_place: MPlaceTy<'tcx>, + dest: MPlaceTy<'tcx>, } @unblock = |this| { let ret = this.init_once_try_begin(id, &pending_place, &dest)?; @@ -97,10 +94,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn InitOnceComplete( &mut self, - init_once_op: &OpTy<'tcx, Provenance>, - flags_op: &OpTy<'tcx, Provenance>, - context_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, Scalar> { + init_once_op: &OpTy<'tcx>, + flags_op: &OpTy<'tcx>, + context_op: &OpTy<'tcx>, + ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); let id = this.init_once_get_id(init_once_op)?; @@ -137,11 +134,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn WaitOnAddress( &mut self, - ptr_op: &OpTy<'tcx, Provenance>, - compare_op: &OpTy<'tcx, Provenance>, - size_op: &OpTy<'tcx, Provenance>, - timeout_op: &OpTy<'tcx, Provenance>, - dest: &MPlaceTy<'tcx, Provenance>, + ptr_op: &OpTy<'tcx>, + compare_op: &OpTy<'tcx>, + size_op: &OpTy<'tcx>, + timeout_op: &OpTy<'tcx>, + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); @@ -193,7 +190,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { Ok(()) } - fn WakeByAddressSingle(&mut self, ptr_op: &OpTy<'tcx, Provenance>) -> InterpResult<'tcx> { + fn WakeByAddressSingle(&mut self, ptr_op: &OpTy<'tcx>) -> InterpResult<'tcx> { let this = self.eval_context_mut(); let ptr = this.read_pointer(ptr_op)?; @@ -206,7 +203,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { Ok(()) } - fn WakeByAddressAll(&mut self, ptr_op: &OpTy<'tcx, Provenance>) -> InterpResult<'tcx> { + fn WakeByAddressAll(&mut self, ptr_op: &OpTy<'tcx>) -> InterpResult<'tcx> { let this = self.eval_context_mut(); let ptr = this.read_pointer(ptr_op)?; diff --git a/src/tools/miri/src/shims/windows/thread.rs b/src/tools/miri/src/shims/windows/thread.rs index a9ef03d14ae4f..f3ddf6072af1f 100644 --- a/src/tools/miri/src/shims/windows/thread.rs +++ b/src/tools/miri/src/shims/windows/thread.rs @@ -10,12 +10,12 @@ impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {} pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn CreateThread( &mut self, - security_op: &OpTy<'tcx, Provenance>, - stacksize_op: &OpTy<'tcx, Provenance>, - start_op: &OpTy<'tcx, Provenance>, - arg_op: &OpTy<'tcx, Provenance>, - flags_op: &OpTy<'tcx, Provenance>, - thread_op: &OpTy<'tcx, Provenance>, + security_op: &OpTy<'tcx>, + stacksize_op: &OpTy<'tcx>, + start_op: &OpTy<'tcx>, + arg_op: &OpTy<'tcx>, + flags_op: &OpTy<'tcx>, + thread_op: &OpTy<'tcx>, ) -> InterpResult<'tcx, ThreadId> { let this = self.eval_context_mut(); @@ -57,8 +57,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn WaitForSingleObject( &mut self, - handle_op: &OpTy<'tcx, Provenance>, - timeout_op: &OpTy<'tcx, Provenance>, + handle_op: &OpTy<'tcx>, + timeout_op: &OpTy<'tcx>, ) -> InterpResult<'tcx, u32> { let this = self.eval_context_mut(); diff --git a/src/tools/miri/src/shims/x86/aesni.rs b/src/tools/miri/src/shims/x86/aesni.rs index e7164d6651137..e4e1531157a42 100644 --- a/src/tools/miri/src/shims/x86/aesni.rs +++ b/src/tools/miri/src/shims/x86/aesni.rs @@ -11,8 +11,8 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, link_name: Symbol, abi: Abi, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { let this = self.eval_context_mut(); this.expect_target_feature_for_intrinsic(link_name, "aes")?; @@ -133,9 +133,9 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { // `state` with the corresponding 128-bit key of `key`. fn aes_round<'tcx>( this: &mut crate::MiriInterpCx<'tcx>, - state: &OpTy<'tcx, Provenance>, - key: &OpTy<'tcx, Provenance>, - dest: &MPlaceTy<'tcx, Provenance>, + state: &OpTy<'tcx>, + key: &OpTy<'tcx>, + dest: &MPlaceTy<'tcx>, f: impl Fn(u128, u128) -> u128, ) -> InterpResult<'tcx, ()> { assert_eq!(dest.layout.size, state.layout.size); diff --git a/src/tools/miri/src/shims/x86/avx.rs b/src/tools/miri/src/shims/x86/avx.rs index 1a912f6ff5d73..07d737e06635e 100644 --- a/src/tools/miri/src/shims/x86/avx.rs +++ b/src/tools/miri/src/shims/x86/avx.rs @@ -18,8 +18,8 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, link_name: Symbol, abi: Abi, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { let this = self.eval_context_mut(); this.expect_target_feature_for_intrinsic(link_name, "avx")?; diff --git a/src/tools/miri/src/shims/x86/avx2.rs b/src/tools/miri/src/shims/x86/avx2.rs index 9b50da79edd2f..016c525e57b41 100644 --- a/src/tools/miri/src/shims/x86/avx2.rs +++ b/src/tools/miri/src/shims/x86/avx2.rs @@ -16,8 +16,8 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, link_name: Symbol, abi: Abi, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { let this = self.eval_context_mut(); this.expect_target_feature_for_intrinsic(link_name, "avx2")?; diff --git a/src/tools/miri/src/shims/x86/mod.rs b/src/tools/miri/src/shims/x86/mod.rs index b5951e9e895bb..7c40f3de54da2 100644 --- a/src/tools/miri/src/shims/x86/mod.rs +++ b/src/tools/miri/src/shims/x86/mod.rs @@ -26,8 +26,8 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, link_name: Symbol, abi: Abi, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { let this = self.eval_context_mut(); // Prefix should have already been checked. @@ -244,9 +244,9 @@ impl FloatBinOp { fn bin_op_float<'tcx, F: rustc_apfloat::Float>( this: &crate::MiriInterpCx<'tcx>, which: FloatBinOp, - left: &ImmTy<'tcx, Provenance>, - right: &ImmTy<'tcx, Provenance>, -) -> InterpResult<'tcx, Scalar> { + left: &ImmTy<'tcx>, + right: &ImmTy<'tcx>, +) -> InterpResult<'tcx, Scalar> { match which { FloatBinOp::Arith(which) => { let res = this.binary_op(which, left, right)?; @@ -306,9 +306,9 @@ fn bin_op_float<'tcx, F: rustc_apfloat::Float>( fn bin_op_simd_float_first<'tcx, F: rustc_apfloat::Float>( this: &mut crate::MiriInterpCx<'tcx>, which: FloatBinOp, - left: &OpTy<'tcx, Provenance>, - right: &OpTy<'tcx, Provenance>, - dest: &MPlaceTy<'tcx, Provenance>, + left: &OpTy<'tcx>, + right: &OpTy<'tcx>, + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { let (left, left_len) = this.operand_to_simd(left)?; let (right, right_len) = this.operand_to_simd(right)?; @@ -337,9 +337,9 @@ fn bin_op_simd_float_first<'tcx, F: rustc_apfloat::Float>( fn bin_op_simd_float_all<'tcx, F: rustc_apfloat::Float>( this: &mut crate::MiriInterpCx<'tcx>, which: FloatBinOp, - left: &OpTy<'tcx, Provenance>, - right: &OpTy<'tcx, Provenance>, - dest: &MPlaceTy<'tcx, Provenance>, + left: &OpTy<'tcx>, + right: &OpTy<'tcx>, + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { let (left, left_len) = this.operand_to_simd(left)?; let (right, right_len) = this.operand_to_simd(right)?; @@ -384,8 +384,8 @@ enum FloatUnaryOp { fn unary_op_f32<'tcx>( this: &mut crate::MiriInterpCx<'tcx>, which: FloatUnaryOp, - op: &ImmTy<'tcx, Provenance>, -) -> InterpResult<'tcx, Scalar> { + op: &ImmTy<'tcx>, +) -> InterpResult<'tcx, Scalar> { match which { FloatUnaryOp::Sqrt => { let op = op.to_scalar(); @@ -435,8 +435,8 @@ fn apply_random_float_error( fn unary_op_ss<'tcx>( this: &mut crate::MiriInterpCx<'tcx>, which: FloatUnaryOp, - op: &OpTy<'tcx, Provenance>, - dest: &MPlaceTy<'tcx, Provenance>, + op: &OpTy<'tcx>, + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { let (op, op_len) = this.operand_to_simd(op)?; let (dest, dest_len) = this.mplace_to_simd(dest)?; @@ -458,8 +458,8 @@ fn unary_op_ss<'tcx>( fn unary_op_ps<'tcx>( this: &mut crate::MiriInterpCx<'tcx>, which: FloatUnaryOp, - op: &OpTy<'tcx, Provenance>, - dest: &MPlaceTy<'tcx, Provenance>, + op: &OpTy<'tcx>, + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { let (op, op_len) = this.operand_to_simd(op)?; let (dest, dest_len) = this.mplace_to_simd(dest)?; @@ -494,10 +494,10 @@ enum ShiftOp { /// bit is copied to all bits. fn shift_simd_by_scalar<'tcx>( this: &mut crate::MiriInterpCx<'tcx>, - left: &OpTy<'tcx, Provenance>, - right: &OpTy<'tcx, Provenance>, + left: &OpTy<'tcx>, + right: &OpTy<'tcx>, which: ShiftOp, - dest: &MPlaceTy<'tcx, Provenance>, + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { let (left, left_len) = this.operand_to_simd(left)?; let (dest, dest_len) = this.mplace_to_simd(dest)?; @@ -550,10 +550,10 @@ fn shift_simd_by_scalar<'tcx>( /// bit is copied to all bits. fn shift_simd_by_simd<'tcx>( this: &mut crate::MiriInterpCx<'tcx>, - left: &OpTy<'tcx, Provenance>, - right: &OpTy<'tcx, Provenance>, + left: &OpTy<'tcx>, + right: &OpTy<'tcx>, which: ShiftOp, - dest: &MPlaceTy<'tcx, Provenance>, + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { let (left, left_len) = this.operand_to_simd(left)?; let (right, right_len) = this.operand_to_simd(right)?; @@ -602,7 +602,7 @@ fn shift_simd_by_simd<'tcx>( /// the first value. fn extract_first_u64<'tcx>( this: &crate::MiriInterpCx<'tcx>, - op: &OpTy<'tcx, Provenance>, + op: &OpTy<'tcx>, ) -> InterpResult<'tcx, u64> { // Transmute vector to `[u64; 2]` let array_layout = this.layout_of(Ty::new_array(this.tcx.tcx, this.tcx.types.u64, 2))?; @@ -616,10 +616,10 @@ fn extract_first_u64<'tcx>( // and copies the remaining elements from `left`. fn round_first<'tcx, F: rustc_apfloat::Float>( this: &mut crate::MiriInterpCx<'tcx>, - left: &OpTy<'tcx, Provenance>, - right: &OpTy<'tcx, Provenance>, - rounding: &OpTy<'tcx, Provenance>, - dest: &MPlaceTy<'tcx, Provenance>, + left: &OpTy<'tcx>, + right: &OpTy<'tcx>, + rounding: &OpTy<'tcx>, + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { let (left, left_len) = this.operand_to_simd(left)?; let (right, right_len) = this.operand_to_simd(right)?; @@ -647,9 +647,9 @@ fn round_first<'tcx, F: rustc_apfloat::Float>( // Rounds all elements of `op` according to `rounding`. fn round_all<'tcx, F: rustc_apfloat::Float>( this: &mut crate::MiriInterpCx<'tcx>, - op: &OpTy<'tcx, Provenance>, - rounding: &OpTy<'tcx, Provenance>, - dest: &MPlaceTy<'tcx, Provenance>, + op: &OpTy<'tcx>, + rounding: &OpTy<'tcx>, + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { let (op, op_len) = this.operand_to_simd(op)?; let (dest, dest_len) = this.mplace_to_simd(dest)?; @@ -699,9 +699,9 @@ fn rounding_from_imm<'tcx>(rounding: i32) -> InterpResult<'tcx, rustc_apfloat::R /// has less elements than `dest`, the rest is filled with zeros. fn convert_float_to_int<'tcx>( this: &mut crate::MiriInterpCx<'tcx>, - op: &OpTy<'tcx, Provenance>, + op: &OpTy<'tcx>, rnd: rustc_apfloat::Round, - dest: &MPlaceTy<'tcx, Provenance>, + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { let (op, op_len) = this.operand_to_simd(op)?; let (dest, dest_len) = this.mplace_to_simd(dest)?; @@ -734,8 +734,8 @@ fn convert_float_to_int<'tcx>( /// will wrap around. fn int_abs<'tcx>( this: &mut crate::MiriInterpCx<'tcx>, - op: &OpTy<'tcx, Provenance>, - dest: &MPlaceTy<'tcx, Provenance>, + op: &OpTy<'tcx>, + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { let (op, op_len) = this.operand_to_simd(op)?; let (dest, dest_len) = this.mplace_to_simd(dest)?; @@ -802,9 +802,9 @@ fn horizontal_bin_op<'tcx>( this: &mut crate::MiriInterpCx<'tcx>, which: mir::BinOp, saturating: bool, - left: &OpTy<'tcx, Provenance>, - right: &OpTy<'tcx, Provenance>, - dest: &MPlaceTy<'tcx, Provenance>, + left: &OpTy<'tcx>, + right: &OpTy<'tcx>, + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { assert_eq!(left.layout, dest.layout); assert_eq!(right.layout, dest.layout); @@ -853,10 +853,10 @@ fn horizontal_bin_op<'tcx>( /// 128-bit blocks of `left` and `right`). fn conditional_dot_product<'tcx>( this: &mut crate::MiriInterpCx<'tcx>, - left: &OpTy<'tcx, Provenance>, - right: &OpTy<'tcx, Provenance>, - imm: &OpTy<'tcx, Provenance>, - dest: &MPlaceTy<'tcx, Provenance>, + left: &OpTy<'tcx>, + right: &OpTy<'tcx>, + imm: &OpTy<'tcx>, + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { assert_eq!(left.layout, dest.layout); assert_eq!(right.layout, dest.layout); @@ -911,8 +911,8 @@ fn conditional_dot_product<'tcx>( /// The second is true when `(op & mask) == mask` fn test_bits_masked<'tcx>( this: &crate::MiriInterpCx<'tcx>, - op: &OpTy<'tcx, Provenance>, - mask: &OpTy<'tcx, Provenance>, + op: &OpTy<'tcx>, + mask: &OpTy<'tcx>, ) -> InterpResult<'tcx, (bool, bool)> { assert_eq!(op.layout, mask.layout); @@ -942,8 +942,8 @@ fn test_bits_masked<'tcx>( /// The second is true when the highest bit of each element of `!op & mask` is zero. fn test_high_bits_masked<'tcx>( this: &crate::MiriInterpCx<'tcx>, - op: &OpTy<'tcx, Provenance>, - mask: &OpTy<'tcx, Provenance>, + op: &OpTy<'tcx>, + mask: &OpTy<'tcx>, ) -> InterpResult<'tcx, (bool, bool)> { assert_eq!(op.layout, mask.layout); @@ -973,9 +973,9 @@ fn test_high_bits_masked<'tcx>( /// element of `mask`. `ptr` does not need to be aligned. fn mask_load<'tcx>( this: &mut crate::MiriInterpCx<'tcx>, - ptr: &OpTy<'tcx, Provenance>, - mask: &OpTy<'tcx, Provenance>, - dest: &MPlaceTy<'tcx, Provenance>, + ptr: &OpTy<'tcx>, + mask: &OpTy<'tcx>, + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { let (mask, mask_len) = this.operand_to_simd(mask)?; let (dest, dest_len) = this.mplace_to_simd(dest)?; @@ -1006,9 +1006,9 @@ fn mask_load<'tcx>( /// element of `mask`. `ptr` does not need to be aligned. fn mask_store<'tcx>( this: &mut crate::MiriInterpCx<'tcx>, - ptr: &OpTy<'tcx, Provenance>, - mask: &OpTy<'tcx, Provenance>, - value: &OpTy<'tcx, Provenance>, + ptr: &OpTy<'tcx>, + mask: &OpTy<'tcx>, + value: &OpTy<'tcx>, ) -> InterpResult<'tcx, ()> { let (mask, mask_len) = this.operand_to_simd(mask)?; let (value, value_len) = this.operand_to_simd(value)?; @@ -1046,10 +1046,10 @@ fn mask_store<'tcx>( /// 128-bit chunks of `left` and `right`). fn mpsadbw<'tcx>( this: &mut crate::MiriInterpCx<'tcx>, - left: &OpTy<'tcx, Provenance>, - right: &OpTy<'tcx, Provenance>, - imm: &OpTy<'tcx, Provenance>, - dest: &MPlaceTy<'tcx, Provenance>, + left: &OpTy<'tcx>, + right: &OpTy<'tcx>, + imm: &OpTy<'tcx>, + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { assert_eq!(left.layout, right.layout); assert_eq!(left.layout.size, dest.layout.size); @@ -1103,9 +1103,9 @@ fn mpsadbw<'tcx>( /// fn pmulhrsw<'tcx>( this: &mut crate::MiriInterpCx<'tcx>, - left: &OpTy<'tcx, Provenance>, - right: &OpTy<'tcx, Provenance>, - dest: &MPlaceTy<'tcx, Provenance>, + left: &OpTy<'tcx>, + right: &OpTy<'tcx>, + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { let (left, left_len) = this.operand_to_simd(left)?; let (right, right_len) = this.operand_to_simd(right)?; @@ -1142,10 +1142,10 @@ fn pmulhrsw<'tcx>( /// 128-bit chunks of `left` and `right`). fn pack_generic<'tcx>( this: &mut crate::MiriInterpCx<'tcx>, - left: &OpTy<'tcx, Provenance>, - right: &OpTy<'tcx, Provenance>, - dest: &MPlaceTy<'tcx, Provenance>, - f: impl Fn(Scalar) -> InterpResult<'tcx, Scalar>, + left: &OpTy<'tcx>, + right: &OpTy<'tcx>, + dest: &MPlaceTy<'tcx>, + f: impl Fn(Scalar) -> InterpResult<'tcx, Scalar>, ) -> InterpResult<'tcx, ()> { assert_eq!(left.layout, right.layout); assert_eq!(left.layout.size, dest.layout.size); @@ -1187,9 +1187,9 @@ fn pack_generic<'tcx>( /// 128-bit chunks of `left` and `right`). fn packsswb<'tcx>( this: &mut crate::MiriInterpCx<'tcx>, - left: &OpTy<'tcx, Provenance>, - right: &OpTy<'tcx, Provenance>, - dest: &MPlaceTy<'tcx, Provenance>, + left: &OpTy<'tcx>, + right: &OpTy<'tcx>, + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { pack_generic(this, left, right, dest, |op| { let op = op.to_i16()?; @@ -1206,9 +1206,9 @@ fn packsswb<'tcx>( /// 128-bit chunks of `left` and `right`). fn packuswb<'tcx>( this: &mut crate::MiriInterpCx<'tcx>, - left: &OpTy<'tcx, Provenance>, - right: &OpTy<'tcx, Provenance>, - dest: &MPlaceTy<'tcx, Provenance>, + left: &OpTy<'tcx>, + right: &OpTy<'tcx>, + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { pack_generic(this, left, right, dest, |op| { let op = op.to_i16()?; @@ -1225,9 +1225,9 @@ fn packuswb<'tcx>( /// 128-bit chunks of `left` and `right`). fn packssdw<'tcx>( this: &mut crate::MiriInterpCx<'tcx>, - left: &OpTy<'tcx, Provenance>, - right: &OpTy<'tcx, Provenance>, - dest: &MPlaceTy<'tcx, Provenance>, + left: &OpTy<'tcx>, + right: &OpTy<'tcx>, + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { pack_generic(this, left, right, dest, |op| { let op = op.to_i32()?; @@ -1244,9 +1244,9 @@ fn packssdw<'tcx>( /// 128-bit chunks of `left` and `right`). fn packusdw<'tcx>( this: &mut crate::MiriInterpCx<'tcx>, - left: &OpTy<'tcx, Provenance>, - right: &OpTy<'tcx, Provenance>, - dest: &MPlaceTy<'tcx, Provenance>, + left: &OpTy<'tcx>, + right: &OpTy<'tcx>, + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { pack_generic(this, left, right, dest, |op| { let op = op.to_i32()?; @@ -1261,9 +1261,9 @@ fn packusdw<'tcx>( /// In other words, multiplies `left` with `right.signum()`. fn psign<'tcx>( this: &mut crate::MiriInterpCx<'tcx>, - left: &OpTy<'tcx, Provenance>, - right: &OpTy<'tcx, Provenance>, - dest: &MPlaceTy<'tcx, Provenance>, + left: &OpTy<'tcx>, + right: &OpTy<'tcx>, + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { let (left, left_len) = this.operand_to_simd(left)?; let (right, right_len) = this.operand_to_simd(right)?; diff --git a/src/tools/miri/src/shims/x86/sse.rs b/src/tools/miri/src/shims/x86/sse.rs index 16c0708182005..32e8e8a66c13c 100644 --- a/src/tools/miri/src/shims/x86/sse.rs +++ b/src/tools/miri/src/shims/x86/sse.rs @@ -15,8 +15,8 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, link_name: Symbol, abi: Abi, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { let this = self.eval_context_mut(); this.expect_target_feature_for_intrinsic(link_name, "sse")?; diff --git a/src/tools/miri/src/shims/x86/sse2.rs b/src/tools/miri/src/shims/x86/sse2.rs index f8b512e7981c5..e10047fefe6a8 100644 --- a/src/tools/miri/src/shims/x86/sse2.rs +++ b/src/tools/miri/src/shims/x86/sse2.rs @@ -14,8 +14,8 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, link_name: Symbol, abi: Abi, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { let this = self.eval_context_mut(); this.expect_target_feature_for_intrinsic(link_name, "sse2")?; diff --git a/src/tools/miri/src/shims/x86/sse3.rs b/src/tools/miri/src/shims/x86/sse3.rs index 58d27ef8f7213..ef5a55d6eb28e 100644 --- a/src/tools/miri/src/shims/x86/sse3.rs +++ b/src/tools/miri/src/shims/x86/sse3.rs @@ -11,8 +11,8 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, link_name: Symbol, abi: Abi, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { let this = self.eval_context_mut(); this.expect_target_feature_for_intrinsic(link_name, "sse3")?; diff --git a/src/tools/miri/src/shims/x86/sse41.rs b/src/tools/miri/src/shims/x86/sse41.rs index 79f885ed09482..9e048fb9eb841 100644 --- a/src/tools/miri/src/shims/x86/sse41.rs +++ b/src/tools/miri/src/shims/x86/sse41.rs @@ -10,8 +10,8 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, link_name: Symbol, abi: Abi, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { let this = self.eval_context_mut(); this.expect_target_feature_for_intrinsic(link_name, "sse4.1")?; diff --git a/src/tools/miri/src/shims/x86/ssse3.rs b/src/tools/miri/src/shims/x86/ssse3.rs index 2bb9a8dec6906..6a815e4cea3c6 100644 --- a/src/tools/miri/src/shims/x86/ssse3.rs +++ b/src/tools/miri/src/shims/x86/ssse3.rs @@ -11,8 +11,8 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, link_name: Symbol, abi: Abi, - args: &[OpTy<'tcx, Provenance>], - dest: &MPlaceTy<'tcx, Provenance>, + args: &[OpTy<'tcx>], + dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, EmulateItemResult> { let this = self.eval_context_mut(); this.expect_target_feature_for_intrinsic(link_name, "ssse3")?; From 98a3ac9e6d762a49d1dc8de106f2b98655e2da51 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 27 May 2024 17:39:45 +0200 Subject: [PATCH 07/41] also add type aliases for the pointer types --- src/tools/miri/src/alloc_addresses/mod.rs | 13 +++--- src/tools/miri/src/borrow_tracker/mod.rs | 2 +- .../src/borrow_tracker/stacked_borrows/mod.rs | 6 +-- .../src/borrow_tracker/tree_borrows/mod.rs | 6 +-- src/tools/miri/src/concurrency/data_race.rs | 8 ++-- src/tools/miri/src/concurrency/thread.rs | 45 +++++++++---------- src/tools/miri/src/diagnostics.rs | 4 +- src/tools/miri/src/helpers.rs | 19 ++++---- src/tools/miri/src/lib.rs | 2 + src/tools/miri/src/machine.rs | 42 +++++++---------- src/tools/miri/src/provenance_gc.rs | 4 +- src/tools/miri/src/shims/alloc.rs | 16 ++----- src/tools/miri/src/shims/os_str.rs | 42 +++++++---------- src/tools/miri/src/shims/panic.rs | 2 +- src/tools/miri/src/shims/time.rs | 2 +- src/tools/miri/src/shims/unix/env.rs | 20 ++++----- src/tools/miri/src/shims/unix/fd.rs | 14 +----- src/tools/miri/src/shims/unix/fs.rs | 4 +- src/tools/miri/src/shims/windows/env.rs | 2 +- 19 files changed, 105 insertions(+), 148 deletions(-) diff --git a/src/tools/miri/src/alloc_addresses/mod.rs b/src/tools/miri/src/alloc_addresses/mod.rs index 002e106206102..ae95d28d3eb65 100644 --- a/src/tools/miri/src/alloc_addresses/mod.rs +++ b/src/tools/miri/src/alloc_addresses/mod.rs @@ -257,7 +257,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { Ok(()) } - fn ptr_from_addr_cast(&self, addr: u64) -> InterpResult<'tcx, Pointer>> { + fn ptr_from_addr_cast(&self, addr: u64) -> InterpResult<'tcx, Pointer> { trace!("Casting {:#x} to a pointer", addr); let ecx = self.eval_context_ref(); @@ -297,10 +297,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// Convert a relative (tcx) pointer to a Miri pointer. fn adjust_alloc_root_pointer( &self, - ptr: Pointer, + ptr: interpret::Pointer, tag: BorTag, kind: MemoryKind, - ) -> InterpResult<'tcx, Pointer> { + ) -> InterpResult<'tcx, interpret::Pointer> { let ecx = self.eval_context_ref(); let (prov, offset) = ptr.into_parts(); // offset is relative (AllocId provenance) @@ -310,12 +310,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { // Add offset with the right kind of pointer-overflowing arithmetic. let dl = ecx.data_layout(); let absolute_addr = dl.overflowing_offset(base_addr, offset.bytes()).0; - Ok(Pointer::new(Provenance::Concrete { alloc_id, tag }, Size::from_bytes(absolute_addr))) + Ok(interpret::Pointer::new( + Provenance::Concrete { alloc_id, tag }, + Size::from_bytes(absolute_addr), + )) } /// When a pointer is used for a memory access, this computes where in which allocation the /// access is going. - fn ptr_get_alloc(&self, ptr: Pointer) -> Option<(AllocId, Size)> { + fn ptr_get_alloc(&self, ptr: interpret::Pointer) -> Option<(AllocId, Size)> { let ecx = self.eval_context_ref(); let (tag, addr) = ptr.into_parts(); // addr is absolute (Tag provenance) diff --git a/src/tools/miri/src/borrow_tracker/mod.rs b/src/tools/miri/src/borrow_tracker/mod.rs index 1b84ecc768608..c9e7e300593bc 100644 --- a/src/tools/miri/src/borrow_tracker/mod.rs +++ b/src/tools/miri/src/borrow_tracker/mod.rs @@ -324,7 +324,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn give_pointer_debug_name( &mut self, - ptr: Pointer>, + ptr: Pointer, nth_parent: u8, name: &str, ) -> InterpResult<'tcx> { diff --git a/src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs b/src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs index 5af2eeeec06ea..603733f9dc000 100644 --- a/src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs +++ b/src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs @@ -531,7 +531,7 @@ impl Stacks { trace!( "read access with tag {:?}: {:?}, size {}", tag, - Pointer::new(alloc_id, range.start), + interpret::Pointer::new(alloc_id, range.start), range.size.bytes() ); let dcx = DiagnosticCxBuilder::read(machine, tag, range); @@ -552,7 +552,7 @@ impl Stacks { trace!( "write access with tag {:?}: {:?}, size {}", tag, - Pointer::new(alloc_id, range.start), + interpret::Pointer::new(alloc_id, range.start), range.size.bytes() ); let dcx = DiagnosticCxBuilder::write(machine, tag, range); @@ -692,7 +692,7 @@ trait EvalContextPrivExt<'tcx, 'ecx>: crate::MiriInterpCxExt<'tcx> { new_tag, orig_tag, place.layout.ty, - Pointer::new(alloc_id, base_offset), + interpret::Pointer::new(alloc_id, base_offset), size.bytes() ); diff --git a/src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs b/src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs index a5867ff24a0cf..77e003ab8a789 100644 --- a/src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs +++ b/src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs @@ -56,7 +56,7 @@ impl<'tcx> Tree { "{} with tag {:?}: {:?}, size {}", access_kind, prov, - Pointer::new(alloc_id, range.start), + interpret::Pointer::new(alloc_id, range.start), range.size.bytes(), ); // TODO: for now we bail out on wildcard pointers. Eventually we should @@ -258,7 +258,7 @@ trait EvalContextPrivExt<'tcx>: crate::MiriInterpCxExt<'tcx> { new_tag, orig_tag, place.layout.ty, - Pointer::new(alloc_id, base_offset), + interpret::Pointer::new(alloc_id, base_offset), ptr_size.bytes() ); @@ -574,7 +574,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// of `ptr` (with 0 representing `ptr` itself) fn tb_give_pointer_debug_name( &mut self, - ptr: Pointer>, + ptr: Pointer, nth_parent: u8, name: &str, ) -> InterpResult<'tcx> { diff --git a/src/tools/miri/src/concurrency/data_race.rs b/src/tools/miri/src/concurrency/data_race.rs index caf74bc70e4ad..2baa09bec168b 100644 --- a/src/tools/miri/src/concurrency/data_race.rs +++ b/src/tools/miri/src/concurrency/data_race.rs @@ -948,7 +948,7 @@ impl VClockAlloc { mem_clocks: &MemoryCellClocks, access: AccessType, access_size: Size, - ptr_dbg: Pointer, + ptr_dbg: interpret::Pointer, ty: Option>, ) -> InterpResult<'tcx> { let (active_index, active_clocks) = global.active_thread_state(thread_mgr); @@ -1063,7 +1063,7 @@ impl VClockAlloc { mem_clocks, AccessType::NaRead(read_type), access_range.size, - Pointer::new(alloc_id, Size::from_bytes(mem_clocks_range.start)), + interpret::Pointer::new(alloc_id, Size::from_bytes(mem_clocks_range.start)), ty, ); } @@ -1108,7 +1108,7 @@ impl VClockAlloc { mem_clocks, AccessType::NaWrite(write_type), access_range.size, - Pointer::new(alloc_id, Size::from_bytes(mem_clocks_range.start)), + interpret::Pointer::new(alloc_id, Size::from_bytes(mem_clocks_range.start)), ty, ); } @@ -1337,7 +1337,7 @@ trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> { mem_clocks, access, place.layout.size, - Pointer::new( + interpret::Pointer::new( alloc_id, Size::from_bytes(mem_clocks_range.start), ), diff --git a/src/tools/miri/src/concurrency/thread.rs b/src/tools/miri/src/concurrency/thread.rs index 16fb69f3c5f2c..da3aafb54e662 100644 --- a/src/tools/miri/src/concurrency/thread.rs +++ b/src/tools/miri/src/concurrency/thread.rs @@ -432,9 +432,8 @@ pub struct ThreadManager<'tcx> { /// /// Note that this vector also contains terminated threads. threads: IndexVec>, - /// A mapping from a thread-local static to an allocation id of a thread - /// specific allocation. - thread_local_alloc_ids: FxHashMap<(DefId, ThreadId), Pointer>, + /// A mapping from a thread-local static to the thread specific allocation. + thread_local_allocs: FxHashMap<(DefId, ThreadId), StrictPointer>, /// A flag that indicates that we should change the active thread. yield_active_thread: bool, } @@ -443,7 +442,7 @@ impl VisitProvenance for ThreadManager<'_> { fn visit_provenance(&self, visit: &mut VisitWith<'_>) { let ThreadManager { threads, - thread_local_alloc_ids, + thread_local_allocs, active_thread: _, yield_active_thread: _, } = self; @@ -451,7 +450,7 @@ impl VisitProvenance for ThreadManager<'_> { for thread in threads { thread.visit_provenance(visit); } - for ptr in thread_local_alloc_ids.values() { + for ptr in thread_local_allocs.values() { ptr.visit_provenance(visit); } } @@ -465,7 +464,7 @@ impl<'tcx> Default for ThreadManager<'tcx> { Self { active_thread: ThreadId::MAIN_THREAD, threads, - thread_local_alloc_ids: Default::default(), + thread_local_allocs: Default::default(), yield_active_thread: false, } } @@ -487,16 +486,16 @@ impl<'tcx> ThreadManager<'tcx> { /// Check if we have an allocation for the given thread local static for the /// active thread. - fn get_thread_local_alloc_id(&self, def_id: DefId) -> Option> { - self.thread_local_alloc_ids.get(&(def_id, self.active_thread)).cloned() + fn get_thread_local_alloc_id(&self, def_id: DefId) -> Option { + self.thread_local_allocs.get(&(def_id, self.active_thread)).cloned() } /// Set the pointer for the allocation of the given thread local /// static for the active thread. /// /// Panics if a thread local is initialized twice for the same thread. - fn set_thread_local_alloc(&mut self, def_id: DefId, ptr: Pointer) { - self.thread_local_alloc_ids.try_insert((def_id, self.active_thread), ptr).unwrap(); + fn set_thread_local_alloc(&mut self, def_id: DefId, ptr: StrictPointer) { + self.thread_local_allocs.try_insert((def_id, self.active_thread), ptr).unwrap(); } /// Borrow the stack of the active thread. @@ -848,7 +847,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn get_or_create_thread_local_alloc( &mut self, def_id: DefId, - ) -> InterpResult<'tcx, Pointer> { + ) -> InterpResult<'tcx, StrictPointer> { let this = self.eval_context_mut(); let tcx = this.tcx; if let Some(old_alloc) = this.machine.threads.get_thread_local_alloc_id(def_id) { @@ -878,7 +877,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn start_regular_thread( &mut self, thread: Option>, - start_routine: Pointer>, + start_routine: Pointer, start_abi: Abi, func_arg: ImmTy<'tcx>, ret_layout: TyAndLayout<'tcx>, @@ -947,18 +946,16 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { let gone_thread = this.active_thread(); { let mut free_tls_statics = Vec::new(); - this.machine.threads.thread_local_alloc_ids.retain( - |&(_def_id, thread), &mut alloc_id| { - if thread != gone_thread { - // A different thread, keep this static around. - return true; - } - // Delete this static from the map and from memory. - // We cannot free directly here as we cannot use `?` in this context. - free_tls_statics.push(alloc_id); - false - }, - ); + this.machine.threads.thread_local_allocs.retain(|&(_def_id, thread), &mut alloc_id| { + if thread != gone_thread { + // A different thread, keep this static around. + return true; + } + // Delete this static from the map and from memory. + // We cannot free directly here as we cannot use `?` in this context. + free_tls_statics.push(alloc_id); + false + }); // Now free the TLS statics. for ptr in free_tls_statics { match tls_alloc_action { diff --git a/src/tools/miri/src/diagnostics.rs b/src/tools/miri/src/diagnostics.rs index d55f21d74efc8..14e29aa423d8d 100644 --- a/src/tools/miri/src/diagnostics.rs +++ b/src/tools/miri/src/diagnostics.rs @@ -42,7 +42,7 @@ pub enum TerminationInfo { }, DataRace { involves_non_atomic: bool, - ptr: Pointer, + ptr: interpret::Pointer, op1: RacingOp, op2: RacingOp, extra: Option<&'static str>, @@ -128,7 +128,7 @@ pub enum NonHaltingDiagnostic { details: bool, }, WeakMemoryOutdatedLoad { - ptr: Pointer>, + ptr: Pointer, }, } diff --git a/src/tools/miri/src/helpers.rs b/src/tools/miri/src/helpers.rs index 6d860f6661a33..c17886c242fc8 100644 --- a/src/tools/miri/src/helpers.rs +++ b/src/tools/miri/src/helpers.rs @@ -413,12 +413,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } /// Test if this pointer equals 0. - fn ptr_is_null(&self, ptr: Pointer>) -> InterpResult<'tcx, bool> { + fn ptr_is_null(&self, ptr: Pointer) -> InterpResult<'tcx, bool> { Ok(ptr.addr().bytes() == 0) } /// Generate some random bytes, and write them to `dest`. - fn gen_random(&mut self, ptr: Pointer>, len: u64) -> InterpResult<'tcx> { + fn gen_random(&mut self, ptr: Pointer, len: u64) -> InterpResult<'tcx> { // Some programs pass in a null pointer and a length of 0 // to their platform's random-generation function (e.g. getrandom()) // on Linux. For compatibility with these programs, we don't perform @@ -520,8 +520,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { let mut cur_addr = start_addr; // Called when we detected an `UnsafeCell` at the given offset and size. // Calls `action` and advances `cur_ptr`. - let mut unsafe_cell_action = |unsafe_cell_ptr: &Pointer>, - unsafe_cell_size: Size| { + let mut unsafe_cell_action = |unsafe_cell_ptr: &Pointer, unsafe_cell_size: Size| { // We assume that we are given the fields in increasing offset order, // and nothing else changes. let unsafe_cell_addr = unsafe_cell_ptr.addr(); @@ -924,7 +923,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } /// Read a sequence of bytes until the first null terminator. - fn read_c_str<'a>(&'a self, ptr: Pointer>) -> InterpResult<'tcx, &'a [u8]> + fn read_c_str<'a>(&'a self, ptr: Pointer) -> InterpResult<'tcx, &'a [u8]> where 'tcx: 'a, { @@ -957,7 +956,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn write_c_str( &mut self, c_str: &[u8], - ptr: Pointer>, + ptr: Pointer, size: u64, ) -> InterpResult<'tcx, (bool, u64)> { // If `size` is smaller or equal than `bytes.len()`, writing `bytes` plus the required null @@ -976,7 +975,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// until the first null terminator. fn read_c_str_with_char_size( &self, - mut ptr: Pointer>, + mut ptr: Pointer, size: Size, align: Align, ) -> InterpResult<'tcx, Vec> @@ -1008,7 +1007,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } /// Read a sequence of u16 until the first null terminator. - fn read_wide_str(&self, ptr: Pointer>) -> InterpResult<'tcx, Vec> { + fn read_wide_str(&self, ptr: Pointer) -> InterpResult<'tcx, Vec> { self.read_c_str_with_char_size(ptr, Size::from_bytes(2), Align::from_bytes(2).unwrap()) } @@ -1021,7 +1020,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn write_wide_str( &mut self, wide_str: &[u16], - ptr: Pointer>, + ptr: Pointer, size: u64, ) -> InterpResult<'tcx, (bool, u64)> { // If `size` is smaller or equal than `bytes.len()`, writing `bytes` plus the required @@ -1046,7 +1045,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// Read a sequence of wchar_t until the first null terminator. /// Always returns a `Vec` no matter the size of `wchar_t`. - fn read_wchar_t_str(&self, ptr: Pointer>) -> InterpResult<'tcx, Vec> { + fn read_wchar_t_str(&self, ptr: Pointer) -> InterpResult<'tcx, Vec> { let this = self.eval_context_ref(); let wchar_t = this.libc_ty_layout("wchar_t"); self.read_c_str_with_char_size(ptr, wchar_t.size, wchar_t.align.abi) diff --git a/src/tools/miri/src/lib.rs b/src/tools/miri/src/lib.rs index 0e79fef564eef..94aed0645fa4d 100644 --- a/src/tools/miri/src/lib.rs +++ b/src/tools/miri/src/lib.rs @@ -100,6 +100,8 @@ pub use rustc_const_eval::interpret::*; pub use rustc_const_eval::interpret::{self, AllocMap, Provenance as _}; // Type aliases that set the provenance parameter. +pub type Pointer = interpret::Pointer>; +pub type StrictPointer = interpret::Pointer; pub type Scalar = interpret::Scalar; pub type ImmTy<'tcx> = interpret::ImmTy<'tcx, machine::Provenance>; pub type OpTy<'tcx> = interpret::OpTy<'tcx, machine::Provenance>; diff --git a/src/tools/miri/src/machine.rs b/src/tools/miri/src/machine.rs index 1dc11054935f3..70f326af8aefb 100644 --- a/src/tools/miri/src/machine.rs +++ b/src/tools/miri/src/machine.rs @@ -241,10 +241,10 @@ pub enum ProvenanceExtra { } #[cfg(target_pointer_width = "64")] -static_assert_size!(Pointer, 24); +static_assert_size!(StrictPointer, 24); // FIXME: this would with in 24bytes but layout optimizations are not smart enough // #[cfg(target_pointer_width = "64")] -//static_assert_size!(Pointer>, 24); +//static_assert_size!(Pointer, 24); #[cfg(target_pointer_width = "64")] static_assert_size!(Scalar, 32); @@ -270,7 +270,7 @@ impl fmt::Debug for Provenance { } impl interpret::Provenance for Provenance { - /// We use absolute addresses in the `offset` of a `Pointer`. + /// We use absolute addresses in the `offset` of a `StrictPointer`. const OFFSET_IS_ADDR: bool = true; fn get_alloc_id(self) -> Option { @@ -280,7 +280,7 @@ impl interpret::Provenance for Provenance { } } - fn fmt(ptr: &Pointer, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fn fmt(ptr: &interpret::Pointer, f: &mut fmt::Formatter<'_>) -> fmt::Result { let (prov, addr) = ptr.into_parts(); // address is absolute write!(f, "{:#x}", addr.bytes())?; if f.alternate() { @@ -447,9 +447,9 @@ pub struct MiriMachine<'tcx> { /// Program arguments (`Option` because we can only initialize them after creating the ecx). /// These are *pointers* to argc/argv because macOS. /// We also need the full command line as one string because of Windows. - pub(crate) argc: Option>>, - pub(crate) argv: Option>>, - pub(crate) cmd_line: Option>>, + pub(crate) argc: Option, + pub(crate) argv: Option, + pub(crate) cmd_line: Option, /// TLS state. pub(crate) tls: TlsData<'tcx>, @@ -504,7 +504,7 @@ pub struct MiriMachine<'tcx> { pub(crate) local_crates: Vec, /// Mapping extern static names to their pointer. - extern_statics: FxHashMap>, + extern_statics: FxHashMap, /// The random number generator used for resolving non-determinism. /// Needs to be queried by ptr_to_int, hence needs interior mutability. @@ -716,11 +716,7 @@ impl<'tcx> MiriMachine<'tcx> { Ok(()) } - pub(crate) fn add_extern_static( - this: &mut MiriInterpCx<'tcx>, - name: &str, - ptr: Pointer>, - ) { + pub(crate) fn add_extern_static(this: &mut MiriInterpCx<'tcx>, name: &str, ptr: Pointer) { // This got just allocated, so there definitely is a pointer here. let ptr = ptr.into_pointer_or_addr().unwrap(); this.machine.extern_statics.try_insert(Symbol::intern(name), ptr).unwrap(); @@ -1047,14 +1043,14 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> { fn thread_local_static_pointer( ecx: &mut MiriInterpCx<'tcx>, def_id: DefId, - ) -> InterpResult<'tcx, Pointer> { + ) -> InterpResult<'tcx, StrictPointer> { ecx.get_or_create_thread_local_alloc(def_id) } fn extern_static_pointer( ecx: &MiriInterpCx<'tcx>, def_id: DefId, - ) -> InterpResult<'tcx, Pointer> { + ) -> InterpResult<'tcx, StrictPointer> { let link_name = ecx.item_link_name(def_id); if let Some(&ptr) = ecx.machine.extern_statics.get(&link_name) { // Various parts of the engine rely on `get_alloc_info` for size and alignment @@ -1153,9 +1149,9 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> { fn adjust_alloc_root_pointer( ecx: &MiriInterpCx<'tcx>, - ptr: Pointer, + ptr: interpret::Pointer, kind: Option, - ) -> InterpResult<'tcx, Pointer> { + ) -> InterpResult<'tcx, interpret::Pointer> { let kind = kind.expect("we set our GLOBAL_KIND so this cannot be None"); let alloc_id = ptr.provenance.alloc_id(); if cfg!(debug_assertions) { @@ -1182,20 +1178,14 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> { /// Called on `usize as ptr` casts. #[inline(always)] - fn ptr_from_addr_cast( - ecx: &MiriInterpCx<'tcx>, - addr: u64, - ) -> InterpResult<'tcx, Pointer>> { + fn ptr_from_addr_cast(ecx: &MiriInterpCx<'tcx>, addr: u64) -> InterpResult<'tcx, Pointer> { ecx.ptr_from_addr_cast(addr) } /// Called on `ptr as usize` casts. /// (Actually computing the resulting `usize` doesn't need machine help, /// that's just `Scalar::try_to_int`.) - fn expose_ptr( - ecx: &mut InterpCx<'tcx, Self>, - ptr: Pointer, - ) -> InterpResult<'tcx> { + fn expose_ptr(ecx: &mut InterpCx<'tcx, Self>, ptr: StrictPointer) -> InterpResult<'tcx> { match ptr.provenance { Provenance::Concrete { alloc_id, tag } => ecx.expose_ptr(alloc_id, tag), Provenance::Wildcard => { @@ -1216,7 +1206,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> { /// stored in machine state). fn ptr_get_alloc( ecx: &MiriInterpCx<'tcx>, - ptr: Pointer, + ptr: StrictPointer, ) -> Option<(AllocId, Size, Self::ProvenanceExtra)> { let rel = ecx.ptr_get_alloc(ptr); diff --git a/src/tools/miri/src/provenance_gc.rs b/src/tools/miri/src/provenance_gc.rs index 67190d3849bfe..af980ca48197c 100644 --- a/src/tools/miri/src/provenance_gc.rs +++ b/src/tools/miri/src/provenance_gc.rs @@ -56,14 +56,14 @@ impl VisitProvenance for Provenance { } } -impl VisitProvenance for Pointer { +impl VisitProvenance for StrictPointer { fn visit_provenance(&self, visit: &mut VisitWith<'_>) { let (prov, _offset) = self.into_parts(); prov.visit_provenance(visit); } } -impl VisitProvenance for Pointer> { +impl VisitProvenance for Pointer { fn visit_provenance(&self, visit: &mut VisitWith<'_>) { let (prov, _offset) = self.into_parts(); prov.visit_provenance(visit); diff --git a/src/tools/miri/src/shims/alloc.rs b/src/tools/miri/src/shims/alloc.rs index d1e5dca0bef05..7b0c54d763e41 100644 --- a/src/tools/miri/src/shims/alloc.rs +++ b/src/tools/miri/src/shims/alloc.rs @@ -92,11 +92,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } } - fn malloc( - &mut self, - size: u64, - zero_init: bool, - ) -> InterpResult<'tcx, Pointer>> { + fn malloc(&mut self, size: u64, zero_init: bool) -> InterpResult<'tcx, Pointer> { let this = self.eval_context_mut(); let align = this.malloc_align(size); let ptr = this.allocate_ptr(Size::from_bytes(size), align, MiriMemoryKind::C.into())?; @@ -137,7 +133,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } } - fn free(&mut self, ptr: Pointer>) -> InterpResult<'tcx> { + fn free(&mut self, ptr: Pointer) -> InterpResult<'tcx> { let this = self.eval_context_mut(); if !this.ptr_is_null(ptr)? { this.deallocate_ptr(ptr, None, MiriMemoryKind::C.into())?; @@ -145,11 +141,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { Ok(()) } - fn realloc( - &mut self, - old_ptr: Pointer>, - new_size: u64, - ) -> InterpResult<'tcx, Pointer>> { + fn realloc(&mut self, old_ptr: Pointer, new_size: u64) -> InterpResult<'tcx, Pointer> { let this = self.eval_context_mut(); let new_align = this.malloc_align(new_size); if this.ptr_is_null(old_ptr)? { @@ -177,7 +169,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, align: &OpTy<'tcx>, size: &OpTy<'tcx>, - ) -> InterpResult<'tcx, Pointer>> { + ) -> InterpResult<'tcx, Pointer> { let this = self.eval_context_mut(); let align = this.read_target_usize(align)?; let size = this.read_target_usize(size)?; diff --git a/src/tools/miri/src/shims/os_str.rs b/src/tools/miri/src/shims/os_str.rs index c00e4384bab41..68eca5a3a0ffd 100644 --- a/src/tools/miri/src/shims/os_str.rs +++ b/src/tools/miri/src/shims/os_str.rs @@ -34,10 +34,7 @@ impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {} pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// Helper function to read an OsString from a null-terminated sequence of bytes, which is what /// the Unix APIs usually handle. - fn read_os_str_from_c_str<'a>( - &'a self, - ptr: Pointer>, - ) -> InterpResult<'tcx, &'a OsStr> + fn read_os_str_from_c_str<'a>(&'a self, ptr: Pointer) -> InterpResult<'tcx, &'a OsStr> where 'tcx: 'a, { @@ -48,10 +45,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// Helper function to read an OsString from a 0x0000-terminated sequence of u16, /// which is what the Windows APIs usually handle. - fn read_os_str_from_wide_str<'a>( - &'a self, - ptr: Pointer>, - ) -> InterpResult<'tcx, OsString> + fn read_os_str_from_wide_str<'a>(&'a self, ptr: Pointer) -> InterpResult<'tcx, OsString> where 'tcx: 'a, { @@ -76,7 +70,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn write_os_str_to_c_str( &mut self, os_str: &OsStr, - ptr: Pointer>, + ptr: Pointer, size: u64, ) -> InterpResult<'tcx, (bool, u64)> { let bytes = os_str.as_encoded_bytes(); @@ -88,7 +82,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn write_os_str_to_wide_str_helper( &mut self, os_str: &OsStr, - ptr: Pointer>, + ptr: Pointer, size: u64, truncate: bool, ) -> InterpResult<'tcx, (bool, u64)> { @@ -125,7 +119,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn write_os_str_to_wide_str( &mut self, os_str: &OsStr, - ptr: Pointer>, + ptr: Pointer, size: u64, ) -> InterpResult<'tcx, (bool, u64)> { self.write_os_str_to_wide_str_helper(os_str, ptr, size, /*truncate*/ false) @@ -136,7 +130,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn write_os_str_to_wide_str_truncated( &mut self, os_str: &OsStr, - ptr: Pointer>, + ptr: Pointer, size: u64, ) -> InterpResult<'tcx, (bool, u64)> { self.write_os_str_to_wide_str_helper(os_str, ptr, size, /*truncate*/ true) @@ -147,7 +141,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, os_str: &OsStr, memkind: MemoryKind, - ) -> InterpResult<'tcx, Pointer>> { + ) -> InterpResult<'tcx, Pointer> { let size = u64::try_from(os_str.len()).unwrap().checked_add(1).unwrap(); // Make space for `0` terminator. let this = self.eval_context_mut(); @@ -163,7 +157,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, os_str: &OsStr, memkind: MemoryKind, - ) -> InterpResult<'tcx, Pointer>> { + ) -> InterpResult<'tcx, Pointer> { let size = u64::try_from(os_str.len()).unwrap().checked_add(1).unwrap(); // Make space for `0x0000` terminator. let this = self.eval_context_mut(); @@ -175,10 +169,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } /// Read a null-terminated sequence of bytes, and perform path separator conversion if needed. - fn read_path_from_c_str<'a>( - &'a self, - ptr: Pointer>, - ) -> InterpResult<'tcx, Cow<'a, Path>> + fn read_path_from_c_str<'a>(&'a self, ptr: Pointer) -> InterpResult<'tcx, Cow<'a, Path>> where 'tcx: 'a, { @@ -192,10 +183,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } /// Read a null-terminated sequence of `u16`s, and perform path separator conversion if needed. - fn read_path_from_wide_str( - &self, - ptr: Pointer>, - ) -> InterpResult<'tcx, PathBuf> { + fn read_path_from_wide_str(&self, ptr: Pointer) -> InterpResult<'tcx, PathBuf> { let this = self.eval_context_ref(); let os_str = this.read_os_str_from_wide_str(ptr)?; @@ -207,7 +195,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn write_path_to_c_str( &mut self, path: &Path, - ptr: Pointer>, + ptr: Pointer, size: u64, ) -> InterpResult<'tcx, (bool, u64)> { let this = self.eval_context_mut(); @@ -221,7 +209,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn write_path_to_wide_str( &mut self, path: &Path, - ptr: Pointer>, + ptr: Pointer, size: u64, ) -> InterpResult<'tcx, (bool, u64)> { let this = self.eval_context_mut(); @@ -235,7 +223,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn write_path_to_wide_str_truncated( &mut self, path: &Path, - ptr: Pointer>, + ptr: Pointer, size: u64, ) -> InterpResult<'tcx, (bool, u64)> { let this = self.eval_context_mut(); @@ -250,7 +238,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, path: &Path, memkind: MemoryKind, - ) -> InterpResult<'tcx, Pointer>> { + ) -> InterpResult<'tcx, Pointer> { let this = self.eval_context_mut(); let os_str = this.convert_path(Cow::Borrowed(path.as_os_str()), PathConversion::HostToTarget); @@ -263,7 +251,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, path: &Path, memkind: MemoryKind, - ) -> InterpResult<'tcx, Pointer>> { + ) -> InterpResult<'tcx, Pointer> { let this = self.eval_context_mut(); let os_str = this.convert_path(Cow::Borrowed(path.as_os_str()), PathConversion::HostToTarget); diff --git a/src/tools/miri/src/shims/panic.rs b/src/tools/miri/src/shims/panic.rs index 3c9c0eb5c60d8..ef832f5bbbd15 100644 --- a/src/tools/miri/src/shims/panic.rs +++ b/src/tools/miri/src/shims/panic.rs @@ -23,7 +23,7 @@ use helpers::check_arg_count; #[derive(Debug)] pub struct CatchUnwindData<'tcx> { /// The `catch_fn` callback to call in case of a panic. - catch_fn: Pointer>, + catch_fn: Pointer, /// The `data` argument for that callback. data: Scalar, /// The return place from the original call to `try`. diff --git a/src/tools/miri/src/shims/time.rs b/src/tools/miri/src/shims/time.rs index 963ee1c3e627f..8206b15d0a084 100644 --- a/src/tools/miri/src/shims/time.rs +++ b/src/tools/miri/src/shims/time.rs @@ -125,7 +125,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, timep: &OpTy<'tcx>, result_op: &OpTy<'tcx>, - ) -> InterpResult<'tcx, Pointer>> { + ) -> InterpResult<'tcx, Pointer> { let this = self.eval_context_mut(); this.assert_target_os_is_unix("localtime_r"); diff --git a/src/tools/miri/src/shims/unix/env.rs b/src/tools/miri/src/shims/unix/env.rs index f21207c52f55b..2f78d0f42967a 100644 --- a/src/tools/miri/src/shims/unix/env.rs +++ b/src/tools/miri/src/shims/unix/env.rs @@ -13,7 +13,7 @@ use crate::*; pub struct UnixEnvVars<'tcx> { /// Stores pointers to the environment variables. These variables must be stored as /// null-terminated target strings (c_str or wide_str) with the `"{name}={value}"` format. - map: FxHashMap>>, + map: FxHashMap, /// Place where the `environ` static is stored. Lazily initialized, but then never changes. environ: MPlaceTy<'tcx>, @@ -65,7 +65,7 @@ impl<'tcx> UnixEnvVars<'tcx> { Ok(()) } - pub(crate) fn environ(&self) -> Pointer> { + pub(crate) fn environ(&self) -> Pointer { self.environ.ptr() } @@ -73,7 +73,7 @@ impl<'tcx> UnixEnvVars<'tcx> { &self, ecx: &InterpCx<'tcx, MiriMachine<'tcx>>, name: &OsStr, - ) -> InterpResult<'tcx, Option>>> { + ) -> InterpResult<'tcx, Option> { // We don't care about the value as we have the `map` to keep track of everything, // but we do want to do this read so it shows up as a data race. let _vars_ptr = ecx.read_pointer(&self.environ)?; @@ -109,7 +109,7 @@ fn alloc_env_var<'tcx>( ecx: &mut InterpCx<'tcx, MiriMachine<'tcx>>, name: &OsStr, value: &OsStr, -) -> InterpResult<'tcx, Pointer>> { +) -> InterpResult<'tcx, Pointer> { let mut name_osstring = name.to_os_string(); name_osstring.push("="); name_osstring.push(value); @@ -119,8 +119,8 @@ fn alloc_env_var<'tcx>( /// Allocates an `environ` block with the given list of pointers. fn alloc_environ_block<'tcx>( ecx: &mut InterpCx<'tcx, MiriMachine<'tcx>>, - mut vars: Vec>>, -) -> InterpResult<'tcx, Pointer>> { + mut vars: Vec, +) -> InterpResult<'tcx, Pointer> { // Add trailing null. vars.push(Pointer::null()); // Make an array with all these pointers inside Miri. @@ -139,7 +139,7 @@ fn alloc_environ_block<'tcx>( impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {} pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { - fn getenv(&mut self, name_op: &OpTy<'tcx>) -> InterpResult<'tcx, Pointer>> { + fn getenv(&mut self, name_op: &OpTy<'tcx>) -> InterpResult<'tcx, Pointer> { let this = self.eval_context_mut(); this.assert_target_os_is_unix("getenv"); @@ -206,11 +206,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } } - fn getcwd( - &mut self, - buf_op: &OpTy<'tcx>, - size_op: &OpTy<'tcx>, - ) -> InterpResult<'tcx, Pointer>> { + fn getcwd(&mut self, buf_op: &OpTy<'tcx>, size_op: &OpTy<'tcx>) -> InterpResult<'tcx, Pointer> { let this = self.eval_context_mut(); this.assert_target_os_is_unix("getcwd"); diff --git a/src/tools/miri/src/shims/unix/fd.rs b/src/tools/miri/src/shims/unix/fd.rs index 4a1a4466ddbde..b6ac841dc9f45 100644 --- a/src/tools/miri/src/shims/unix/fd.rs +++ b/src/tools/miri/src/shims/unix/fd.rs @@ -355,12 +355,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { Ok((-1).into()) } - fn read( - &mut self, - fd: i32, - buf: Pointer>, - count: u64, - ) -> InterpResult<'tcx, i64> { + fn read(&mut self, fd: i32, buf: Pointer, count: u64) -> InterpResult<'tcx, i64> { let this = self.eval_context_mut(); // Isolation check is done via `FileDescriptor` trait. @@ -409,12 +404,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } } - fn write( - &mut self, - fd: i32, - buf: Pointer>, - count: u64, - ) -> InterpResult<'tcx, i64> { + fn write(&mut self, fd: i32, buf: Pointer, count: u64) -> InterpResult<'tcx, i64> { let this = self.eval_context_mut(); // Isolation check is done via `FileDescriptor` trait. diff --git a/src/tools/miri/src/shims/unix/fs.rs b/src/tools/miri/src/shims/unix/fs.rs index 438f8b2c7e652..c8805f054ecca 100644 --- a/src/tools/miri/src/shims/unix/fs.rs +++ b/src/tools/miri/src/shims/unix/fs.rs @@ -180,7 +180,7 @@ struct OpenDir { read_dir: ReadDir, /// The most recent entry returned by readdir(). /// Will be freed by the next call. - entry: Option>>, + entry: Option, } impl OpenDir { @@ -900,7 +900,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { dirent64_layout.align.abi, MiriMemoryKind::Runtime.into(), )?; - let entry: Pointer> = entry.into(); + let entry: Pointer = entry.into(); // If the host is a Unix system, fill in the inode number with its real value. // If not, use 0 as a fallback value. diff --git a/src/tools/miri/src/shims/windows/env.rs b/src/tools/miri/src/shims/windows/env.rs index f90e5644d027f..ed3eb69798637 100644 --- a/src/tools/miri/src/shims/windows/env.rs +++ b/src/tools/miri/src/shims/windows/env.rs @@ -71,7 +71,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } #[allow(non_snake_case)] - fn GetEnvironmentStringsW(&mut self) -> InterpResult<'tcx, Pointer>> { + fn GetEnvironmentStringsW(&mut self) -> InterpResult<'tcx, Pointer> { let this = self.eval_context_mut(); this.assert_target_os("windows", "GetEnvironmentStringsW"); From 4277ddf54e0a511f196bf3b411d26436f5717479 Mon Sep 17 00:00:00 2001 From: The Miri Cronjob Bot Date: Tue, 28 May 2024 05:12:58 +0000 Subject: [PATCH 08/41] Preparing for merge from rustc --- src/tools/miri/rust-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/miri/rust-version b/src/tools/miri/rust-version index 3b24a903d3af7..cf698c31801f0 100644 --- a/src/tools/miri/rust-version +++ b/src/tools/miri/rust-version @@ -1 +1 @@ -a59072ec4fb6824213df5e9de8cae4812fd4fe97 +d86e1229411c086e1267c80dd9872959ca13b8b9 From 4991fd95dd8a710b859e44d1e984e785e1e56462 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 28 May 2024 18:26:41 +0200 Subject: [PATCH 09/41] move ./miri environment variables to CONTRIBUTING --- src/tools/miri/CONTRIBUTING.md | 17 ++++++++++++++++- src/tools/miri/README.md | 21 ++++++--------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/tools/miri/CONTRIBUTING.md b/src/tools/miri/CONTRIBUTING.md index 092ad46a7cad3..4534e54ad5e95 100644 --- a/src/tools/miri/CONTRIBUTING.md +++ b/src/tools/miri/CONTRIBUTING.md @@ -287,7 +287,22 @@ https. Add the following to your `.gitconfig`: pushInsteadOf = https://github.com/ ``` -## Internal environment variables +## Further environment variables + +The following environment variables are relevant to `./miri`: + +* `MIRI_AUTO_OPS` indicates whether the automatic execution of rustfmt, clippy and toolchain setup + (as controlled by the `./auto-*` files) should be skipped. If it is set to `no`, they are skipped. + This is used to allow automated IDE actions to avoid the auto ops. +* `MIRI_LOG`, `MIRI_BACKTRACE` control logging and backtrace printing during Miri executions. +* `MIRI_TEST_THREADS` (recognized by `./miri test`) sets the number of threads to use for running + tests. By default, the number of cores is used. +* `MIRI_SKIP_UI_CHECKS` (recognized by `./miri test`) disables checking that the `stderr` or + `stdout` files match the actual output. + +Furthermore, the usual environment variables recognized by `cargo miri` also work for `./miri`, e.g. +`MIRI_LIB_SRC`. Note that `MIRIFLAGS` is ignored by `./miri test` as each test controls the flags it +is run with. The following environment variables are *internal* and must not be used by anyone but Miri itself. They are used to communicate between different Miri diff --git a/src/tools/miri/README.md b/src/tools/miri/README.md index 208a8b9ee617d..c437619a76eab 100644 --- a/src/tools/miri/README.md +++ b/src/tools/miri/README.md @@ -448,28 +448,19 @@ Some native rustc `-Z` flags are also very relevant for Miri: * `-Zmir-emit-retag` controls whether `Retag` statements are emitted. Miri enables this per default because it is needed for [Stacked Borrows] and [Tree Borrows]. -Moreover, Miri recognizes some environment variables (unless noted otherwise, these are supported -by all intended entry points, i.e. `cargo miri` and `./miri {test,run}`): - -* `MIRI_AUTO_OPS` indicates whether the automatic execution of rustfmt, clippy and toolchain setup - should be skipped. If it is set to `no`, they are skipped. This is used to allow automated IDE - actions to avoid the auto ops. -* `MIRI_LOG`, `MIRI_BACKTRACE` control logging and backtrace printing during - Miri executions, also [see "Testing the Miri driver" in `CONTRIBUTING.md`][testing-miri]. +Moreover, Miri recognizes some environment variables: + * `MIRIFLAGS` defines extra flags to be passed to Miri. * `MIRI_LIB_SRC` defines the directory where Miri expects the sources of the standard library that it will build and use for interpretation. This directory must point to the `library` subdirectory of a `rust-lang/rust` repository checkout. -* `MIRI_SYSROOT` indicates the sysroot to use. When using `cargo miri`, this skips the automatic +* `MIRI_SYSROOT` indicates the sysroot to use. When using `cargo miri test`/`cargo miri run`, this skips the automatic setup -- only set this if you do not want to use the automatically created sysroot. When invoking `cargo miri setup`, this indicates where the sysroot will be put. -* `MIRI_TEST_THREADS` (recognized by `./miri test`): set the number of threads to use for running tests. - By default, the number of cores is used. * `MIRI_NO_STD` makes sure that the target's sysroot is built without libstd. This allows testing - and running no_std programs. (Miri has a heuristic to detect no-std targets based on the target - name; this environment variable is only needed when that heuristic fails.) -* `MIRI_SKIP_UI_CHECKS` (recognized by `./miri test`): don't check whether the - `stderr` or `stdout` files match the actual output. + and running no_std programs. This should *not usually be used*; Miri has a heuristic to detect + no-std targets based on the target name. Setting this on a target that does support libstd can + lead to confusing results. [testing-miri]: CONTRIBUTING.md#testing-the-miri-driver From d5235f91ad4807a955bace31668c03c5afa353eb Mon Sep 17 00:00:00 2001 From: Paul Gey Date: Tue, 28 May 2024 22:28:55 +0200 Subject: [PATCH 10/41] Fix "local crate" detection `PackageId` is an opaque identifier whose internal format is subject to change, so looking up the names of local crates by ID is more robust than parsing the ID. Resolves #3643. --- src/tools/miri/cargo-miri/src/util.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/tools/miri/cargo-miri/src/util.rs b/src/tools/miri/cargo-miri/src/util.rs index 5b6a391aabcda..f36cff1f7981e 100644 --- a/src/tools/miri/cargo-miri/src/util.rs +++ b/src/tools/miri/cargo-miri/src/util.rs @@ -1,3 +1,4 @@ +use std::collections::HashMap; use std::env; use std::ffi::OsString; use std::fs::File; @@ -233,21 +234,18 @@ pub fn get_cargo_metadata() -> Metadata { } /// Pulls all the crates in this workspace from the cargo metadata. -/// Workspace members are emitted like "miri 0.1.0 (path+file:///path/to/miri)" /// Additionally, somewhere between cargo metadata and TyCtxt, '-' gets replaced with '_' so we /// make that same transformation here. pub fn local_crates(metadata: &Metadata) -> String { assert!(!metadata.workspace_members.is_empty()); - let mut local_crates = String::new(); - for member in &metadata.workspace_members { - let name = member.repr.split(' ').next().unwrap(); - let name = name.replace('-', "_"); - local_crates.push_str(&name); - local_crates.push(','); - } - local_crates.pop(); // Remove the trailing ',' - - local_crates + let package_name_by_id: HashMap<_, _> = + metadata.packages.iter().map(|package| (&package.id, package.name.as_str())).collect(); + metadata + .workspace_members + .iter() + .map(|id| package_name_by_id[id].replace('-', "_")) + .collect::>() + .join(",") } /// Debug-print a command that is going to be run. From 483485e19eb792e822f3388c6cf58785ab726cfa Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Mon, 27 May 2024 18:38:39 -0400 Subject: [PATCH 11/41] Add a benchmark for creating large uninit allocations --- .../miri/bench-cargo-miri/big-allocs/Cargo.lock | 7 +++++++ .../miri/bench-cargo-miri/big-allocs/Cargo.toml | 8 ++++++++ .../miri/bench-cargo-miri/big-allocs/src/main.rs | 13 +++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 src/tools/miri/bench-cargo-miri/big-allocs/Cargo.lock create mode 100644 src/tools/miri/bench-cargo-miri/big-allocs/Cargo.toml create mode 100644 src/tools/miri/bench-cargo-miri/big-allocs/src/main.rs diff --git a/src/tools/miri/bench-cargo-miri/big-allocs/Cargo.lock b/src/tools/miri/bench-cargo-miri/big-allocs/Cargo.lock new file mode 100644 index 0000000000000..da0db7f47ea44 --- /dev/null +++ b/src/tools/miri/bench-cargo-miri/big-allocs/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "big-allocs" +version = "0.1.0" diff --git a/src/tools/miri/bench-cargo-miri/big-allocs/Cargo.toml b/src/tools/miri/bench-cargo-miri/big-allocs/Cargo.toml new file mode 100644 index 0000000000000..7234c9371cff3 --- /dev/null +++ b/src/tools/miri/bench-cargo-miri/big-allocs/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "big-allocs" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/src/tools/miri/bench-cargo-miri/big-allocs/src/main.rs b/src/tools/miri/bench-cargo-miri/big-allocs/src/main.rs new file mode 100644 index 0000000000000..a1c1708cf3baa --- /dev/null +++ b/src/tools/miri/bench-cargo-miri/big-allocs/src/main.rs @@ -0,0 +1,13 @@ +//! This is a regression test for https://github.com/rust-lang/miri/issues/3637. +//! `Allocation`s are backed by a `Box<[u8]>`, which we create using `alloc_zeroed`, which should +//! make very large allocations cheap. But then we also need to not clone those `Allocation`s, or +//! we end up slow anyway. + +fn main() { + // We can't use too big of an allocation or this code will encounter an allocation failure in + // CI. Since the allocation can't be huge, we need to do a few iterations so that the effect + // we're trying to measure is clearly visible above the interpreter's startup time. + for _ in 0..10 { + drop(Vec::::with_capacity(512 * 1024 * 1024)); + } +} From a9631038983cf01c4e47823ff4dd24ab0a507869 Mon Sep 17 00:00:00 2001 From: Paul Gey Date: Tue, 28 May 2024 23:07:44 +0200 Subject: [PATCH 12/41] add tests for local crate detection --- src/tools/miri/test-cargo-miri/Cargo.lock | 4 ++++ src/tools/miri/test-cargo-miri/Cargo.toml | 2 +- src/tools/miri/test-cargo-miri/run-test.py | 4 ++++ src/tools/miri/test-cargo-miri/run.local_crate.stderr.ref | 0 src/tools/miri/test-cargo-miri/run.local_crate.stdout.ref | 1 + .../test-cargo-miri/test-local-crate-detection/Cargo.toml | 4 ++++ .../test-cargo-miri/test-local-crate-detection/src/main.rs | 3 +++ 7 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/tools/miri/test-cargo-miri/run.local_crate.stderr.ref create mode 100644 src/tools/miri/test-cargo-miri/run.local_crate.stdout.ref create mode 100644 src/tools/miri/test-cargo-miri/test-local-crate-detection/Cargo.toml create mode 100644 src/tools/miri/test-cargo-miri/test-local-crate-detection/src/main.rs diff --git a/src/tools/miri/test-cargo-miri/Cargo.lock b/src/tools/miri/test-cargo-miri/Cargo.lock index 4783f79ea8fb4..8f618e7ffb38f 100644 --- a/src/tools/miri/test-cargo-miri/Cargo.lock +++ b/src/tools/miri/test-cargo-miri/Cargo.lock @@ -123,6 +123,10 @@ dependencies = [ "byteorder 1.5.0", ] +[[package]] +name = "test-local-crate-detection" +version = "0.1.0" + [[package]] name = "unicode-ident" version = "1.0.12" diff --git a/src/tools/miri/test-cargo-miri/Cargo.toml b/src/tools/miri/test-cargo-miri/Cargo.toml index bfef388669d17..574f1d05a6fae 100644 --- a/src/tools/miri/test-cargo-miri/Cargo.toml +++ b/src/tools/miri/test-cargo-miri/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["subcrate", "issue-1567", "exported-symbol-dep"] +members = ["subcrate", "issue-1567", "exported-symbol-dep", "test-local-crate-detection"] exclude = ["no-std-smoke"] # it wants to be panic="abort" [package] diff --git a/src/tools/miri/test-cargo-miri/run-test.py b/src/tools/miri/test-cargo-miri/run-test.py index 83f3e4c919b9a..d855c333a7568 100755 --- a/src/tools/miri/test-cargo-miri/run-test.py +++ b/src/tools/miri/test-cargo-miri/run-test.py @@ -131,6 +131,10 @@ def test_cargo_miri_run(): cargo_miri("run") + ["--target-dir=custom-run", "--", "--target-dir=target/custom-run"], "run.args.stdout.ref", "run.custom-target-dir.stderr.ref", ) + test("`cargo miri run --package=test-local-crate-detection` (test local crate detection)", + cargo_miri("run") + ["--package=test-local-crate-detection"], + "run.local_crate.stdout.ref", "run.local_crate.stderr.ref", + ) def test_cargo_miri_test(): # rustdoc is not run on foreign targets diff --git a/src/tools/miri/test-cargo-miri/run.local_crate.stderr.ref b/src/tools/miri/test-cargo-miri/run.local_crate.stderr.ref new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/src/tools/miri/test-cargo-miri/run.local_crate.stdout.ref b/src/tools/miri/test-cargo-miri/run.local_crate.stdout.ref new file mode 100644 index 0000000000000..1587de9ff3f87 --- /dev/null +++ b/src/tools/miri/test-cargo-miri/run.local_crate.stdout.ref @@ -0,0 +1 @@ +subcrate,issue_1567,exported_symbol_dep,test_local_crate_detection,cargo_miri_test,cdylib,exported_symbol,issue_1691,issue_1705,issue_rust_86261,proc_macro_crate diff --git a/src/tools/miri/test-cargo-miri/test-local-crate-detection/Cargo.toml b/src/tools/miri/test-cargo-miri/test-local-crate-detection/Cargo.toml new file mode 100644 index 0000000000000..2d41b210d4c1a --- /dev/null +++ b/src/tools/miri/test-cargo-miri/test-local-crate-detection/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "test-local-crate-detection" +version = "0.1.0" +edition = "2021" diff --git a/src/tools/miri/test-cargo-miri/test-local-crate-detection/src/main.rs b/src/tools/miri/test-cargo-miri/test-local-crate-detection/src/main.rs new file mode 100644 index 0000000000000..94acf9b7b2296 --- /dev/null +++ b/src/tools/miri/test-cargo-miri/test-local-crate-detection/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("{}", env!("MIRI_LOCAL_CRATES")); +} From 5bf78323750fed4bd9803f94377c51efd48c2b2f Mon Sep 17 00:00:00 2001 From: The Miri Cronjob Bot Date: Thu, 30 May 2024 04:56:50 +0000 Subject: [PATCH 13/41] Preparing for merge from rustc --- src/tools/miri/rust-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/miri/rust-version b/src/tools/miri/rust-version index cf698c31801f0..cbaa740e52f59 100644 --- a/src/tools/miri/rust-version +++ b/src/tools/miri/rust-version @@ -1 +1 @@ -d86e1229411c086e1267c80dd9872959ca13b8b9 +caa187f3bc9604c78dfbc3ffabbe1372cb528639 From a200d38ce9786cc12da7cf2087b20ee0e475807e Mon Sep 17 00:00:00 2001 From: The Miri Cronjob Bot Date: Thu, 30 May 2024 05:05:24 +0000 Subject: [PATCH 14/41] fmt --- src/tools/miri/src/concurrency/thread.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tools/miri/src/concurrency/thread.rs b/src/tools/miri/src/concurrency/thread.rs index 07d41772ba4da..e76c16fb83067 100644 --- a/src/tools/miri/src/concurrency/thread.rs +++ b/src/tools/miri/src/concurrency/thread.rs @@ -863,7 +863,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } let alloc = this.ctfe_query(|tcx| tcx.eval_static_initializer(def_id))?; // We make a full copy of this allocation. - let mut alloc = alloc.inner().adjust_from_tcx(&this.tcx, |ptr| this.global_root_pointer(ptr))?; + let mut alloc = + alloc.inner().adjust_from_tcx(&this.tcx, |ptr| this.global_root_pointer(ptr))?; // This allocation will be deallocated when the thread dies, so it is not in read-only memory. alloc.mutability = Mutability::Mut; // Create a fresh allocation with this content. From daeb68a579d0a0e8e3de0d1cd39c60c2d0a30a87 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 30 May 2024 09:05:03 +0200 Subject: [PATCH 15/41] make env/var test deterministic --- src/tools/miri/tests/pass/shims/env/var.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/tools/miri/tests/pass/shims/env/var.rs b/src/tools/miri/tests/pass/shims/env/var.rs index babaf00578a7a..a576c1fc8bb8c 100644 --- a/src/tools/miri/tests/pass/shims/env/var.rs +++ b/src/tools/miri/tests/pass/shims/env/var.rs @@ -1,3 +1,4 @@ +//@compile-flags: -Zmiri-preemption-rate=0 use std::env; use std::thread; @@ -26,6 +27,8 @@ fn main() { println!("{:#?}", env::vars().collect::>()); // Do things concurrently, to make sure there's no data race. + // We disable preemption to make sure the lock is not contended; + // that means we don't hit e.g. the futex codepath on Android (which we don't support). let t = thread::spawn(|| { env::set_var("MIRI_TEST", "42"); }); From 00644c12ed77e6f3e5bf38d98e359d101e3f9188 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 30 May 2024 10:23:54 +0200 Subject: [PATCH 16/41] add a comment --- .../miri/test-cargo-miri/test-local-crate-detection/src/main.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tools/miri/test-cargo-miri/test-local-crate-detection/src/main.rs b/src/tools/miri/test-cargo-miri/test-local-crate-detection/src/main.rs index 94acf9b7b2296..0991aa384607b 100644 --- a/src/tools/miri/test-cargo-miri/test-local-crate-detection/src/main.rs +++ b/src/tools/miri/test-cargo-miri/test-local-crate-detection/src/main.rs @@ -1,3 +1,5 @@ fn main() { + // Make sure we detect all crates from this workspace as "local". + // The env var is set during the "build" so we can use `env!` to access it directly. println!("{}", env!("MIRI_LOCAL_CRATES")); } From 0453f374e85bc364a9c8a6188460d87f2241ad65 Mon Sep 17 00:00:00 2001 From: The Miri Cronjob Bot Date: Wed, 5 Jun 2024 05:05:48 +0000 Subject: [PATCH 17/41] Preparing for merge from rustc --- src/tools/miri/rust-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/miri/rust-version b/src/tools/miri/rust-version index cbaa740e52f59..5032f225227a9 100644 --- a/src/tools/miri/rust-version +++ b/src/tools/miri/rust-version @@ -1 +1 @@ -caa187f3bc9604c78dfbc3ffabbe1372cb528639 +a330e49593ee890f9197727a3a558b6e6b37f843 From 9a77692189f641d80a82ae07722569f6ce61c8d4 Mon Sep 17 00:00:00 2001 From: The Miri Cronjob Bot Date: Wed, 5 Jun 2024 05:14:39 +0000 Subject: [PATCH 18/41] fmt --- src/tools/miri/tests/pass/drop_in_place.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/tools/miri/tests/pass/drop_in_place.rs b/src/tools/miri/tests/pass/drop_in_place.rs index 0615a43c80003..cac8d76dd9d41 100644 --- a/src/tools/miri/tests/pass/drop_in_place.rs +++ b/src/tools/miri/tests/pass/drop_in_place.rs @@ -6,7 +6,5 @@ use std::ptr; fn main() { let mut not_a_bool = 13u8; - unsafe { - ptr::drop_in_place(&mut not_a_bool as *mut u8 as *mut bool) - }; + unsafe { ptr::drop_in_place(&mut not_a_bool as *mut u8 as *mut bool) }; } From 14f65cbeeaa34a41de69cb26a917ae9ec6e870f2 Mon Sep 17 00:00:00 2001 From: The Miri Cronjob Bot Date: Fri, 7 Jun 2024 04:56:19 +0000 Subject: [PATCH 19/41] Preparing for merge from rustc --- src/tools/miri/rust-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/miri/rust-version b/src/tools/miri/rust-version index 5032f225227a9..8d038c0f78824 100644 --- a/src/tools/miri/rust-version +++ b/src/tools/miri/rust-version @@ -1 +1 @@ -a330e49593ee890f9197727a3a558b6e6b37f843 +76e7a0849c07d73e4d9afde8036ee8c450127cc8 From 27d9a46221cb39b5ab491623c78b114e04235518 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Fri, 7 Jun 2024 21:31:13 +0200 Subject: [PATCH 20/41] Fix stage in contributing --- src/tools/miri/CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tools/miri/CONTRIBUTING.md b/src/tools/miri/CONTRIBUTING.md index 4534e54ad5e95..edb551c15ea12 100644 --- a/src/tools/miri/CONTRIBUTING.md +++ b/src/tools/miri/CONTRIBUTING.md @@ -223,7 +223,7 @@ will eventually sync those changes back into this repository. When working on Miri in the rustc tree, here's how you can run tests: ``` -./x.py test miri --stage 0 +./x.py test miri --stage 1 ``` `--bless` will work, too. @@ -231,7 +231,7 @@ When working on Miri in the rustc tree, here's how you can run tests: You can also directly run Miri on a Rust source file: ``` -./x.py run miri --stage 0 --args src/tools/miri/tests/pass/hello.rs +./x.py run miri --stage 1 --args src/tools/miri/tests/pass/hello.rs ``` ## Advanced topic: Syncing with the rustc repo From dce1bbf31977550ba53528d2d4bc3a21ddd564f8 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Fri, 7 Jun 2024 21:50:59 +0200 Subject: [PATCH 21/41] Remove --stage entirely from contributing --- src/tools/miri/CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/miri/CONTRIBUTING.md b/src/tools/miri/CONTRIBUTING.md index edb551c15ea12..9067cbc603261 100644 --- a/src/tools/miri/CONTRIBUTING.md +++ b/src/tools/miri/CONTRIBUTING.md @@ -223,7 +223,7 @@ will eventually sync those changes back into this repository. When working on Miri in the rustc tree, here's how you can run tests: ``` -./x.py test miri --stage 1 +./x.py test miri ``` `--bless` will work, too. From a269cf5657262e8a1dcd1377b116db6223f1f54a Mon Sep 17 00:00:00 2001 From: tiif Date: Sat, 8 Jun 2024 08:58:47 +0800 Subject: [PATCH 22/41] Add eventfd shim --- .../miri/src/shims/unix/linux/eventfd.rs | 113 +++++++++++++++--- .../fail-dep/libc/libc_eventfd_read_block.rs | 12 ++ .../libc/libc_eventfd_read_block.stderr | 14 +++ .../fail-dep/libc/libc_eventfd_write_block.rs | 22 ++++ .../libc/libc_eventfd_write_block.stderr | 14 +++ .../miri/tests/pass-dep/libc/libc-eventfd.rs | 101 ++++++++++++++++ 6 files changed, 257 insertions(+), 19 deletions(-) create mode 100644 src/tools/miri/tests/fail-dep/libc/libc_eventfd_read_block.rs create mode 100644 src/tools/miri/tests/fail-dep/libc/libc_eventfd_read_block.stderr create mode 100644 src/tools/miri/tests/fail-dep/libc/libc_eventfd_write_block.rs create mode 100644 src/tools/miri/tests/fail-dep/libc/libc_eventfd_write_block.stderr create mode 100644 src/tools/miri/tests/pass-dep/libc/libc-eventfd.rs diff --git a/src/tools/miri/src/shims/unix/linux/eventfd.rs b/src/tools/miri/src/shims/unix/linux/eventfd.rs index 777142b25c47b..3080d5b8d0716 100644 --- a/src/tools/miri/src/shims/unix/linux/eventfd.rs +++ b/src/tools/miri/src/shims/unix/linux/eventfd.rs @@ -1,14 +1,20 @@ //! Linux `eventfd` implementation. -//! Currently just a stub. use std::io; +use std::io::{Error, ErrorKind}; use rustc_target::abi::Endian; use crate::shims::unix::*; -use crate::*; +use crate::{concurrency::VClock, *}; use self::shims::unix::fd::FileDescriptor; +/// Minimum size of u8 array to hold u64 value. +const U64_MIN_ARRAY_SIZE: usize = 8; + +/// Maximum value that the eventfd counter can hold. +const MAX_COUNTER: u64 = u64::MAX - 1; + /// A kind of file descriptor created by `eventfd`. /// The `Event` type isn't currently written to by `eventfd`. /// The interface is meant to keep track of objects associated @@ -20,7 +26,9 @@ use self::shims::unix::fd::FileDescriptor; struct Event { /// The object contains an unsigned 64-bit integer (uint64_t) counter that is maintained by the /// kernel. This counter is initialized with the value specified in the argument initval. - val: u64, + counter: u64, + is_nonblock: bool, + clock: VClock, } impl FileDescription for Event { @@ -35,6 +43,38 @@ impl FileDescription for Event { Ok(Ok(())) } + /// Read the counter in the buffer and return the counter if succeeded. + fn read<'tcx>( + &mut self, + _communicate_allowed: bool, + bytes: &mut [u8], + ecx: &mut MiriInterpCx<'tcx>, + ) -> InterpResult<'tcx, io::Result> { + // Check the size of slice, and return error only if the size of the slice < 8. + let Some(bytes) = bytes.first_chunk_mut::() else { + return Ok(Err(Error::from(ErrorKind::InvalidInput))); + }; + // Block when counter == 0. + if self.counter == 0 { + if self.is_nonblock { + return Ok(Err(Error::from(ErrorKind::WouldBlock))); + } else { + //FIXME: blocking is not supported + throw_unsup_format!("eventfd: blocking is unsupported"); + } + } else { + // Prevent false alarm in data race detection when doing synchronisation via eventfd. + ecx.acquire_clock(&self.clock); + // Return the counter in the host endianness using the buffer provided by caller. + *bytes = match ecx.tcx.sess.target.endian { + Endian::Little => self.counter.to_le_bytes(), + Endian::Big => self.counter.to_be_bytes(), + }; + self.counter = 0; + return Ok(Ok(U64_MIN_ARRAY_SIZE)); + } + } + /// A write call adds the 8-byte integer value supplied in /// its buffer (in native endianness) to the counter. The maximum value that may be /// stored in the counter is the largest unsigned 64-bit value @@ -53,16 +93,37 @@ impl FileDescription for Event { bytes: &[u8], ecx: &mut MiriInterpCx<'tcx>, ) -> InterpResult<'tcx, io::Result> { - let bytes: [u8; 8] = bytes.try_into().unwrap(); // FIXME fail gracefully when this has the wrong size - // Convert from target endianness to host endianness. + // Check the size of slice, and return error only if the size of the slice < 8. + let Some(bytes) = bytes.first_chunk::() else { + return Ok(Err(Error::from(ErrorKind::InvalidInput))); + }; + // Convert from bytes to int according to host endianness. let num = match ecx.tcx.sess.target.endian { - Endian::Little => u64::from_le_bytes(bytes), - Endian::Big => u64::from_be_bytes(bytes), + Endian::Little => u64::from_le_bytes(*bytes), + Endian::Big => u64::from_be_bytes(*bytes), + }; + // u64::MAX as input is invalid because the maximum value of counter is u64::MAX - 1. + if num == u64::MAX { + return Ok(Err(Error::from(ErrorKind::InvalidInput))); + } + // If the addition does not let the counter to exceed the maximum value, update the counter. + // Else, block. + match self.counter.checked_add(num) { + Some(new_count @ 0..=MAX_COUNTER) => { + // Prevent false alarm in data race detection when doing synchronisation via eventfd. + self.clock.join(&ecx.release_clock().unwrap()); + self.counter = new_count; + } + None | Some(u64::MAX) => { + if self.is_nonblock { + return Ok(Err(Error::from(ErrorKind::WouldBlock))); + } else { + //FIXME: blocking is not supported + throw_unsup_format!("eventfd: blocking is unsupported"); + } + } }; - // FIXME handle blocking when addition results in exceeding the max u64 value - // or fail with EAGAIN if the file descriptor is nonblocking. - self.val = self.val.checked_add(num).unwrap(); - Ok(Ok(8)) + Ok(Ok(U64_MIN_ARRAY_SIZE)) } } @@ -87,27 +148,41 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn eventfd(&mut self, val: &OpTy<'tcx>, flags: &OpTy<'tcx>) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); + // eventfd is Linux specific. + this.assert_target_os("linux", "eventfd"); + let val = this.read_scalar(val)?.to_u32()?; - let flags = this.read_scalar(flags)?.to_i32()?; + let mut flags = this.read_scalar(flags)?.to_i32()?; let efd_cloexec = this.eval_libc_i32("EFD_CLOEXEC"); let efd_nonblock = this.eval_libc_i32("EFD_NONBLOCK"); let efd_semaphore = this.eval_libc_i32("EFD_SEMAPHORE"); - if flags & (efd_cloexec | efd_nonblock | efd_semaphore) != flags { - throw_unsup_format!("eventfd: flag {flags:#x} is unsupported"); + if flags & efd_semaphore == efd_semaphore { + throw_unsup_format!("eventfd: EFD_SEMAPHORE is unsupported"); } + + let mut is_nonblock = false; + // Unload the flag that we support. + // After unloading, flags != 0 means other flags are used. if flags & efd_cloexec == efd_cloexec { - // cloexec does nothing as we don't support `exec` + flags &= !efd_cloexec; } if flags & efd_nonblock == efd_nonblock { - // FIXME remember the nonblock flag + flags &= !efd_nonblock; + is_nonblock = true; } - if flags & efd_semaphore == efd_semaphore { - throw_unsup_format!("eventfd: EFD_SEMAPHORE is unsupported"); + if flags != 0 { + let einval = this.eval_libc("EINVAL"); + this.set_last_error(einval)?; + return Ok(Scalar::from_i32(-1)); } - let fd = this.machine.fds.insert_fd(FileDescriptor::new(Event { val: val.into() })); + let fd = this.machine.fds.insert_fd(FileDescriptor::new(Event { + counter: val.into(), + is_nonblock, + clock: VClock::default(), + })); Ok(Scalar::from_i32(fd)) } } diff --git a/src/tools/miri/tests/fail-dep/libc/libc_eventfd_read_block.rs b/src/tools/miri/tests/fail-dep/libc/libc_eventfd_read_block.rs new file mode 100644 index 0000000000000..b24635f93404c --- /dev/null +++ b/src/tools/miri/tests/fail-dep/libc/libc_eventfd_read_block.rs @@ -0,0 +1,12 @@ +//@ignore-target-windows: No eventfd on Windows +//@ignore-target-apple: No eventfd in macos +fn main() { + // eventfd read will block when EFD_NONBLOCK flag is clear and counter = 0. + // This will pass when blocking is implemented. + let flags = libc::EFD_CLOEXEC; + let fd = unsafe { libc::eventfd(0, flags) }; + let mut buf: [u8; 8] = [0; 8]; + let _res: i32 = unsafe { + libc::read(fd, buf.as_mut_ptr().cast(), buf.len() as libc::size_t).try_into().unwrap() //~ERROR: blocking is unsupported + }; +} diff --git a/src/tools/miri/tests/fail-dep/libc/libc_eventfd_read_block.stderr b/src/tools/miri/tests/fail-dep/libc/libc_eventfd_read_block.stderr new file mode 100644 index 0000000000000..fdd0b4272cafb --- /dev/null +++ b/src/tools/miri/tests/fail-dep/libc/libc_eventfd_read_block.stderr @@ -0,0 +1,14 @@ +error: unsupported operation: eventfd: blocking is unsupported + --> $DIR/libc_eventfd_read_block.rs:LL:CC + | +LL | libc::read(fd, buf.as_mut_ptr().cast(), buf.len() as libc::size_t).try_into().unwrap() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ eventfd: blocking is unsupported + | + = help: this is likely not a bug in the program; it indicates that the program performed an operation that Miri does not support + = note: BACKTRACE: + = note: inside `main` at $DIR/libc_eventfd_read_block.rs:LL:CC + +note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace + +error: aborting due to 1 previous error + diff --git a/src/tools/miri/tests/fail-dep/libc/libc_eventfd_write_block.rs b/src/tools/miri/tests/fail-dep/libc/libc_eventfd_write_block.rs new file mode 100644 index 0000000000000..32ca4a919f7be --- /dev/null +++ b/src/tools/miri/tests/fail-dep/libc/libc_eventfd_write_block.rs @@ -0,0 +1,22 @@ +//@ignore-target-windows: No eventfd on Windows +//@ignore-target-apple: No eventfd in macos +fn main() { + // eventfd write will block when EFD_NONBLOCK flag is clear + // and the addition caused counter to exceed u64::MAX - 1. + // This will pass when blocking is implemented. + let flags = libc::EFD_CLOEXEC; + let fd = unsafe { libc::eventfd(0, flags) }; + // Write u64 - 1. + let mut sized_8_data: [u8; 8] = (u64::MAX - 1).to_ne_bytes(); + let res: i64 = unsafe { + libc::write(fd, sized_8_data.as_ptr() as *const libc::c_void, 8).try_into().unwrap() + }; + assert_eq!(res, 8); + + // Write 1. + sized_8_data = 1_u64.to_ne_bytes(); + // Write 1 to the counter. + let _res: i64 = unsafe { + libc::write(fd, sized_8_data.as_ptr() as *const libc::c_void, 8).try_into().unwrap() //~ERROR: blocking is unsupported + }; +} diff --git a/src/tools/miri/tests/fail-dep/libc/libc_eventfd_write_block.stderr b/src/tools/miri/tests/fail-dep/libc/libc_eventfd_write_block.stderr new file mode 100644 index 0000000000000..f12c0ddfb1717 --- /dev/null +++ b/src/tools/miri/tests/fail-dep/libc/libc_eventfd_write_block.stderr @@ -0,0 +1,14 @@ +error: unsupported operation: eventfd: blocking is unsupported + --> $DIR/libc_eventfd_write_block.rs:LL:CC + | +LL | libc::write(fd, sized_8_data.as_ptr() as *const libc::c_void, 8).try_into().unwrap() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ eventfd: blocking is unsupported + | + = help: this is likely not a bug in the program; it indicates that the program performed an operation that Miri does not support + = note: BACKTRACE: + = note: inside `main` at $DIR/libc_eventfd_write_block.rs:LL:CC + +note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace + +error: aborting due to 1 previous error + diff --git a/src/tools/miri/tests/pass-dep/libc/libc-eventfd.rs b/src/tools/miri/tests/pass-dep/libc/libc-eventfd.rs new file mode 100644 index 0000000000000..6af195316e8df --- /dev/null +++ b/src/tools/miri/tests/pass-dep/libc/libc-eventfd.rs @@ -0,0 +1,101 @@ +//@ignore-target-windows: No eventfd in windows +//@ignore-target-apple: No eventfd in macos +// test_race depends on a deterministic schedule. +//@compile-flags: -Zmiri-preemption-rate=0 + +use std::thread; + +fn main() { + test_read_write(); + test_race(); +} + +fn read_bytes(fd: i32, buf: &mut [u8; N]) -> i32 { + let res: i32 = unsafe { libc::read(fd, buf.as_mut_ptr().cast(), N).try_into().unwrap() }; + return res; +} + +fn write_bytes(fd: i32, data: [u8; N]) -> i32 { + let res: i32 = + unsafe { libc::write(fd, data.as_ptr() as *const libc::c_void, N).try_into().unwrap() }; + return res; +} + +fn test_read_write() { + let flags = libc::EFD_NONBLOCK | libc::EFD_CLOEXEC; + let fd = unsafe { libc::eventfd(0, flags) }; + let sized_8_data: [u8; 8] = 1_u64.to_ne_bytes(); + // Write 1 to the counter. + let res = write_bytes(fd, sized_8_data); + assert_eq!(res, 8); + + // Read 1 from the counter. + let mut buf: [u8; 8] = [0; 8]; + let res = read_bytes(fd, &mut buf); + // Read returns number of bytes has been read, which is always 8. + assert_eq!(res, 8); + // Check the value of counter read. + let counter = u64::from_ne_bytes(buf); + assert_eq!(counter, 1); + + // After read, the counter is currently 0, read counter 0 should fail with return + // value -1. + let mut buf: [u8; 8] = [0; 8]; + let res = read_bytes(fd, &mut buf); + assert_eq!(res, -1); + + // Write with supplied buffer that > 8 bytes should be allowed. + let sized_9_data: [u8; 9]; + if cfg!(target_endian = "big") { + // Adjust the data based on the endianness of host system. + sized_9_data = [0, 0, 0, 0, 0, 0, 0, 1, 0]; + } else { + sized_9_data = [1, 0, 0, 0, 0, 0, 0, 0, 0]; + } + let res = write_bytes(fd, sized_9_data); + assert_eq!(res, 8); + + // Read with supplied buffer that < 8 bytes should fail with return + // value -1. + let mut buf: [u8; 7] = [1; 7]; + let res = read_bytes(fd, &mut buf); + assert_eq!(res, -1); + + // Write with supplied buffer that < 8 bytes should fail with return + // value -1. + let size_7_data: [u8; 7] = [1; 7]; + let res = write_bytes(fd, size_7_data); + assert_eq!(res, -1); + + // Read with supplied buffer > 8 bytes should be allowed. + let mut buf: [u8; 9] = [1; 9]; + let res = read_bytes(fd, &mut buf); + assert_eq!(res, 8); + + // Write u64::MAX should fail. + let u64_max_bytes: [u8; 8] = [255; 8]; + let res = write_bytes(fd, u64_max_bytes); + assert_eq!(res, -1); +} + +fn test_race() { + static mut VAL: u8 = 0; + let flags = libc::EFD_NONBLOCK | libc::EFD_CLOEXEC; + let fd = unsafe { libc::eventfd(0, flags) }; + let thread1 = thread::spawn(move || { + let mut buf: [u8; 8] = [0; 8]; + let res = read_bytes(fd, &mut buf); + // read returns number of bytes has been read, which is always 8. + assert_eq!(res, 8); + let counter = u64::from_ne_bytes(buf); + assert_eq!(counter, 1); + unsafe { assert_eq!(VAL, 1) }; + }); + unsafe { VAL = 1 }; + let data: [u8; 8] = 1_u64.to_ne_bytes(); + let res = write_bytes(fd, data); + // write returns number of bytes written, which is always 8. + assert_eq!(res, 8); + thread::yield_now(); + thread1.join().unwrap(); +} From 3fa1d4726746a5bf35083a47ae9559682252f176 Mon Sep 17 00:00:00 2001 From: Folkert Date: Tue, 28 May 2024 16:28:23 +0200 Subject: [PATCH 23/41] add support for `pclmulqdq` --- src/tools/miri/src/shims/x86/mod.rs | 69 +++++++++++++++++++ .../shims/x86/intrinsics-x86-pclmulqdq.rs | 48 +++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 src/tools/miri/tests/pass/shims/x86/intrinsics-x86-pclmulqdq.rs diff --git a/src/tools/miri/src/shims/x86/mod.rs b/src/tools/miri/src/shims/x86/mod.rs index 7c40f3de54da2..0374cfedc5aa3 100644 --- a/src/tools/miri/src/shims/x86/mod.rs +++ b/src/tools/miri/src/shims/x86/mod.rs @@ -105,6 +105,13 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } } + "pclmulqdq" => { + let [left, right, imm] = + this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; + + pclmulqdq(this, left, right, imm, dest)?; + } + name if name.starts_with("sse.") => { return sse::EvalContextExt::emulate_x86_sse_intrinsic( this, link_name, abi, args, dest, @@ -1133,6 +1140,68 @@ fn pmulhrsw<'tcx>( Ok(()) } +/// Perform a carry-less multiplication of two 64-bit integers, selected from left and right according to imm8, +/// and store the results in dst. +/// +/// Left and right are both vectors of type 2 x i64. Only bits 0 and 4 of imm8 matter; +/// they select the element of left and right, respectively. +/// +/// +fn pclmulqdq<'tcx>( + this: &mut crate::MiriInterpCx<'tcx>, + left: &OpTy<'tcx>, + right: &OpTy<'tcx>, + imm8: &OpTy<'tcx>, + dest: &MPlaceTy<'tcx>, +) -> InterpResult<'tcx, ()> { + assert_eq!(left.layout, right.layout); + assert_eq!(left.layout.size, dest.layout.size); + + // Transmute to `[u64; 2]` + + let array_layout = this.layout_of(Ty::new_array(this.tcx.tcx, this.tcx.types.u64, 2))?; + let left = left.transmute(array_layout, this)?; + let right = right.transmute(array_layout, this)?; + let dest = dest.transmute(array_layout, this)?; + + let imm8 = this.read_scalar(imm8)?.to_u8()?; + + // select the 64-bit integer from left that the user specified (low or high) + let index = if (imm8 & 0x01) == 0 { 0 } else { 1 }; + let left = this.read_scalar(&this.project_index(&left, index)?)?.to_u64()?; + + // select the 64-bit integer from right that the user specified (low or high) + let index = if (imm8 & 0x10) == 0 { 0 } else { 1 }; + let right = this.read_scalar(&this.project_index(&right, index)?)?.to_u64()?; + + // Perform carry-less multiplication + // + // This operation is like long multiplication, but ignores all carries. + // That idea corresponds to the xor operator, which is used in the implementation. + // + // Wikipedia has an example https://en.wikipedia.org/wiki/Carry-less_product#Example + let mut result: u128 = 0; + + for i in 0..64 { + // if the i-th bit in right is set + if (right & (1 << i)) != 0 { + // xor result with `left` shifted to the left by i positions + result ^= (left as u128) << i; + } + } + + let result_low = (result & 0xFFFF_FFFF_FFFF_FFFF) as u64; + let result_high = (result >> 64) as u64; + + let dest_low = this.project_index(&dest, 0)?; + this.write_scalar(Scalar::from_u64(result_low), &dest_low)?; + + let dest_high = this.project_index(&dest, 1)?; + this.write_scalar(Scalar::from_u64(result_high), &dest_high)?; + + Ok(()) +} + /// Packs two N-bit integer vectors to a single N/2-bit integers. /// /// The conversion from N-bit to N/2-bit should be provided by `f`. diff --git a/src/tools/miri/tests/pass/shims/x86/intrinsics-x86-pclmulqdq.rs b/src/tools/miri/tests/pass/shims/x86/intrinsics-x86-pclmulqdq.rs new file mode 100644 index 0000000000000..2f242dd5379d2 --- /dev/null +++ b/src/tools/miri/tests/pass/shims/x86/intrinsics-x86-pclmulqdq.rs @@ -0,0 +1,48 @@ +// Ignore everything except x86 and x86_64 +// Any new targets that are added to CI should be ignored here. +// (We cannot use `cfg`-based tricks here since the `target-feature` flags below only work on x86.) +//@ignore-target-aarch64 +//@ignore-target-arm +//@ignore-target-avr +//@ignore-target-s390x +//@ignore-target-thumbv7em +//@ignore-target-wasm32 +//@compile-flags: -C target-feature=+pclmulqdq + +#[cfg(target_arch = "x86")] +use std::arch::x86::*; +#[cfg(target_arch = "x86_64")] +use std::arch::x86_64::*; + +fn main() { + assert!(is_x86_feature_detected!("pclmulqdq")); + + let a = (0x7fffffffffffffff, 0x4317e40ab4ddcf05); + let b = (0xdd358416f52ecd34, 0x633d11cc638ca16b); + + unsafe { + assert_eq!(clmulepi64_si128::<0x00>(a, b), (13036940098130298092, 2704901987789626761)); + assert_eq!(clmulepi64_si128::<0x01>(a, b), (6707488474444649956, 3901733953304450635)); + assert_eq!(clmulepi64_si128::<0x10>(a, b), (11607166829323378905, 1191897396234301548)); + assert_eq!(clmulepi64_si128::<0x11>(a, b), (7731954893213347271, 1760130762532070957)); + } +} + +#[target_feature(enable = "pclmulqdq")] +unsafe fn clmulepi64_si128( + (a1, a2): (u64, u64), + (b1, b2): (u64, u64), +) -> (u64, u64) { + // SAFETY: There are no safety requirements for calling `_mm_clmulepi64_si128`. + // It's just unsafe for API consistency with other intrinsics. + unsafe { + let a = core::mem::transmute::<_, __m128i>([a1, a2]); + let b = core::mem::transmute::<_, __m128i>([b1, b2]); + + let out = _mm_clmulepi64_si128::(a, b); + + let [c1, c2] = core::mem::transmute::<_, [u64; 2]>(out); + + (c1, c2) + } +} From ea73f0067fa6274a7c845f8ff0a9418cbde243bb Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 8 Jun 2024 18:31:46 +0200 Subject: [PATCH 24/41] comment nits --- src/tools/miri/src/shims/x86/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/tools/miri/src/shims/x86/mod.rs b/src/tools/miri/src/shims/x86/mod.rs index 0374cfedc5aa3..f2d120df21c41 100644 --- a/src/tools/miri/src/shims/x86/mod.rs +++ b/src/tools/miri/src/shims/x86/mod.rs @@ -1140,15 +1140,15 @@ fn pmulhrsw<'tcx>( Ok(()) } -/// Perform a carry-less multiplication of two 64-bit integers, selected from left and right according to imm8, -/// and store the results in dst. +/// Perform a carry-less multiplication of two 64-bit integers, selected from `left` and `right` according to `imm8`, +/// and store the results in `dst`. /// -/// Left and right are both vectors of type 2 x i64. Only bits 0 and 4 of imm8 matter; -/// they select the element of left and right, respectively. +/// `left` and `right` are both vectors of type 2 x i64. Only bits 0 and 4 of `imm8` matter; +/// they select the element of `left` and `right`, respectively. /// /// fn pclmulqdq<'tcx>( - this: &mut crate::MiriInterpCx<'tcx>, + this: &mut MiriInterpCx<'tcx>, left: &OpTy<'tcx>, right: &OpTy<'tcx>, imm8: &OpTy<'tcx>, From ca3d93aab050c87a18ee2142cc90e7ef79f405ea Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 8 Jun 2024 17:26:18 +0200 Subject: [PATCH 25/41] portable-simd: add test for non-power-of-2 bitmask --- .../tests/pass/intrinsics/portable-simd.rs | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/tools/miri/tests/pass/intrinsics/portable-simd.rs b/src/tools/miri/tests/pass/intrinsics/portable-simd.rs index 248a57d68504d..de87f153b6f4a 100644 --- a/src/tools/miri/tests/pass/intrinsics/portable-simd.rs +++ b/src/tools/miri/tests/pass/intrinsics/portable-simd.rs @@ -1,5 +1,5 @@ //@compile-flags: -Zmiri-strict-provenance -#![feature(portable_simd, adt_const_params, core_intrinsics)] +#![feature(portable_simd, adt_const_params, core_intrinsics, repr_simd)] #![allow(incomplete_features, internal_features)] use std::intrinsics::simd as intrinsics; use std::ptr; @@ -318,6 +318,44 @@ fn simd_mask() { assert_eq!(selected1, i32x4::from_array([0, 0, 0, 1])); assert_eq!(selected2, selected1); } + + // Non-power-of-2 multi-byte mask. + #[repr(simd, packed)] + #[allow(non_camel_case_types)] + #[derive(Copy, Clone, Debug, PartialEq)] + struct i32x10(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32); + impl i32x10 { + fn splat(x: i32) -> Self { + Self(x, x, x, x, x, x, x, x, x, x) + } + fn from_array(a: [i32; 10]) -> Self { + unsafe { std::mem::transmute(a) } + } + } + unsafe { + let mask = i32x10::from_array([!0, !0, 0, !0, 0, 0, !0, 0, !0, 0]); + let bitmask1: u16 = simd_bitmask(mask); + let bitmask2: [u8; 2] = simd_bitmask(mask); + if cfg!(target_endian = "little") { + assert_eq!(bitmask1, 0b0101001011); + assert_eq!(bitmask2, [0b01001011, 0b01]); + } else { + assert_eq!(bitmask1, 0b1101001010); + assert_eq!(bitmask2, [0b11, 0b01001010]); + } + let selected1 = simd_select_bitmask::( + if cfg!(target_endian = "little") { 0b0101001011 } else { 0b1101001010 }, + i32x10::splat(!0), // yes + i32x10::splat(0), // no + ); + let selected2 = simd_select_bitmask::<[u8; 2], _>( + if cfg!(target_endian = "little") { [0b01001011, 0b01] } else { [0b11, 0b01001010] }, + i32x10::splat(!0), // yes + i32x10::splat(0), // no + ); + assert_eq!(selected1, mask); + assert_eq!(selected2, selected1); + } } fn simd_cast() { From 1ae0053d97a1efc5293aa7143376eda52f7ffb28 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 8 Jun 2024 21:41:46 +0200 Subject: [PATCH 26/41] Preparing for merge from rustc --- src/tools/miri/rust-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/miri/rust-version b/src/tools/miri/rust-version index 8d038c0f78824..0f738653b14a7 100644 --- a/src/tools/miri/rust-version +++ b/src/tools/miri/rust-version @@ -1 +1 @@ -76e7a0849c07d73e4d9afde8036ee8c450127cc8 +565cadb514d35e7b851540edbc172af0f606014f From a13a9ab75997c9a5130956873532260428046499 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 9 Jun 2024 09:09:15 +0200 Subject: [PATCH 27/41] simd_bitmask: nicer error when the mask is too big --- src/tools/miri/src/intrinsics/simd.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/tools/miri/src/intrinsics/simd.rs b/src/tools/miri/src/intrinsics/simd.rs index d82c523b81717..7aa37ba449eb1 100644 --- a/src/tools/miri/src/intrinsics/simd.rs +++ b/src/tools/miri/src/intrinsics/simd.rs @@ -452,13 +452,17 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { let (no, no_len) = this.operand_to_simd(no)?; let (dest, dest_len) = this.mplace_to_simd(dest)?; let bitmask_len = dest_len.next_multiple_of(8); + if bitmask_len > 64 { + throw_unsup_format!( + "simd_bitmask: masks larger than 64 elements are currently not supported" + ); + } // The mask must be an integer or an array. assert!( mask.layout.ty.is_integral() || matches!(mask.layout.ty.kind(), ty::Array(elemty, _) if elemty == &this.tcx.types.u8) ); - assert!(bitmask_len <= 64); assert_eq!(bitmask_len, mask.layout.size.bits()); assert_eq!(dest_len, yes_len); assert_eq!(dest_len, no_len); @@ -498,13 +502,17 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { let [op] = check_arg_count(args)?; let (op, op_len) = this.operand_to_simd(op)?; let bitmask_len = op_len.next_multiple_of(8); + if bitmask_len > 64 { + throw_unsup_format!( + "simd_bitmask: masks larger than 64 elements are currently not supported" + ); + } // Returns either an unsigned integer or array of `u8`. assert!( dest.layout.ty.is_integral() || matches!(dest.layout.ty.kind(), ty::Array(elemty, _) if elemty == &this.tcx.types.u8) ); - assert!(bitmask_len <= 64); assert_eq!(bitmask_len, dest.layout.size.bits()); let op_len = u32::try_from(op_len).unwrap(); From 91e53aa8edcf59abf963910f4ac47518c711ff57 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 9 Jun 2024 09:56:30 +0200 Subject: [PATCH 28/41] simd_select_bitmask: fix intrinsic name in error --- src/tools/miri/src/intrinsics/simd.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tools/miri/src/intrinsics/simd.rs b/src/tools/miri/src/intrinsics/simd.rs index 7aa37ba449eb1..df52f223db39e 100644 --- a/src/tools/miri/src/intrinsics/simd.rs +++ b/src/tools/miri/src/intrinsics/simd.rs @@ -454,7 +454,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { let bitmask_len = dest_len.next_multiple_of(8); if bitmask_len > 64 { throw_unsup_format!( - "simd_bitmask: masks larger than 64 elements are currently not supported" + "simd_select_bitmask: vectors larger than 64 elements are currently not supported" ); } @@ -504,7 +504,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { let bitmask_len = op_len.next_multiple_of(8); if bitmask_len > 64 { throw_unsup_format!( - "simd_bitmask: masks larger than 64 elements are currently not supported" + "simd_bitmask: vectors larger than 64 elements are currently not supported" ); } From 110b09220321ee529368ec19d6d31d0f00c4ac70 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 9 Jun 2024 11:35:16 +0200 Subject: [PATCH 29/41] simd_bitmask: work correctly for sizes like 24 --- src/tools/miri/src/helpers.rs | 3 +- src/tools/miri/src/intrinsics/mod.rs | 2 + src/tools/miri/src/intrinsics/simd.rs | 88 +++++++++++++------ .../tests/pass/intrinsics/portable-simd.rs | 71 +++++++++++---- 4 files changed, 122 insertions(+), 42 deletions(-) diff --git a/src/tools/miri/src/helpers.rs b/src/tools/miri/src/helpers.rs index e6ef2f5dc60af..87b53d87ac87e 100644 --- a/src/tools/miri/src/helpers.rs +++ b/src/tools/miri/src/helpers.rs @@ -374,7 +374,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { let val = if dest.layout().abi.is_signed() { Scalar::from_int(i, dest.layout().size) } else { - Scalar::from_uint(u64::try_from(i.into()).unwrap(), dest.layout().size) + // `unwrap` can only fail here if `i` is negative + Scalar::from_uint(u128::try_from(i.into()).unwrap(), dest.layout().size) }; self.eval_context_mut().write_scalar(val, dest) } diff --git a/src/tools/miri/src/intrinsics/mod.rs b/src/tools/miri/src/intrinsics/mod.rs index 9f7e2baaaf972..74e39ffd9332a 100644 --- a/src/tools/miri/src/intrinsics/mod.rs +++ b/src/tools/miri/src/intrinsics/mod.rs @@ -1,3 +1,5 @@ +#![warn(clippy::arithmetic_side_effects)] + mod atomic; mod simd; diff --git a/src/tools/miri/src/intrinsics/simd.rs b/src/tools/miri/src/intrinsics/simd.rs index df52f223db39e..7818227c3bde7 100644 --- a/src/tools/miri/src/intrinsics/simd.rs +++ b/src/tools/miri/src/intrinsics/simd.rs @@ -458,23 +458,45 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { ); } - // The mask must be an integer or an array. - assert!( - mask.layout.ty.is_integral() - || matches!(mask.layout.ty.kind(), ty::Array(elemty, _) if elemty == &this.tcx.types.u8) - ); - assert_eq!(bitmask_len, mask.layout.size.bits()); assert_eq!(dest_len, yes_len); assert_eq!(dest_len, no_len); - let dest_len = u32::try_from(dest_len).unwrap(); - let bitmask_len = u32::try_from(bitmask_len).unwrap(); - // To read the mask, we transmute it to an integer. - // That does the right thing wrt endianness. - let mask_ty = this.machine.layouts.uint(mask.layout.size).unwrap(); - let mask = mask.transmute(mask_ty, this)?; - let mask: u64 = this.read_scalar(&mask)?.to_bits(mask_ty.size)?.try_into().unwrap(); + // Read the mask, either as an integer or as an array. + let mask: u64 = match mask.layout.ty.kind() { + ty::Uint(_) => { + // Any larger integer type is fine. + assert!(mask.layout.size.bits() >= bitmask_len); + this.read_scalar(mask)?.to_bits(mask.layout.size)?.try_into().unwrap() + } + ty::Array(elem, _len) if elem == &this.tcx.types.u8 => { + // The array must have exactly the right size. + assert_eq!(mask.layout.size.bits(), bitmask_len); + // Read the raw bytes. + let mask = mask.assert_mem_place(); // arrays cannot be immediate + let mask_bytes = + this.read_bytes_ptr_strip_provenance(mask.ptr(), mask.layout.size)?; + // Turn them into a `u64` in the right way. + let mask_size = mask.layout.size.bytes_usize(); + let mut mask_arr = [0u8; 8]; + match this.data_layout().endian { + Endian::Little => { + // Fill the first N bytes. + mask_arr[..mask_size].copy_from_slice(mask_bytes); + u64::from_le_bytes(mask_arr) + } + Endian::Big => { + // Fill the last N bytes. + let i = mask_arr.len().strict_sub(mask_size); + mask_arr[i..].copy_from_slice(mask_bytes); + u64::from_be_bytes(mask_arr) + } + } + } + _ => bug!("simd_select_bitmask: invalid mask type {}", mask.layout.ty), + }; + let dest_len = u32::try_from(dest_len).unwrap(); + let bitmask_len = u32::try_from(bitmask_len).unwrap(); for i in 0..dest_len { let bit_i = simd_bitmask_index(i, dest_len, this.data_layout().endian); let mask = mask & 1u64.checked_shl(bit_i).unwrap(); @@ -508,14 +530,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { ); } - // Returns either an unsigned integer or array of `u8`. - assert!( - dest.layout.ty.is_integral() - || matches!(dest.layout.ty.kind(), ty::Array(elemty, _) if elemty == &this.tcx.types.u8) - ); - assert_eq!(bitmask_len, dest.layout.size.bits()); let op_len = u32::try_from(op_len).unwrap(); - let mut res = 0u64; for i in 0..op_len { let op = this.read_immediate(&this.project_index(&op, i.into())?)?; @@ -525,11 +540,34 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { .unwrap(); } } - // We have to change the type of the place to be able to write `res` into it. This - // transmutes the integer to an array, which does the right thing wrt endianness. - let dest = - dest.transmute(this.machine.layouts.uint(dest.layout.size).unwrap(), this)?; - this.write_int(res, &dest)?; + // Write the result, depending on the `dest` type. + // Returns either an unsigned integer or array of `u8`. + match dest.layout.ty.kind() { + ty::Uint(_) => { + // Any larger integer type is fine, it will be zero-extended. + assert!(dest.layout.size.bits() >= bitmask_len); + this.write_int(res, dest)?; + } + ty::Array(elem, _len) if elem == &this.tcx.types.u8 => { + // The array must have exactly the right size. + assert_eq!(dest.layout.size.bits(), bitmask_len); + // We have to write the result byte-for-byte. + let res_size = dest.layout.size.bytes_usize(); + let res_bytes; + let res_bytes_slice = match this.data_layout().endian { + Endian::Little => { + res_bytes = res.to_le_bytes(); + &res_bytes[..res_size] // take the first N bytes + } + Endian::Big => { + res_bytes = res.to_be_bytes(); + &res_bytes[res_bytes.len().strict_sub(res_size)..] // take the last N bytes + } + }; + this.write_bytes_ptr(dest.ptr(), res_bytes_slice.iter().cloned())?; + } + _ => bug!("simd_bitmask: invalid return type {}", dest.layout.ty), + } } "cast" | "as" | "cast_ptr" | "expose_provenance" | "with_exposed_provenance" => { let [op] = check_arg_count(args)?; diff --git a/src/tools/miri/tests/pass/intrinsics/portable-simd.rs b/src/tools/miri/tests/pass/intrinsics/portable-simd.rs index de87f153b6f4a..c4ec45e4bbef9 100644 --- a/src/tools/miri/tests/pass/intrinsics/portable-simd.rs +++ b/src/tools/miri/tests/pass/intrinsics/portable-simd.rs @@ -323,38 +323,77 @@ fn simd_mask() { #[repr(simd, packed)] #[allow(non_camel_case_types)] #[derive(Copy, Clone, Debug, PartialEq)] - struct i32x10(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32); + struct i32x10([i32; 10]); impl i32x10 { fn splat(x: i32) -> Self { - Self(x, x, x, x, x, x, x, x, x, x) - } - fn from_array(a: [i32; 10]) -> Self { - unsafe { std::mem::transmute(a) } + Self([x; 10]) } } unsafe { - let mask = i32x10::from_array([!0, !0, 0, !0, 0, 0, !0, 0, !0, 0]); + let mask = i32x10([!0, !0, 0, !0, 0, 0, !0, 0, !0, 0]); + let mask_bits = if cfg!(target_endian = "little") { 0b0101001011 } else { 0b1101001010 }; + let mask_bytes = + if cfg!(target_endian = "little") { [0b01001011, 0b01] } else { [0b11, 0b01001010] }; + let bitmask1: u16 = simd_bitmask(mask); let bitmask2: [u8; 2] = simd_bitmask(mask); - if cfg!(target_endian = "little") { - assert_eq!(bitmask1, 0b0101001011); - assert_eq!(bitmask2, [0b01001011, 0b01]); - } else { - assert_eq!(bitmask1, 0b1101001010); - assert_eq!(bitmask2, [0b11, 0b01001010]); - } + assert_eq!(bitmask1, mask_bits); + assert_eq!(bitmask2, mask_bytes); + let selected1 = simd_select_bitmask::( - if cfg!(target_endian = "little") { 0b0101001011 } else { 0b1101001010 }, + mask_bits, i32x10::splat(!0), // yes i32x10::splat(0), // no ); let selected2 = simd_select_bitmask::<[u8; 2], _>( - if cfg!(target_endian = "little") { [0b01001011, 0b01] } else { [0b11, 0b01001010] }, + mask_bytes, i32x10::splat(!0), // yes i32x10::splat(0), // no ); assert_eq!(selected1, mask); - assert_eq!(selected2, selected1); + assert_eq!(selected2, mask); + } + + // Test for a mask where the next multiple of 8 is not a power of two. + #[repr(simd, packed)] + #[allow(non_camel_case_types)] + #[derive(Copy, Clone, Debug, PartialEq)] + struct i32x20([i32; 20]); + impl i32x20 { + fn splat(x: i32) -> Self { + Self([x; 20]) + } + } + unsafe { + let mask = i32x20([!0, !0, 0, !0, 0, 0, !0, 0, !0, 0, 0, 0, 0, !0, !0, !0, !0, !0, !0, !0]); + let mask_bits = if cfg!(target_endian = "little") { + 0b11111110000101001011 + } else { + 0b11010010100001111111 + }; + let mask_bytes = if cfg!(target_endian = "little") { + [0b01001011, 0b11100001, 0b1111] + } else { + [0b1101, 0b00101000, 0b01111111] + }; + + let bitmask1: u32 = simd_bitmask(mask); + let bitmask2: [u8; 3] = simd_bitmask(mask); + assert_eq!(bitmask1, mask_bits); + assert_eq!(bitmask2, mask_bytes); + + let selected1 = simd_select_bitmask::( + mask_bits, + i32x20::splat(!0), // yes + i32x20::splat(0), // no + ); + let selected2 = simd_select_bitmask::<[u8; 3], _>( + mask_bytes, + i32x20::splat(!0), // yes + i32x20::splat(0), // no + ); + assert_eq!(selected1, mask); + assert_eq!(selected2, mask); } } From ba45198c9bff9e7ab7d36171595e78a0f5f636d1 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 9 Jun 2024 11:36:32 +0200 Subject: [PATCH 30/41] use strict ops in some places --- src/tools/miri/src/intrinsics/simd.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/tools/miri/src/intrinsics/simd.rs b/src/tools/miri/src/intrinsics/simd.rs index 7818227c3bde7..b2b81df55bb31 100644 --- a/src/tools/miri/src/intrinsics/simd.rs +++ b/src/tools/miri/src/intrinsics/simd.rs @@ -499,7 +499,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { let bitmask_len = u32::try_from(bitmask_len).unwrap(); for i in 0..dest_len { let bit_i = simd_bitmask_index(i, dest_len, this.data_layout().endian); - let mask = mask & 1u64.checked_shl(bit_i).unwrap(); + let mask = mask & 1u64.strict_shl(bit_i); let yes = this.read_immediate(&this.project_index(&yes, i.into())?)?; let no = this.read_immediate(&this.project_index(&no, i.into())?)?; let dest = this.project_index(&dest, i.into())?; @@ -511,7 +511,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { // If the mask is "padded", ensure that padding is all-zero. // This deliberately does not use `simd_bitmask_index`; these bits are outside // the bitmask. It does not matter in which order we check them. - let mask = mask & 1u64.checked_shl(i).unwrap(); + let mask = mask & 1u64.strict_shl(i); if mask != 0 { throw_ub_format!( "a SIMD bitmask less than 8 bits long must be filled with 0s for the remaining bits" @@ -535,9 +535,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { for i in 0..op_len { let op = this.read_immediate(&this.project_index(&op, i.into())?)?; if simd_element_to_bool(op)? { - res |= 1u64 - .checked_shl(simd_bitmask_index(i, op_len, this.data_layout().endian)) - .unwrap(); + let bit_i = simd_bitmask_index(i, op_len, this.data_layout().endian); + res |= 1u64.strict_shl(bit_i); } } // Write the result, depending on the `dest` type. @@ -653,8 +652,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { let val = if src_index < left_len { this.read_immediate(&this.project_index(&left, src_index)?)? - } else if src_index < left_len.checked_add(right_len).unwrap() { - let right_idx = src_index.checked_sub(left_len).unwrap(); + } else if src_index < left_len.strict_add(right_len) { + let right_idx = src_index.strict_sub(left_len); this.read_immediate(&this.project_index(&right, right_idx)?)? } else { throw_ub_format!( @@ -693,8 +692,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { let val = if src_index < left_len { this.read_immediate(&this.project_index(&left, src_index)?)? - } else if src_index < left_len.checked_add(right_len).unwrap() { - let right_idx = src_index.checked_sub(left_len).unwrap(); + } else if src_index < left_len.strict_add(right_len) { + let right_idx = src_index.strict_sub(left_len); this.read_immediate(&this.project_index(&right, right_idx)?)? } else { throw_ub_format!( From 844450ae3a8e5beec3ee514d5d87f688b0822b09 Mon Sep 17 00:00:00 2001 From: tiif Date: Fri, 7 Jun 2024 22:07:49 +0800 Subject: [PATCH 31/41] First attempt --- src/tools/miri/src/clock.rs | 25 +++++++++++++------ .../tests/pass-dep/concurrency/linux-futex.rs | 16 ++++++++++++ 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/tools/miri/src/clock.rs b/src/tools/miri/src/clock.rs index fd0c121626b65..c18e1bc7a9ec6 100644 --- a/src/tools/miri/src/clock.rs +++ b/src/tools/miri/src/clock.rs @@ -6,7 +6,7 @@ use std::time::{Duration, Instant as StdInstant}; /// This number is pretty random, but it has been shown to approximately cause /// some sample programs to run within an order of magnitude of real time on desktop CPUs. /// (See `tests/pass/shims/time-with-isolation*.rs`.) -const NANOSECONDS_PER_BASIC_BLOCK: u64 = 5000; +const NANOSECONDS_PER_BASIC_BLOCK: u128 = 5000; #[derive(Debug)] pub struct Instant { @@ -16,7 +16,7 @@ pub struct Instant { #[derive(Debug)] enum InstantKind { Host(StdInstant), - Virtual { nanoseconds: u64 }, + Virtual { nanoseconds: u128 }, } impl Instant { @@ -25,9 +25,8 @@ impl Instant { InstantKind::Host(instant) => instant.checked_add(duration).map(|i| Instant { kind: InstantKind::Host(i) }), InstantKind::Virtual { nanoseconds } => - u128::from(nanoseconds) + nanoseconds .checked_add(duration.as_nanos()) - .and_then(|n| u64::try_from(n).ok()) .map(|nanoseconds| Instant { kind: InstantKind::Virtual { nanoseconds } }), } } @@ -39,7 +38,19 @@ impl Instant { ( InstantKind::Virtual { nanoseconds }, InstantKind::Virtual { nanoseconds: earlier }, - ) => Duration::from_nanos(nanoseconds.saturating_sub(earlier)), + ) => { + // Trade some nanosecond precision to prevent as much overflow as possible. + let duration = match u64::try_from( + // Manually convert from nanosecond to millisecond. + // If it exceeded u64::MAX millisecond, we will just use u64::MAX millisecond, + // Duration can't take in more than u64::MAX millisecond. + nanoseconds.saturating_sub(earlier).saturating_div(1_000_000), + ) { + Ok(millisecond) => Duration::from_millis(millisecond), + _ => Duration::from_millis(u64::MAX), + }; + Duration::new(duration.as_secs(), duration.subsec_nanos()) + } _ => panic!("all `Instant` must be of the same kind"), } } @@ -59,7 +70,7 @@ enum ClockKind { }, Virtual { /// The "current virtual time". - nanoseconds: Cell, + nanoseconds: Cell, }, } @@ -93,7 +104,7 @@ impl Clock { ClockKind::Host { .. } => std::thread::sleep(duration), ClockKind::Virtual { nanoseconds } => { // Just pretend that we have slept for some time. - let nanos: u64 = duration.as_nanos().try_into().unwrap(); + let nanos: u128 = duration.as_nanos().try_into().unwrap(); nanoseconds.update(|x| x + nanos); } } diff --git a/src/tools/miri/tests/pass-dep/concurrency/linux-futex.rs b/src/tools/miri/tests/pass-dep/concurrency/linux-futex.rs index d21f953672dee..59319b93748ba 100644 --- a/src/tools/miri/tests/pass-dep/concurrency/linux-futex.rs +++ b/src/tools/miri/tests/pass-dep/concurrency/linux-futex.rs @@ -280,7 +280,23 @@ fn concurrent_wait_wake() { assert!(woken > 0 && woken < rounds); } +// Reproduce of https://github.com/rust-lang/miri/issues/3647. +fn large_timeout() { + let futex: i32 = 123; + + unsafe { + libc::syscall( + libc::SYS_futex, + addr_of!(futex), + libc::FUTEX_WAIT, + 123, + &libc::timespec { tv_sec: 184467440839020, tv_nsec: 117558982 }, + ); + } +} + fn main() { + large_timeout(); wake_nobody(); wake_dangling(); wait_wrong_val(); From 0bca4e1a227665a3b1c737f874048ccd9633b248 Mon Sep 17 00:00:00 2001 From: tiif Date: Fri, 7 Jun 2024 22:59:36 +0800 Subject: [PATCH 32/41] Convert u128 to nanosecond --- src/tools/miri/src/clock.rs | 16 ++++++---------- .../tests/pass-dep/concurrency/linux-futex.rs | 4 ++-- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/tools/miri/src/clock.rs b/src/tools/miri/src/clock.rs index c18e1bc7a9ec6..da2c54745a031 100644 --- a/src/tools/miri/src/clock.rs +++ b/src/tools/miri/src/clock.rs @@ -39,15 +39,11 @@ impl Instant { InstantKind::Virtual { nanoseconds }, InstantKind::Virtual { nanoseconds: earlier }, ) => { - // Trade some nanosecond precision to prevent as much overflow as possible. - let duration = match u64::try_from( - // Manually convert from nanosecond to millisecond. - // If it exceeded u64::MAX millisecond, we will just use u64::MAX millisecond, - // Duration can't take in more than u64::MAX millisecond. - nanoseconds.saturating_sub(earlier).saturating_div(1_000_000), - ) { - Ok(millisecond) => Duration::from_millis(millisecond), - _ => Duration::from_millis(u64::MAX), + // If it exceeded u64::MAX nanosecond, we will just keep u64::MAX nanosecond, + // Duration can't take in more than u64::MAX. + let duration = match u64::try_from(nanoseconds.saturating_sub(earlier)) { + Ok(nanosecond) => Duration::from_nanos(nanosecond), + Err(_err) => Duration::from_nanos(u64::MAX), }; Duration::new(duration.as_secs(), duration.subsec_nanos()) } @@ -104,7 +100,7 @@ impl Clock { ClockKind::Host { .. } => std::thread::sleep(duration), ClockKind::Virtual { nanoseconds } => { // Just pretend that we have slept for some time. - let nanos: u128 = duration.as_nanos().try_into().unwrap(); + let nanos: u128 = duration.as_nanos(); nanoseconds.update(|x| x + nanos); } } diff --git a/src/tools/miri/tests/pass-dep/concurrency/linux-futex.rs b/src/tools/miri/tests/pass-dep/concurrency/linux-futex.rs index 59319b93748ba..5e266c7949fa6 100644 --- a/src/tools/miri/tests/pass-dep/concurrency/linux-futex.rs +++ b/src/tools/miri/tests/pass-dep/concurrency/linux-futex.rs @@ -280,7 +280,7 @@ fn concurrent_wait_wake() { assert!(woken > 0 && woken < rounds); } -// Reproduce of https://github.com/rust-lang/miri/issues/3647. +// Reproduce https://github.com/rust-lang/miri/issues/3647. This should not ICE. fn large_timeout() { let futex: i32 = 123; @@ -296,7 +296,6 @@ fn large_timeout() { } fn main() { - large_timeout(); wake_nobody(); wake_dangling(); wait_wrong_val(); @@ -305,4 +304,5 @@ fn main() { wait_wake(); wait_wake_bitset(); concurrent_wait_wake(); + large_timeout(); } From 9f60709ffd1d9d0fc7d775d18cce23d0c60ed649 Mon Sep 17 00:00:00 2001 From: tiif Date: Fri, 7 Jun 2024 23:12:07 +0800 Subject: [PATCH 33/41] Remove test --- .../tests/pass-dep/concurrency/linux-futex.rs | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/tools/miri/tests/pass-dep/concurrency/linux-futex.rs b/src/tools/miri/tests/pass-dep/concurrency/linux-futex.rs index 5e266c7949fa6..d21f953672dee 100644 --- a/src/tools/miri/tests/pass-dep/concurrency/linux-futex.rs +++ b/src/tools/miri/tests/pass-dep/concurrency/linux-futex.rs @@ -280,21 +280,6 @@ fn concurrent_wait_wake() { assert!(woken > 0 && woken < rounds); } -// Reproduce https://github.com/rust-lang/miri/issues/3647. This should not ICE. -fn large_timeout() { - let futex: i32 = 123; - - unsafe { - libc::syscall( - libc::SYS_futex, - addr_of!(futex), - libc::FUTEX_WAIT, - 123, - &libc::timespec { tv_sec: 184467440839020, tv_nsec: 117558982 }, - ); - } -} - fn main() { wake_nobody(); wake_dangling(); @@ -304,5 +289,4 @@ fn main() { wait_wake(); wait_wake_bitset(); concurrent_wait_wake(); - large_timeout(); } From 9cf04b5a22e20fd0a537196a610b0e2b85b8d485 Mon Sep 17 00:00:00 2001 From: tiif Date: Sat, 8 Jun 2024 00:56:48 +0800 Subject: [PATCH 34/41] Use modulo operation to convert nanosecond to Duration --- src/tools/miri/src/clock.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/tools/miri/src/clock.rs b/src/tools/miri/src/clock.rs index da2c54745a031..942593530c377 100644 --- a/src/tools/miri/src/clock.rs +++ b/src/tools/miri/src/clock.rs @@ -39,13 +39,14 @@ impl Instant { InstantKind::Virtual { nanoseconds }, InstantKind::Virtual { nanoseconds: earlier }, ) => { - // If it exceeded u64::MAX nanosecond, we will just keep u64::MAX nanosecond, - // Duration can't take in more than u64::MAX. - let duration = match u64::try_from(nanoseconds.saturating_sub(earlier)) { - Ok(nanosecond) => Duration::from_nanos(nanosecond), - Err(_err) => Duration::from_nanos(u64::MAX), - }; - Duration::new(duration.as_secs(), duration.subsec_nanos()) + // It is possible for second to overflow because u64::MAX < (u128::MAX / 1e9). + let seconds = u64::try_from( + nanoseconds.saturating_sub(earlier).saturating_div(1_000_000_000), + ) + .unwrap(); + // It is impossible for nanosecond to overflow because u32::MAX > 1e9. + let nanosecond = u32::try_from(nanoseconds.wrapping_rem(1_000_000_000)).unwrap(); + Duration::new(seconds, nanosecond) } _ => panic!("all `Instant` must be of the same kind"), } From aa8323585cf3b8846b4dd83f48404a26f7df63c9 Mon Sep 17 00:00:00 2001 From: tiif Date: Sat, 8 Jun 2024 01:21:56 +0800 Subject: [PATCH 35/41] Move duration division out --- src/tools/miri/src/clock.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/tools/miri/src/clock.rs b/src/tools/miri/src/clock.rs index 942593530c377..b8d0c847069c1 100644 --- a/src/tools/miri/src/clock.rs +++ b/src/tools/miri/src/clock.rs @@ -39,13 +39,11 @@ impl Instant { InstantKind::Virtual { nanoseconds }, InstantKind::Virtual { nanoseconds: earlier }, ) => { + let duration = nanoseconds.saturating_sub(earlier); // It is possible for second to overflow because u64::MAX < (u128::MAX / 1e9). - let seconds = u64::try_from( - nanoseconds.saturating_sub(earlier).saturating_div(1_000_000_000), - ) - .unwrap(); + let seconds = u64::try_from(duration.saturating_div(1_000_000_000)).unwrap(); // It is impossible for nanosecond to overflow because u32::MAX > 1e9. - let nanosecond = u32::try_from(nanoseconds.wrapping_rem(1_000_000_000)).unwrap(); + let nanosecond = u32::try_from(duration.wrapping_rem(1_000_000_000)).unwrap(); Duration::new(seconds, nanosecond) } _ => panic!("all `Instant` must be of the same kind"), From d0fb350b6adaebfe342ddadb220baa415ab29824 Mon Sep 17 00:00:00 2001 From: byt <55319043+tiif@users.noreply.github.com> Date: Sun, 9 Jun 2024 17:59:06 +0800 Subject: [PATCH 36/41] Add comment for u128 to u64 conversion. Co-authored-by: Ralf Jung --- src/tools/miri/src/clock.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tools/miri/src/clock.rs b/src/tools/miri/src/clock.rs index b8d0c847069c1..2ace9b66de7b1 100644 --- a/src/tools/miri/src/clock.rs +++ b/src/tools/miri/src/clock.rs @@ -40,6 +40,8 @@ impl Instant { InstantKind::Virtual { nanoseconds: earlier }, ) => { let duration = nanoseconds.saturating_sub(earlier); + // `Duration` does not provide a nice constructor from a `u128` of nanoseconds, + // so we have to implement this ourselves. // It is possible for second to overflow because u64::MAX < (u128::MAX / 1e9). let seconds = u64::try_from(duration.saturating_div(1_000_000_000)).unwrap(); // It is impossible for nanosecond to overflow because u32::MAX > 1e9. From e85c521f371ff6f5ffd813ccc453827064d2473d Mon Sep 17 00:00:00 2001 From: byt <55319043+tiif@users.noreply.github.com> Date: Sun, 9 Jun 2024 17:59:30 +0800 Subject: [PATCH 37/41] Checked add for duration update Co-authored-by: Ralf Jung --- src/tools/miri/src/clock.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/miri/src/clock.rs b/src/tools/miri/src/clock.rs index 2ace9b66de7b1..e730f523c7b0b 100644 --- a/src/tools/miri/src/clock.rs +++ b/src/tools/miri/src/clock.rs @@ -102,7 +102,7 @@ impl Clock { ClockKind::Virtual { nanoseconds } => { // Just pretend that we have slept for some time. let nanos: u128 = duration.as_nanos(); - nanoseconds.update(|x| x + nanos); + nanoseconds.update(|x| x.checked_add(nanos).expect("Miri's virtual clock cannot represent an execution this long")); } } } From 21d66afb8f9f3736fcd2a2ff82f1d7aa31f15915 Mon Sep 17 00:00:00 2001 From: tiif Date: Sun, 9 Jun 2024 17:58:21 +0800 Subject: [PATCH 38/41] Saturate to u64::MAX --- src/tools/miri/src/clock.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tools/miri/src/clock.rs b/src/tools/miri/src/clock.rs index e730f523c7b0b..de6e883f117ec 100644 --- a/src/tools/miri/src/clock.rs +++ b/src/tools/miri/src/clock.rs @@ -43,7 +43,8 @@ impl Instant { // `Duration` does not provide a nice constructor from a `u128` of nanoseconds, // so we have to implement this ourselves. // It is possible for second to overflow because u64::MAX < (u128::MAX / 1e9). - let seconds = u64::try_from(duration.saturating_div(1_000_000_000)).unwrap(); + // It will be saturated to u64::MAX seconds if the value after division exceeds u64::MAX. + let seconds = u64::try_from(duration / 1_000_000_000).unwrap_or(u64::MAX); // It is impossible for nanosecond to overflow because u32::MAX > 1e9. let nanosecond = u32::try_from(duration.wrapping_rem(1_000_000_000)).unwrap(); Duration::new(seconds, nanosecond) From 40182becc33908598d6ee00e5741fd6d218fa2c1 Mon Sep 17 00:00:00 2001 From: tiif Date: Sun, 9 Jun 2024 18:00:43 +0800 Subject: [PATCH 39/41] Run cargo fmt --- src/tools/miri/src/clock.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tools/miri/src/clock.rs b/src/tools/miri/src/clock.rs index de6e883f117ec..3f86767277afb 100644 --- a/src/tools/miri/src/clock.rs +++ b/src/tools/miri/src/clock.rs @@ -103,7 +103,10 @@ impl Clock { ClockKind::Virtual { nanoseconds } => { // Just pretend that we have slept for some time. let nanos: u128 = duration.as_nanos(); - nanoseconds.update(|x| x.checked_add(nanos).expect("Miri's virtual clock cannot represent an execution this long")); + nanoseconds.update(|x| { + x.checked_add(nanos) + .expect("Miri's virtual clock cannot represent an execution this long") + }); } } } From 87c4d29ce247111f5bdc2d139fe0ac44c72b506e Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 9 Jun 2024 13:07:30 +0200 Subject: [PATCH 40/41] don't panic if time computaton overflows --- src/tools/miri/src/clock.rs | 33 ++++++++----- src/tools/miri/src/concurrency/sync.rs | 5 +- src/tools/miri/src/concurrency/thread.rs | 55 +++++++++++++++++++-- src/tools/miri/src/lib.rs | 4 +- src/tools/miri/src/shims/time.rs | 18 ++----- src/tools/miri/src/shims/unix/linux/sync.rs | 39 ++++++--------- src/tools/miri/src/shims/unix/sync.rs | 9 ++-- src/tools/miri/src/shims/windows/sync.rs | 6 +-- 8 files changed, 102 insertions(+), 67 deletions(-) diff --git a/src/tools/miri/src/clock.rs b/src/tools/miri/src/clock.rs index 3f86767277afb..c9bffc449f7f0 100644 --- a/src/tools/miri/src/clock.rs +++ b/src/tools/miri/src/clock.rs @@ -20,14 +20,20 @@ enum InstantKind { } impl Instant { - pub fn checked_add(&self, duration: Duration) -> Option { + /// Will try to add `duration`, but if that overflows it may add less. + pub fn add_lossy(&self, duration: Duration) -> Instant { match self.kind { - InstantKind::Host(instant) => - instant.checked_add(duration).map(|i| Instant { kind: InstantKind::Host(i) }), - InstantKind::Virtual { nanoseconds } => - nanoseconds - .checked_add(duration.as_nanos()) - .map(|nanoseconds| Instant { kind: InstantKind::Virtual { nanoseconds } }), + InstantKind::Host(instant) => { + // If this overflows, try adding just 1h and assume that will not overflow. + let i = instant + .checked_add(duration) + .unwrap_or_else(|| instant.checked_add(Duration::from_secs(3600)).unwrap()); + Instant { kind: InstantKind::Host(i) } + } + InstantKind::Virtual { nanoseconds } => { + let n = nanoseconds.saturating_add(duration.as_nanos()); + Instant { kind: InstantKind::Virtual { nanoseconds: n } } + } } } @@ -63,8 +69,9 @@ pub struct Clock { #[derive(Debug)] enum ClockKind { Host { - /// The "time anchor" for this machine's monotone clock. - time_anchor: StdInstant, + /// The "epoch" for this machine's monotone clock: + /// the moment we consider to be time = 0. + epoch: StdInstant, }, Virtual { /// The "current virtual time". @@ -76,7 +83,7 @@ impl Clock { /// Create a new clock based on the availability of communication with the host. pub fn new(communicate: bool) -> Self { let kind = if communicate { - ClockKind::Host { time_anchor: StdInstant::now() } + ClockKind::Host { epoch: StdInstant::now() } } else { ClockKind::Virtual { nanoseconds: 0.into() } }; @@ -111,10 +118,10 @@ impl Clock { } } - /// Return the `anchor` instant, to convert between monotone instants and durations relative to the anchor. - pub fn anchor(&self) -> Instant { + /// Return the `epoch` instant (time = 0), to convert between monotone instants and absolute durations. + pub fn epoch(&self) -> Instant { match &self.kind { - ClockKind::Host { time_anchor } => Instant { kind: InstantKind::Host(*time_anchor) }, + ClockKind::Host { epoch } => Instant { kind: InstantKind::Host(*epoch) }, ClockKind::Virtual { .. } => Instant { kind: InstantKind::Virtual { nanoseconds: 0 } }, } } diff --git a/src/tools/miri/src/concurrency/sync.rs b/src/tools/miri/src/concurrency/sync.rs index 030546b7cb518..76a045c4dc166 100644 --- a/src/tools/miri/src/concurrency/sync.rs +++ b/src/tools/miri/src/concurrency/sync.rs @@ -1,5 +1,6 @@ use std::collections::{hash_map::Entry, VecDeque}; use std::ops::Not; +use std::time::Duration; use rustc_data_structures::fx::FxHashMap; use rustc_index::{Idx, IndexVec}; @@ -623,7 +624,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, condvar: CondvarId, mutex: MutexId, - timeout: Option, + timeout: Option<(TimeoutClock, TimeoutAnchor, Duration)>, retval_succ: Scalar, retval_timeout: Scalar, dest: MPlaceTy<'tcx>, @@ -704,7 +705,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &mut self, addr: u64, bitset: u32, - timeout: Option, + timeout: Option<(TimeoutClock, TimeoutAnchor, Duration)>, retval_succ: Scalar, retval_timeout: Scalar, dest: MPlaceTy<'tcx>, diff --git a/src/tools/miri/src/concurrency/thread.rs b/src/tools/miri/src/concurrency/thread.rs index e76c16fb83067..6a2b99825adc4 100644 --- a/src/tools/miri/src/concurrency/thread.rs +++ b/src/tools/miri/src/concurrency/thread.rs @@ -407,7 +407,7 @@ impl VisitProvenance for Frame<'_, Provenance, FrameExtra<'_>> { /// The moment in time when a blocked thread should be woken up. #[derive(Debug)] -pub enum Timeout { +enum Timeout { Monotonic(Instant), RealTime(SystemTime), } @@ -421,6 +421,34 @@ impl Timeout { time.duration_since(SystemTime::now()).unwrap_or(Duration::ZERO), } } + + /// Will try to add `duration`, but if that overflows it may add less. + fn add_lossy(&self, duration: Duration) -> Self { + match self { + Timeout::Monotonic(i) => Timeout::Monotonic(i.add_lossy(duration)), + Timeout::RealTime(s) => { + // If this overflows, try adding just 1h and assume that will not overflow. + Timeout::RealTime( + s.checked_add(duration) + .unwrap_or_else(|| s.checked_add(Duration::from_secs(3600)).unwrap()), + ) + } + } + } +} + +/// The clock to use for the timeout you are asking for. +#[derive(Debug, Copy, Clone)] +pub enum TimeoutClock { + Monotonic, + RealTime, +} + +/// Whether the timeout is relative or absolute. +#[derive(Debug, Copy, Clone)] +pub enum TimeoutAnchor { + Relative, + Absolute, } /// A set of threads. @@ -995,13 +1023,30 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { fn block_thread( &mut self, reason: BlockReason, - timeout: Option, + timeout: Option<(TimeoutClock, TimeoutAnchor, Duration)>, callback: impl UnblockCallback<'tcx> + 'tcx, ) { let this = self.eval_context_mut(); - if !this.machine.communicate() && matches!(timeout, Some(Timeout::RealTime(..))) { - panic!("cannot have `RealTime` callback with isolation enabled!") - } + let timeout = timeout.map(|(clock, anchor, duration)| { + let anchor = match clock { + TimeoutClock::RealTime => { + assert!( + this.machine.communicate(), + "cannot have `RealTime` timeout with isolation enabled!" + ); + Timeout::RealTime(match anchor { + TimeoutAnchor::Absolute => SystemTime::UNIX_EPOCH, + TimeoutAnchor::Relative => SystemTime::now(), + }) + } + TimeoutClock::Monotonic => + Timeout::Monotonic(match anchor { + TimeoutAnchor::Absolute => this.machine.clock.epoch(), + TimeoutAnchor::Relative => this.machine.clock.now(), + }), + }; + anchor.add_lossy(duration) + }); this.machine.threads.block_thread(reason, timeout, callback); } diff --git a/src/tools/miri/src/lib.rs b/src/tools/miri/src/lib.rs index 94aed0645fa4d..11cbbde06aa08 100644 --- a/src/tools/miri/src/lib.rs +++ b/src/tools/miri/src/lib.rs @@ -132,8 +132,8 @@ pub use crate::concurrency::{ init_once::{EvalContextExt as _, InitOnceId}, sync::{CondvarId, EvalContextExt as _, MutexId, RwLockId, SynchronizationObjects}, thread::{ - BlockReason, EvalContextExt as _, StackEmptyCallback, ThreadId, ThreadManager, Timeout, - UnblockCallback, + BlockReason, EvalContextExt as _, StackEmptyCallback, ThreadId, ThreadManager, + TimeoutAnchor, TimeoutClock, UnblockCallback, }, }; pub use crate::diagnostics::{ diff --git a/src/tools/miri/src/shims/time.rs b/src/tools/miri/src/shims/time.rs index 8206b15d0a084..ae17196f0b78d 100644 --- a/src/tools/miri/src/shims/time.rs +++ b/src/tools/miri/src/shims/time.rs @@ -78,7 +78,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { this.check_no_isolation("`clock_gettime` with `REALTIME` clocks")?; system_time_to_duration(&SystemTime::now())? } else if relative_clocks.contains(&clk_id) { - this.machine.clock.now().duration_since(this.machine.clock.anchor()) + this.machine.clock.now().duration_since(this.machine.clock.epoch()) } else { let einval = this.eval_libc("EINVAL"); this.set_last_error(einval)?; @@ -246,7 +246,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { // QueryPerformanceCounter uses a hardware counter as its basis. // Miri will emulate a counter with a resolution of 1 nanosecond. - let duration = this.machine.clock.now().duration_since(this.machine.clock.anchor()); + let duration = this.machine.clock.now().duration_since(this.machine.clock.epoch()); let qpc = i64::try_from(duration.as_nanos()).map_err(|_| { err_unsup_format!("programs running longer than 2^63 nanoseconds are not supported") })?; @@ -282,7 +282,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { // This returns a u64, with time units determined dynamically by `mach_timebase_info`. // We return plain nanoseconds. - let duration = this.machine.clock.now().duration_since(this.machine.clock.anchor()); + let duration = this.machine.clock.now().duration_since(this.machine.clock.epoch()); let res = u64::try_from(duration.as_nanos()).map_err(|_| { err_unsup_format!("programs running longer than 2^64 nanoseconds are not supported") })?; @@ -323,16 +323,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { return Ok(-1); } }; - // If adding the duration overflows, let's just sleep for an hour. Waking up early is always acceptable. - let now = this.machine.clock.now(); - let timeout_time = now - .checked_add(duration) - .unwrap_or_else(|| now.checked_add(Duration::from_secs(3600)).unwrap()); - let timeout_time = Timeout::Monotonic(timeout_time); this.block_thread( BlockReason::Sleep, - Some(timeout_time), + Some((TimeoutClock::Monotonic, TimeoutAnchor::Relative, duration)), callback!( @capture<'tcx> {} @unblock = |_this| { panic!("sleeping thread unblocked before time is up") } @@ -351,12 +345,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { let timeout_ms = this.read_scalar(timeout)?.to_u32()?; let duration = Duration::from_millis(timeout_ms.into()); - let timeout_time = this.machine.clock.now().checked_add(duration).unwrap(); - let timeout_time = Timeout::Monotonic(timeout_time); this.block_thread( BlockReason::Sleep, - Some(timeout_time), + Some((TimeoutClock::Monotonic, TimeoutAnchor::Relative, duration)), callback!( @capture<'tcx> {} @unblock = |_this| { panic!("sleeping thread unblocked before time is up") } diff --git a/src/tools/miri/src/shims/unix/linux/sync.rs b/src/tools/miri/src/shims/unix/linux/sync.rs index 3e0d5e58d4cda..bd21203907419 100644 --- a/src/tools/miri/src/shims/unix/linux/sync.rs +++ b/src/tools/miri/src/shims/unix/linux/sync.rs @@ -1,5 +1,3 @@ -use std::time::SystemTime; - use crate::*; /// Implementation of the SYS_futex syscall. @@ -84,15 +82,9 @@ pub fn futex<'tcx>( } let timeout = this.deref_pointer_as(&args[3], this.libc_ty_layout("timespec"))?; - let timeout_time = if this.ptr_is_null(timeout.ptr())? { + let timeout = if this.ptr_is_null(timeout.ptr())? { None } else { - let realtime = op & futex_realtime == futex_realtime; - if realtime { - this.check_no_isolation( - "`futex` syscall with `op=FUTEX_WAIT` and non-null timeout with `FUTEX_CLOCK_REALTIME`", - )?; - } let duration = match this.read_timespec(&timeout)? { Some(duration) => duration, None => { @@ -102,23 +94,22 @@ pub fn futex<'tcx>( return Ok(()); } }; - Some(if wait_bitset { + let timeout_clock = if op & futex_realtime == futex_realtime { + this.check_no_isolation( + "`futex` syscall with `op=FUTEX_WAIT` and non-null timeout with `FUTEX_CLOCK_REALTIME`", + )?; + TimeoutClock::RealTime + } else { + TimeoutClock::Monotonic + }; + let timeout_anchor = if wait_bitset { // FUTEX_WAIT_BITSET uses an absolute timestamp. - if realtime { - Timeout::RealTime(SystemTime::UNIX_EPOCH.checked_add(duration).unwrap()) - } else { - Timeout::Monotonic( - this.machine.clock.anchor().checked_add(duration).unwrap(), - ) - } + TimeoutAnchor::Absolute } else { // FUTEX_WAIT uses a relative timestamp. - if realtime { - Timeout::RealTime(SystemTime::now().checked_add(duration).unwrap()) - } else { - Timeout::Monotonic(this.machine.clock.now().checked_add(duration).unwrap()) - } - }) + TimeoutAnchor::Relative + }; + Some((timeout_clock, timeout_anchor, duration)) }; // There may be a concurrent thread changing the value of addr // and then invoking the FUTEX_WAKE syscall. It is critical that the @@ -172,7 +163,7 @@ pub fn futex<'tcx>( this.futex_wait( addr_usize, bitset, - timeout_time, + timeout, Scalar::from_target_isize(0, this), // retval_succ Scalar::from_target_isize(-1, this), // retval_timeout dest.clone(), diff --git a/src/tools/miri/src/shims/unix/sync.rs b/src/tools/miri/src/shims/unix/sync.rs index 7d4c32bc87e91..be6732b1b67ed 100644 --- a/src/tools/miri/src/shims/unix/sync.rs +++ b/src/tools/miri/src/shims/unix/sync.rs @@ -1,5 +1,4 @@ use std::sync::atomic::{AtomicBool, Ordering}; -use std::time::SystemTime; use rustc_target::abi::Size; @@ -849,11 +848,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { return Ok(()); } }; - let timeout_time = if is_cond_clock_realtime(this, clock_id) { + let timeout_clock = if is_cond_clock_realtime(this, clock_id) { this.check_no_isolation("`pthread_cond_timedwait` with `CLOCK_REALTIME`")?; - Timeout::RealTime(SystemTime::UNIX_EPOCH.checked_add(duration).unwrap()) + TimeoutClock::RealTime } else if clock_id == this.eval_libc_i32("CLOCK_MONOTONIC") { - Timeout::Monotonic(this.machine.clock.anchor().checked_add(duration).unwrap()) + TimeoutClock::Monotonic } else { throw_unsup_format!("unsupported clock id: {}", clock_id); }; @@ -861,7 +860,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { this.condvar_wait( id, mutex_id, - Some(timeout_time), + Some((timeout_clock, TimeoutAnchor::Absolute, duration)), Scalar::from_i32(0), this.eval_libc("ETIMEDOUT"), // retval_timeout dest.clone(), diff --git a/src/tools/miri/src/shims/windows/sync.rs b/src/tools/miri/src/shims/windows/sync.rs index e77986dd5fe02..e1fbb77037cfb 100644 --- a/src/tools/miri/src/shims/windows/sync.rs +++ b/src/tools/miri/src/shims/windows/sync.rs @@ -157,11 +157,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { }; let size = Size::from_bytes(size); - let timeout_time = if timeout_ms == this.eval_windows_u32("c", "INFINITE") { + let timeout = if timeout_ms == this.eval_windows_u32("c", "INFINITE") { None } else { let duration = Duration::from_millis(timeout_ms.into()); - Some(Timeout::Monotonic(this.machine.clock.now().checked_add(duration).unwrap())) + Some((TimeoutClock::Monotonic, TimeoutAnchor::Relative, duration)) }; // See the Linux futex implementation for why this fence exists. @@ -177,7 +177,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { this.futex_wait( addr, u32::MAX, // bitset - timeout_time, + timeout, Scalar::from_i32(1), // retval_succ Scalar::from_i32(0), // retval_timeout dest.clone(), From 69512c7b1e000da54aba7e4f8aa1c64473dff9c0 Mon Sep 17 00:00:00 2001 From: tiif Date: Sun, 9 Jun 2024 19:44:06 +0800 Subject: [PATCH 41/41] Follow up fix for eventfd shim --- .../miri/src/shims/unix/linux/eventfd.rs | 28 ++++++++++--------- .../fail-dep/libc/libc_eventfd_read_block.rs | 3 +- .../fail-dep/libc/libc_eventfd_write_block.rs | 3 +- .../miri/tests/pass-dep/libc/libc-eventfd.rs | 19 +++++++++---- 4 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/tools/miri/src/shims/unix/linux/eventfd.rs b/src/tools/miri/src/shims/unix/linux/eventfd.rs index 3080d5b8d0716..cae5abca3bd08 100644 --- a/src/tools/miri/src/shims/unix/linux/eventfd.rs +++ b/src/tools/miri/src/shims/unix/linux/eventfd.rs @@ -1,6 +1,7 @@ //! Linux `eventfd` implementation. use std::io; use std::io::{Error, ErrorKind}; +use std::mem; use rustc_target::abi::Endian; @@ -9,8 +10,8 @@ use crate::{concurrency::VClock, *}; use self::shims::unix::fd::FileDescriptor; -/// Minimum size of u8 array to hold u64 value. -const U64_MIN_ARRAY_SIZE: usize = 8; +// We'll only do reads and writes in chunks of size u64. +const U64_ARRAY_SIZE: usize = mem::size_of::(); /// Maximum value that the eventfd counter can hold. const MAX_COUNTER: u64 = u64::MAX - 1; @@ -51,7 +52,7 @@ impl FileDescription for Event { ecx: &mut MiriInterpCx<'tcx>, ) -> InterpResult<'tcx, io::Result> { // Check the size of slice, and return error only if the size of the slice < 8. - let Some(bytes) = bytes.first_chunk_mut::() else { + let Some(bytes) = bytes.first_chunk_mut::() else { return Ok(Err(Error::from(ErrorKind::InvalidInput))); }; // Block when counter == 0. @@ -63,7 +64,7 @@ impl FileDescription for Event { throw_unsup_format!("eventfd: blocking is unsupported"); } } else { - // Prevent false alarm in data race detection when doing synchronisation via eventfd. + // Synchronize with all prior `write` calls to this FD. ecx.acquire_clock(&self.clock); // Return the counter in the host endianness using the buffer provided by caller. *bytes = match ecx.tcx.sess.target.endian { @@ -71,7 +72,7 @@ impl FileDescription for Event { Endian::Big => self.counter.to_be_bytes(), }; self.counter = 0; - return Ok(Ok(U64_MIN_ARRAY_SIZE)); + return Ok(Ok(U64_ARRAY_SIZE)); } } @@ -94,7 +95,7 @@ impl FileDescription for Event { ecx: &mut MiriInterpCx<'tcx>, ) -> InterpResult<'tcx, io::Result> { // Check the size of slice, and return error only if the size of the slice < 8. - let Some(bytes) = bytes.first_chunk::() else { + let Some(bytes) = bytes.first_chunk::() else { return Ok(Err(Error::from(ErrorKind::InvalidInput))); }; // Convert from bytes to int according to host endianness. @@ -110,8 +111,10 @@ impl FileDescription for Event { // Else, block. match self.counter.checked_add(num) { Some(new_count @ 0..=MAX_COUNTER) => { - // Prevent false alarm in data race detection when doing synchronisation via eventfd. - self.clock.join(&ecx.release_clock().unwrap()); + // Future `read` calls will synchronize with this write, so update the FD clock. + if let Some(clock) = &ecx.release_clock() { + self.clock.join(clock); + } self.counter = new_count; } None | Some(u64::MAX) => { @@ -123,7 +126,7 @@ impl FileDescription for Event { } } }; - Ok(Ok(U64_MIN_ARRAY_SIZE)) + Ok(Ok(U64_ARRAY_SIZE)) } } @@ -163,9 +166,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } let mut is_nonblock = false; - // Unload the flag that we support. + // Unset the flag that we support. // After unloading, flags != 0 means other flags are used. if flags & efd_cloexec == efd_cloexec { + // cloexec is ignored because Miri does not support exec. flags &= !efd_cloexec; } if flags & efd_nonblock == efd_nonblock { @@ -173,9 +177,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { is_nonblock = true; } if flags != 0 { - let einval = this.eval_libc("EINVAL"); - this.set_last_error(einval)?; - return Ok(Scalar::from_i32(-1)); + throw_unsup_format!("eventfd: encountered unknown unsupported flags {:#x}", flags); } let fd = this.machine.fds.insert_fd(FileDescriptor::new(Event { diff --git a/src/tools/miri/tests/fail-dep/libc/libc_eventfd_read_block.rs b/src/tools/miri/tests/fail-dep/libc/libc_eventfd_read_block.rs index b24635f93404c..fb9a23206c604 100644 --- a/src/tools/miri/tests/fail-dep/libc/libc_eventfd_read_block.rs +++ b/src/tools/miri/tests/fail-dep/libc/libc_eventfd_read_block.rs @@ -1,5 +1,4 @@ -//@ignore-target-windows: No eventfd on Windows -//@ignore-target-apple: No eventfd in macos +//@only-target-linux fn main() { // eventfd read will block when EFD_NONBLOCK flag is clear and counter = 0. // This will pass when blocking is implemented. diff --git a/src/tools/miri/tests/fail-dep/libc/libc_eventfd_write_block.rs b/src/tools/miri/tests/fail-dep/libc/libc_eventfd_write_block.rs index 32ca4a919f7be..2037a516dea1c 100644 --- a/src/tools/miri/tests/fail-dep/libc/libc_eventfd_write_block.rs +++ b/src/tools/miri/tests/fail-dep/libc/libc_eventfd_write_block.rs @@ -1,5 +1,4 @@ -//@ignore-target-windows: No eventfd on Windows -//@ignore-target-apple: No eventfd in macos +//@only-target-linux fn main() { // eventfd write will block when EFD_NONBLOCK flag is clear // and the addition caused counter to exceed u64::MAX - 1. diff --git a/src/tools/miri/tests/pass-dep/libc/libc-eventfd.rs b/src/tools/miri/tests/pass-dep/libc/libc-eventfd.rs index 6af195316e8df..a3567eeb7cb4a 100644 --- a/src/tools/miri/tests/pass-dep/libc/libc-eventfd.rs +++ b/src/tools/miri/tests/pass-dep/libc/libc-eventfd.rs @@ -1,5 +1,4 @@ -//@ignore-target-windows: No eventfd in windows -//@ignore-target-apple: No eventfd in macos +//@only-target-linux // test_race depends on a deterministic schedule. //@compile-flags: -Zmiri-preemption-rate=0 @@ -42,9 +41,11 @@ fn test_read_write() { // value -1. let mut buf: [u8; 8] = [0; 8]; let res = read_bytes(fd, &mut buf); + let e = std::io::Error::last_os_error(); + assert_eq!(e.raw_os_error(), Some(libc::EAGAIN)); assert_eq!(res, -1); - // Write with supplied buffer that > 8 bytes should be allowed. + // Write with supplied buffer bigger than 8 bytes should be allowed. let sized_9_data: [u8; 9]; if cfg!(target_endian = "big") { // Adjust the data based on the endianness of host system. @@ -55,19 +56,23 @@ fn test_read_write() { let res = write_bytes(fd, sized_9_data); assert_eq!(res, 8); - // Read with supplied buffer that < 8 bytes should fail with return + // Read with supplied buffer smaller than 8 bytes should fail with return // value -1. let mut buf: [u8; 7] = [1; 7]; let res = read_bytes(fd, &mut buf); + let e = std::io::Error::last_os_error(); + assert_eq!(e.raw_os_error(), Some(libc::EINVAL)); assert_eq!(res, -1); - // Write with supplied buffer that < 8 bytes should fail with return + // Write with supplied buffer smaller than 8 bytes should fail with return // value -1. let size_7_data: [u8; 7] = [1; 7]; let res = write_bytes(fd, size_7_data); + let e = std::io::Error::last_os_error(); + assert_eq!(e.raw_os_error(), Some(libc::EINVAL)); assert_eq!(res, -1); - // Read with supplied buffer > 8 bytes should be allowed. + // Read with supplied buffer bigger than 8 bytes should be allowed. let mut buf: [u8; 9] = [1; 9]; let res = read_bytes(fd, &mut buf); assert_eq!(res, 8); @@ -75,6 +80,8 @@ fn test_read_write() { // Write u64::MAX should fail. let u64_max_bytes: [u8; 8] = [255; 8]; let res = write_bytes(fd, u64_max_bytes); + let e = std::io::Error::last_os_error(); + assert_eq!(e.raw_os_error(), Some(libc::EINVAL)); assert_eq!(res, -1); }