Skip to content

parallel rustc: async closures not reproducible #140425

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

Open
matthiaskrgr opened this issue Apr 29, 2025 · 0 comments
Open

parallel rustc: async closures not reproducible #140425

matthiaskrgr opened this issue Apr 29, 2025 · 0 comments
Labels
A-async-closures `async || {}` A-parallel-compiler Area: parallel compiler A-reproducibility Area: Reproducible / deterministic builds C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

I tried this code:

//@ edition:2021
// skip-filecheck

#![allow(unused)]

use std::future::Future;
use std::ops::{AsyncFn, AsyncFnMut, AsyncFnOnce};
use std::pin::pin;
use std::task::*;

pub fn block_on<T>(fut: impl Future<Output = T>) -> 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(f: &impl AsyncFn(i32)) {
    f(0).await;
}

async fn call_mut(f: &mut impl AsyncFnMut(i32)) {
    f(0).await;
}

async fn call_once(f: impl AsyncFnOnce(i32)) {
    f(1).await;
}

async fn call_normal<F: Future<Output = ()>>(f: &impl Fn(i32) -> F) {
    f(1).await;
}

async fn call_normal_mut<F: Future<Output = ()>>(f: &mut impl FnMut(i32) -> F) {
    f(1).await;
}

// EMIT_MIR async_closure_shims.main-{closure#0}-{closure#0}.coroutine_closure_by_move.0.mir
// EMIT_MIR async_closure_shims.main-{closure#0}-{closure#0}-{closure#0}.built.after.mir
// EMIT_MIR async_closure_shims.main-{closure#0}-{closure#0}-{synthetic#0}.built.after.mir
// EMIT_MIR async_closure_shims.main-{closure#0}-{closure#1}.coroutine_closure_by_ref.0.mir
// EMIT_MIR async_closure_shims.main-{closure#0}-{closure#1}.coroutine_closure_by_move.0.mir
// EMIT_MIR async_closure_shims.main-{closure#0}-{closure#1}-{closure#0}.built.after.mir
// EMIT_MIR async_closure_shims.main-{closure#0}-{closure#1}-{synthetic#0}.built.after.mir
pub fn main() {
    block_on(async {
        let b = 2i32;
        let mut async_closure = async move |a: i32| {
            let a = &a;
            let b = &b;
        };
        call(&async_closure).await;
        call_mut(&mut async_closure).await;
        call_once(async_closure).await;

        let b = 2i32;
        let mut async_closure = async |a: i32| {
            let a = &a;
            let b = &b;
        };
        call_normal(&async_closure).await;
        call_normal_mut(&mut async_closure).await;
        call_once(async_closure).await;
    });
}

`rustc async_closure_shims.rs -Zthreads=16 --edition=2021; md5sum async_closure_shims

I expected to see this happen: explanation
same md5 every time

Instead, this happened: explanation
different md5 from time to time

Meta

rustc --version --verbose:

rustc 1.88.0-nightly (25cdf1f67 2025-04-28)
binary: rustc
commit-hash: 25cdf1f67463c9365d8d83778c933ec7480e940b
commit-date: 2025-04-28
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2
Backtrace

--- /proc/self/fd/11	2025-04-29 06:44:18.100415395 +0200
+++ /proc/self/fd/12	2025-04-29 06:44:18.097415424 +0200
@@ -49,8 +49,8 @@
 │000002f0│ 78 38 36 2d 36 34 2e 73 ┊ 6f 2e 32 00 04 00 00 00 │x86-64.s┊o.2⋄•⋄⋄⋄│
 │00000300│ 10 00 00 00 01 00 00 00 ┊ 47 4e 55 00 00 00 00 00 │•⋄⋄⋄•⋄⋄⋄┊GNU⋄⋄⋄⋄⋄│
 │00000310│ 04 00 00 00 04 00 00 00 ┊ 00 00 00 00 04 00 00 00 │•⋄⋄⋄•⋄⋄⋄┊⋄⋄⋄⋄•⋄⋄⋄│
-│00000320│ 14 00 00 00 03 00 00 00 ┊ 47 4e 55 00 67 24 f6 cd │•⋄⋄⋄•⋄⋄⋄┊GNU⋄g$××│
-│00000330│ 69 dd 6a eb ff 37 f1 29 ┊ 4d ef 35 87 ab c4 b5 26 │i×j××7×)┊M×5××××&│
+│00000320│ 14 00 00 00 03 00 00 00 ┊ 47 4e 55 00 d5 f4 67 b4 │•⋄⋄⋄•⋄⋄⋄┊GNU⋄××g×│
+│00000330│ 2f 28 18 02 c7 8a a5 0a ┊ 1d 7b 09 7b 4e 5c fa e1 │/(••×××_┊•{_{N\××│
 │00000340│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊⋄⋄⋄⋄⋄⋄⋄⋄│
 │00000350│ 00 00 00 00 00 00 00 00 ┊ 01 00 00 00 12 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊•⋄⋄⋄•⋄⋄⋄│
 │00000360│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊⋄⋄⋄⋄⋄⋄⋄⋄│
@@ -3787,9 +3787,9 @@
 │0000ed20│ e0 83 00 00 0e 00 00 00 ┊ 00 00 00 00 18 00 00 00 │××⋄⋄•⋄⋄⋄┊⋄⋄⋄⋄•⋄⋄⋄│
 │0000ed30│ 18 03 00 00 dc 83 00 00 ┊ 53 00 00 00 00 44 0e 20 │••⋄⋄××⋄⋄┊S⋄⋄⋄⋄D• │
 │0000ed40│ 02 41 0e 08 41 0e 20 00 ┊ 18 00 00 00 34 03 00 00 │•A••A• ⋄┊•⋄⋄⋄4•⋄⋄│
-│0000ed50│ 20 84 00 00 52 00 00 00 ┊ 00 44 0e 20 02 40 0e 08 │ ×⋄⋄R⋄⋄⋄┊⋄D• •@••│
+│0000ed50│ 20 84 00 00 53 00 00 00 ┊ 00 44 0e 20 02 41 0e 08 │ ×⋄⋄S⋄⋄⋄┊⋄D• •A••│
 │0000ed60│ 41 0e 20 00 18 00 00 00 ┊ 50 03 00 00 64 84 00 00 │A• ⋄•⋄⋄⋄┊P•⋄⋄d×⋄⋄│
-│0000ed70│ 53 00 00 00 00 44 0e 20 ┊ 02 41 0e 08 41 0e 20 00 │S⋄⋄⋄⋄D• ┊•A••A• ⋄│
+│0000ed70│ 52 00 00 00 00 44 0e 20 ┊ 02 40 0e 08 41 0e 20 00 │R⋄⋄⋄⋄D• ┊•@••A• ⋄│
 │0000ed80│ 14 00 00 00 6c 03 00 00 ┊ a8 84 00 00 17 00 00 00 │•⋄⋄⋄l•⋄⋄┊××⋄⋄•⋄⋄⋄│
 │0000ed90│ 00 41 0e 10 55 0e 08 00 ┊ 10 00 00 00 84 03 00 00 │⋄A••U••⋄┊•⋄⋄⋄ו⋄⋄│
 │0000eda0│ b0 84 00 00 05 00 00 00 ┊ 00 00 00 00 10 00 00 00 │××⋄⋄•⋄⋄⋄┊⋄⋄⋄⋄•⋄⋄⋄│
@@ -5441,7 +5441,7 @@
 │00015480│ 0c 1f 04 00 48 8b 7c 24 ┊ 28 48 83 c7 04 e8 5e f5 │_••⋄H×|$┊(H×ו×^×│
 │00015490│ ff ff e9 7a ff ff ff 48 ┊ 89 c1 89 d0 48 89 4c 24 │×××z×××H┊××××H×L$│
 │000154a0│ 58 89 44 24 60 eb dd 48 ┊ 8b 7c 24 10 48 8b 74 24 │X×D$`××H┊×|$•H×t$│
-│000154b0│ 50 e8 ba 0c 00 00 88 44 ┊ 24 0f eb 00 8a 44 24 0f │P××_⋄⋄×D┊$•×⋄×D$•│
+│000154b0│ 50 e8 1a 0d 00 00 88 44 ┊ 24 0f eb 00 8a 44 24 0f │Pו_⋄⋄×D┊$•×⋄×D$•│
 │000154c0│ 24 01 0f b6 c0 48 a9 01 ┊ 00 00 00 74 19 c6 44 24 │$••××Hו┊⋄⋄⋄t•×D$│
 │000154d0│ 37 01 48 8b 44 24 28 c6 ┊ 40 10 03 8a 44 24 37 24 │7•H×D$(×┊@••×D$7$│
 │000154e0│ 01 48 83 c4 68 c3 48 8b ┊ 7c 24 28 48 83 c7 04 e8 │•H××h×H×┊|$(H×ו×│
@@ -5465,7 +5465,7 @@
 │00015600│ 00 ff 15 89 1d 04 00 48 ┊ 8b 7c 24 20 48 83 c7 08 │⋄וו•⋄H┊×|$ H×ו│
 │00015610│ e8 eb f3 ff ff e9 78 ff ┊ ff ff 48 89 c1 89 d0 48 │××××××x×┊××H××××H│
 │00015620│ 89 4c 24 58 89 44 24 60 ┊ eb dd 48 8b 7c 24 08 48 │×L$X×D$`┊××H×|$•H│
-│00015630│ 8b 74 24 50 e8 97 0b 00 ┊ 00 88 44 24 07 eb 00 8a │×t$P×ו⋄┊⋄×D$•×⋄×│
+│00015630│ 8b 74 24 50 e8 37 0b 00 ┊ 00 88 44 24 07 eb 00 8a │×t$P×7•⋄┊⋄×D$•×⋄×│
 │00015640│ 44 24 07 24 01 0f b6 c0 ┊ 48 a9 01 00 00 00 74 19 │D$•$••××┊Hו⋄⋄⋄t•│
 │00015650│ c6 44 24 2f 01 48 8b 44 ┊ 24 20 c6 40 18 03 8a 44 │×D$/•H×D┊$ ×@••×D│
 │00015660│ 24 2f 24 01 48 83 c4 68 ┊ c3 48 8b 7c 24 20 48 83 │$/$•H××h┊×H×|$ H×│
@@ -5490,7 +5490,7 @@
 │00015790│ 00 ff 15 f9 1b 04 00 48 ┊ 8b 7c 24 20 48 83 c7 08 │⋄וו•⋄H┊×|$ H×ו│
 │000157a0│ e8 5b f2 ff ff e9 78 ff ┊ ff ff 48 89 c1 89 d0 48 │×[××××x×┊××H××××H│
 │000157b0│ 89 4c 24 58 89 44 24 60 ┊ eb dd 48 8b 7c 24 08 48 │×L$X×D$`┊××H×|$•H│
-│000157c0│ 8b 74 24 50 e8 07 0a 00 ┊ 00 88 44 24 07 eb 00 8a │×t$Pו_⋄┊⋄×D$•×⋄×│
+│000157c0│ 8b 74 24 50 e8 a7 09 00 ┊ 00 88 44 24 07 eb 00 8a │×t$P××_⋄┊⋄×D$•×⋄×│
 │000157d0│ 44 24 07 24 01 0f b6 c0 ┊ 48 a9 01 00 00 00 74 19 │D$•$••××┊Hו⋄⋄⋄t•│
 │000157e0│ c6 44 24 2f 01 48 8b 44 ┊ 24 20 c6 40 18 03 8a 44 │×D$/•H×D┊$ ×@••×D│
 │000157f0│ 24 2f 24 01 48 83 c4 68 ┊ c3 48 8b 7c 24 20 48 83 │$/$•H××h┊×H×|$ H×│
@@ -5515,7 +5515,7 @@
 │00015920│ 00 ff 15 69 1a 04 00 48 ┊ 8b 7c 24 20 48 83 c7 08 │⋄וi••⋄H┊×|$ H×ו│
 │00015930│ e8 cb f0 ff ff e9 78 ff ┊ ff ff 48 89 c1 89 d0 48 │××××××x×┊××H××××H│
 │00015940│ 89 4c 24 58 89 44 24 60 ┊ eb dd 48 8b 7c 24 08 48 │×L$X×D$`┊××H×|$•H│
-│00015950│ 8b 74 24 50 e8 77 08 00 ┊ 00 88 44 24 07 eb 00 8a │×t$P×w•⋄┊⋄×D$•×⋄×│
+│00015950│ 8b 74 24 50 e8 17 08 00 ┊ 00 88 44 24 07 eb 00 8a │×t$Pו•⋄┊⋄×D$•×⋄×│
 │00015960│ 44 24 07 24 01 0f b6 c0 ┊ 48 a9 01 00 00 00 74 19 │D$•$••××┊Hו⋄⋄⋄t•│
 │00015970│ c6 44 24 2f 01 48 8b 44 ┊ 24 20 c6 40 18 03 8a 44 │×D$/•H×D┊$ ×@••×D│
 │00015980│ 24 2f 24 01 48 83 c4 68 ┊ c3 48 8b 7c 24 20 48 83 │$/$•H××h┊×H×|$ H×│
@@ -5646,17 +5646,17 @@
 │00016150│ 01 48 83 c4 18 c3 48 8d ┊ 3d 2b ea 03 00 ff 15 25 │•H×ו×H×┊=+ו⋄ו%│
 │00016160│ 12 04 00 cc cc cc cc cc ┊ cc cc cc cc cc cc cc cc │••⋄×××××┊××××××××│
 │00016170│ 48 83 ec 18 48 89 7c 24 ┊ 08 48 8b 44 24 08 0f b6 │H×וH×|$┊•H×D$••×│
-│00016180│ 40 08 a9 01 00 00 00 74 ┊ 08 31 c0 a8 01 75 fa eb │@•ו⋄⋄⋄t┊•1×וu××│
-│00016190│ 24 48 8b 44 24 08 8b 00 ┊ 89 44 24 14 c6 44 24 13 │$H×D$•×⋄┊×D$•×D$•│
-│000161a0│ 00 48 8b 44 24 08 c6 40 ┊ 08 01 8a 44 24 13 24 01 │⋄H×D$•×@┊••×D$•$•│
-│000161b0│ 48 83 c4 18 c3 48 8d 3d ┊ cc e9 03 00 ff 15 c6 11 │H×ו×H×=┊×ו⋄וו│
-│000161c0│ 04 00 cc cc cc cc cc cc ┊ cc cc cc cc cc cc cc cc │•⋄××××××┊××××××××│
+│00016180│ 40 0c a9 01 00 00 00 74 ┊ 08 31 c0 a8 01 75 fa eb │@_ו⋄⋄⋄t┊•1×וu××│
+│00016190│ 25 48 8b 44 24 08 8b 40 ┊ 08 89 44 24 14 c6 44 24 │%H×D$•×@┊•×D$•×D$│
+│000161a0│ 13 00 48 8b 44 24 08 c6 ┊ 40 0c 01 8a 44 24 13 24 │•⋄H×D$•×┊@_•×D$•$│
+│000161b0│ 01 48 83 c4 18 c3 48 8d ┊ 3d e3 e9 03 00 ff 15 c5 │•H×ו×H×┊=×ו⋄ו×│
+│000161c0│ 11 04 00 cc cc cc cc cc ┊ cc cc cc cc cc cc cc cc │••⋄×××××┊××××××××│
 │000161d0│ 48 83 ec 18 48 89 7c 24 ┊ 08 48 8b 44 24 08 0f b6 │H×וH×|$┊•H×D$••×│
-│000161e0│ 40 0c a9 01 00 00 00 74 ┊ 08 31 c0 a8 01 75 fa eb │@_ו⋄⋄⋄t┊•1×וu××│
-│000161f0│ 25 48 8b 44 24 08 8b 40 ┊ 08 89 44 24 14 c6 44 24 │%H×D$•×@┊•×D$•×D$│
-│00016200│ 13 00 48 8b 44 24 08 c6 ┊ 40 0c 01 8a 44 24 13 24 │•⋄H×D$•×┊@_•×D$•$│
-│00016210│ 01 48 83 c4 18 c3 48 8d ┊ 3d 83 e9 03 00 ff 15 65 │•H×ו×H×┊=×ו⋄וe│
-│00016220│ 11 04 00 cc cc cc cc cc ┊ cc cc cc cc cc cc cc cc │••⋄×××××┊××××××××│
+│000161e0│ 40 08 a9 01 00 00 00 74 ┊ 08 31 c0 a8 01 75 fa eb │@•ו⋄⋄⋄t┊•1×וu××│
+│000161f0│ 24 48 8b 44 24 08 8b 00 ┊ 89 44 24 14 c6 44 24 13 │$H×D$•×⋄┊×D$•×D$•│
+│00016200│ 00 48 8b 44 24 08 c6 40 ┊ 08 01 8a 44 24 13 24 01 │⋄H×D$•×@┊••×D$•$•│
+│00016210│ 48 83 c4 18 c3 48 8d 3d ┊ 6c e9 03 00 ff 15 66 11 │H×ו×H×=┊lו⋄וf•│
+│00016220│ 04 00 cc cc cc cc cc cc ┊ cc cc cc cc cc cc cc cc │•⋄××××××┊××××××××│
 │00016230│ 50 48 89 f2 48 63 f7 48 ┊ 8d 3d 82 f7 ff ff 31 c9 │PH××Hc×H┊×=××××1×│
 │00016240│ e8 cb e5 ff ff 59 c3 cc ┊ cc cc cc cc cc cc cc cc │×××××Y××┊××××××××│
 │00016250│ e9 9b fa 01 00 cc cc cc ┊ cc cc cc cc cc cc cc cc │××ו⋄×××┊××××××××│
@@ -226718,12 +226718,12 @@
 │00376e60│ 5f 16 00 00 02 00 0f 00 ┊ 90 63 01 00 00 00 00 00 │_•⋄⋄•⋄•⋄┊×c•⋄⋄⋄⋄⋄│
 │00376e70│ 0b 00 00 00 00 00 00 00 ┊ 96 16 00 00 02 00 0f 00 │•⋄⋄⋄⋄⋄⋄⋄┊ו⋄⋄•⋄•⋄│
 │00376e80│ a0 63 01 00 00 00 00 00 ┊ 75 01 00 00 00 00 00 00 │×c•⋄⋄⋄⋄⋄┊u•⋄⋄⋄⋄⋄⋄│
-│00376e90│ eb 16 00 00 02 00 0f 00 ┊ 70 71 01 00 00 00 00 00 │ו⋄⋄•⋄•⋄┊pq•⋄⋄⋄⋄⋄│
+│00376e90│ eb 16 00 00 02 00 0f 00 ┊ d0 71 01 00 00 00 00 00 │ו⋄⋄•⋄•⋄┊×q•⋄⋄⋄⋄⋄│
 │00376ea0│ 52 00 00 00 00 00 00 00 ┊ 79 17 00 00 00 00 0b 00 │R⋄⋄⋄⋄⋄⋄⋄┊y•⋄⋄⋄⋄•⋄│
 │00376eb0│ 70 5b 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │p[⋄⋄⋄⋄⋄⋄┊⋄⋄⋄⋄⋄⋄⋄⋄│
 │00376ec0│ 8c 17 00 00 02 00 0f 00 ┊ 20 65 01 00 00 00 00 00 │ו⋄⋄•⋄•⋄┊ e•⋄⋄⋄⋄⋄│
 │00376ed0│ 78 01 00 00 00 00 00 00 ┊ e1 17 00 00 02 00 0f 00 │x•⋄⋄⋄⋄⋄⋄┊ו⋄⋄•⋄•⋄│
-│00376ee0│ d0 71 01 00 00 00 00 00 ┊ 53 00 00 00 00 00 00 00 │×q•⋄⋄⋄⋄⋄┊S⋄⋄⋄⋄⋄⋄⋄│
+│00376ee0│ 70 71 01 00 00 00 00 00 ┊ 53 00 00 00 00 00 00 00 │pq•⋄⋄⋄⋄⋄┊S⋄⋄⋄⋄⋄⋄⋄│
 │00376ef0│ 6f 18 00 00 00 00 0b 00 ┊ a4 5b 00 00 00 00 00 00 │o•⋄⋄⋄⋄•⋄┊×[⋄⋄⋄⋄⋄⋄│
 │00376f00│ 00 00 00 00 00 00 00 00 ┊ 82 18 00 00 02 00 0f 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊ו⋄⋄•⋄•⋄│
 │00376f10│ a0 66 01 00 00 00 00 00 ┊ 0b 00 00 00 00 00 00 00 │×f•⋄⋄⋄⋄⋄┊•⋄⋄⋄⋄⋄⋄⋄│

@matthiaskrgr matthiaskrgr added the C-bug Category: This is a bug. label Apr 29, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 29, 2025
@matthiaskrgr matthiaskrgr added A-async-closures `async || {}` A-reproducibility Area: Reproducible / deterministic builds A-parallel-compiler Area: parallel compiler labels Apr 29, 2025
@jieyouxu jieyouxu added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-closures `async || {}` A-parallel-compiler Area: parallel compiler A-reproducibility Area: Reproducible / deterministic builds C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants