Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/tools/miri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name = "miri"
repository = "https://github.com/rust-lang/miri"
version = "0.1.0"
default-run = "miri"
edition = "2021"
edition = "2024"

[lib]
test = true # we have unit tests
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/cargo-miri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ license = "MIT OR Apache-2.0"
name = "cargo-miri"
repository = "https://github.com/rust-lang/miri"
version = "0.1.0"
edition = "2021"
edition = "2024"

[[bin]]
name = "cargo-miri"
Expand Down
34 changes: 22 additions & 12 deletions src/tools/miri/cargo-miri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,37 @@ fn main() {
return;
}

let Some(first) = args.next() else {
show_error!(
"`cargo-miri` called without first argument; please only invoke this binary through `cargo miri`"
)
};

// The way rustdoc invokes rustc is indistinguishable from the way cargo invokes rustdoc by the
// arguments alone. `phase_cargo_rustdoc` sets this environment variable to let us disambiguate.
if env::var_os("MIRI_CALLED_FROM_RUSTDOC").is_some() {
// ...however, we then also see this variable when rustdoc invokes us as the testrunner!
// The runner is invoked as `$runtool ($runtool-arg)* output_file`;
// since we don't specify any runtool-args, and rustdoc supplies multiple arguments to
// the test-builder unconditionally, we can just check the number of remaining arguments:
if args.len() == 1 {
phase_runner(args, RunnerPhase::Rustdoc);
} else {
phase_rustc(args, RustcPhase::Rustdoc);
// In that case the first argument is `runner` and there are no more arguments.
match first.as_str() {
"runner" => phase_runner(args, RunnerPhase::Rustdoc),
flag if flag.starts_with("--") || flag.starts_with("@") => {
// This is probably rustdoc invoking us to build the test. But we need to get `first`
// "back onto the iterator", it is some part of the rustc invocation.
phase_rustc(iter::once(first).chain(args), RustcPhase::Rustdoc);
}
_ => {
show_error!(
"`cargo-miri` failed to recognize which phase of the build process this is, please report a bug.\n\
We are inside MIRI_CALLED_FROM_RUSTDOC.\n\
The command-line arguments were: {:#?}",
Vec::from_iter(env::args()),
);
}
}

return;
}

let Some(first) = args.next() else {
show_error!(
"`cargo-miri` called without first argument; please only invoke this binary through `cargo miri`"
)
};
match first.as_str() {
"miri" => phase_cargo_miri(args),
"runner" => phase_runner(args, RunnerPhase::Cargo),
Expand Down
11 changes: 4 additions & 7 deletions src/tools/miri/cargo-miri/src/phases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
// Set `--target-dir` to `miri` inside the original target directory.
let target_dir = get_target_dir(&metadata);
cmd.arg("--target-dir").arg(target_dir);
// Enable cross-target doctests (for consistency between different cargo versions).
cmd.arg("-Zdoctest-xcompile");

// *After* we set all the flags that need setting, forward everything else. Make sure to skip
// `--target-dir` (which would otherwise be set twice).
Expand Down Expand Up @@ -666,11 +668,6 @@ pub fn phase_rustdoc(mut args: impl Iterator<Item = String>) {
if arg == "--extern" {
// Patch --extern arguments to use *.rmeta files, since phase_cargo_rustc only creates stub *.rlib files.
forward_patched_extern_arg(&mut args, &mut cmd);
} else if arg == "--test-runtool" {
// An existing --test-runtool flag indicates cargo is running in cross-target mode, which we don't support.
// Note that this is only passed when cargo is run with the unstable -Zdoctest-xcompile flag;
// otherwise, we won't be called as rustdoc at all.
show_error!("cross-interpreting doctests is not currently supported by Miri.");
} else {
cmd.arg(arg);
}
Expand Down Expand Up @@ -702,10 +699,10 @@ pub fn phase_rustdoc(mut args: impl Iterator<Item = String>) {
// make sure the 'miri' flag is set for rustdoc
cmd.arg("--cfg").arg("miri");

// Make rustdoc call us back.
// Make rustdoc call us back for the build.
// (cargo already sets `--test-runtool` to us since we are the cargo test runner.)
let cargo_miri_path = env::current_exe().expect("current executable path invalid");
cmd.arg("--test-builder").arg(&cargo_miri_path); // invoked by forwarding most arguments
cmd.arg("--test-runtool").arg(&cargo_miri_path); // invoked with just a single path argument

debug_cmd("[cargo-miri rustdoc]", verbose, &cmd);
exec(cmd)
Expand Down
8 changes: 3 additions & 5 deletions src/tools/miri/cargo-miri/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ pub fn setup(
let ask_user = !only_setup;
let print_sysroot = only_setup && has_arg_flag("--print-sysroot"); // whether we just print the sysroot path
let show_setup = only_setup && !print_sysroot;
if !only_setup {
if let Some(sysroot) = std::env::var_os("MIRI_SYSROOT") {
// Skip setup step if MIRI_SYSROOT is explicitly set, *unless* we are `cargo miri setup`.
return sysroot.into();
}
if !only_setup && let Some(sysroot) = std::env::var_os("MIRI_SYSROOT") {
// Skip setup step if MIRI_SYSROOT is explicitly set, *unless* we are `cargo miri setup`.
return sysroot.into();
}

// Determine where the rust sources are located. The env var trumps auto-detection.
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/miri-script/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name = "miri-script"
repository = "https://github.com/rust-lang/miri"
version = "0.1.0"
default-run = "miri-script"
edition = "2021"
edition = "2024"

[workspace]
# We make this a workspace root so that cargo does not go looking in ../Cargo.toml for the workspace root.
Expand Down
14 changes: 5 additions & 9 deletions src/tools/miri/miri-script/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,11 +675,9 @@ impl Command {
let mut early_flags = Vec::<OsString>::new();

// In `dep` mode, the target is already passed via `MIRI_TEST_TARGET`
if !dep {
if let Some(target) = &target {
early_flags.push("--target".into());
early_flags.push(target.into());
}
if !dep && let Some(target) = &target {
early_flags.push("--target".into());
early_flags.push(target.into());
}
early_flags.push("--edition".into());
early_flags.push(edition.as_deref().unwrap_or("2021").into());
Expand Down Expand Up @@ -707,10 +705,8 @@ impl Command {
// Add Miri flags
let mut cmd = cmd.args(&miri_flags).args(&early_flags).args(&flags);
// For `--dep` we also need to set the target in the env var.
if dep {
if let Some(target) = &target {
cmd = cmd.env("MIRI_TEST_TARGET", target);
}
if dep && let Some(target) = &target {
cmd = cmd.env("MIRI_TEST_TARGET", target);
}
// Finally, run the thing.
Ok(cmd.run()?)
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/miri-script/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl MiriEnv {
let toolchain = &self.toolchain;
let mut cmd = cmd!(
self.sh,
"rustfmt +{toolchain} --edition=2021 --config-path {config_path} --unstable-features --skip-children {flags...}"
"rustfmt +{toolchain} --edition=2024 --config-path {config_path} --unstable-features --skip-children {flags...}"
);
if first {
// Log an abbreviating command, and only once.
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2ad5f8607d0e192b60b130e5cc416b477b351c18
a69bc17fb8026bdc0d24bb1896ff95f0eba1da4e
2 changes: 1 addition & 1 deletion src/tools/miri/src/bin/miri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ fn jemalloc_magic() {
// linking, so we need to explicitly depend on the function.
#[cfg(target_os = "macos")]
{
extern "C" {
unsafe extern "C" {
fn _rjem_je_zone_register();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl NodeDebugInfo {
/// Add a name to the tag. If a same tag is associated to several pointers,
/// it can have several names which will be separated by commas.
pub fn add_name(&mut self, name: &str) {
if let Some(ref mut prev_name) = &mut self.name {
if let Some(prev_name) = &mut self.name {
prev_name.push_str(", ");
prev_name.push_str(name);
} else {
Expand Down
3 changes: 1 addition & 2 deletions src/tools/miri/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,7 @@ impl<'tcx> MiriMachine<'tcx> {
AccessedAlloc(AllocId(id), access_kind) =>
format!("{access_kind} to allocation with id {id}"),
FreedAlloc(AllocId(id)) => format!("freed allocation with id {id}"),
RejectedIsolatedOp(ref op) =>
format!("{op} was made to return an error due to isolation"),
RejectedIsolatedOp(op) => format!("{op} was made to return an error due to isolation"),
ProgressReport { .. } =>
format!("progress report: current operation being executed is here"),
Int2Ptr { .. } => format!("integer-to-pointer cast"),
Expand Down
1 change: 0 additions & 1 deletion src/tools/miri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#![feature(variant_count)]
#![feature(yeet_expr)]
#![feature(nonzero_ops)]
#![feature(let_chains)]
#![feature(strict_overflow_ops)]
#![feature(pointer_is_aligned_to)]
#![feature(unqualified_local_imports)]
Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/src/shims/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Now we make a function call, and pass `data` as first and only argument.
let f_instance = this.get_ptr_fn(try_fn)?.as_instance()?;
trace!("try_fn: {:?}", f_instance);
#[allow(clippy::cloned_ref_to_slice_refs)] // the code is clearer as-is
this.call_function(
f_instance,
ExternAbi::Rust,
Expand Down
17 changes: 6 additions & 11 deletions src/tools/miri/test-cargo-miri/run-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,24 +142,19 @@ def test_cargo_miri_run():
)

def test_cargo_miri_test():
# rustdoc is not run on foreign targets
is_foreign = ARGS.target is not None
default_ref = "test.cross-target.stdout.ref" if is_foreign else "test.default.stdout.ref"
filter_ref = "test.filter.cross-target.stdout.ref" if is_foreign else "test.filter.stdout.ref"

test("`cargo miri test`",
cargo_miri("test"),
default_ref, "test.empty.ref",
"test.default.stdout.ref", "test.empty.ref",
env={'MIRIFLAGS': "-Zmiri-seed=4242"},
)
test("`cargo miri test` (no isolation, no doctests)",
cargo_miri("test") + ["--bins", "--tests"], # no `--lib`, we disabled that in `Cargo.toml`
"test.cross-target.stdout.ref", "test.empty.ref",
"test.no-doc.stdout.ref", "test.empty.ref",
env={'MIRIFLAGS': "-Zmiri-disable-isolation"},
)
test("`cargo miri test` (with filter)",
cargo_miri("test") + ["--", "--format=pretty", "pl"],
filter_ref, "test.empty.ref",
"test.filter.stdout.ref", "test.empty.ref",
)
test("`cargo miri test` (test target)",
cargo_miri("test") + ["--test", "test", "--", "--format=pretty"],
Expand All @@ -171,7 +166,7 @@ def test_cargo_miri_test():
)
test("`cargo miri t` (subcrate, no isolation)",
cargo_miri("t") + ["-p", "subcrate"],
"test.subcrate.cross-target.stdout.ref" if is_foreign else "test.subcrate.stdout.ref",
"test.subcrate.stdout.ref",
"test.empty.ref",
env={'MIRIFLAGS': "-Zmiri-disable-isolation"},
)
Expand All @@ -181,12 +176,12 @@ def test_cargo_miri_test():
)
test("`cargo miri test` (custom target dir)",
cargo_miri("test") + ["--target-dir=custom-test"],
default_ref, "test.empty.ref",
"test.default.stdout.ref", "test.empty.ref",
)
del os.environ["CARGO_TARGET_DIR"] # this overrides `build.target-dir` passed by `--config`, so unset it
test("`cargo miri test` (config-cli)",
cargo_miri("test") + ["--config=build.target-dir=\"config-cli\""],
default_ref, "test.empty.ref",
"test.default.stdout.ref", "test.empty.ref",
)
if ARGS.multi_target:
test_cargo_miri_multi_target()
Expand Down
12 changes: 0 additions & 12 deletions src/tools/miri/test-cargo-miri/test.filter.cross-target.stdout.ref

This file was deleted.

10 changes: 10 additions & 0 deletions src/tools/miri/test-cargo-miri/test.multiple_targets.stdout.ref
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@ running 6 tests
...i..
test result: ok. 5 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in $TIME


running 5 tests
.....
test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME


running 5 tests
.....
test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

This file was deleted.

22 changes: 0 additions & 22 deletions src/tools/miri/tests/fail/weak_memory/racing_mixed_size.stderr

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fn main() {
mut_raw_mut();
partially_invalidate_mut();
drop_after_sharing();
// direct_mut_to_const_raw();
two_raw();
shr_and_raw();
disjoint_mutable_subborrows();
Expand Down
8 changes: 4 additions & 4 deletions src/tools/miri/tests/pass/coroutine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,18 @@ fn basic() {

fn smoke_resume_arg() {
fn drain<G: Coroutine<R, Yield = Y> + Unpin, R, Y>(
gen: &mut G,
gen_: &mut G,
inout: Vec<(R, CoroutineState<Y, G::Return>)>,
) where
Y: Debug + PartialEq,
G::Return: Debug + PartialEq,
{
let mut gen = Pin::new(gen);
let mut gen_ = Pin::new(gen_);

for (input, out) in inout {
assert_eq!(gen.as_mut().resume(input), out);
assert_eq!(gen_.as_mut().resume(input), out);
// Test if the coroutine is valid (according to type invariants).
let _ = unsafe { ManuallyDrop::new(ptr::read(gen.as_mut().get_unchecked_mut())) };
let _ = unsafe { ManuallyDrop::new(ptr::read(gen_.as_mut().get_unchecked_mut())) };
}
}

Expand Down
13 changes: 6 additions & 7 deletions src/tools/miri/tests/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ pub fn flagsplit(flags: &str) -> Vec<String> {
fn build_native_lib() -> PathBuf {
let cc = env::var("CC").unwrap_or_else(|_| "cc".into());
// Target directory that we can write to.
let so_target_dir =
Path::new(&env::var_os("CARGO_TARGET_DIR").unwrap()).join("miri-native-lib");
let so_target_dir = Path::new(env!("CARGO_TARGET_TMPDIR")).join("miri-native-lib");
// Create the directory if it does not already exist.
std::fs::create_dir_all(&so_target_dir)
.expect("Failed to create directory for shared object file");
Expand Down Expand Up @@ -101,7 +100,7 @@ fn miri_config(
let mut config = Config {
target: Some(target.to_owned()),
program,
out_dir: PathBuf::from(std::env::var_os("CARGO_TARGET_DIR").unwrap()).join("miri_ui"),
out_dir: PathBuf::from(env!("CARGO_TARGET_TMPDIR")).join("miri_ui"),
threads: std::env::var("MIRI_TEST_THREADS")
.ok()
.map(|threads| NonZero::new(threads.parse().unwrap()).unwrap()),
Expand Down Expand Up @@ -319,10 +318,10 @@ fn main() -> Result<()> {
let mut args = std::env::args_os();

// Skip the program name and check whether this is a `./miri run-dep` invocation
if let Some(first) = args.nth(1) {
if first == "--miri-run-dep-mode" {
return run_dep_mode(target, args);
}
if let Some(first) = args.nth(1)
&& first == "--miri-run-dep-mode"
{
return run_dep_mode(target, args);
}

ui(Mode::Pass, "tests/pass", &target, WithoutDependencies, tmpdir.path())?;
Expand Down
Loading