Skip to content

Commit

Permalink
Auto merge of #132512 - workingjubilee:update-miri-for-rustc-abi, r=R…
Browse files Browse the repository at this point in the history
…alfJung

miri: Directly use rustc_abi

I tried to make this a PR to the miri repo for funsies. Ironically, the integration flow meant that it would use a too-old toolchain hash, and I didn't understand the build system there enough to want to manually fiddle with the hashes.
  • Loading branch information
bors committed Nov 2, 2024
2 parents 07cbbdd + a953b32 commit 00ed73c
Show file tree
Hide file tree
Showing 61 changed files with 526 additions and 485 deletions.
2 changes: 1 addition & 1 deletion src/tools/miri/clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
arithmetic-side-effects-allowed = ["rustc_target::abi::Size"]
arithmetic-side-effects-allowed = ["rustc_abi::Size"]
2 changes: 1 addition & 1 deletion src/tools/miri/src/alloc_addresses/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use std::cell::RefCell;
use std::cmp::max;

use rand::Rng;
use rustc_abi::{Align, Size};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_span::Span;
use rustc_target::abi::{Align, Size};

use self::reuse_pool::ReusePool;
use crate::concurrency::VClock;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/alloc_addresses/reuse_pool.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Manages a pool of addresses that can be reused.
use rand::Rng;
use rustc_target::abi::{Align, Size};
use rustc_abi::{Align, Size};

use crate::concurrency::VClock;
use crate::{MemoryKind, MiriConfig, ThreadId};
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/alloc_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::alloc::Layout;
use std::borrow::Cow;
use std::{alloc, slice};

use rustc_abi::{Align, Size};
use rustc_middle::mir::interpret::AllocBytes;
use rustc_target::abi::{Align, Size};

/// Allocation bytes that explicitly handle the layout of the data they're storing.
/// This is necessary to interface with native code that accesses the program store in Miri.
Expand Down
6 changes: 3 additions & 3 deletions src/tools/miri/src/bin/miri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
extern crate tracing;

// The rustc crates we need
extern crate rustc_abi;
extern crate rustc_data_structures;
extern crate rustc_driver;
extern crate rustc_hir;
Expand All @@ -21,14 +22,14 @@ extern crate rustc_metadata;
extern crate rustc_middle;
extern crate rustc_session;
extern crate rustc_span;
extern crate rustc_target;

use std::env::{self, VarError};
use std::num::NonZero;
use std::path::PathBuf;
use std::str::FromStr;

use miri::{BacktraceStyle, BorrowTrackerMethod, ProvenanceMode, RetagFields, ValidationMode};
use rustc_abi::ExternAbi;
use rustc_data_structures::sync::Lrc;
use rustc_driver::Compilation;
use rustc_hir::def_id::LOCAL_CRATE;
Expand All @@ -47,7 +48,6 @@ use rustc_session::config::{CrateType, EntryFnType, ErrorOutputType, OptLevel};
use rustc_session::search_paths::PathKind;
use rustc_session::{CtfeBacktrace, EarlyDiagCtxt};
use rustc_span::def_id::DefId;
use rustc_target::spec::abi::Abi;
use tracing::debug;

struct MiriCompilerCalls {
Expand Down Expand Up @@ -368,7 +368,7 @@ fn entry_fn(tcx: TyCtxt<'_>) -> (DefId, EntryFnType) {
tcx.types.isize,
false,
hir::Safety::Safe,
Abi::Rust,
ExternAbi::Rust,
));

let correct_func_sig = check_function_signature(
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/borrow_tracker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::cell::RefCell;
use std::fmt;
use std::num::NonZero;

use rustc_abi::Size;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_middle::mir::RetagKind;
use rustc_target::abi::Size;
use smallvec::SmallVec;

use crate::*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::fmt;

use rustc_abi::Size;
use rustc_data_structures::fx::FxHashSet;
use rustc_span::{Span, SpanData};
use rustc_target::abi::Size;
use smallvec::SmallVec;

use crate::borrow_tracker::{GlobalStateInner, ProtectorKind};
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/borrow_tracker/tree_borrows/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
use std::{fmt, mem};

use rustc_abi::Size;
use rustc_data_structures::fx::FxHashSet;
use rustc_span::Span;
use rustc_target::abi::Size;
use smallvec::SmallVec;

use crate::borrow_tracker::tree_borrows::Permission;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/concurrency/cpu_affinity.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc_abi::Endian;
use rustc_middle::ty::layout::LayoutOf;
use rustc_target::abi::Endian;

use crate::*;

Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/concurrency/data_race.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ use std::cell::{Cell, Ref, RefCell, RefMut};
use std::fmt::Debug;
use std::mem;

use rustc_abi::{Align, HasDataLayout, Size};
use rustc_ast::Mutability;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_index::{Idx, IndexVec};
use rustc_middle::mir;
use rustc_middle::ty::Ty;
use rustc_span::Span;
use rustc_target::abi::{Align, HasDataLayout, Size};

use super::vector_clock::{VClock, VTimestamp, VectorIdx};
use super::weak_memory::EvalContextExt as _;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/concurrency/range_object_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
use std::ops::{Index, IndexMut, Range};

use rustc_abi::Size;
use rustc_const_eval::interpret::AllocRange;
use rustc_target::abi::Size;

#[derive(Clone, Debug)]
struct Elem<T> {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/concurrency/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use std::collections::hash_map::Entry;
use std::ops::Not;
use std::time::Duration;

use rustc_abi::Size;
use rustc_data_structures::fx::FxHashMap;
use rustc_index::{Idx, IndexVec};
use rustc_target::abi::Size;

use super::init_once::InitOnce;
use super::vector_clock::VClock;
Expand Down
4 changes: 2 additions & 2 deletions src/tools/miri/src/concurrency/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use std::task::Poll;
use std::time::{Duration, SystemTime};

use either::Either;
use rustc_abi::ExternAbi;
use rustc_const_eval::CTRL_C_RECEIVED;
use rustc_data_structures::fx::FxHashMap;
use rustc_hir::def_id::DefId;
use rustc_index::{Idx, IndexVec};
use rustc_middle::mir::Mutability;
use rustc_middle::ty::layout::TyAndLayout;
use rustc_span::Span;
use rustc_target::spec::abi::Abi;

use crate::concurrency::data_race;
use crate::shims::tls;
Expand Down Expand Up @@ -911,7 +911,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
&mut self,
thread: Option<MPlaceTy<'tcx>>,
start_routine: Pointer,
start_abi: Abi,
start_abi: ExternAbi,
func_arg: ImmTy<'tcx>,
ret_layout: TyAndLayout<'tcx>,
) -> InterpResult<'tcx, ThreadId> {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::fmt::{self, Write};
use std::num::NonZero;

use rustc_abi::{Align, Size};
use rustc_errors::{Diag, DiagMessage, Level};
use rustc_span::{DUMMY_SP, SpanData, Symbol};
use rustc_target::abi::{Align, Size};

use crate::borrow_tracker::stacked_borrows::diagnostics::TagHistory;
use crate::borrow_tracker::tree_borrows::diagnostics as tree_diagnostics;
Expand Down
6 changes: 3 additions & 3 deletions src/tools/miri/src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use std::path::PathBuf;
use std::task::Poll;
use std::{iter, thread};

use rustc_abi::ExternAbi;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_hir::def::Namespace;
use rustc_hir::def_id::DefId;
use rustc_middle::ty::layout::{LayoutCx, LayoutOf};
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_session::config::EntryFnType;
use rustc_target::spec::abi::Abi;

use crate::concurrency::thread::TlsAllocAction;
use crate::diagnostics::report_leaks;
Expand Down Expand Up @@ -391,7 +391,7 @@ pub fn create_ecx<'tcx>(

ecx.call_function(
start_instance,
Abi::Rust,
ExternAbi::Rust,
&[
ImmTy::from_scalar(
Scalar::from_pointer(main_ptr, &ecx),
Expand All @@ -409,7 +409,7 @@ pub fn create_ecx<'tcx>(
EntryFnType::Start => {
ecx.call_function(
entry_instance,
Abi::Rust,
ExternAbi::Rust,
&[argc, argv],
Some(&ret_place),
StackPopCleanup::Root { cleanup: true },
Expand Down
15 changes: 7 additions & 8 deletions src/tools/miri/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::time::Duration;
use std::{cmp, iter};

use rand::RngCore;
use rustc_abi::{Align, ExternAbi, FieldIdx, FieldsShape, Size, Variants};
use rustc_apfloat::Float;
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
use rustc_hir::Safety;
Expand All @@ -18,8 +19,6 @@ use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, MaybeResult, TyAndLayout};
use rustc_middle::ty::{self, FloatTy, IntTy, Ty, TyCtxt, UintTy};
use rustc_session::config::CrateType;
use rustc_span::{Span, Symbol};
use rustc_target::abi::{Align, FieldIdx, FieldsShape, Size, Variants};
use rustc_target::spec::abi::Abi;

use crate::*;

Expand Down Expand Up @@ -435,7 +434,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn call_function(
&mut self,
f: ty::Instance<'tcx>,
caller_abi: Abi,
caller_abi: ExternAbi,
args: &[ImmTy<'tcx>],
dest: Option<&MPlaceTy<'tcx>>,
stack_pop: StackPopCleanup,
Expand Down Expand Up @@ -917,7 +916,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
}

/// Check that the ABI is what we expect.
fn check_abi<'a>(&self, abi: Abi, exp_abi: Abi) -> InterpResult<'a, ()> {
fn check_abi<'a>(&self, abi: ExternAbi, exp_abi: ExternAbi) -> InterpResult<'a, ()> {
if abi != exp_abi {
throw_ub_format!(
"calling a function with ABI {} using caller ABI {}",
Expand Down Expand Up @@ -953,8 +952,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {

fn check_abi_and_shim_symbol_clash(
&mut self,
abi: Abi,
exp_abi: Abi,
abi: ExternAbi,
exp_abi: ExternAbi,
link_name: Symbol,
) -> InterpResult<'tcx, ()> {
self.check_abi(abi, exp_abi)?;
Expand All @@ -978,8 +977,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {

fn check_shim<'a, const N: usize>(
&mut self,
abi: Abi,
exp_abi: Abi,
abi: ExternAbi,
exp_abi: ExternAbi,
link_name: Symbol,
args: &'a [OpTy<'tcx>],
) -> InterpResult<'tcx, &'a [OpTy<'tcx>; N]>
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/intrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ mod atomic;
mod simd;

use rand::Rng;
use rustc_abi::Size;
use rustc_apfloat::{Float, Round};
use rustc_middle::mir;
use rustc_middle::ty::{self, FloatTy};
use rustc_span::{Symbol, sym};
use rustc_target::abi::Size;

use self::atomic::EvalContextExt as _;
use self::helpers::{ToHost, ToSoft, check_arg_count};
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/intrinsics/simd.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use either::Either;
use rustc_abi::{Endian, HasDataLayout};
use rustc_apfloat::{Float, Round};
use rustc_middle::ty::FloatTy;
use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::{mir, ty};
use rustc_span::{Symbol, sym};
use rustc_target::abi::{Endian, HasDataLayout};

use crate::helpers::{ToHost, ToSoft, bool_to_simd_element, check_arg_count, simd_element_to_bool};
use crate::*;
Expand Down
9 changes: 4 additions & 5 deletions src/tools/miri/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::{fmt, process};

use rand::rngs::StdRng;
use rand::{Rng, SeedableRng};
use rustc_abi::{Align, ExternAbi, Size};
use rustc_attr::InlineAttr;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
#[allow(unused)]
Expand All @@ -21,8 +22,6 @@ use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
use rustc_session::config::InliningThreshold;
use rustc_span::def_id::{CrateNum, DefId};
use rustc_span::{Span, SpanData, Symbol};
use rustc_target::abi::{Align, Size};
use rustc_target::spec::abi::Abi;

use crate::concurrency::cpu_affinity::{self, CpuAffinityMask};
use crate::concurrency::data_race::{self, NaReadType, NaWriteType};
Expand Down Expand Up @@ -1006,7 +1005,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
fn find_mir_or_eval_fn(
ecx: &mut MiriInterpCx<'tcx>,
instance: ty::Instance<'tcx>,
abi: Abi,
abi: ExternAbi,
args: &[FnArg<'tcx, Provenance>],
dest: &MPlaceTy<'tcx>,
ret: Option<mir::BasicBlock>,
Expand All @@ -1033,7 +1032,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
fn call_extra_fn(
ecx: &mut MiriInterpCx<'tcx>,
fn_val: DynSym,
abi: Abi,
abi: ExternAbi,
args: &[FnArg<'tcx, Provenance>],
dest: &MPlaceTy<'tcx>,
ret: Option<mir::BasicBlock>,
Expand Down Expand Up @@ -1075,7 +1074,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
// Call the lang item.
let panic = ecx.tcx.lang_items().get(reason.lang_item()).unwrap();
let panic = ty::Instance::mono(ecx.tcx.tcx, panic);
ecx.call_function(panic, Abi::Rust, &[], None, StackPopCleanup::Goto {
ecx.call_function(panic, ExternAbi::Rust, &[], None, StackPopCleanup::Goto {
ret: None,
unwind: mir::UnwindAction::Unreachable,
})?;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::iter;

use rand::Rng;
use rand::seq::IteratorRandom;
use rustc_abi::Size;
use rustc_apfloat::{Float, FloatConvert};
use rustc_middle::mir;
use rustc_target::abi::Size;

use crate::*;

Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/range_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use std::ops;

use rustc_target::abi::Size;
use rustc_abi::Size;

#[derive(Clone, Debug)]
struct Elem<T> {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/shims/alloc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::iter;

use rustc_abi::{Align, Size};
use rustc_ast::expand::allocator::AllocatorKind;
use rustc_target::abi::{Align, Size};

use crate::*;

Expand Down
Loading

0 comments on commit 00ed73c

Please sign in to comment.