Skip to content

Miri subtree update #132849

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 44 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
9622a79
Implement LLVM x86 vpclmulqdq intrinsics
TDecking Oct 22, 2024
05530b6
Adjust the vpclmulqdq test case
TDecking Oct 26, 2024
fb7bcd1
Merge pull request #3987 from TDecking/vpclmul
RalfJung Oct 27, 2024
cdc40a4
Add option for generating coverage reports
Mandragorian Oct 9, 2024
9023e35
Merge pull request #3954 from Mandragorian/coverage-report
RalfJung Oct 28, 2024
c8ce9e6
Android: Added syscall support
YohDeadfall Oct 25, 2024
f736269
Merge pull request #3992 from YohDeadfall/android-syscall
RalfJung Oct 28, 2024
6365ea1
contributing guide: mention expectations around force pushes and squa…
RalfJung Oct 27, 2024
d581d80
Merge pull request #3998 from RalfJung/contrib
oli-obk Oct 28, 2024
ff6e703
Preparing for merge from rustc
Oct 30, 2024
7d12e50
Merge from rustc
Oct 30, 2024
8a5f34a
Merge pull request #4001 from rust-lang/rustup-2024-10-30
RalfJung Oct 30, 2024
042f762
Change futex_wait errno from Scalar to IoError
noahmbright Oct 29, 2024
4ca9c07
Merge pull request #4000 from noahmbright/futex
RalfJung Oct 30, 2024
c5e86c4
Fixed a typo in the GetThreadDescription shim
YohDeadfall Oct 30, 2024
445a340
Merge pull request #4003 from YohDeadfall/windows-shim-typo
saethlin Oct 31, 2024
1c88af6
Preparing for merge from rustc
Oct 31, 2024
4828592
Merge from rustc
Oct 31, 2024
ef6b9a9
fmt
Oct 31, 2024
b8bd7be
silence clippy
RalfJung Oct 31, 2024
6630802
Merge pull request #4005 from rust-lang/rustup-2024-10-31
RalfJung Oct 31, 2024
06d869b
Preparing for merge from rustc
RalfJung Nov 2, 2024
3253cc6
Merge from rustc
RalfJung Nov 2, 2024
c1b8d66
teach clippy about IeeeFloat, and make all 'allow' into 'expect'
RalfJung Nov 2, 2024
c67ea44
Merge pull request #4009 from RalfJung/rustup
RalfJung Nov 2, 2024
9c75eff
Preparing for merge from rustc
Nov 3, 2024
b58cbe2
Merge from rustc
Nov 3, 2024
b17cf41
Merge pull request #4010 from rust-lang/rustup-2024-11-03
RalfJung Nov 3, 2024
dc62c34
Renamed ecx variales to this
YohDeadfall Nov 7, 2024
1254d8e
Get/set thread name shims return errors for invalid handles
YohDeadfall Oct 30, 2024
c8e089e
Merge pull request #4018 from YohDeadfall/ecx-name-standardization
RalfJung Nov 8, 2024
d7aceee
Merge pull request #4004 from YohDeadfall/thread-name-ice-fix
RalfJung Nov 8, 2024
beb8d6f
Preparing for merge from rustc
Nov 9, 2024
15d883e
Merge from rustc
Nov 9, 2024
c272bb4
Merge pull request #4019 from rust-lang/rustup-2024-11-09
saethlin Nov 9, 2024
fe39888
pthread-sync: avoid confusing error when running with preemption
RalfJung Nov 9, 2024
5ff90d0
Merge pull request #4020 from RalfJung/thread-sope
RalfJung Nov 9, 2024
ce7a560
Preparing for merge from rustc
RalfJung Nov 10, 2024
a01f37c
Merge from rustc
RalfJung Nov 10, 2024
a839fbf
Merge pull request #4021 from RalfJung/rustup
RalfJung Nov 10, 2024
d1a4812
store futexes in per-allocation data rather than globally
RalfJung Oct 12, 2024
673d9c3
Merge pull request #3971 from RalfJung/futex-virtual
RalfJung Nov 10, 2024
e8a3ffe
fix linux-futex test being accidentally disabled
RalfJung Nov 10, 2024
881f2ec
Merge pull request #4022 from RalfJung/linux-futex
RalfJung Nov 10, 2024
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
13 changes: 11 additions & 2 deletions src/tools/miri/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,20 @@ jobs:
- name: rustdoc
run: RUSTDOCFLAGS="-Dwarnings" ./miri doc --document-private-items

coverage:
name: coverage report
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/workflows/setup
- name: coverage
run: ./miri test --coverage

# Summary job for the merge queue.
# ALL THE PREVIOUS JOBS NEED TO BE ADDED TO THE `needs` SECTION OF THIS JOB!
# And they should be added below in `cron-fail-notify` as well.
conclusion:
needs: [build, style]
needs: [build, style, coverage]
# We need to ensure this job does *not* get skipped if its dependencies fail,
# because a skipped job is considered a success by GitHub. So we have to
# overwrite `if:`. We use `!cancelled()` to ensure the job does still not get run
Expand All @@ -86,7 +95,7 @@ jobs:
contents: write
# ... and create a PR.
pull-requests: write
needs: [build, style]
needs: [build, style, coverage]
if: ${{ github.event_name == 'schedule' && failure() }}
steps:
# Send a Zulip notification
Expand Down
27 changes: 19 additions & 8 deletions src/tools/miri/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,25 @@ for a list of Miri maintainers.

[Rust Zulip]: https://rust-lang.zulipchat.com

### Pull review process

When you get a review, please take care of the requested changes in new commits. Do not amend
existing commits. Generally avoid force-pushing. The only time you should force push is when there
is a conflict with the master branch (in that case you should rebase across master, not merge), and
all the way at the end of the review process when the reviewer tells you that the PR is done and you
should squash the commits. For the latter case, use `git rebase --keep-base ...` to squash without
changing the base commit your PR branches off of. Use your own judgment and the reviewer's guidance
to decide whether the PR should be squashed into a single commit or multiple logically separate
commits. (All this is to work around the fact that Github is quite bad at dealing with force pushes
and does not support `git range-diff`. Maybe one day Github will be good at git and then life can
become easier.)

Most PRs bounce back and forth between the reviewer and the author several times, so it is good to
keep track of who is expected to take the next step. We are using the `S-waiting-for-review` and
`S-waiting-for-author` labels for that. If a reviewer asked you to do some changes and you think
they are all taken care of, post a comment saying `@rustbot ready` to mark a PR as ready for the
next round of review.

### Larger-scale contributions

If you are thinking about making a larger-scale contribution -- in particular anything that needs
Expand Down Expand Up @@ -45,14 +64,6 @@ process for such contributions:
This process is largely informal, and its primary goal is to more clearly communicate expectations.
Please get in touch with us if you have any questions!

### Managing the review state

Most PRs bounce back and forth between the reviewer and the author several times, so it is good to
keep track of who is expected to take the next step. We are using the `S-waiting-for-review` and
`S-waiting-for-author` labels for that. If a reviewer asked you to do some changes and you think
they are all taken care of, post a comment saying `@rustbot ready` to mark a PR as ready for the
next round of review.

## Preparing the build environment

Miri heavily relies on internal and unstable rustc interfaces to execute MIR,
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/ci/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ case $HOST_TARGET in
TEST_TARGET=i686-unknown-freebsd run_tests_minimal $BASIC $UNIX time hashmap random threadname pthread fs libc-pipe
TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $BASIC $UNIX time hashmap random thread sync available-parallelism tls libc-pipe
TEST_TARGET=x86_64-pc-solaris run_tests_minimal $BASIC $UNIX time hashmap random thread sync available-parallelism tls libc-pipe
TEST_TARGET=aarch64-linux-android run_tests_minimal $BASIC $UNIX time hashmap threadname pthread
TEST_TARGET=aarch64-linux-android run_tests_minimal $BASIC $UNIX time hashmap random sync threadname pthread
TEST_TARGET=wasm32-wasip2 run_tests_minimal $BASIC wasm
TEST_TARGET=wasm32-unknown-unknown run_tests_minimal no_std empty_main wasm # this target doesn't really have std
TEST_TARGET=thumbv7em-none-eabihf run_tests_minimal no_std
Expand Down
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_abi::Size"]
arithmetic-side-effects-allowed = ["rustc_abi::Size", "rustc_apfloat::ieee::IeeeFloat"]
43 changes: 39 additions & 4 deletions src/tools/miri/miri-script/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ dependencies = [
"windows-sys 0.52.0",
]

[[package]]
name = "fastrand"
version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6"

[[package]]
name = "getrandom"
version = "0.2.12"
Expand Down Expand Up @@ -100,9 +106,9 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b"

[[package]]
name = "libc"
version = "0.2.153"
version = "0.2.159"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5"

[[package]]
name = "libredox"
Expand Down Expand Up @@ -138,11 +144,18 @@ dependencies = [
"rustc_version",
"serde_json",
"shell-words",
"tempfile",
"walkdir",
"which",
"xshell",
]

[[package]]
name = "once_cell"
version = "1.20.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"

[[package]]
name = "option-ext"
version = "0.2.0"
Expand Down Expand Up @@ -195,9 +208,9 @@ dependencies = [

[[package]]
name = "rustix"
version = "0.38.34"
version = "0.38.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f"
checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811"
dependencies = [
"bitflags",
"errno",
Expand Down Expand Up @@ -276,6 +289,19 @@ dependencies = [
"unicode-ident",
]

[[package]]
name = "tempfile"
version = "3.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b"
dependencies = [
"cfg-if",
"fastrand",
"once_cell",
"rustix",
"windows-sys 0.59.0",
]

[[package]]
name = "thiserror"
version = "1.0.57"
Expand Down Expand Up @@ -357,6 +383,15 @@ dependencies = [
"windows-targets 0.52.6",
]

[[package]]
name = "windows-sys"
version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [
"windows-targets 0.52.6",
]

[[package]]
name = "windows-targets"
version = "0.48.5"
Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/miri-script/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ rustc_version = "0.4"
dunce = "1.0.4"
directories = "5"
serde_json = "1"
tempfile = "3.13.0"
21 changes: 19 additions & 2 deletions src/tools/miri/miri-script/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ impl Command {
Command::Install { flags } => Self::install(flags),
Command::Build { flags } => Self::build(flags),
Command::Check { flags } => Self::check(flags),
Command::Test { bless, flags, target } => Self::test(bless, flags, target),
Command::Test { bless, flags, target, coverage } =>
Self::test(bless, flags, target, coverage),
Command::Run { dep, verbose, many_seeds, target, edition, flags } =>
Self::run(dep, verbose, many_seeds, target, edition, flags),
Command::Doc { flags } => Self::doc(flags),
Expand Down Expand Up @@ -458,9 +459,20 @@ impl Command {
Ok(())
}

fn test(bless: bool, mut flags: Vec<String>, target: Option<String>) -> Result<()> {
fn test(
bless: bool,
mut flags: Vec<String>,
target: Option<String>,
coverage: bool,
) -> Result<()> {
let mut e = MiriEnv::new()?;

let coverage = coverage.then_some(crate::coverage::CoverageReport::new()?);

if let Some(report) = &coverage {
report.add_env_vars(&mut e)?;
}

// Prepare a sysroot. (Also builds cargo-miri, which we need.)
e.build_miri_sysroot(/* quiet */ false, target.as_deref())?;

Expand All @@ -479,6 +491,11 @@ impl Command {
// Then test, and let caller control flags.
// Only in root project as `cargo-miri` has no tests.
e.test(".", &flags)?;

if let Some(coverage) = &coverage {
coverage.show_coverage_report(&e)?;
}

Ok(())
}

Expand Down
91 changes: 91 additions & 0 deletions src/tools/miri/miri-script/src/coverage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
use std::path::PathBuf;

use anyhow::{Context, Result};
use path_macro::path;
use tempfile::TempDir;
use xshell::cmd;

use crate::util::MiriEnv;

/// CoverageReport can generate code coverage reports for miri.
pub struct CoverageReport {
/// path is a temporary directory where intermediate coverage artifacts will be stored.
/// (The final output will be stored in a permanent location.)
path: TempDir,
}

impl CoverageReport {
/// Creates a new CoverageReport.
///
/// # Errors
///
/// An error will be returned if a temporary directory could not be created.
pub fn new() -> Result<Self> {
Ok(Self { path: TempDir::new()? })
}

/// add_env_vars will add the required environment variables to MiriEnv `e`.
pub fn add_env_vars(&self, e: &mut MiriEnv) -> Result<()> {
let mut rustflags = e.sh.var("RUSTFLAGS")?;
rustflags.push_str(" -C instrument-coverage");
e.sh.set_var("RUSTFLAGS", rustflags);

// Copy-pasting from: https://doc.rust-lang.org/rustc/instrument-coverage.html#instrumentation-based-code-coverage
// The format symbols below have the following meaning:
// - %p - The process ID.
// - %Nm - the instrumented binary’s signature:
// The runtime creates a pool of N raw profiles, used for on-line
// profile merging. The runtime takes care of selecting a raw profile
// from the pool, locking it, and updating it before the program
// exits. N must be between 1 and 9, and defaults to 1 if omitted
// (with simply %m).
//
// Additionally the default for LLVM_PROFILE_FILE is default_%m_%p.profraw.
// So we just use the same template, replacing "default" with "miri".
let file_template = self.path.path().join("miri_%m_%p.profraw");
e.sh.set_var("LLVM_PROFILE_FILE", file_template);
Ok(())
}

/// show_coverage_report will print coverage information using the artifact
/// files in `self.path`.
pub fn show_coverage_report(&self, e: &MiriEnv) -> Result<()> {
let profraw_files = self.profraw_files()?;

let profdata_bin = path!(e.libdir / ".." / "bin" / "llvm-profdata");

let merged_file = path!(e.miri_dir / "target" / "coverage.profdata");

// Merge the profraw files
cmd!(e.sh, "{profdata_bin} merge -sparse {profraw_files...} -o {merged_file}")
.quiet()
.run()?;

// Create the coverage report.
let cov_bin = path!(e.libdir / ".." / "bin" / "llvm-cov");
let miri_bin =
e.build_get_binary(".").context("failed to get filename of miri executable")?;
cmd!(
e.sh,
"{cov_bin} report --instr-profile={merged_file} --object {miri_bin} --sources src/"
)
.run()?;

println!("Profile data saved in {}", merged_file.display());
Ok(())
}

/// profraw_files returns the profraw files in `self.path`.
///
/// # Errors
///
/// An error will be returned if `self.path` can't be read.
fn profraw_files(&self) -> Result<Vec<PathBuf>> {
Ok(std::fs::read_dir(&self.path)?
.filter_map(|r| r.ok())
.filter(|e| e.file_type().is_ok_and(|t| t.is_file()))
.map(|e| e.path())
.filter(|p| p.extension().is_some_and(|e| e == "profraw"))
.collect())
}
}
8 changes: 7 additions & 1 deletion src/tools/miri/miri-script/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

mod args;
mod commands;
mod coverage;
mod util;

use std::ops::Range;
Expand Down Expand Up @@ -34,6 +35,8 @@ pub enum Command {
/// The cross-interpretation target.
/// If none then the host is the target.
target: Option<String>,
/// Produce coverage report if set.
coverage: bool,
/// Flags that are passed through to the test harness.
flags: Vec<String>,
},
Expand Down Expand Up @@ -158,9 +161,12 @@ fn main() -> Result<()> {
let mut target = None;
let mut bless = false;
let mut flags = Vec::new();
let mut coverage = false;
loop {
if args.get_long_flag("bless")? {
bless = true;
} else if args.get_long_flag("coverage")? {
coverage = true;
} else if let Some(val) = args.get_long_opt("target")? {
target = Some(val);
} else if let Some(flag) = args.get_other() {
Expand All @@ -169,7 +175,7 @@ fn main() -> Result<()> {
break;
}
}
Command::Test { bless, flags, target }
Command::Test { bless, flags, target, coverage }
}
Some("run") => {
let mut dep = false;
Expand Down
7 changes: 5 additions & 2 deletions src/tools/miri/miri-script/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pub struct MiriEnv {
pub sysroot: PathBuf,
/// The shell we use.
pub sh: Shell,
/// The library dir in the sysroot.
pub libdir: PathBuf,
}

impl MiriEnv {
Expand Down Expand Up @@ -96,7 +98,8 @@ impl MiriEnv {
// so that Windows can find the DLLs.
if cfg!(windows) {
let old_path = sh.var("PATH")?;
let new_path = env::join_paths(iter::once(libdir).chain(env::split_paths(&old_path)))?;
let new_path =
env::join_paths(iter::once(libdir.clone()).chain(env::split_paths(&old_path)))?;
sh.set_var("PATH", new_path);
}

Expand All @@ -111,7 +114,7 @@ impl MiriEnv {
std::process::exit(1);
}

Ok(MiriEnv { miri_dir, toolchain, sh, sysroot, cargo_extra_flags })
Ok(MiriEnv { miri_dir, toolchain, sh, sysroot, cargo_extra_flags, libdir })
}

pub fn cargo_cmd(&self, crate_dir: impl AsRef<OsStr>, cmd: &str) -> Cmd<'_> {
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 @@
814df6e50eaf89b90793e7d9618bb60f1f18377a
668959740f97e7a22ae340742886d330ab63950f
Loading
Loading