Skip to content

Document consteval behavior of ub_checks, overflow_checks, is_val_statically_known.#154140

Merged
rust-bors[bot] merged 2 commits intorust-lang:mainfrom
theemathas:checks_always_on_in_const
Mar 23, 2026
Merged

Document consteval behavior of ub_checks, overflow_checks, is_val_statically_known.#154140
rust-bors[bot] merged 2 commits intorust-lang:mainfrom
theemathas:checks_always_on_in_const

Conversation

@theemathas
Copy link
Contributor

No description provided.

@rustbot
Copy link
Collaborator

rustbot commented Mar 20, 2026

Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter
gets adapted for the changes, if necessary.

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

@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 Mar 20, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 20, 2026

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @scottmcm, libs
  • @scottmcm, libs expanded to 8 candidates
  • Random selection from Mark-Simulacrum, joboet, scottmcm

@rust-log-analyzer

This comment has been minimized.

@RalfJung
Copy link
Member

r? me

@rustbot rustbot assigned RalfJung and unassigned Mark-Simulacrum Mar 20, 2026
@RalfJung
Copy link
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 20, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 20, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@theemathas theemathas force-pushed the checks_always_on_in_const branch from 8c10a41 to 72958b5 Compare March 21, 2026 04:32
@theemathas theemathas changed the title Document consteval behavior of ub_checks & overflow_checks. Document consteval behavior of ub_checks, overflow_checks, is_val_statically_known. Mar 21, 2026
@theemathas
Copy link
Contributor Author

I've addressed the comments. While we're at it, I also documented is_val_statically_known, which previously had incorrect documentation.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 21, 2026
Comment on lines +2538 to +2541
/// is currently done in consteval. Note that this function must always return
/// the same value for any given call site in consteval, for soundness.
/// For an example of an unsoundness that nondeterministic consteval could cause,
/// see [#148328](https://github.com/rust-lang/rust/issues/148328).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should say anything about what is_val_statically_known does in const-eval. It's an implementation detail, we can change it any time, users should never care.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I undo the changes for is_val_statically_known, and leave the old documentation as-is?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think removing the old section is fine. We have meanwhile accepted non-determinism in const fn by stabilizing float operations there, this isn't really any different.

/// In consteval, this function currently returns `true`. This is because the value of the `ub_checks`
/// configuration can differ across crates, but we need this function to always return the same
/// value in consteval in order to avoid unsoundness. For an example of an unsoundness that
/// nondeterministic consteval could cause, see [#148328](https://github.com/rust-lang/rust/issues/148328).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it's a waste of space to describe this soundness issues here -- it's relevant to implementors of the intrinsic, but not to users, so if we have such a comment it makes much more sense at the implementation than here (and I think we already have a comment at the implementation).

But I don't have a strong opinion here so if for some reason you really want to keep this here then 🤷 whatever.

We've already stabilized float operations in const,
which means we've already accepted that a `const fn`
might behave differently in consteval vs at run time.
@theemathas theemathas force-pushed the checks_always_on_in_const branch from 72958b5 to 338deef Compare March 23, 2026 03:58
@theemathas
Copy link
Contributor Author

Hopefully this PR should be good to go now?

@RalfJung
Copy link
Member

Thanks. :)

@bors r+ rollup

@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 23, 2026

📌 Commit 338deef has been approved by RalfJung

It is now in the queue for this repository.

@rust-bors rust-bors bot 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 Mar 23, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Mar 23, 2026
…st, r=RalfJung

Document consteval behavior of ub_checks, overflow_checks, is_val_statically_known.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Mar 23, 2026
…st, r=RalfJung

Document consteval behavior of ub_checks, overflow_checks, is_val_statically_known.
rust-bors bot pushed a commit that referenced this pull request Mar 23, 2026
…uwer

Rollup of 13 pull requests

Successful merges:

 - #154241 (`rust-analyzer` subtree update)
 - #153686 (`std`: include `dlmalloc` for all non-wasi Wasm targets)
 - #154105 (bootstrap: Pass `--features=rustc` to rustc_transmute)
 - #153069 ([BPF] add target feature allows-misaligned-mem-access)
 - #154085 (Parenthesize or-patterns in prefix pattern positions in pretty printer)
 - #154191 (refactor RangeFromIter overflow-checks impl)
 - #154207 (Refactor query loading)
 - #153540 (drop derive helpers during attribute parsing)
 - #154140 (Document consteval behavior of ub_checks, overflow_checks, is_val_statically_known.)
 - #154161 (On E0277 tweak help when single type impls traits)
 - #154218 (interpret/validity: remove unreachable error kind)
 - #154225 (diagnostics: avoid ICE in confusable_method_name for associated functions)
 - #154228 (Improve inline assembly error messages)
@rust-bors rust-bors bot merged commit 452af7e into rust-lang:main Mar 23, 2026
11 checks passed
@rustbot rustbot added this to the 1.96.0 milestone Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

6 participants