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

Request: mark all integer platform intrinsics as const #66061

Open
Lokathor opened this issue Nov 3, 2019 · 3 comments
Open

Request: mark all integer platform intrinsics as const #66061

Lokathor opened this issue Nov 3, 2019 · 3 comments
Labels
A-const-eval Area: constant evaluation (mir interpretation) C-feature-request Category: A feature request, i.e: not implemented / a PR. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@Lokathor
Copy link
Contributor

Lokathor commented Nov 3, 2019

The platform intrinsics for floating point suffer the standard floating point problems of not being fully deterministic at all times, which is a requirement for const.

However, the platform intrinsics for integer data do not suffer these problems at all. They are plain integer math operations and you can deterministically know exactly what bit pattern you'll get out for any bit pattern you send in. This means that they are eligible for becoming const. At compile time we could even emulate the operations if necessary.

So, we should make all of these const.

@Lokathor
Copy link
Contributor Author

Lokathor commented Nov 3, 2019

PS: yes, obviously it's not as easy as flipping a switch, i'm not an idiot. This is a long term goal that requires quite a bit of compiler support work to be built up as part of the ongoing const project, etc etc etc

@rodrimati1992
Copy link
Contributor

rodrimati1992 commented Nov 3, 2019

If you want the intrinsics to use them in const fns,they already do work:

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=8add7918cb0e2edd3bf22d02041f1f22

#![feature(core_intrinsics)]

const fn hello()->u32{
    // The intrinsic is not a const fn,yet it can be called inside a const fn
    // pub fn saturating_sub<T>(a: T, b: T) -> T;
    std::intrinsics::saturating_sub::<u32>(0,10)
}

const HI:u32=hello();

fn main(){
    dbg!(HI);
}

I agree that they should be marked const to avoid confusion though.

@Lokathor
Copy link
Contributor Author

Lokathor commented Nov 3, 2019

I believe that's considered a bug, based on what I read in another issue.

However, either way, I was meaning the arch intrinsics, eg, SSE2 and similar.

@Centril Centril added T-lang Relevant to the language team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. A-const-eval Area: constant evaluation (mir interpretation) labels Nov 6, 2019
@JohnTitor JohnTitor added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Feb 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: constant evaluation (mir interpretation) C-feature-request Category: A feature request, i.e: not implemented / a PR. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants