-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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: broken MIR: equate_inputs_and_outputs: NoSolution #112604
Labels
A-borrow-checker
Area: The borrow checker
C-bug
Category: This is a bug.
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
K4rakara
added
C-bug
Category: This is a bug.
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.
labels
Jun 14, 2023
Reduced: trait FnRet {
type Ret;
}
impl<T> FnRet for fn() -> T {
type Ret = T;
}
type Never = <fn() -> ! as FnRet>::Ret;
mod higher_kinded_types {
use with_lifetime::WithLifetime;
pub(crate) mod with_lifetime {
pub(crate) trait WithLifetime<'lt>: Send + Sync + Unpin {
type T;
}
impl<'lt, T: ?Sized + WithLifetime<'lt>> WithLifetime<'lt>
for crate::higher_kinded_types::__private::Hkt<T>
{
type T = T::T;
}
}
pub(crate) trait Hkt: Send + Sync + Unpin + seal::Sealed {
type __<'lt>;
}
mod seal {
pub(crate) trait Sealed {}
impl<T: ?Sized> Sealed for super::__private::Hkt<T> {}
}
impl<T: ?Sized> Hkt for T
where
Self: for<'any> WithLifetime<'any> + seal::Sealed,
{
type __<'lt> = <Self as WithLifetime<'lt>>::T;
}
pub(crate) mod __private {
use crate::Never;
pub(crate) struct Hkt<T: ?Sized>(::core::marker::PhantomData<T>, Never);
}
}
use higher_kinded_types::Hkt;
use std::{marker::PhantomData, str::CharIndices};
pub(crate) trait DynParser {
type Output: Hkt;
fn dyn_parse<'a>(&self) -> Result<'a, <Self::Output as Hkt>::__<'a>>;
}
impl<T> DynParser for T
where
T: Parser,
{
type Output = crate::higher_kinded_types::__private::Hkt<
dyn for<'a> crate::higher_kinded_types::with_lifetime::WithLifetime<'a, T = T::Output<'a>>,
>;
fn dyn_parse<'a>(&self) -> Result<'a, <Self::Output as Hkt>::__<'a>> {
loop {}
}
}
pub trait Parser {
type Output<'a>;
fn parse<'a>(&self) -> Result<'a, Self::Output<'a>>;
}
impl<Output: Hkt> Parser for dyn '_ + DynParser<Output = Output> {
type Output<'a> = Output::__<'a>;
fn parse<'a>(&self) -> Result<'a, Self::Output<'a>> {
loop {}
}
}
impl<T> Parser for Box<T>
where
T: ?Sized + Parser,
{
type Output<'a> = T::Output<'a>;
fn parse<'a>(&self) -> Result<'a, Self::Output<'a>> {
loop {}
}
}
pub(crate) type Result<'a, T, E = ()> = ::std::result::Result<(CharIndices<'a>, T), E>;
pub(crate) const fn always<T>(value: T) -> impl for<'a> Parser<Output<'a> = T> {
struct Always<T> {
value: T,
}
impl<T> Parser for Always<T> {
type Output<'a> = T;
fn parse<'a>(&self) -> Result<'a, Self::Output<'a>> {
loop {}
}
}
Always { value }
}
pub(crate) fn lazy<T, F>(_: F) -> impl for<'a> Parser<Output<'a> = T::Output<'a>>
where
F: FnOnce() -> T,
T: Parser,
{
struct Lazy<F, T> {
inner: PhantomData<T>,
inner2: PhantomData<F>,
}
impl<F, T> Parser for Lazy<F, T>
where
F: FnOnce() -> T,
T: Parser,
{
type Output<'a> = T::Output<'a>;
fn parse<'a>(&self) -> Result<'a, Self::Output<'a>> {
loop {}
}
}
Lazy {
inner: PhantomData,
inner2: PhantomData::<F>,
}
}
pub(crate) fn uncycle<'a, T>(
parser: T,
) -> Box<
dyn 'a
+ DynParser<
Output = crate::higher_kinded_types::__private::Hkt<
dyn for<'b> crate::higher_kinded_types::with_lifetime::WithLifetime<
'b,
T = T::Output<'b>,
>,
>,
>,
>
where
T: Parser + 'a,
{
Box::new(parser)
}
/// vvv HERE vvv
pub fn foo() -> impl for<'a> Parser<Output<'a> = ()> {
lazy(|| uncycle(always(())))
} |
jyn514
changed the title
ICE: no errors encountered even though
ICE: broken MIR: equate_inputs_and_outputs: NoSolution
Jun 14, 2023
delay_span_bug
issued
Further reduced. HKTsuse higher_kinded_types::HKT;
mod higher_kinded_types {
pub(crate) trait HKT {
type Of<'lt>;
}
pub(crate) trait WithLifetime<'lt> {
type T;
}
impl<T: ?Sized + for<'any> WithLifetime<'any>> HKT
for T
{
type Of<'lt> = <T as WithLifetime<'lt>>::T;
}
macro_rules! __ {(
<$lt:lifetime> = $T:ty
) => (
dyn for<$lt> crate::higher_kinded_types::WithLifetime<$lt, T = $T>
)}
pub(crate) use __ as HKT;
} Problematic codetrait Trait {
type Gat<'lt>;
}
impl Trait for () {
type Gat<'lt> = ();
}
/// Same as `Trait`, but using HKTs rather than GATs
trait HTrait {
type Hat: ?Sized + HKT;
}
impl<Hat: ?Sized + HKT> Trait for Box<dyn HTrait<Hat = Hat>> {
type Gat<'lt> = Hat::Of<'lt>;
}
fn existential()
-> impl for<'a> Trait<Gat<'a> = ()>
{}
fn dyn_hoops<T: Trait>(_: T)
-> Box<dyn HTrait<Hat = HKT!(<'a> = T::Gat<'a>)>>
// ^^^^^^^^^^ seems to be key to cause the ICE.
{loop {}}
fn bound_on_fn_output<Output: Trait>(
_: impl FnOnce() -> Output,
)
{}
fn ice() {
bound_on_fn_output(|| -> _ { // not annotating `-> Box<dyn HTrait<Hat = _>>` seems important as well.
dyn_hoops(existential())
});
} |
Further minimized: trait Trait {
type Gat<'lt>;
}
impl Trait for () {
type Gat<'lt> = ();
}
fn dyn_hoops<T: Trait>(_: T) -> *const dyn FnOnce(T::Gat<'_>) {
loop {}
}
fn main() {
let _ = || { dyn_hoops(()) };
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-borrow-checker
Area: The borrow checker
C-bug
Category: This is a bug.
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.
All of this is yanked out of my work-in-progress bug-for-bug* Misskey Flavored markdown parser, which uses the
Parser
trait, as defined below, to hopefully allow the compiler to create well-optimized functions via inlining and such.Where things get messy is in the introduction of the
DynParser
trait, which uses the same technique used by thelending_iterator
andhigher-kinded-types
crates in order to remove the generic lifetime from its associated type,Output
, since lifetime-only generic associated types aren't object-safe (yet?), despite lifetime-only generic parameters being object-safe.Object-safety is required in this case, because the
impl Trait
syntax doesn't support cyclic types (for obvious reasons), so boxing and dynamic dispatch is necessary in order to break said cycle.*as in, it behaves identically to
mfm-js
, regardless of if that behavior is really "correct" behavior for a markdown parser or not.Code
Sorry for the rather large reproduction, this was as small as I was able to get it 😓
Meta
rustc --version --verbose
:Error output
Backtrace
The text was updated successfully, but these errors were encountered: