Generalise the implicit prelude import
[ghc.git] / ghc / hschooks.c
1 /*
2 These routines customise the error messages
3 for various bits of the RTS. They are linked
4 in instead of the defaults.
5 */
6
7 #include "../rts/PosixSource.h"
8 #include "Rts.h"
9
10 #include "HsFFI.h"
11
12 #include <string.h>
13
14 #ifdef HAVE_UNISTD_H
15 #include <unistd.h>
16 #endif
17
18 void
19 initGCStatistics(void)
20 {
21 /* Workaround for #8754: if the GC stats aren't enabled because the
22 compiler couldn't use -Bsymbolic to link the default hooks, then
23 initialize them sensibly. See Note [-Bsymbolic and hooks] in
24 Main.hs. */
25 if (RtsFlags.GcFlags.giveStats == NO_GC_STATS) {
26 RtsFlags.GcFlags.giveStats = COLLECT_GC_STATS;
27 }
28 }
29
30 void
31 defaultsHook (void)
32 {
33 // This helps particularly with large compiles, but didn't work
34 // very well with earlier GHCs because it caused large amounts of
35 // fragmentation. See rts/sm/BlockAlloc.c:allocLargeChunk().
36 RtsFlags.GcFlags.heapSizeSuggestionAuto = rtsTrue;
37
38 RtsFlags.GcFlags.maxStkSize = 512*1024*1024 / sizeof(W_);
39
40 initGCStatistics();
41
42 // See #3408: the default idle GC time of 0.3s is too short on
43 // Windows where we receive console events once per second or so.
44 RtsFlags.GcFlags.idleGCDelayTime = SecondsToTime(5);
45 }
46
47 void
48 StackOverflowHook (StgWord stack_size) /* in bytes */
49 {
50 fprintf(stderr, "GHC stack-space overflow: current limit is %zu bytes.\nUse the `-K<size>' option to increase it.\n", (size_t)stack_size);
51 }
52
53 int main (int argc, char *argv[])
54 {
55 RtsConfig conf = defaultRtsConfig;
56 #if __GLASGOW_HASKELL__ >= 711
57 conf.defaultsHook = defaultsHook;
58 conf.rts_opts_enabled = RtsOptsAll;
59 conf.stackOverflowHook = StackOverflowHook;
60 #endif
61 extern StgClosure ZCMain_main_closure;
62
63 hs_main(argc, argv, &ZCMain_main_closure, conf);
64 }