From 285e8803e1a2cdf16d38dbf2be2f39bfcf58821c Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sun, 17 Mar 2024 22:26:39 -0400 Subject: [PATCH 1/4] Codegen const panic messages as function calls This skips emitting extra arguments at every callsite (of which there can be many). For a librustc_driver build with overflow checks enabled, this cuts 0.7MB from the resulting binary. --- src/shims/panic.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/shims/panic.rs b/src/shims/panic.rs index 34b6481dd3..bb31ef733c 100644 --- a/src/shims/panic.rs +++ b/src/shims/panic.rs @@ -256,8 +256,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { } _ => { - // Forward everything else to `panic` lang item. - this.start_panic(msg.description(), unwind)?; + // Call the lang item associated with this message. + let fn_item = this.tcx.require_lang_item(msg.panic_function(), None); + let instance = ty::Instance::mono(this.tcx.tcx, fn_item); + this.call_function( + instance, + Abi::Rust, + &[], + None, + StackPopCleanup::Goto { ret: None, unwind }, + )?; } } Ok(()) From ff2ef05afcee9147e52bfd354b3ec49d687222b8 Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Mon, 25 Mar 2024 23:34:01 +0300 Subject: [PATCH 2/4] enable cargo miri test doctests Signed-off-by: onur-ozkan --- README.md | 2 ++ cargo-miri/src/phases.rs | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b043805291..26e55b8970 100644 --- a/README.md +++ b/README.md @@ -505,6 +505,8 @@ binaries, and as such worth documenting: * `MIRI_LOCAL_CRATES` is set by `cargo-miri` to tell the Miri driver which crates should be given special treatment in diagnostics, in addition to the crate currently being compiled. +* `MIRI_ORIG_RUSTDOC` is set and read by different phases of `cargo-miri` to remember the + value of `RUSTDOC` from before it was overwritten. * `MIRI_VERBOSE` when set to any value tells the various `cargo-miri` phases to perform verbose logging. * `MIRI_HOST_SYSROOT` is set by bootstrap to tell `cargo-miri` which sysroot to use for *host* diff --git a/cargo-miri/src/phases.rs b/cargo-miri/src/phases.rs index 81ff68545c..799731320a 100644 --- a/cargo-miri/src/phases.rs +++ b/cargo-miri/src/phases.rs @@ -202,6 +202,9 @@ pub fn phase_cargo_miri(mut args: impl Iterator) { cmd.env("MIRI_BE_RUSTC", "target"); // we better remember to *unset* this in the other phases! // Set rustdoc to us as well, so we can run doctests. + if let Some(orig_rustdoc) = env::var_os("RUSTDOC") { + cmd.env("MIRI_ORIG_RUSTDOC", orig_rustdoc); + } cmd.env("RUSTDOC", &cargo_miri_path); cmd.env("MIRI_LOCAL_CRATES", local_crates(&metadata)); @@ -581,9 +584,10 @@ pub fn phase_rustdoc(mut args: impl Iterator) { let verbose = std::env::var("MIRI_VERBOSE") .map_or(0, |verbose| verbose.parse().expect("verbosity flag must be an integer")); - // phase_cargo_miri sets the RUSTDOC env var to ourselves, so we can't use that here; - // just default to a straight-forward invocation for now: - let mut cmd = Command::new("rustdoc"); + // phase_cargo_miri sets the RUSTDOC env var to ourselves, and puts a backup + // of the old value into MIRI_ORIG_RUSTDOC. So that's what we have to invoke now. + let rustdoc = env::var("MIRI_ORIG_RUSTDOC").unwrap_or("rustdoc".to_string()); + let mut cmd = Command::new(rustdoc); let extern_flag = "--extern"; let runtool_flag = "--runtool"; From 4bf56fae8fb81fef7210308cc8db02deb0b18684 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 25 Mar 2024 15:29:00 -0400 Subject: [PATCH 3/4] In ConstructCoroutineInClosureShim, pass receiver by ref, not pointer --- tests/pass/async-closure-drop.rs | 40 ++++++++++++++++++++++++++++ tests/pass/async-closure-drop.stdout | 3 +++ tests/pass/async-closure.rs | 34 +++++++++++++++-------- tests/pass/async-closure.stdout | 7 ++--- 4 files changed, 70 insertions(+), 14 deletions(-) create mode 100644 tests/pass/async-closure-drop.rs create mode 100644 tests/pass/async-closure-drop.stdout diff --git a/tests/pass/async-closure-drop.rs b/tests/pass/async-closure-drop.rs new file mode 100644 index 0000000000..9b2fc2948b --- /dev/null +++ b/tests/pass/async-closure-drop.rs @@ -0,0 +1,40 @@ +#![feature(async_closure, noop_waker, async_fn_traits)] + +use std::future::Future; +use std::pin::pin; +use std::task::*; + +pub fn block_on(fut: impl Future) -> T { + let mut fut = pin!(fut); + let ctx = &mut Context::from_waker(Waker::noop()); + + loop { + match fut.as_mut().poll(ctx) { + Poll::Pending => {} + Poll::Ready(t) => break t, + } + } +} + +async fn call_once(f: impl async FnOnce(DropMe)) { + f(DropMe("world")).await; +} + +#[derive(Debug)] +struct DropMe(&'static str); + +impl Drop for DropMe { + fn drop(&mut self) { + println!("{}", self.0); + } +} + +pub fn main() { + block_on(async { + let b = DropMe("hello"); + let async_closure = async move |a: DropMe| { + println!("{a:?} {b:?}"); + }; + call_once(async_closure).await; + }); +} diff --git a/tests/pass/async-closure-drop.stdout b/tests/pass/async-closure-drop.stdout new file mode 100644 index 0000000000..34cfdedc44 --- /dev/null +++ b/tests/pass/async-closure-drop.stdout @@ -0,0 +1,3 @@ +DropMe("world") DropMe("hello") +world +hello diff --git a/tests/pass/async-closure.rs b/tests/pass/async-closure.rs index 9b2fc2948b..2f7ec2b9e6 100644 --- a/tests/pass/async-closure.rs +++ b/tests/pass/async-closure.rs @@ -1,6 +1,7 @@ #![feature(async_closure, noop_waker, async_fn_traits)] use std::future::Future; +use std::ops::{AsyncFnMut, AsyncFnOnce}; use std::pin::pin; use std::task::*; @@ -16,25 +17,36 @@ pub fn block_on(fut: impl Future) -> T { } } -async fn call_once(f: impl async FnOnce(DropMe)) { - f(DropMe("world")).await; +async fn call_mut(f: &mut impl AsyncFnMut(i32)) { + f(0).await; } -#[derive(Debug)] -struct DropMe(&'static str); +async fn call_once(f: impl AsyncFnOnce(i32)) { + f(1).await; +} -impl Drop for DropMe { - fn drop(&mut self) { - println!("{}", self.0); - } +async fn call_normal>(f: &impl Fn(i32) -> F) { + f(0).await; +} + +async fn call_normal_once>(f: impl FnOnce(i32) -> F) { + f(1).await; } pub fn main() { block_on(async { - let b = DropMe("hello"); - let async_closure = async move |a: DropMe| { - println!("{a:?} {b:?}"); + let b = 2i32; + let mut async_closure = async move |a: i32| { + println!("{a} {b}"); }; + call_mut(&mut async_closure).await; call_once(async_closure).await; + + // No-capture closures implement `Fn`. + let async_closure = async move |a: i32| { + println!("{a}"); + }; + call_normal(&async_closure).await; + call_normal_once(async_closure).await; }); } diff --git a/tests/pass/async-closure.stdout b/tests/pass/async-closure.stdout index 34cfdedc44..7baae1aa94 100644 --- a/tests/pass/async-closure.stdout +++ b/tests/pass/async-closure.stdout @@ -1,3 +1,4 @@ -DropMe("world") DropMe("hello") -world -hello +0 2 +1 2 +0 +1 From 8c2b112de5f1c57606b5a27a89642a0da01c31fc Mon Sep 17 00:00:00 2001 From: The Miri Cronjob Bot Date: Fri, 29 Mar 2024 04:54:51 +0000 Subject: [PATCH 4/4] Preparing for merge from rustc --- rust-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-version b/rust-version index acf96cfab7..6b432dde3b 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -b13a71a2e77f4625d1a2b8a5b9488414686ebca9 +760e567af5398a0d8c512f904e551e1f38e00d79