Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 0c3307b

Browse files
Geod24dlang-bot
authored andcommitted
Document and expose core.internal.dassert
Give this module a proper documentation to make it easier to maintain.
1 parent 362cdc1 commit 0c3307b

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

mak/DOCS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ DOCS=\
8181
$(DOCDIR)\core_thread_fiber.html \
8282
$(DOCDIR)\core_thread_osthread.html \
8383
\
84+
$(DOCDIR)\core_internal_dassert.html \
8485
$(DOCDIR)\core_internal_execinfo.html \
8586
$(DOCDIR)\core_internal_qsort.html \
8687
\

src/core/internal/dassert.d

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,61 @@
11
/*
2-
Provides light-weight formatting utilities for pretty-printing
3-
on assertion failures
4-
*/
2+
* Support for rich error messages generation with `assert`
3+
*
4+
* This module provides the `_d_assert_fail` hooks which are instantiated
5+
* by the compiler whenever `-checkaction=context` is used.
6+
* There are two hooks, one for unary expressions, and one for binary.
7+
* When used, the compiler will rewrite `assert(a >= b)` as
8+
* `assert(a >= b, _d_assert_fail!">="(a, b))`.
9+
* Temporaries will be created to avoid side effects if deemed necessary
10+
* by the compiler.
11+
*
12+
* For more information, refer to the implementation in DMD frontend
13+
* for `AssertExpression`'s semantic analysis.
14+
*
15+
* Copyright: D Language Foundation 2018 - 2020
16+
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
17+
* Source: $(LINK2 https://github.com/dlang/druntime/blob/master/src/core/internal/dassert.d, _dassert.d)
18+
* Documentation: https://dlang.org/phobos/core_internal_dassert.html
19+
*/
520
module core.internal.dassert;
621

7-
/// Allows customized assert error messages for unary expressions
22+
/**
23+
* Generates rich assert error messages for unary expressions
24+
*
25+
* The unary expression `assert(!una)` will be turned into
26+
* `assert(!una, _d_assert_fail!"!"(una))`.
27+
* This routine simply acts as if the user wrote `assert(una == false)`.
28+
*
29+
* Params:
30+
* op = Operator that was used in the expression, currently only "!"
31+
* is supported.
32+
* a = Result of the expression that was used in `assert` before
33+
* its implicit conversion to `bool`.
34+
*
35+
* Returns:
36+
* A string such as "$a != true" or "$a == true".
37+
*/
838
string _d_assert_fail(string op, A)(auto ref const scope A a)
939
{
1040
string val = miniFormatFakeAttributes(a);
1141
enum token = op == "!" ? "==" : "!=";
1242
return combine(val, token, "true");
1343
}
1444

15-
/// Allows customized assert error messages for binary expressions
45+
/**
46+
* Generates rich assert error messages for binary expressions
47+
*
48+
* The binary expression `assert(x == y)` will be turned into
49+
* `assert(x == y, _d_assert_fail!"=="(x, y))`.
50+
*
51+
* Params:
52+
* comp = Comparison operator that was used in the expression.
53+
* a = Left hand side operand.
54+
* b = Right hand side operand.
55+
*
56+
* Returns:
57+
* A string such as "$a $comp $b".
58+
*/
1659
string _d_assert_fail(string comp, A, B)(auto ref const scope A a, auto ref const scope B b)
1760
{
1861
/*

0 commit comments

Comments
 (0)