Skip to content

update Miri #114560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 51 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
8ddc72e
Preparing for merge from rustc
Jul 30, 2023
16816aa
Merge from rustc
Jul 30, 2023
a4bfcbe
fmt
Jul 30, 2023
2183cda
Auto merge of #2996 - rust-lang:rustup-2023-07-30, r=oli-obk
bors Jul 30, 2023
e565624
refactor tests/utils a bit, and move some FS functions there
RalfJung Jul 30, 2023
a95a432
Auto merge of #2997 - RalfJung:test-utils, r=RalfJung
bors Jul 30, 2023
7f2eca6
rewrite miri script in Rust
osiewicz May 17, 2023
3f952f4
miri-script refactor
RalfJung Jul 30, 2023
efbd2a5
port to hand-rolled parser, since clap doesn't behave just the right way
RalfJung Jul 30, 2023
e1071af
Auto merge of #2909 - osiewicz:rewrite-miri-script-in-rust-2883, r=Ra…
bors Jul 31, 2023
a63db6d
add some interesting tests for alignment corner cases
RalfJung Jul 31, 2023
10d77b9
Auto merge of #3001 - RalfJung:align, r=RalfJung
bors Jul 31, 2023
26fc26f
fix oversight from new miri-script
RalfJung Jul 31, 2023
320cd7d
Auto merge of #3002 - RalfJung:miri-script, r=RalfJung
bors Jul 31, 2023
552700a
Preparing for merge from rustc
Aug 2, 2023
743be66
Merge from rustc
Aug 2, 2023
2d01258
fmt
Aug 2, 2023
f128057
Auto merge of #3003 - rust-lang:rustup-2023-08-02, r=RalfJung
bors Aug 2, 2023
c951208
add write_does_not_invalidate_all_aliases test, and enable direct_mut…
RalfJung Aug 2, 2023
42269c3
miri-script: simplify flag computation a bit
RalfJung Aug 2, 2023
df3b25f
add local_addr_of_mut test
RalfJung Aug 2, 2023
0ea879f
Auto merge of #3005 - RalfJung:miriscript, r=RalfJung
bors Aug 2, 2023
0640ae9
Auto merge of #3004 - RalfJung:borrow-tests, r=RalfJung
bors Aug 2, 2023
751cfa8
no need to forward all env vars
RalfJung Aug 2, 2023
27377cb
fix miri-script being silent when running './miri test'
RalfJung Aug 2, 2023
7fc0cbb
Command debug printing prints the environment these days, we can kill…
RalfJung Aug 2, 2023
6e9479f
cargo-miri: avoid set_env
RalfJung Aug 2, 2023
042cfd8
Auto merge of #3006 - RalfJung:miri-script-shell, r=RalfJung
bors Aug 2, 2023
0728354
Preparing for merge from rustc
Aug 3, 2023
adb446c
Merge from rustc
Aug 3, 2023
9bb8b66
fmt
Aug 3, 2023
460e92b
Auto merge of #3007 - rust-lang:rustup-2023-08-03, r=oli-obk
bors Aug 3, 2023
7956dbd
Avoid infinite recursion for auto-fmt and auto-clippy
oli-obk Aug 3, 2023
3c39dc2
add test checking that overlapping assignments work
RalfJung Aug 3, 2023
b8cfa76
Auto merge of #3010 - RalfJung:assign_overlapping, r=RalfJung
bors Aug 3, 2023
f8d75a4
Auto merge of #3009 - oli-obk:auto_actions, r=oli-obk
bors Aug 3, 2023
3df2884
A bit of spell-checking
saethlin Aug 3, 2023
325dc92
Preparing for merge from rustc
Aug 4, 2023
1a803a0
Merge from rustc
Aug 4, 2023
15c05fe
Auto merge of #3012 - rust-lang:rustup-2023-08-04, r=oli-obk
bors Aug 4, 2023
646f564
Auto merge of #3011 - saethlin:spellck, r=RalfJung
bors Aug 4, 2023
b3a8e8e
Preparing for merge from rustc
RalfJung Aug 5, 2023
e4540ed
Merge from rustc
RalfJung Aug 5, 2023
621aeeb
fmt
RalfJung Aug 5, 2023
3d9e8f1
Auto merge of #3014 - RalfJung:rustup, r=RalfJung
bors Aug 5, 2023
a73c86d
fix return place protection when the place is given as a local
RalfJung Aug 4, 2023
e55f494
borrow tracking: simplify provenance updating
RalfJung Aug 4, 2023
f0cbc7d
ensure we allow zero-sized references to functions and vtables
RalfJung Aug 4, 2023
ee674e7
tree borrows: consider some retags as writes for the purpose of data …
RalfJung Aug 4, 2023
36716dc
add a test ensuring that we enforce noalias on accesses
RalfJung Aug 5, 2023
d1174a9
Auto merge of #3013 - RalfJung:tree-borrow-data-races, r=RalfJung
bors Aug 5, 2023
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/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ jobs:
- name: clippy
run: ./miri clippy -- -D warnings
- name: rustdoc
run: RUSTDOCFLAGS="-Dwarnings" cargo doc --document-private-items
run: RUSTDOCFLAGS="-Dwarnings" ./miri cargo doc --document-private-items

# These jobs doesn't actually test anything, but they're only used to tell
# bors the build completed, as there is no practical way to detect when a
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ evaluation error was originally raised.
### UI testing

We use ui-testing in Miri, meaning we generate `.stderr` and `.stdout` files for the output
produced by Miri. You can use `./miri bless` to automatically (re)generate these files when
produced by Miri. You can use `./miri test --bless` to automatically (re)generate these files when
you add new tests or change how Miri presents certain output.

Note that when you also use `MIRIFLAGS` to change optimizations and similar, the ui output
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/cargo-miri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn main() {
return;
}

// The way rustdoc invokes rustc is indistuingishable from the way cargo invokes rustdoc by the
// 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!
Expand Down
9 changes: 5 additions & 4 deletions src/tools/miri/cargo-miri/src/phases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
let target = target.as_ref().unwrap_or(host);

// We always setup.
setup(&subcommand, target, &rustc_version, verbose);
let miri_sysroot = setup(&subcommand, target, &rustc_version, verbose);

// Invoke actual cargo for the job, but with different flags.
// We re-use `cargo test` and `cargo run`, which makes target and binary handling very easy but
Expand Down Expand Up @@ -159,6 +159,8 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
// Forward all further arguments (not consumed by `ArgSplitFlagValue`) to cargo.
cmd.args(args);

// Let it know where the Miri sysroot lives.
cmd.env("MIRI_SYSROOT", miri_sysroot);
// Set `RUSTC_WRAPPER` to ourselves. Cargo will prepend that binary to its usual invocation,
// i.e., the first argument is `rustc` -- which is what we use in `main` to distinguish
// the two codepaths. (That extra argument is why we prefer this over setting `RUSTC`.)
Expand Down Expand Up @@ -519,7 +521,7 @@ pub fn phase_runner(mut binary_args: impl Iterator<Item = String>, phase: Runner
// `.rmeta`.
// We also need to remove `--error-format` as cargo specifies that to be JSON,
// but when we run here, cargo does not interpret the JSON any more. `--json`
// then also nees to be dropped.
// then also needs to be dropped.
let mut args = info.args.into_iter();
let error_format_flag = "--error-format";
let json_flag = "--json";
Expand All @@ -538,8 +540,7 @@ pub fn phase_runner(mut binary_args: impl Iterator<Item = String>, phase: Runner
}
// Respect `MIRIFLAGS`.
if let Ok(a) = env::var("MIRIFLAGS") {
// This code is taken from `RUSTFLAGS` handling in cargo.
let args = a.split(' ').map(str::trim).filter(|s| !s.is_empty()).map(str::to_string);
let args = flagsplit(&a);
cmd.args(args);
}

Expand Down
23 changes: 16 additions & 7 deletions src/tools/miri/cargo-miri/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,20 @@ use crate::util::*;
/// Performs the setup required to make `cargo miri` work: Getting a custom-built libstd. Then sets
/// `MIRI_SYSROOT`. Skipped if `MIRI_SYSROOT` is already set, in which case we expect the user has
/// done all this already.
pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta, verbose: usize) {
pub fn setup(
subcommand: &MiriCommand,
target: &str,
rustc_version: &VersionMeta,
verbose: usize,
) -> PathBuf {
let only_setup = matches!(subcommand, MiriCommand::Setup);
let ask_user = !only_setup;
let print_sysroot = only_setup && has_arg_flag("--print-sysroot"); // whether we just print the sysroot path
if !only_setup && std::env::var_os("MIRI_SYSROOT").is_some() {
// Skip setup step if MIRI_SYSROOT is explicitly set, *unless* we are `cargo miri setup`.
return;
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();
}
}

// Determine where the rust sources are located. The env var trumps auto-detection.
Expand Down Expand Up @@ -92,6 +99,8 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
command.env("RUSTC", &cargo_miri_path);
}
command.env("MIRI_CALLED_FROM_SETUP", "1");
// Miri expects `MIRI_SYSROOT` to be set when invoked in target mode. Even if that directory is empty.
command.env("MIRI_SYSROOT", &sysroot_dir);
// Make sure there are no other wrappers getting in our way (Cc
// https://github.com/rust-lang/miri/issues/1421,
// https://github.com/rust-lang/miri/issues/2429). Looks like setting
Expand All @@ -105,7 +114,7 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
command.arg("-v");
}
} else {
// Supress output.
// Suppress output.
command.stdout(process::Stdio::null());
command.stderr(process::Stdio::null());
}
Expand All @@ -117,8 +126,6 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
// the user might have set, which is consistent with normal `cargo build` that does
// not apply `RUSTFLAGS` to the sysroot either.
let rustflags = &["-Cdebug-assertions=off", "-Coverflow-checks=on"];
// Make sure all target-level Miri invocations know their sysroot.
std::env::set_var("MIRI_SYSROOT", &sysroot_dir);

// Do the build.
if print_sysroot {
Expand Down Expand Up @@ -159,4 +166,6 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
// Print just the sysroot and nothing else to stdout; this way we do not need any escaping.
println!("{}", sysroot_dir.display());
}

sysroot_dir
}
45 changes: 6 additions & 39 deletions src/tools/miri/cargo-miri/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::collections::HashMap;
use std::env;
use std::ffi::OsString;
use std::fmt::Write as _;
use std::fs::File;
use std::io::{self, BufWriter, Read, Write};
use std::ops::Not;
Expand Down Expand Up @@ -114,6 +112,11 @@ pub fn cargo() -> Command {
Command::new(env::var_os("CARGO").unwrap_or_else(|| OsString::from("cargo")))
}

pub fn flagsplit(flags: &str) -> Vec<String> {
// This code is taken from `RUSTFLAGS` handling in cargo.
flags.split(' ').map(str::trim).filter(|s| !s.is_empty()).map(str::to_string).collect()
}

/// Execute the `Command`, where possible by replacing the current process with a new process
/// described by the `Command`. Then exit this process with the exit code of the new process.
pub fn exec(mut cmd: Command) -> ! {
Expand Down Expand Up @@ -242,46 +245,10 @@ pub fn local_crates(metadata: &Metadata) -> String {
local_crates
}

fn env_vars_from_cmd(cmd: &Command) -> Vec<(String, String)> {
let mut envs = HashMap::new();
for (key, value) in std::env::vars() {
envs.insert(key, value);
}
for (key, value) in cmd.get_envs() {
if let Some(value) = value {
envs.insert(key.to_string_lossy().to_string(), value.to_string_lossy().to_string());
} else {
envs.remove(&key.to_string_lossy().to_string());
}
}
let mut envs: Vec<_> = envs.into_iter().collect();
envs.sort();
envs
}

/// Debug-print a command that is going to be run.
pub fn debug_cmd(prefix: &str, verbose: usize, cmd: &Command) {
if verbose == 0 {
return;
}
// We only do a single `eprintln!` call to minimize concurrency interactions.
let mut out = prefix.to_string();
writeln!(out, " running command: env \\").unwrap();
if verbose > 1 {
// Print the full environment this will be called in.
for (key, value) in env_vars_from_cmd(cmd) {
writeln!(out, "{key}={value:?} \\").unwrap();
}
} else {
// Print only what has been changed for this `cmd`.
for (var, val) in cmd.get_envs() {
if let Some(val) = val {
writeln!(out, "{}={val:?} \\", var.to_string_lossy()).unwrap();
} else {
writeln!(out, "--unset={}", var.to_string_lossy()).unwrap();
}
}
}
write!(out, "{cmd:?}").unwrap();
eprintln!("{out}");
eprintln!("{prefix} running command: {cmd:?}");
}
Loading