2037a977eac8defeeda8b13bc006d8d5ca14dd1f
[ghc-hetmet.git] / ghc / docs / users_guide / gone_wrong.vsgml
1 %************************************************************************
2 %*                                                                      *
3 <sect>What to do when something goes wrong
4 <label id="wrong">
5 <p>
6 <nidx>problems</nidx>
7 %*                                                                      *
8 %************************************************************************
9
10 If you still have a problem after consulting this section, then you
11 may have found a <em>bug</em>---please report it!  See
12 Section <ref name="How to report a bug in the GHC system" id="bug-reports"> for a list of things we'd like to know about
13 your bug.  If in doubt, send a report---we love mail from irate users :-!
14
15 (Section <ref name="Haskell 1.4 vs. Glasgow Haskell 3.00: language
16 non-compliance" id="vs-Haskell-defn">, which describes Glasgow
17 Haskell's shortcomings vs.~the Haskell language definition, may also
18 be of interest.)
19
20 %************************************************************************
21 %*                                                                      *
22 <sect1>When the compiler ``does the wrong thing''
23 <label id="wrong-compiler">
24 <p>
25 <nidx>compiler problems</nidx>
26 <nidx>problems with the compiler</nidx>
27 %*                                                                      *
28 %************************************************************************
29
30 <descrip>
31 %-------------------------------------------------------------------
32 <tag>``Help! The compiler crashed (or `panic'd)!''</tag>
33 These events are <em>always</em> bugs in the GHC system---please report
34 them.
35
36 %-------------------------------------------------------------------
37 <tag>``The compiler ran out of heap (or stack) when compiling itself!''</tag>
38 It happens.  We try to supply reasonable @-H<n>@ flags for
39 @ghc/compiler/@ and @ghc/lib/@, but GHC's memory consumption
40 can vary by platform (e.g., on a 64-bit machine).
41
42 Just say @make all EXTRA_HC_OPTS=-H<a reasonable number>@ and see
43 how you get along.
44
45 %-------------------------------------------------------------------
46 <tag>``The compiler died with a pattern-matching error.''</tag>
47 This is a bug just as surely as a ``panic.'' Please report it.
48
49 %-------------------------------------------------------------------
50 <tag>``This is a terrible error message.''</tag>
51 If you think that GHC could have produced a better error message,
52 please report it as a bug.
53
54 %-------------------------------------------------------------------
55 <tag>``What about these `trace' messages from GHC?''</tag>
56 Almost surely not a problem.  About some specific cases...
57 <descrip>
58 <tag>Simplifier still going after N iterations:</tag>
59 Sad, but harmless.  You can change the number with a
60 @-fmax-simplifier-iterations<N>@<nidx>-fmax-simplifier-iterations&lt;N&gt; option</nidx> option (no space);
61 and you can see what actions took place in each iteration by
62 turning on the @-fshow-simplifier-progress@
63 <nidx>-fshow-simplifier-progress option</nidx> option.
64
65 If the simplifier definitely seems to be ``looping,'' please report
66 it.
67 </descrip>
68
69 %-------------------------------------------------------------------
70 <tag>``What about this warning from the C compiler?''</tag>
71
72 For example: ``...warning: `Foo' declared `static' but never defined.''
73 Unsightly, but not a problem.
74
75 %-------------------------------------------------------------------
76 <tag>Sensitivity to @.hi@ interface files:</tag>
77
78 GHC is very sensitive about interface files.  For example, if it picks
79 up a non-standard @Prelude.hi@ file, pretty terrible things will
80 happen.  If you turn on
81 @-fno-implicit-prelude@<nidx>-fno-implicit-prelude option</nidx>, the
82 compiler will almost surely die, unless you know what you are doing.
83
84 Furthermore, as sketched below, you may have big problems
85 running programs compiled using unstable interfaces.
86
87 %-------------------------------------------------------------------
88 <tag>``I think GHC is producing incorrect code'':</tag>
89
90 Unlikely :-) A useful be-more-paranoid option to give to GHC is
91 @-dcore-lint@<nidx>-dcore-lint option</nidx>; this causes a ``lint''
92 pass to check for errors (notably type errors) after each Core-to-Core
93 transformation pass.  We run with @-dcore-lint@ on all the time; it
94 costs about 5\% in compile time.  (Or maybe 25\%; who knows?)
95
96 %-------------------------------------------------------------------
97 <tag>``Why did I get a link error?''</tag>
98
99 If the linker complains about not finding @_<something>_fast@, then
100 your interface files haven't settled---keep on compiling!  (In
101 particular, this error means that arity information, which you can see
102 in any @.hi@ file, has changed.)
103
104 %-------------------------------------------------------------------
105 <tag>``What's a `consistency error'?''</tag>
106 (These are reported just after linking your program.)
107
108 You tried to link incompatible object files, e.g., normal ones
109 (registerised, Appel garbage-collector) with profiling ones (two-space
110 collector).  Or those compiled by a previous version of GHC
111 with an incompatible newer version.
112
113 If you run @nm -o *.o | egrep 't (cc|hsc)\.'@ (or, on
114 unregisterised files: @what *.o@), you'll see all the consistency
115 tags/strings in your object files.  They must all be the same!
116 (ToDo: tell you what they mean...)
117
118 %-------------------------------------------------------------------
119 <tag>``Is this line number right?''</tag>
120 On this score, GHC usually does pretty well, especially
121 if you ``allow'' it to be off by one or two.  In the case of an
122 instance or class declaration, the line number
123 may only point you to the declaration, not to a specific method.
124
125 Please report line-number errors that you find particularly unhelpful.
126 </descrip>
127
128 %************************************************************************
129 %*                                                                      *
130 <sect1>When your program ``does the wrong thing''
131 <label id="wrong-compilee">
132 <p>
133 <nidx>problems running your program</nidx>
134 %*                                                                      *
135 %************************************************************************
136
137 (For advice about overly slow or memory-hungry Haskell programs,
138 please see Section <ref name="Advice on: sooner, faster, smaller,
139 stingier" id="sooner-faster-quicker">).
140
141 <descrip>
142 %-----------------------------------------------------------------------
143 <tag>``Help! My program crashed!''</tag>
144 (e.g., a `segmentation fault' or `core dumped')
145
146 If your program has no @_ccall_@s/@_casm_@s in it, then a crash is always
147 a BUG in the GHC system, except in one case: If your program is made
148 of several modules, each module must have been compiled with a stable
149 group of interface (@.hi@) files.
150
151 For example, if an interface is lying about the type of an imported
152 value then GHC may well generate duff code for the importing module.
153 <em>This applies to pragmas inside interfaces too!</em>  If the pragma is
154 lying (e.g., about the ``arity'' of a value), then duff code may result.
155 Furthermore, arities may change even if types do not.
156
157 In short, if you compile a module and its interface changes, then all
158 the modules that import that interface <em>must</em> be re-compiled.
159
160 A useful option to alert you when interfaces change is
161 @-hi-diffs@<nidx>-hi-diffs option</nidx>.  It will run @diff@ on the
162 changed interface file, before and after, when applicable.
163
164 If you are using @make@, a useful tool to make sure that every module
165 <em>is</em> up-to-date with respect to its imported interfaces is
166 @mkdependHS@ (which comes with GHC).  Please see Section <ref
167 name="Makefile dependencies in Haskell: using mkdependHS"
168 id="mkdependHS">.
169
170 If you are down to your last-compile-before-a-bug-report, we would
171 recommend that you add a @-dcore-lint@ option (for extra checking) to
172 your compilation options.
173
174 So, before you report a bug because of a core dump, you should probably:
175 <tscreen><verb>
176 % rm *.o        # scrub your object files
177 % make my_prog  # re-make your program; use -hi-diffs to highlight changes;
178                 # as mentioned above, use -dcore-lint to be more paranoid
179 % ./my_prog ... # retry...
180 </verb></tscreen>
181
182 Of course, if you have @_ccall_@s/@_casm_@s in your program then all
183 bets are off, because you can trash the heap, the stack, or whatever.
184
185 If you are interested in hard-core debugging of a crashing
186 GHC-compiled program, please see Section <ref name="Hard-core
187 debugging of GHC-compiled programs" id="hard-core-debug">.
188
189 % (If you have an ``unregisterised'' arity-checking
190 % (@-O0 -darity-checks@) around [as we sometimes do at Glasgow], then you
191 % might recompile with @-darity-checks@<nidx>-darity-checks option</nidx>,
192 % which will definitely detect arity-compatibility errors.)
193
194 %-------------------------------------------------------------------
195 <tag>``My program entered an `absent' argument.''</tag>
196 This is definitely caused by a bug in GHC. Please report it.
197
198 %-----------------------------------------------------------------------
199 <tag>``What's with this `arithmetic (or `floating') exception' ''?</tag>
200
201 @Int@, @Float@, and @Double@ arithmetic is <em>unchecked</em>.
202 Overflows, underflows and loss of precision are either silent or
203 reported as an exception by the operating system (depending on the
204 architecture).  Divide-by-zero <em>may</em> cause an untrapped
205 exception (please report it if it does).
206
207 </descrip>
208
209 %************************************************************************
210 %*                                                                      *
211 <sect1>How to report a bug in the GHC system
212 <label id="bug-reports">
213 <p>
214 <nidx>bug reports</nidx>
215 %*                                                                      *
216 %************************************************************************
217
218 Glasgow Haskell is a changing system so there are sure to be bugs in
219 it.  Please report them to <htmlurl
220 name="glasgow-haskell-bugs@@dcs.gla.ac.uk"
221 url="mailto:glasgow-haskell-bugs@@dcs.gla.ac.uk">!  (However, please
222 check the earlier part of this section to be sure it's not a known
223 not-really-a problem.)
224
225 The name of the bug-reporting game is: facts, facts, facts.
226 Don't omit them because ``Oh, they won't be interested...''
227
228 <enum>
229
230 <item> What kind of machine are you running on, and exactly what
231 version of the operating system are you using? (@uname -a@ or @cat
232 /etc/motd@ will show the desired information.)
233
234 <item> What version of GCC are you using? @gcc -v@ will tell you.
235
236 <item> Run the sequence of compiles/runs that caused the offending
237 behaviour, capturing all the input/output in a ``script'' (a UNIX
238 command) or in an Emacs shell window.  We'd prefer to see the whole
239 thing.
240
241 <item> Be sure any Haskell compilations are run with a @-v@ (verbose)
242 flag, so we can see exactly what was run, what versions of things you
243 have, etc.
244
245 <item> What is the program behaviour that is wrong, in your opinion?
246
247 <item> If practical, please send enough source files/interface files
248 for us to duplicate the problem.
249
250 <item> If you are a Hero and track down the problem in the
251 compilation-system sources, please send us patches relative to a known
252 released version of GHC, or whole files if you prefer.
253
254 </enum>
255
256 %************************************************************************
257 %*                                                                      *
258 <sect1>Hard-core debugging of GHC-compiled programs
259 <label id="hard-core-debug">
260 <p>
261 <nidx>debugging, hard-core</nidx>
262 %*                                                                      *
263 %************************************************************************
264
265 If your program is crashing, you should almost surely file a bug
266 report, as outlined in previous sections.
267
268 This section suggests ways to Make Further Progress Anyway.
269
270 The first thing to establish is: Is it a garbage-collection (GC) bug?
271 Try your program with a very large heap and a @-Sstderr@ RTS
272 flag.
273 <itemize>
274 <item>
275 If it crashes <em>without</em> garbage-collecting, then it is
276 definitely <em>not</em> a GC bug.
277 <item>
278 If you can make it crash with one heap size but not with another, then
279 it <em>probably is</em> a GC bug.
280 <item>
281 If it crashes with the normal
282 collector, but not when you force two-space collection (@-F2s@
283 runtime flag), then it <em>probably is</em> a GC bug.
284 </itemize>
285
286 If it <em>is</em> a GC bug, you may be able to avoid it by using a
287 particular heap size or by using a @-F2s@ runtime flag.  (But don't
288 forget to report the bug!!!)
289
290 ToDo: more here?