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

linker error with feature(generic_const_exprs) #82268

Closed
e2-71828 opened this issue Feb 18, 2021 · 3 comments · Fixed by #100315
Closed

linker error with feature(generic_const_exprs) #82268

e2-71828 opened this issue Feb 18, 2021 · 3 comments · Fixed by #100315
Labels
C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example F-generic_const_exprs `#![feature(generic_const_exprs)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@e2-71828
Copy link

e2-71828 commented Feb 18, 2021

edit: current minimal repro #82268 (comment)

Error Message

   Compiling playground v0.0.1 (/playground)
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
 --> src/main.rs:1:12
  |
1 | #![feature(const_generics, const_evaluatable_checked)]
  |            ^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information

warning: the feature `const_evaluatable_checked` is incomplete and may not be safe to use and/or cause compiler crashes
 --> src/main.rs:1:28
  |
1 | #![feature(const_generics, const_evaluatable_checked)]
  |                            ^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information

error: internal compiler error: compiler/rustc_middle/src/ty/subst.rs:568:17: const parameter `MASK/#2` (Const { ty: u32, val: Param(MASK/#2) }/2) out of range when substituting substs=[]

thread 'rustc' panicked at 'Box<Any>', /rustc/5fa22fe6f821ac3801d05f624b123dda25fde32c/library/std/src/panic.rs:59:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.52.0-nightly (5fa22fe6f 2021-02-14) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type bin

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [check_item_well_formed] checking that `<(H, T) as Collate<MASK>>` is well-formed
#1 [analysis] running analysis passes on this crate
end of query stack
thread 'rustc' panicked at 'Box<Any>', /rustc/5fa22fe6f821ac3801d05f624b123dda25fde32c/library/std/src/panic.rs:59:5

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.52.0-nightly (5fa22fe6f 2021-02-14) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type bin

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [eval_to_allocation_raw] const-evaluating + checking `<(H, T) as Collate<MASK>>::{constant#0}`
#1 [eval_to_const_value_raw] simplifying constant for the type system `<(H, T) as Collate<MASK>>::{constant#0}`
end of query stack
error: aborting due to previous error; 2 warnings emitted

error: could not compile `playground`

To learn more, run the command again with --verbose.

Code

#![feature(const_generics, const_evaluatable_checked)]

struct True;
struct False;

trait ConstBool {
    type Val;
}
struct TypeBool<const X: bool>;

impl ConstBool for TypeBool<true> {
    type Val = True;
}

impl ConstBool for TypeBool<false> {
    type Val = False;
}

trait Collate<const MASK: u32> {
    type Pass;
    type Fail;

    fn collate(self) -> (Self::Pass, Self::Fail);
}

impl<const MASK: u32> Collate<MASK> for () {
    type Pass = ();
    type Fail = ();

    fn collate(self) -> ((), ()) {
        ((), ())
    }
}

trait CollateStep<X, Prev> {
    type Pass;
    type Fail;
    fn collate_step(x: X, prev: Prev) -> (Self::Pass, Self::Fail);
}

impl<X, P, F> CollateStep<X, (P, F)> for TypeBool<true> {
    type Pass = (X, P);
    type Fail = F;

    fn collate_step(x: X, (p, f): (P, F)) -> ((X, P), F) {
        ((x, p), f)
    }
}

impl<X, P, F> CollateStep<X, (P, F)> for TypeBool<false> {
    type Pass = P;
    type Fail = (X, F);

    fn collate_step(x: X, (p, f): (P, F)) -> (P, (X, F)) {
        (p, (x, f))
    }
}

impl<H, T: Collate<{ MASK >> 1 }>, const MASK: u32> Collate<MASK> for (H, T)
where
    TypeBool<{ 1 == MASK & 1 }>: CollateStep<H, (T::Pass, T::Fail)>,
{
    type Pass =
        <TypeBool<{ 1 == MASK & 1 }> as CollateStep<H, (T::Pass, T::Fail)>>::Pass;
    type Fail =
        <TypeBool<{ 1 == MASK & 1 }> as CollateStep<H, (T::Pass, T::Fail)>>::Fail;

    fn collate(self) -> (Self::Pass, Self::Fail) {
        <TypeBool<{ 1 == MASK & 1 }>
         as CollateStep<H, (T::Pass, T::Fail)>>
         ::collate_step(self.0, self.1.collate())
    }
}

fn collate<X,const MASK:u32>(x:X)->(X::Pass, X::Fail)
where X:Collate<MASK> {
    x.collate()
}

fn main() {
    dbg!(collate::<_,3>((4, ('!',()))));
}

(Playground)

@e2-71828 e2-71828 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 Feb 18, 2021
@jonas-schievink jonas-schievink added F-generic_const_exprs `#![feature(generic_const_exprs)]` requires-nightly This issue requires a nightly compiler in some way. labels Feb 18, 2021
@e2-71828
Copy link
Author

This appears to be related to using a const generic as a trait parameter. A couple of variants I've tried:

  • Wrapping the parameter in a struct still errors: (Playground)
  • But extracting the const computations into a separate trait compiles: (Playground)

fanninpm added a commit to fanninpm/glacier that referenced this issue Feb 20, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Feb 21, 2021
@JohnTitor
Copy link
Member

Triage: The original ICE has been fixed in the latest nightly but the following examples (#82268 (comment)) return a linker error for me. cc #84299 and @lcnr

@BoxyUwU BoxyUwU changed the title ICE with #![feature(const_evaluatable_checked)] linker error with feature(generic_const_exprs) Jun 24, 2022
@lcnr
Copy link
Contributor

lcnr commented Jun 24, 2022

we still get a linker error for

#![feature(generic_const_exprs)]

trait Collate<Op> {
    type Pass;
    type Fail;

    fn collate(self) -> (Self::Pass, Self::Fail);
}

impl<Op> Collate<Op> for () {
    type Pass = ();
    type Fail = ();

    fn collate(self) -> ((), ()) {
        ((), ())
    }
}

trait CollateStep<X, Prev> {
    type Pass;
    type Fail;
    fn collate_step(x: X, prev: Prev) -> (Self::Pass, Self::Fail);
}

impl<X, P, F> CollateStep<X, (P, F)> for () {
    type Pass = (X, P);
    type Fail = F;

    fn collate_step(x: X, (p, f): (P, F)) -> ((X, P), F) {
        ((x, p), f)
    }
}

struct CollateOpImpl<const MASK: u32>;
trait CollateOpStep {
    type NextOp;
    type Apply;
}

impl<const MASK: u32> CollateOpStep for CollateOpImpl<MASK>
where
    CollateOpImpl<{ MASK >> 1 }>: Sized,
{
    type NextOp = CollateOpImpl<{ MASK >> 1 }>;
    type Apply = ();
}

impl<H, T, Op: CollateOpStep> Collate<Op> for (H, T)
where
    T: Collate<Op::NextOp>,
    Op::Apply: CollateStep<H, (T::Pass, T::Fail)>,
{
    type Pass = <Op::Apply as CollateStep<H, (T::Pass, T::Fail)>>::Pass;
    type Fail = <Op::Apply as CollateStep<H, (T::Pass, T::Fail)>>::Fail;

    fn collate(self) -> (Self::Pass, Self::Fail) {
        <Op::Apply as CollateStep<H, (T::Pass, T::Fail)>>::collate_step(self.0, self.1.collate())
    }
}

fn collate<X, const MASK: u32>(x: X) -> (X::Pass, X::Fail)
where
    X: Collate<CollateOpImpl<MASK>>,
{
    x.collate()
}

fn main() {
    dbg!(collate::<_, 5>(("Hello", (42, ('!', ())))));
}

Would be great to get a more minimal example for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example F-generic_const_exprs `#![feature(generic_const_exprs)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
5 participants