Skip to content
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

regression on nightly-2024-03-16 #122618

Open
xxchan opened this issue Mar 17, 2024 · 3 comments
Open

regression on nightly-2024-03-16 #122618

xxchan opened this issue Mar 17, 2024 · 3 comments
Labels
A-coroutines Area: Coroutines C-bug Category: This is a bug. F-coroutines `#![feature(coroutines)]` F-impl_trait_in_assoc_type `#![feature(impl_trait_in_assoc_type)]` P-medium Medium priority regression-untriaged Untriaged performance or correctness regression. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@xxchan
Copy link
Contributor

xxchan commented Mar 17, 2024

Code

I tried this code:

[dependencies]
futures = "0.3.30"
futures-async-stream = "0.2.10"
#![feature(coroutines)]
#![feature(impl_trait_in_assoc_type)]
use futures::Stream;
use futures_async_stream::try_stream;
use std::future::Future;
pub trait IterItem: Send + 'static {
    type ItemRef<'a>: Send + 'a;
}

type StorageError = ();
type StorageResult<T> = Result<T, StorageError>;

pub trait StateStoreIter<T: IterItem>: Send {
    fn try_next(
        &mut self,
    ) -> impl Future<Output = StorageResult<Option<T::ItemRef<'_>>>> + Send + '_;
}

#[try_stream(ok = O, error = StorageError)]
async fn into_stream_inner<
    T: IterItem,
    I: StateStoreIter<T>,
    O: Send,
    F: for<'a> Fn(T::ItemRef<'a>) -> StorageResult<O> + Send,
>(
    mut iter: I,
    f: F,
) {
    while let Some(item) = iter.try_next().await? {
        yield f(item)?;
    }
}

pub trait StateStoreIterExt<T: IterItem>: StateStoreIter<T> + Sized {
    type ItemStream<O: Send, F: Send>: Stream<Item = StorageResult<O>> + Send;

    fn into_stream<O: Send, F: for<'a> Fn(T::ItemRef<'a>) -> StorageResult<O> + Send>(
        self,
        f: F,
    ) -> Self::ItemStream<O, F>;
}

impl<T: IterItem, I: StateStoreIter<T>> StateStoreIterExt<T> for I {
    type ItemStream<O: Send, F: Send> = impl Stream<Item = StorageResult<O>> + Send;

    fn into_stream<O: Send, F: for<'a> Fn(T::ItemRef<'a>) -> StorageResult<O> + Send>(
        self,
        f: F,
    ) -> Self::ItemStream<O, F> {
        into_stream_inner(self, f)
    }
}

fn main() {
    println!("Hello, world!");
}

Version it worked on

It compiles on nightly-2024-03-14

Version with regression

ICE on nightly-2024-03-15 #122508

Compile error on nightly-2024-03-16:

error[E0277]: expected a `Fn(<T as IterItem>::ItemRef<'a>)` closure, found `F`
  --> src/main.rs:50:9
   |
50 |         into_stream_inner(self, f)
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected an `Fn(<T as IterItem>::ItemRef<'a>)` closure, found `F`
   |
note: required by a bound in `into_stream_inner`
  --> src/main.rs:24:8
   |
20 | async fn into_stream_inner<
   |          ----------------- required by a bound in this function
...
24 |     F: for<'a> Fn(T::ItemRef<'a>) -> StorageResult<O> + Send,
   |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `into_stream_inner`
help: consider further restricting this bound
   |
44 |     type ItemStream<O: Send, F: Send + for<'a> std::ops::Fn<(<T as IterItem>::ItemRef<'a>,)>> = impl Stream<Item = StorageResult<O>> + Send;
   |                                      +++++++++++++++++++++++++++++++++++++++++++++++++++++++

@xxchan xxchan added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Mar 17, 2024
@rustbot rustbot added I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 17, 2024
@xxchan
Copy link
Contributor Author

xxchan commented Mar 17, 2024

cc @petrochenkov not sure if you have any ideas

@jieyouxu jieyouxu added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 17, 2024
@apiraino
Copy link
Contributor

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Mar 18, 2024
@jieyouxu jieyouxu added A-coroutines Area: Coroutines F-impl_trait_in_assoc_type `#![feature(impl_trait_in_assoc_type)]` F-coroutines `#![feature(coroutines)]` labels Mar 20, 2024
@GrigorenkoPV
Copy link
Contributor

Somewhat reduced:

#![feature(impl_trait_in_assoc_type)]

trait Marker {}

fn into_opaque<T: Marker>() -> impl Sized {}

trait Trait {
    type Assoc<Inner>;

    fn method<T: Marker>(_: T) -> Self::Assoc<T>;
}

impl Trait for () {
    type Assoc<Inner> = impl Sized;

    fn method<T: Marker>(_: T) -> Self::Assoc<T> {
        into_opaque::<T>()
    }
}

Regression in 1ca424c (#122341, cc @compiler-errors).

As for the ICE on nightly-2024-03-15, while reducing, I have noticed that the ICE only happened with incremental compilation. (Also the reduced example above does not ICE anymore.) Should this be investigated further / a separate issue opened / this issue re-labeled / someone pinged?

@jieyouxu jieyouxu added A-incr-comp Area: Incremental compilation and removed A-incr-comp Area: Incremental compilation labels Mar 28, 2024
@jieyouxu jieyouxu added S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-coroutines Area: Coroutines C-bug Category: This is a bug. F-coroutines `#![feature(coroutines)]` F-impl_trait_in_assoc_type `#![feature(impl_trait_in_assoc_type)]` P-medium Medium priority regression-untriaged Untriaged performance or correctness regression. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue 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

5 participants