Skip to content

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented Oct 27, 2020

This is needed for #20138. Please refer to the added documentation for motivation.

@laanwj
Copy link
Member

laanwj commented Oct 27, 2020

Concept ACK. It's mildly interesting that we're sort of reinventing the original assert() here, which gets disabled on NDEBUG, which we had to always force on, but I think it's fine to reinvent the wheel here instead of assuming any specific compiler semantics.

@maflcko
Copy link
Member Author

maflcko commented Oct 27, 2020

Indeed, this Assume is like the traditional assert.

@jnewbery
Copy link
Contributor

Concept ACK. If you're willing to entertain paint color requests, I prefer the name Check(), as was originally proposed in #16136.

@maflcko
Copy link
Member Author

maflcko commented Oct 27, 2020

I think @ryanofsky also likes check, so I might change to that

@jnewbery
Copy link
Contributor

I think Russ doesn't care about the name, but would prefer a pair of check/dcheck macros: #16136 (comment)

@sipa
Copy link
Member

sipa commented Oct 27, 2020

FWIW, libsecp256k1 has CHECK() (always enabled) and VERIFY_CHECK() functions (enabled with -DVERIFY, used in test builds).

@practicalswift
Copy link
Contributor

Concept ACK

@maflcko
Copy link
Member Author

maflcko commented Oct 28, 2020

FWIW, libsecp256k1 has CHECK() (always enabled) and VERIFY_CHECK() functions (enabled with -DVERIFY, used in test builds).

That is good to know, because that means we can't use that name due to name-clashing.

Copy link
Contributor

@ajtowns ajtowns left a comment

Choose a reason for hiding this comment

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

ACK fa96726

I think this is a good choice of behaviour that should be easy to use correctly. Would like to see the ability to turn on logging of violated Assumptions even in production builds in a followup.

@practicalswift
Copy link
Contributor

practicalswift commented Oct 29, 2020

ACK fa96726: patch looks correct

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

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

Approach ACK fa96726

Are there any cases when assert is preferable to Assert. If "yes", it would be nice to have an example in the docs. If "no", why do we mention assert in the docs?

practicalswift and others added 3 commits November 24, 2020 09:46
Fixes the compile error when used inside operator[]:

./chain.h:404:23: error: C++11 only allows consecutive left square brackets when introducing an attribute
        return (*this)[Assert(pindex)->nHeight] == pindex;
                      ^
The TODO has been added by me, but I don't remember how to solve it. The
current code works fine, so just remove the TODO.
@maflcko
Copy link
Member Author

maflcko commented Nov 24, 2020

Are there any cases when assert is preferable to Assert

No

If "no", why do we mention assert in the docs?

It documents how the assert is used in existing code

@practicalswift
Copy link
Contributor

cr ACK faa0585

@jnewbery
Copy link
Contributor

utACK faa0585

Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

Approach ACK, some doc nits if you retouch

failure, it will throw an exception, which can be caught to recover from the
error.
- For example, a nullptr dereference or any other logic bug in RPC code
means that the RPC code is faulty and can not be executed. However, the
Copy link
Member

Choose a reason for hiding this comment

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

s/can not/cannot/

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.
- For example it can be assumed that a variable is only initialized once,
Copy link
Member

Choose a reason for hiding this comment

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

s/For example it can/For example, it may/

@maflcko
Copy link
Member Author

maflcko commented Nov 25, 2020

Will leave style nits alone to preserve ACKs

@maflcko
Copy link
Member Author

maflcko commented Dec 4, 2020

I think this is ready, but I am waiting on one more (re?)ACK before merge

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

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

ACK faa0585, I have reviewed the code and it looks OK, I agree it can be merged.

@maflcko maflcko merged commit dca80ff into bitcoin:master Dec 4, 2020
@maflcko maflcko deleted the 2010-assume branch December 4, 2020 10:09
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Dec 4, 2020
faa0585 util: Remove probably misleading TODO (MarcoFalke)
fac5efe util: Add Assume() identity function (MarcoFalke)
fa86156 util: Allow Assert(...) to be used in all contexts (practicalswift)

Pull request description:

  This is needed for bitcoin#20138. Please refer to the added documentation for motivation.

ACKs for top commit:
  practicalswift:
    cr ACK faa0585
  jnewbery:
    utACK faa0585
  hebasto:
    ACK faa0585, I have reviewed the code and it looks OK, I agree it can be merged.

Tree-SHA512: 72165fbd898b92ab9a79b070993fa1faa86c2e3545b6645e72c652bda295d5107bc298d0482bf3aaf0926fc0c3e6418a445c0e073b08568c44231f547f76a688
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jun 15, 2021
Summary:
```
This is needed for #20138. Please refer to the added documentation for
motivation.
```

Backport of [[bitcoin/bitcoin#20255 | core#20255]].

Depends on D9681.

Comes with a linter fix for an edge case where a macro defining
`((void)(val))` would be linted as `(()(val))`.

Ref T1611.

Test Plan:
With and without debug:
  ninja all check

Reviewers: #bitcoin_abc, PiRK

Reviewed By: #bitcoin_abc, PiRK

Maniphest Tasks: T1611

Differential Revision: https://reviews.bitcoinabc.org/D9680
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants