Skip to content

Commit

Permalink
Documentation improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Bronek committed Oct 23, 2024
1 parent 1db9890 commit 83808fa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,13 +385,19 @@ For this reason:
function name. NOTE: the purpose of name is to provide stable means of
unique identification of every contract; for this reason try to avoid elements
which can change in some obvious refactors or when reinforcing the condition.
* Contract description typically (except for `UNREACHABLE`) should describe the
_expected_ condition, as in "I assert that _expected_ is true".
* Contract description for `UNREACHABLE` should describe the _unexpected_
situation which caused the line to have been reached.
* Example good name for an
`UNREACHABLE` macro `"Json::operator==(Value, Value) : invalid type"`; example
good name for an `ASSERT` macro `"Json::Value::asCString : valid type"`.
* Example **bad** name
`"RFC1751::insert(char* s, int x, int start, int length) : length is greater than or equal zero"`
(missing namespace, unnecessary full function signature, description too verbose).
Good name: `"ripple::RFC1751::insert : minimum length"`.
* In **few** well-justified cases a non-standard name can be used, in which case a
comment should be placed to explain the rationale (example in `contract.cpp`)
* Do **not** rename a contract without a good reason (e.g. the name no longer
reflects the location or the condition being checked)
* Do not use `std::unreachable`
Expand Down
9 changes: 5 additions & 4 deletions include/xrpl/beast/utility/instrumentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
//
// NOTE: UNREACHABLE does *not* have the same semantics as std::unreachable.
// The program will continue execution past an UNREACHABLE in a Release build
// and during fuzzing (similar to ASSERT). Also the naming convention is subtly
// different from all other macros - name in UNREACHABLE describes the condition
// which was meant to never happen, while name in other macros describe the
// condition that is meant to happen (e.g. as in "assert that this happens").
// and during fuzzing (similar to ASSERT).
// Also, the naming convention in UNREACHABLE is subtly different from other
// instrumentation macros - its name describes the condition which was *not*
// meant to happen, while name in other macros describe the condition that is
// meant to happen (e.g. as in "assert that this happens").

#endif
6 changes: 4 additions & 2 deletions src/libxrpl/basics/contract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ LogicError(std::string const& s) noexcept
{
JLOG(debugLog().fatal()) << s;
std::cerr << "Logic error: " << s << std::endl;
// Use a non-standard contract naming here (without namespace), because
// Use a non-standard contract naming here (without namespace) because
// it's the only location where various unrelated execution paths may
// register an error; this is also why "message" parameter is passed here.
// register an error; this is also why the "message" parameter is passed
// here.
// For the above reasons, we want this contract to stand out.
UNREACHABLE("LogicError", {{"message", s}});

Check warning on line 57 in src/libxrpl/basics/contract.cpp

View check run for this annotation

Codecov / codecov/patch

src/libxrpl/basics/contract.cpp#L57

Added line #L57 was not covered by tests
detail::accessViolation();
}
Expand Down

0 comments on commit 83808fa

Please sign in to comment.