Skip to content

Commit 6ac52df

Browse files
Add a debug context for generics (#2455)
2 parents 1abbff9 + a8541a9 commit 6ac52df

File tree

15 files changed

+649
-22
lines changed

15 files changed

+649
-22
lines changed

doc/source/gr_domains.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,31 @@ Domain properties
5555

5656
Sets or retrieves the floating-point precision in bits.
5757

58+
Debugging
59+
-------------------------------------------------------------------------------
60+
61+
.. function:: void gr_ctx_init_debug(gr_ctx_t ctx, gr_ctx_t elem_ctx, int flags, double unable_probability)
62+
63+
Initialize *ctx* to a wrapper around *elem_ctx* for debugging.
64+
This will execute supported methods (currently only a handful
65+
of methods are supported, e.g. ``gr_add``) as if one is computing
66+
directly over *elem_ctx*, but with added debugging features.
67+
68+
If *unable_probability* is positive, some methods will randomly return
69+
``GR_UNABLE`` and predicates will randomly return ``T_UNKNOWN``.
70+
71+
The following flags are supported:
72+
73+
* ``GR_DEBUG_WRAP`` - wrap elements in a box with a pointer. This allows
74+
performing extra checks such as whether a variable is being cleared
75+
twice or whether the wrong context object is passed as input. It can
76+
also help catch some bugs that are not revealed when entries are
77+
stored shallowly.
78+
79+
* ``GR_DEBUG_VERBOSE`` - print debugging information for each operation.
80+
81+
* ``GR_DEBUG_TIMING`` - print elapsed time for each operation.
82+
5883

5984
Groups
6085
-------------------------------------------------------------------------------

src/gr.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@ typedef enum
725725
GR_CTX_GR_VEC,
726726
GR_CTX_PSL2Z, GR_CTX_DIRICHLET_GROUP, GR_CTX_PERM,
727727
GR_CTX_FEXPR,
728+
GR_CTX_DEBUG,
728729
GR_CTX_UNKNOWN_DOMAIN,
729730
GR_CTX_WHICH_STRUCTURE_TAB_SIZE
730731
}
@@ -1516,6 +1517,13 @@ int gr_ctx_cmp_coercion(gr_ctx_t ctx1, gr_ctx_t ctx2);
15161517

15171518
/* Testing */
15181519

1520+
#define GR_DEBUG_WRAP 1
1521+
#define GR_DEBUG_VERBOSE 2
1522+
#define GR_DEBUG_CHECK_ALWAYS_ABLE 4
1523+
#define GR_DEBUG_TIMING 8
1524+
1525+
void gr_ctx_init_debug(gr_ctx_t ctx, gr_ctx_t elem_ctx, int flags, double unable_probability);
1526+
15191527
#define GR_TEST_VERBOSE 8
15201528
#define GR_TEST_ALWAYS_ABLE 16
15211529

0 commit comments

Comments
 (0)