rust-lang / reference

The Rust Reference
https://doc.rust-lang.org/nightly/reference/
Apache License 2.0
1.25k stars 493 forks source link

const_eval: update for const-fn float stabilization #1566

Closed RalfJung closed 3 months ago

RalfJung commented 3 months ago

Accompanying reference update for https://github.com/rust-lang/rust/pull/128596.

The float semantics RFC decided that this is not a guarantee we actually provide (and I am surprised to see that this was ever documented here, since we have other plans that will make this even less true):

Calling a const function at compile-time will always yield the same result as calling it at runtime, even when called multiple times.

Therefore, I removed this paragraph. I am not sure what its purpose was.

Also fixes https://github.com/rust-lang/reference/issues/1581.

RalfJung commented 3 months ago

Seems like this guarantee was added a long time ago, in https://github.com/rust-lang/reference/pull/440. Cc @oli-obk

oli-obk commented 3 months ago

I am not sure what its purpose was.

the purpose was to be able to land the reference change and doing any work, as there was resistance to breaking that "guarantee" that we accidentally had

joshtriplett commented 3 months ago

Accompanying reference update for rust-lang/rust#128596.

The float semantics RFC decided that this is not a guarantee we actually provide (and I am surprised to see that this was ever documented here, since we have other plans that will make this even less true):

Calling a const function at compile-time will always yield the same result as calling it at runtime, even when called multiple times.

Therefore, I removed this paragraph. I am not sure what its purpose was.

Would it be feasible, rather than deleting this paragraph, to document exceptions to it (e.g. NaN bit patterns, calls to some floating-point functions)? It still seems to generally be true with the current set of things we've accepted.

(This is not an objection or a blocker, just a question.)

RalfJung commented 3 months ago

Yes, it is feasible. Currently, the NaN bit patterns returned by some float operations are the only case. However, I'm not very fond of the idea that we'll have to update the reference each time we add a new source of potential non-determinism or other kinds of difference between compiletime and runtime behavior...

chorman0773 commented 3 months ago

Also sounds like a stability nightmare.