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

stability break in rust 1.54: generic Self types are currently not permitted in anonymous constants #88888

Closed
eduardosm opened this issue Sep 12, 2021 · 8 comments
Labels
A-const-generics Area: const generics (parameters and arguments) A-simd Area: SIMD (Single Instruction Multiple Data) C-bug Category: This is a bug. P-high High priority PG-const-generics Project group: Const generics regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@eduardosm
Copy link
Contributor

eduardosm commented Sep 12, 2021

I tried this code:

use std::arch::x86_64::*;

struct Test<const X: u8>;

impl<const X: u8> Test<X> {
    const Y: i32 = (X | (X << 2) | (X << 4) | (X << 6)) as i32;

    unsafe fn f(v: __m128i) -> __m128i {
        _mm_shufflelo_epi16(v, Self::Y)
    }
}

I expected to see this happen:

This code was accepted in Rust 1.53, so newer versions should also accept it.

Instead, this happened:

error: generic `Self` types are currently not permitted in anonymous constants
 --> <source>:9:32
  |
9 |         _mm_shufflelo_epi16(v, Self::Y)
  |                                ^^^^
  |
note: not a concrete type
 --> <source>:5:19
  |
5 | impl<const X: u8> Test<X> {
  |                   ^^^^^^^

error: aborting due to previous error

Meta

Tested using rustc 1.53 and 1.54 (and newer) from Compiler Explorer.

@eduardosm eduardosm added the C-bug Category: This is a bug. label Sep 12, 2021
@jonas-schievink jonas-schievink added A-simd Area: SIMD (Single Instruction Multiple Data) regression-from-stable-to-stable Performance or correctness regression from one stable version to another. labels Sep 12, 2021
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Sep 12, 2021
@Mark-Simulacrum
Copy link
Member

I suspect this might actually be down to #83167, but not sure.

@eduardosm
Copy link
Contributor Author

This example, which does not use const generics, also compiled in 1.53 and fails in newer versions:

use std::arch::x86_64::*;

trait GenU8 {
    const X: i32;
}

unsafe fn f<X: GenU8>(v: __m128i) -> __m128i {
    _mm_shufflelo_epi16(v, X::X)
}

@Mark-Simulacrum
Copy link
Member

That example is similarly using const generics; just implicitly. From 1.54 onwards, the immediate parameter in _mm_shufflelo_epi16 is defined using const generics, with desugaring from the function form implicitly done by the compiler.

@eduardosm
Copy link
Contributor Author

That example is similarly using const generics; just implicitly. From 1.54 onwards, the immediate parameter in _mm_shufflelo_epi16 is defined using const generics, with desugaring from the function form implicitly done by the compiler.

My point is that it breaks code that compiled much before (explicit) const generics were introduced.

@steffahn
Copy link
Member

Bisection on the second example

searched nightlies: from nightly-2020-04-01 to nightly-2021-09-11
regressed nightly: nightly-2021-05-09
searched commits: from 770792f to 881c1ac
regressed commit: 881c1ac

bisected with cargo-bisect-rustc v0.6.0

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --start 2020-04-01 --access github --regress error 

Which is #83278 which indeed belongs to #83167.

@camelid camelid added A-const-generics Area: const generics (parameters and arguments) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 12, 2021
@apiraino
Copy link
Contributor

Assigning priority as discussed in the Zulip thread of the Prioritization Working Group.

@rustbot label -I-prioritize +P-high

@rustbot rustbot added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Sep 22, 2021
@pnkfelix
Copy link
Member

Visited during P-high review

@rust-lang/project-const-generics , can you all spend some time trying to brainstorm best way to resolve this?

@pnkfelix pnkfelix added the PG-const-generics Project group: Const generics label Nov 18, 2022
@oli-obk
Copy link
Contributor

oli-obk commented Nov 19, 2022

This breakage was known and cratered. The fix is to get generic const expressions stabilized. Closing as duplicate of #76560

@oli-obk oli-obk closed this as completed Nov 19, 2022
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) A-simd Area: SIMD (Single Instruction Multiple Data) C-bug Category: This is a bug. P-high High priority PG-const-generics Project group: Const generics regression-from-stable-to-stable Performance or correctness regression from one stable version to another. 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

9 participants