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

Adding extra information about invariant messages #2142

Merged
merged 2 commits into from
Sep 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions CODING_STANDARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,14 @@ Formatting is enforced using clang-format. For more information about this, see
- The type is explicitly repeated on the RHS (e.g. a constructor call)
- Adding the type will increase confusion (e.g. iterators, function pointers)
- Avoid `assert`. If the condition is an actual invariant, use INVARIANT,
PRECONDITION, POSTCONDITION, CHECK_RETURN, UNREACHABLE or DATA_INVARIANT. If
there are possible reasons why it might fail, throw an exception.
PRECONDITION, POSTCONDITION, CHECK_RETURN, UNREACHABLE or DATA_INVARIANT (also
see the documentation of the macros in `src/util/invariant.h`). If there are
possible reasons why it might fail, throw an exception.
- Use "should" style statements for messages in invariants (e.g. "array
should have a non-zero size") to make both the violation and the expected
behavior clear. (As opposed to "no zero size arrays" where it isn't clear
if the zero-size array is the problem, or the lack of it).
- The statements should start with a lower case letter.
- All raw pointers (such as those returned by `symbol_tablet::lookup`) are
assumed to be non-owning, and should not be `delete`d. Raw pointers that
point to heap-allocated memory should be private data members of an object
Expand Down
13 changes: 11 additions & 2 deletions src/util/invariant.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,19 @@ Author: Martin Brain, [email protected]
** evaluate to a boolean.
**
** As well as the condition they have a text argument that should be
** used to say why they are true. The reason should be a string literals.
** used to say why they are true. The reason should be a string literal
** starting with a lower case character.
** Longer diagnostics should be output to error(). For example:
**
** INVARIANT(x > 0, "x negative and zero case handled by other branches");
** INVARIANT(
** x > 0,
** "x should have a positive value as others are handled by other branches");
**
** Use "should" style statements for messages in invariants (also see
** CODING_STANDARD.md). An example would be "array should have a non-zero size")
** to make both the violation and the expected behavior clear. (As opposed to
** "no zero size arrays" where it isn't clear if the zero-size array is the
** problem, or the lack of it).
**
** To help classify different kinds of invariants, various short-hand
** macros are provided.
Expand Down