Merge bitcoin/bitcoin#32100: doc: clarify the documentation of Assume assertion

329a0dcdafe05002f662e8737a76bfdeaba9a3ed doc: clarify the documentation of `Assume` (ismaelsadeeq)

Pull request description:

  An Expression inside `Assume` may be optimized away in production builds when the compiler proves they are side-effect-free.
  This use case is demonstrated in #31363 and is suggested to be documented in https://github.com/bitcoin/bitcoin/pull/31363#issuecomment-2736410023.

ACKs for top commit:
  l0rinc:
    ACK 329a0dcdafe05002f662e8737a76bfdeaba9a3ed
  hodlinator:
    re-ACK 329a0dcdafe05002f662e8737a76bfdeaba9a3ed
  jonatack:
    ACK 329a0dcdafe05002f662e8737a76bfdeaba9a3ed
  rkrux:
    re-ACK 329a0dcdafe05002f662e8737a76bfdeaba9a3ed

Tree-SHA512: 4bbb807a1e632694863c1a1fa2e93cc5a756b19f8d78f0642ebe7ffafb01835765fa66c76a680dc6f3c412a5abb0c4a33fb7212c26b4b2d80b6b3b7ee8284b2e
This commit is contained in:
merge-script 2025-03-27 15:52:21 +08:00
commit a54baa8698
No known key found for this signature in database
GPG Key ID: 2EEB9F5CC09526C1

View File

@ -460,7 +460,10 @@ other input.
safely continue even if the assumption is violated. In debug builds it
behaves like `Assert`/`assert` to notify developers and testers about
nonfatal errors. In production it doesn't warn or log anything, though the
expression is always evaluated.
expression is always evaluated. However, if the compiler can prove that
an expression inside `Assume` is side-effect-free, it may optimize the call away,
skipping its evaluation in production. This enables a lower-cost way of
making explicit statements about the code, aiding review.
- For example it can be assumed that a variable is only initialized once,
but a failed assumption does not result in a fatal bug. A failed
assumption may or may not result in a slightly degraded user experience,