-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
ICE in async closure that takes ref to boxed dyn trait #128554
Comments
update on the issue i changed ResourceLoader::start_loading from using async_trait to manually returning BoxFuture<'static, Box<dyn Any + Send>> here is the updated code pub trait ResourceLoader: Send {
fn start_loading(&mut self) -> BoxFuture<'static, Box<dyn Any + Send>>;
}
pub struct FileResourceLoader<T: FileLoadable + 'static> {
pub path: String,
_p: PhantomData<T>,
}
impl<T: FileLoadable + Send + 'static> ResourceLoader for FileResourceLoader<T> {
fn start_loading(&mut self) -> BoxFuture<'static, Box<dyn Any + Send>> {
let path = self.path.clone();
async move {
let bytes = fs::read(path).await;
let mut load_provider = T::default();
Box::new(load_provider.process_bytes(bytes)) as Box<dyn Any + Send>
}
.boxed()
}
} |
good news! let thread_rx: flume::Receiver<(Uuid, Box<dyn ResourceLoader>)> =
runtime.render_resource_manager.thread_rx.clone();
let thread_tx: flume::Sender<(Uuid, Box<dyn Any + Send>)> =
runtime.render_resource_manager.thread_tx.clone();
std::thread::spawn(move || {
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();
let rx = thread_rx;
let tx = thread_tx;
rt.spawn(async move {
let futures = FuturesUnordered::new();
loop {
let tx = tx.clone();
match rx.recv() {
Ok((uuid, mut loader)) => {
let future = async move {
let result: Box<dyn Any + Send> = loader.start_loading().await;
tx.send((uuid, result)).unwrap();
}
.boxed();
futures.push(future);
}
Err(_) => continue,
}
}
});
}); i dont now for sure what was the problem but i have an idea and i think the problem was with the futures variable type representation at the start i was pushing futures to the "futures" variable that had in the types signiture "impl", let futures: FuturesUnordered<impl FnMut() -> impl Future<Output = ()>> =FuturesUnordered::new(); i couldnt because rust didnt allow the use of "impl" here, cargo check was throwing errors, let futures: FuturesUnordered<std::pin::Pin<Box<dyn Future<Output = ()> + Send>>> = FuturesUnordered::new(); and the ICE error disapperad i think the reason why the compiler was crashing is because internally it couldnt use the impl in the generic type signiture but i could be totally wrong, i have never worked on the rust compiler i wont close this issue because the error is still in the compiler and it probably worth a fix |
You should probably provide a fully working reproduction for this crash. Specifically, you shared a lot of code but it's still missing whatever |
yeah dupe is a little bit sketchy and i probably shouldnt it basically transforms any lifetime into 'static here is the repo https://github.com/Almale02/krajc i will try to post the minimal reproduction to it later, probably tomorrow here is the dupe pub fn dupe<T: ?Sized>(value: &T) -> &'static mut T {
unsafe { &mut *((value as *const T) as *mut T) }
} |
for the record, that is super duper hyper major unsound! but it shouldn't crash the compiler |
yeah "dupe" definitely not the problem here |
Well, could you please still provide a full reproduction? I don't have any idea how to actually reproduce this ICE with the code you've shared. |
yeah i will try to do it, probably tomorrow btw are you talking about the minimal reproduction of the error? |
No, I just mean something that's complete. You've shared a bunch of random snippets of code and I have no idea how to put them together in context to make something that actually compiles, let alone ICEs 😃 |
Minimal reproduction: #![feature(async_closure)]
use std::pin::Pin;
use std::future::Future;
pub trait ResourceLoader {
fn start_loading(&mut self);
}
fn run(mut loader: Box<dyn ResourceLoader>) {
async move || {
loader.start_loading();
};
} |
the reproduction looks correct, i dont know if you need that FuturesUnordered for it i am pretty new to this github stuff i am currenlty figuring out things i will also try to do some kind of reproduction myself |
This is just a bug in async closures. I don't need a reproduction anymore; I doubt you'll get one that's smaller than the one I pased above. |
that was the problem? well, thanks for figuring out what was the problem with it! so the problem basically was that you cannot call trait object methods inside async move closures? |
also it is strange that cargo check works but build doesnt glad i could help with this issue! |
just remove the two unused imports to get a smaller repro 🤡 |
@Almale02 While it is secondary to this issue, if |
yes let v = vec![1000, 2000, 3000];
let dup = dupe(&v[0]);
println!("{}", v[0]);
println!("{}", dup);
drop(v);
//let v = vec![9001; 9001];
*dup = 3; // HERE!
println!("{}", dup); you could modify freed values, because the dup variable has 'static lifetime and it is not bounded at all to the dupe(&physics).physics_pipeline.step(
&gravity.0,
&IntegrationParameters::default(),
&mut dupe(&physics).island_manager,
&mut dupe(&physics).broad_phase,
&mut dupe(&physics).narrow_phase,
&mut dupe(&physics).rigid_body_set,
&mut dupe(&physics).collider_set,
&mut dupe(&physics).impulse_joint_set,
&mut dupe(&physics).multibody_joint_set,
&mut dupe(&physics).ccd_solver,
Some(&mut dupe(&physics).query_pipeline),
&event_handler,
&event_handler,
); i need to use pass down multiple &mut references, then i also use it, technically there could be problems with it, but i have plans to migrate my project to use proper lifetimes, but i couldnt get the rendering code to work with lifetimes so yes, i never stated that |
@Almale02 Ah! You should mark that function as |
Code
Meta
rustc --version --verbose
:Error output
Backtrace
this was at the end of the error
i have put a comment in the code where the problematic line is,
the problem could be caused by async trait object method in ResourceLoader::start_loading
i am using async_trait crate
here is the library code that the problematic code uses
the ResourceLoader trait is at the end
[rustc-ice-2024-08-02T15_03_52-2852.txt](https://github.com/user-attachments/files/16472328/rustc-ice-2024-08-02T15_03_52-
The text was updated successfully, but these errors were encountered: