-
Notifications
You must be signed in to change notification settings - Fork 13.3k
ICE on Current Stable #84073
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Labels
A-trait-system
Area: Trait system
C-bug
Category: This is a bug.
glacier
ICE tracked in rust-lang/glacier.
I-ICE
Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Comments
@AldaronLau I can't reproduce: your original code gives errors about import errors, and once I add all the necessary imports it compiles successfully. use core::pin::Pin;
use core::marker::PhantomData;
use core::task::Poll;
use core::task::Context;
use core::future::Future; |
@jyn514 Sorry, I missed some important pieces when I copied. This should work better (at reproducing the bug): use core::future::Future;
use core::pin::Pin;
use core::task::{Context, Poll};
mod race {
use core::future::Future;
use core::marker::PhantomData;
use core::pin::Pin;
use core::task::{Context, Poll};
pub struct RaceFuture<T, F, S, G, U>
where F: StatefulFuture<Option<T>, S>,
G: Future<Output = Option<U>>,
{
inner: F,
future: G,
event: fn(&mut S, U) -> T,
}
impl<T, F, S, G, U> StatefulFuture<Option<T>, S> for RaceFuture<T, F, S, G, U>
where F: StatefulFuture<Option<T>, S>,
G: Future<Output = Option<U>>,
{
fn poll(&mut self, cx: &mut Context<'_>, state: &mut S) -> Poll<Option<T>> {
Poll::Pending // FIXME
}
}
pub trait StatefulFuture<T, S> {
fn poll(&mut self, cx: &mut Context<'_>, state: &mut S) -> Poll<T>;
}
pub struct Never<T, S>(PhantomData<(T, S)>);
impl<T, S> StatefulFuture<T, S> for Never<T, S> {
fn poll(&mut self, cx: &mut Context<'_>, state: &mut S) -> Poll<T> {
Poll::Pending
}
}
/// Race builder. Add tasks by calling `when()`.
pub struct RaceBuilder<T, F, S>
where F: StatefulFuture<Option<T>, S>
{
future: F,
_phantom: PhantomData<(S, T)>,
}
impl<T, F, S> RaceBuilder<T, F, S>
where F: StatefulFuture<Option<T>, S>
{
pub fn when<U, G>(self, future: G, event: fn(&mut S, U) -> T)
-> RaceBuilder<T, RaceFuture<T, F, S, G, U>, S>
where G: Future<Output = Option<U>>,
{
RaceBuilder {
future: RaceFuture {
inner: self.future, future, event
},
_phantom: PhantomData,
}
}
}
/// A future that returns a closure for the first completed future.
#[derive(Debug)]
pub struct Race<'a, T, S, R, F>
where R: Fn(RaceBuilder<T, Never<T, S>, S>, &mut S) -> RaceBuilder<T, F, S>,
F: StatefulFuture<Option<T>, S>,
{
state: &'a mut S,
race: R,
_phantom: PhantomData<(T, F)>,
}
impl<'a, T, S, R, F> Race<'a, T, S, R, F>
where R: Fn(RaceBuilder<T, Never<T, S>, S>, &mut S) -> RaceBuilder<T, F, S>,
F: StatefulFuture<Option<T>, S>,
{
pub fn new(state: &'a mut S, race: R) -> Self {
Self { state, race, _phantom: PhantomData }
}
}
impl<T, S, R, F> Future for Race<'_, T, S, R, F>
where R: Fn(RaceBuilder<T, Never<T, S>, S>, &mut S) -> RaceBuilder<T, F, S>,
F: StatefulFuture<Option<T>, S>,
{
type Output = T;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<T> {
Poll::Pending // FIXME
}
}
}
/// Shared state between tasks on the thread.
struct State {
counter: usize,
one: Never,
}
impl State {
fn one(&mut self, _: ()) -> Option<()> {
todo!()
}
}
struct Never();
impl Never {
fn new() -> Self {}
}
impl Future for Never {
type Output = ();
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
Poll::Pending
}
}
async fn run() {
let mut state = State {
counter: 0,
one: Never::new(),
};
loop {
if let Some(x) = race::Race::new(&mut state, |race, state| {
race.when(&mut state.one, State::one)
}).await {
break x;
}
}
} |
Reduced: use std::marker::PhantomData;
pub trait StatefulFuture<S> {}
pub struct Never<T>(PhantomData<T>);
impl<T> StatefulFuture<T> for Never<T> {}
pub struct RaceBuilder<F, S> {
future: F,
_phantom: PhantomData<S>,
}
impl<T, F> RaceBuilder<T, F>
where
F: StatefulFuture<Option<T>>,
{
pub fn when(self) {}
}
pub struct Race<T, R> {
race: R,
_phantom: PhantomData<T>,
}
impl<T, R> Race<T, R>
where
R: Fn(RaceBuilder<T, Never<T>>),
{
pub fn new(race: R) {}
}
fn main() {
Race::new(|race| race.when());
} |
fanninpm
added a commit
to fanninpm/glacier
that referenced
this issue
Apr 16, 2021
Issue: rust-lang/rust#84073
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Labels
A-trait-system
Area: Trait system
C-bug
Category: This is a bug.
glacier
ICE tracked in rust-lang/glacier.
I-ICE
Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Interestingly, this error only happens when building a binary, and not when building a library.
Code
Meta
rustc --version --verbose
:Also happens on nightly:
rustc +nightly --version --verbose
Error output
Backtrace
The text was updated successfully, but these errors were encountered: