Skip to content

ICE (unwrap of None) after type error with aggressive use of higher-kinded types and variance #23046

Closed
@arielb1

Description

@arielb1

Will minify later

http://is.gd/B0NXIN

pub mod ltseal {
    use std::marker::PhantomData;

    #[derive(Copy)]
    pub struct ContraLifetimeCell<'a, T>(T, PhantomData<*mut FnOnce(&'a ())>);

    #[derive(Copy)]
    pub struct ContraLifetimeSeal<'a>(PhantomData<*mut FnOnce(&'a ())>);

    impl<'s> ContraLifetimeSeal<'s> {
        pub fn seal<'a, T>(&'a self, t: T) -> ContraLifetimeCell<'s, T> {
            ContraLifetimeCell(t, PhantomData)
        }

        pub fn unseal<'a, T>(&'a self, c: ContraLifetimeCell<'s, T>) -> T {
            c.0
        }

        pub fn ref_unseal<'a, 'b, T>(&'a self,
                                     c: &'b ContraLifetimeCell<'s, T>)
                                     -> &'b T {
            &c.0
        }

        pub fn with_seal<T, F: for<'a> FnOnce(ContraLifetimeSeal<'a>) -> T>
                (f: F) -> T {
            f(ContraLifetimeSeal(PhantomData))
        }
    }
}

pub mod deep {
    /* language with only let, variables, addition as PoC */
    use ltseal::ContraLifetimeCell as CLC;

    pub enum Op {
        Add,
    }

    pub enum Expr<'var, VAR> {
        Lit(u32),
        Op(Op, Box<Expr<'var, VAR>>, Box<Expr<'var, VAR>>),
        Var(CLC<'var, VAR>),
        Let(Box<Expr<'var, VAR>>,
            Box<for<'v: 'var> Fn(Expr<'v, VAR>) -> Expr<'v, VAR> + 'var>)
    }

    pub fn add<'var, VAR, E1: ExprLike<'var, VAR>,
                          E2: ExprLike<'var, VAR>>
                          (a: E1, b: E2) -> Expr<'var, VAR> {
        Expr::Op(Op::Add, a.as_expr(), b.as_expr())
    }

    pub fn let_<'var, VAR, E: ExprLike<'var, VAR>,
                           F: for<'v: 'var>
                             Fn(Expr<'v, VAR>) -> Expr<'v, VAR>>
                           (a: E, b: F) -> Expr<'var, VAR> {
        Expr::Let(a.as_expr(), Box::new(b))
    }


    pub trait ExprLike<'var, VAR> {
        fn as_expr(self) -> Box<Expr<'var, VAR>>;
    }

    impl<'var, VAR> ExprLike<'var, VAR> for u32 {
        fn as_expr(self) -> Box<Expr<'var, VAR>> { Box::new(Expr::Lit(self)) }
    }

    impl<'var, VAR> ExprLike<'var, VAR> for Expr<'var, VAR> {
        fn as_expr(self) -> Box<Expr<'var, VAR>> { Box::new(self) }
    }



}

pub use deep::Expr as E;
pub use deep as d;

fn main() {
//let x=5 in let y=3 in let x=x+y in x
    let ex = d::let_(5, |x| {
        d::let_(3, |y| {
            d::let_(d::add(x, y), |x|x
        )})
    });
    drop(ex);
}

Errors:

rror: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libcore/option.rs:362

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions