X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=docs%2Fcomm%2Frts-libs%2Fcoding-style.html;fp=docs%2Fcomm%2Frts-libs%2Fcoding-style.html;h=58f5b4f9bb485f448ae1e10f2884821c0e142cc2;hp=0000000000000000000000000000000000000000;hb=0065d5ab628975892cea1ec7303f968c3338cbe1;hpb=28a464a75e14cece5db40f2765a29348273ff2d2 diff --git a/docs/comm/rts-libs/coding-style.html b/docs/comm/rts-libs/coding-style.html new file mode 100644 index 0000000..58f5b4f --- /dev/null +++ b/docs/comm/rts-libs/coding-style.html @@ -0,0 +1,516 @@ + + + + + The GHC Commentary - Style Guidelines for RTS C code + + + +

The GHC Commentary - Style Guidelines for RTS C code

+ +

Comments

+ +

These coding style guidelines are mainly intended for use in +ghc/rts and ghc/includes. + +

NB These are just suggestions. They're not set in stone. Some of +them are probably misguided. If you disagree with them, feel free to +modify this document (and make your commit message reasonably +informative) or mail someone (eg. The GHC mailing list) + +

References

+ +If you haven't read them already, you might like to check the following. +Where they conflict with our suggestions, they're probably right. + + + + +

Portability issues

+ + + +

Debugging/robustness tricks

+ + +Anyone who has tried to debug a garbage collector or code generator +will tell you: "If a program is going to crash, it should crash as +soon, as noisily and as often as possible." There's nothing worse +than trying to find a bug which only shows up when running GHC on +itself and doesn't manifest itself until 10 seconds after the actual +cause of the problem. + +

We put all our debugging code inside #ifdef DEBUG. The +general policy is we don't ship code with debugging checks and +assertions in it, but we do run with those checks in place when +developing and testing. Anything inside #ifdef DEBUG should +not slow down the code by more than a factor of 2. + +

We also have more expensive "sanity checking" code for hardcore +debugging - this can slow down the code by a large factor, but is only +enabled on demand by a command-line flag. General sanity checking in +the RTS is currently enabled with the -DS RTS flag. + +

There are a number of RTS flags which control debugging output and +sanity checking in various parts of the system when DEBUG is +defined. For example, to get the scheduler to be verbose about what +it is doing, you would say +RTS -Ds -RTS. See +includes/RtsFlags.h and rts/RtsFlags.c for the full +set of debugging flags. To check one of these flags in the code, +write: + +

+  IF_DEBUG(gc, fprintf(stderr, "..."));
+
+ +would check the gc flag before generating the output (and the +code is removed altogether if DEBUG is not defined). + +

All debugging output should go to stderr. + +

+Particular guidelines for writing robust code: + +

+ +

Syntactic details

+ + + +

CVS issues

+ + + + + +