There should be a uniform interface for assertions, debugging, and emitting traces, that is used across the generated C code and the platform-generic runtime, but that has a platform-specific implementation. This is useful because each platform might have a different way of logging information (or may even ignore debug statements altogether if not applicable).
A related interface should exist within the Haskell interpreter, to support emitting an Output trace from a program, or for just evaluating it purely.
This all involves some slight code reorganization, but first requires us to figure out what the interface should look like. I like the idea of splitting this interface into 4 levels:
ERROR: used for reporting errors, and terminating execution. Should take the place of any asserts we currently have.
WARN: used for indicating any critical issues detected, but without immediately terminating. I don't currently see where this would be useful yet, but it seems in line.
INFO: this would be used to log information that may be useful to the user when running a program in simulation, e.g., to selectively report the internal information throughout execution.
TRACE: this would be used to log information that is used to produce event traces for property-based testing. The difference between this and INFO is that this level should define a rigit set of primitives, designed to produce output that can be parsed into an event trace, wheras INFO should be used for printing arbitrary strings and other such information.
All these will take the form of macros, to ensure that they are zero-cost when not needed. the ERROR, WARN, and INFO macros should all take a variable number of arguments and support printf-style formatting.
WARN and INFO will essentially be print statements, i.e., WARN("this should have your attention: %d\n", x) and INFO("some potentially useful debug information: %d\n", x).
At the ERROR level, we should have ERROR("this is bad: %d\n", x), which prints the error and quits (similar to Linux's BUG macro) , and ERROR_ON(condition, "that error condition was met: %d", x) (similar to Linux's BUG_ON).
For TRACE, we should start with one primitive per notable event in the event trace. Since we expect the output to be in a parseable format, the formatting of each primitive should all be defined in one place (rather than scattered throughout the runtime implementation and generated code). The TRACE primitives should all be #define TRACE_WTV do {} while(0); for non-trace platforms.
There should be a uniform interface for assertions, debugging, and emitting traces, that is used across the generated C code and the platform-generic runtime, but that has a platform-specific implementation. This is useful because each platform might have a different way of logging information (or may even ignore debug statements altogether if not applicable).
A related interface should exist within the Haskell interpreter, to support emitting an
Output
trace from a program, or for just evaluating it purely.This all involves some slight code reorganization, but first requires us to figure out what the interface should look like. I like the idea of splitting this interface into 4 levels:
ERROR
: used for reporting errors, and terminating execution. Should take the place of anyassert
s we currently have.WARN
: used for indicating any critical issues detected, but without immediately terminating. I don't currently see where this would be useful yet, but it seems in line.INFO
: this would be used to log information that may be useful to the user when running a program in simulation, e.g., to selectively report the internal information throughout execution.TRACE
: this would be used to log information that is used to produce event traces for property-based testing. The difference between this andINFO
is that this level should define a rigit set of primitives, designed to produce output that can be parsed into an event trace, wherasINFO
should be used for printing arbitrary strings and other such information.All these will take the form of macros, to ensure that they are zero-cost when not needed. the
ERROR
,WARN
, andINFO
macros should all take a variable number of arguments and support printf-style formatting.WARN
andINFO
will essentially be print statements, i.e.,WARN("this should have your attention: %d\n", x)
andINFO("some potentially useful debug information: %d\n", x)
.At the
ERROR
level, we should haveERROR("this is bad: %d\n", x)
, which prints the error and quits (similar to Linux'sBUG
macro) , andERROR_ON(condition, "that error condition was met: %d", x)
(similar to Linux'sBUG_ON
).For
TRACE
, we should start with one primitive per notable event in the event trace. Since we expect the output to be in a parseable format, the formatting of each primitive should all be defined in one place (rather than scattered throughout the runtime implementation and generated code). TheTRACE
primitives should all be#define TRACE_WTV do {} while(0);
for non-trace
platforms.