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

Bad generic inference on very recent nightly #105037

Closed
dlubarov opened this issue Nov 29, 2022 · 2 comments · Fixed by #105292
Closed

Bad generic inference on very recent nightly #105037

dlubarov opened this issue Nov 29, 2022 · 2 comments · Fixed by #105292
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]`

Comments

@dlubarov
Copy link

We noticed a build error in Plonky2 on the nightly build 2022-11-27. The same code was building last week, on a slightly older nightly.

Here's a minimal reproducible example (Playground):

#![feature(generic_const_exprs)]

trait Table<const D: usize>: Sync {
    const COLUMNS: usize;
}

struct Table1<const D: usize>;
impl<const D: usize> Table<D> for Table1<D> {
    const COLUMNS: usize = 123;
}

struct Table2<const D: usize>;
impl<const D: usize> Table<D> for Table2<D> {
    const COLUMNS: usize = 456;
}

fn process_table<T: Table<D>, const D: usize>(table: T)
where
    [(); T::COLUMNS]:,
{
}

fn process_all_tables<const D: usize>()
where
    [(); Table1::<D>::COLUMNS]:,
    [(); Table2::<D>::COLUMNS]:,
{
    process_table(Table1::<D>);
    process_table(Table2::<D>);
}

Nightly 2022-11-27 gives this error:

error[[E0308]](https://doc.rust-lang.org/nightly/error-index.html#E0308): mismatched types
  --> src/lib.rs:28:19
   |
28 |     process_table(Table1::<D>);
   |     ------------- ^^^^^^^^^^^ expected struct `Table2`, found struct `Table1`
   |     |
   |     arguments to this function are incorrect
   |
   = note: expected struct `Table2<D>`
              found struct `Table1<D>`

It seems to be sensitive to the order of the where clauses, [(); Table1::<D>::COLUMNS]: and [(); Table2::<D>::COLUMNS]:. I.e. for a process_table call, it seems to infer that T is whichever Table appeared last in the where list.

@dlubarov dlubarov added the C-bug Category: This is a bug. label Nov 29, 2022
BGluth added a commit to 0xPolygonZero/plonky2 that referenced this issue Nov 29, 2022
@compiler-errors compiler-errors added the E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc label Nov 29, 2022
@mucinoab
Copy link
Contributor

mucinoab commented Nov 29, 2022

@compiler-errors Please remove the "E-needs-bisection" (also, how can I do that?)

searched nightlies: from nightly-2022-11-25 to nightly-2022-11-29
regressed nightly: nightly-2022-11-27
searched commit range: 8681d4c...80a9646
regressed commit: aff003b

bisected with cargo-bisect-rustc v0.6.4

Host triple: x86_64-unknown-linux-gnu

@compiler-errors compiler-errors removed the E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc label Nov 29, 2022
@compiler-errors
Copy link
Member

thanks @mucinoab

cc @BoxyUwU @JulianKnodt

@BoxyUwU BoxyUwU added A-const-generics Area: const generics (parameters and arguments) F-generic_const_exprs `#![feature(generic_const_exprs)]` labels Nov 29, 2022
JohnTitor pushed a commit to JohnTitor/rust that referenced this issue Jan 9, 2023
…yUwU

Change a commit_if_ok call to probe

Removes an over-eager `commit_if_ok` which makes inference worse.

I'm not entirely sure whether it's ok to remove the check that types are the same, because casting seems to cause equality checks with incorrect types?

Fixes rust-lang#105037

r? `@BoxyUwU`
JohnTitor pushed a commit to JohnTitor/rust that referenced this issue Jan 9, 2023
…yUwU

Change a commit_if_ok call to probe

Removes an over-eager `commit_if_ok` which makes inference worse.

I'm not entirely sure whether it's ok to remove the check that types are the same, because casting seems to cause equality checks with incorrect types?

Fixes rust-lang#105037

r? ``@BoxyUwU``
@bors bors closed this as completed in b7587f1 Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]`
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants