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

Update is_val_statically_known Docs #124502

Merged
merged 1 commit into from Apr 29, 2024

Conversation

NCGThompson
Copy link
Contributor

@NCGThompson NCGThompson commented Apr 29, 2024

Fixes #121115

Sorry this took so long.

* Add `Type Requirements` section, listing the allowed inputs, as requested by rust-lang#121115
* Add `Pointers` subsection, explaining is_val_statically_known handles pointers.
* Add `Stability concerns` section, referring to other documentation relating to consistency in `const` functions.
@rustbot
Copy link
Collaborator

rustbot commented Apr 29, 2024

r? @Nilstrieb

rustbot has assigned @Nilstrieb.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 29, 2024
@jhpratt
Copy link
Member

jhpratt commented Apr 29, 2024

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Apr 29, 2024

📌 Commit 5969ad4 has been approved by jhpratt

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 29, 2024
@bors
Copy link
Contributor

bors commented Apr 29, 2024

⌛ Testing commit 5969ad4 with merge 5b1d58c...

@bors
Copy link
Contributor

bors commented Apr 29, 2024

☀️ Test successful - checks-actions
Approved by: jhpratt
Pushing 5b1d58c to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Apr 29, 2024
@bors bors merged commit 5b1d58c into rust-lang:master Apr 29, 2024
11 checks passed
@rustbot rustbot added this to the 1.80.0 milestone Apr 29, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (5b1d58c): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.1% [0.1%, 0.1%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.1% [0.1%, 0.1%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 674.79s -> 673.986s (-0.12%)
Artifact size: 315.95 MiB -> 316.05 MiB (0.03%)

@NCGThompson NCGThompson deleted the statically-known-docs branch April 29, 2024 13:16
@NCGThompson
Copy link
Contributor Author

this intrinsic isn't guaranteed to behave deterministically even in a const context.

@RalfJung It's too late to change it, but I wonder if we can guarantee that it will behave deterministically while in const context? I don't know of any other const function that doesn't come with that guarantee. Miri randomly selects an output at runtime, but not in const.

@RalfJung
Copy link
Member

I don't know of any other const function that doesn't come with that guarantee.

See rust-lang/rfcs#3514, rust-lang/rfcs#3352.

@NCGThompson
Copy link
Contributor Author

Thanks, that clears things up.

A const fn being called in a const context will still be required to be deterministic, as this is required for type system soundness. This invariant is required by the compiler and cannot be broken, even with unsafe code.

While that is from a not-yet accepted RFC, this seems to also apply to the current state. Considering that in const contexts, const functions already must be deterministic, the intrinsic currently is deterministic (it always returns false), and there is no foreseeable reason to make it non-deterministic (we don't actually care about the output), and that it is an unstable core intrinsic, I believe we should make that guarantee.

I'm not going to open another PR to remove the disclaimer just yet though; there are other changes I can make along with it.

@RalfJung
Copy link
Member

RalfJung commented Apr 30, 2024

This is the relevant part of the float RFC for that:

It is entirely possible to implement a non-deterministic language on a deterministic machine, by simply making some fixed choices. However, we will not specify a particular choice, and we will not guarantee it to remain the same in the future.

The intrinsic is not deterministic, but it is "determinised" by the const-eval machine to ensure sound compilation. However, the exact way it is "determinised" is an unspecified implementation detail; users should treat the operation as non-deterministic.

Also, discussing things in a closed PR is somewhat pointless, and I don't understand what problem you intend to solve by specifying is_val_statically_known differently. I want const-eval to support operations that are non-deterministic (like float ops) or that behave different at compiletime and runtime (like const_eval_select). This is not a bug, it's a feature. It is true that currently no such operation is stable, but so what?

If there is a problem, please open an issue so we have a proper place for discussion. If you are just wondering how it can make sense that is_val_statically_known is specified as non-deterministic, then probably a topic on Zulip asking for someone to explain this is the best way to proceed. Non-determinism is a non-trivial topic and I think many people are confused about its subtler points.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document is_val_statically_known only supports primitives (ICE otherwise)
7 participants