11cb66aed3c68425df20dcfaa385c2a95ad14c40
[ghc-hetmet.git] / ghc / docs / users_guide / gone_wrong.sgml
1 <Chapter id="wrong">
2 <Title>What to do when something goes wrong
3 </Title>
4
5 <Para>
6 <IndexTerm><Primary>problems</Primary></IndexTerm>
7 </Para>
8
9 <Para>
10 If you still have a problem after consulting this section, then you
11 may have found a <Emphasis>bug</Emphasis>&mdash;please report it!  See <XRef LinkEnd="bug-reports"> for a
12 list of things we'd like to know about your bug.  If in doubt, send a
13 report&mdash;we love mail from irate users :-!
14 </Para>
15
16 <Para>
17 (<XRef LinkEnd="vs-Haskell-defn">, which describes Glasgow
18 Haskell's shortcomings vs.&nbsp;the Haskell language definition, may also
19 be of interest.)
20 </Para>
21
22 <Sect1 id="wrong-compiler">
23 <Title>When the compiler &ldquo;does the wrong thing&rdquo;
24 </Title>
25
26 <Para>
27 <IndexTerm><Primary>compiler problems</Primary></IndexTerm>
28 <IndexTerm><Primary>problems with the compiler</Primary></IndexTerm>
29 </Para>
30
31 <Para>
32 <VariableList>
33
34 <VarListEntry>
35 <Term>&ldquo;Help! The compiler crashed (or `panic'd)!&rdquo;</Term>
36 <ListItem>
37 <Para>
38 These events are <Emphasis>always</Emphasis> bugs in the GHC system&mdash;please report them.
39 </Para>
40 </ListItem>
41 </VarListEntry>
42 <VarListEntry>
43 <Term>&ldquo;The compiler ran out of heap (or stack) when compiling itself!&rdquo;</Term>
44 <ListItem>
45 <Para>
46 It happens.  We try to supply reasonable <Option>-H&lt;n&gt;</Option> flags for
47 <Filename>ghc/compiler/</Filename> and <Filename>ghc/lib/</Filename>, but GHC's memory consumption
48 can vary by platform (e.g., on a 64-bit machine).
49 </Para>
50
51 <Para>
52 Just say <Command>make all EXTRA&lowbar;HC&lowbar;OPTS=-H&lt;a reasonable number&gt;</Command> and see
53 how you get along.
54 </Para>
55
56 <Para>
57 Note that this is less likely to happen if you are compiling with GHC
58 4.00 or later, since the introduction of the dynamically expanding
59 heap.
60 </Para>
61 </ListItem>
62 </VarListEntry>
63 <VarListEntry>
64 <Term>&ldquo;The compiler died with a pattern-matching error.&rdquo;</Term>
65 <ListItem>
66 <Para>
67 This is a bug just as surely as a &ldquo;panic.&rdquo; Please report it.
68 </Para>
69 </ListItem>
70 </VarListEntry>
71 <VarListEntry>
72 <Term>&ldquo;This is a terrible error message.&rdquo;</Term>
73 <ListItem>
74 <Para>
75 If you think that GHC could have produced a better error message,
76 please report it as a bug.
77 </Para>
78 </ListItem>
79 </VarListEntry>
80 <VarListEntry>
81 <Term>&ldquo;What about these `trace' messages from GHC?&rdquo;</Term>
82 <ListItem>
83 <Para>
84 Almost surely not a problem.  About some specific cases&hellip;
85 <VariableList>
86
87 <VarListEntry>
88 <Term>Simplifier still going after N iterations:</Term>
89 <ListItem>
90 <Para>
91 Sad, but harmless.  You can change the number with a
92 <Option>-fmax-simplifier-iterations&lt;N&gt;</Option><IndexTerm><Primary>-fmax-simplifier-iterations&lt;N&gt; option</Primary></IndexTerm> option (no space);
93 and you can see what actions took place in each iteration by
94 turning on the <Option>-fshow-simplifier-progress</Option>
95 <IndexTerm><Primary>-fshow-simplifier-progress option</Primary></IndexTerm> option.
96 </Para>
97
98 <Para>
99 If the simplifier definitely seems to be &ldquo;looping,&rdquo; please report
100 it.
101 </Para>
102 </ListItem>
103 </VarListEntry>
104 </VariableList>
105 </Para>
106 </ListItem>
107 </VarListEntry>
108 <VarListEntry>
109 <Term>&ldquo;What about this warning from the C compiler?&rdquo;</Term>
110 <ListItem>
111 <Para>
112 For example: &ldquo;&hellip;warning: `Foo' declared `static' but never defined.&rdquo;
113 Unsightly, but shouldn't be a problem.
114 </Para>
115 </ListItem>
116 </VarListEntry>
117 <VarListEntry>
118 <Term>Sensitivity to <Filename>.hi</Filename> interface files:</Term>
119 <ListItem>
120 <Para>
121 GHC is very sensitive about interface files.  For example, if it picks
122 up a non-standard <Filename>Prelude.hi</Filename> file, pretty terrible things will
123 happen.  If you turn on
124 <Option>-fno-implicit-prelude</Option><IndexTerm><Primary>-fno-implicit-prelude option</Primary></IndexTerm>, the
125 compiler will almost surely die, unless you know what you are doing.
126 </Para>
127
128 <Para>
129 Furthermore, as sketched below, you may have big problems
130 running programs compiled using unstable interfaces.
131 </Para>
132 </ListItem>
133 </VarListEntry>
134 <VarListEntry>
135 <Term>&ldquo;I think GHC is producing incorrect code&rdquo;:</Term>
136 <ListItem>
137 <Para>
138 Unlikely :-) A useful be-more-paranoid option to give to GHC is
139 <Option>-dcore-lint</Option><IndexTerm><Primary>-dcore-lint option</Primary></IndexTerm>; this causes a &ldquo;lint&rdquo;
140 pass to check for errors (notably type errors) after each Core-to-Core
141 transformation pass.  We run with <Option>-dcore-lint</Option> on all the time; it
142 costs about 5&percnt; in compile time.
143 </Para>
144 </ListItem>
145 </VarListEntry>
146 <VarListEntry>
147 <Term>&ldquo;Why did I get a link error?&rdquo;</Term>
148 <ListItem>
149 <Para>
150 If the linker complains about not finding <Literal>&lowbar;&lt;something&gt;&lowbar;fast</Literal>, then
151 something is inconsistent: you probably didn't compile modules in the
152 proper dependency order.
153 </Para>
154 </ListItem>
155 </VarListEntry>
156 <VarListEntry>
157 <Term>&ldquo;What's a `consistency error'?&rdquo;</Term>
158 <ListItem>
159 <Para>
160 (These are reported just after linking your program.)
161 </Para>
162
163 <Para>
164 You tried to link incompatible object files, e.g., normal ones
165 (registerised, Appel garbage-collector) with profiling ones (two-space
166 collector).  Or those compiled by a previous version of GHC
167 with an incompatible newer version.
168 </Para>
169
170 <Para>
171 If you run <Command>nm -o *.o &verbar; egrep 't (cc&verbar;hsc)\.'</Command> (or, on
172 unregisterised files: <Command>what *.o</Command>), you'll see all the consistency
173 tags/strings in your object files.  They must all be the same!
174 (ToDo: tell you what they mean&hellip;)
175 </Para>
176 </ListItem>
177 </VarListEntry>
178 <VarListEntry>
179 <Term>&ldquo;Is this line number right?&rdquo;</Term>
180 <ListItem>
181 <Para>
182 On this score, GHC usually does pretty well, especially
183 if you &ldquo;allow&rdquo; it to be off by one or two.  In the case of an
184 instance or class declaration, the line number
185 may only point you to the declaration, not to a specific method.
186 </Para>
187
188 <Para>
189 Please report line-number errors that you find particularly unhelpful.
190 </Para>
191 </ListItem>
192 </VarListEntry>
193 </VariableList>
194 </Para>
195
196 </Sect1>
197
198 <Sect1 id="wrong-compilee">
199 <Title>When your program &ldquo;does the wrong thing&rdquo;
200 </Title>
201
202 <Para>
203 <IndexTerm><Primary>problems running your program</Primary></IndexTerm>
204 </Para>
205
206 <Para>
207 (For advice about overly slow or memory-hungry Haskell programs,
208 please see <XRef LinkEnd="sooner-faster-quicker">).
209 </Para>
210
211 <Para>
212 <VariableList>
213
214 <VarListEntry>
215 <Term>&ldquo;Help! My program crashed!&rdquo;</Term>
216 <ListItem>
217 <Para>
218 (e.g., a `segmentation fault' or `core dumped')
219 <IndexTerm><Primary>segmentation fault</Primary></IndexTerm>
220 </Para>
221
222 <Para>
223 If your program has no foreign calls in it, then a crash is always a BUG in
224 the GHC system, except in one case: If your program is made of several
225 modules, each module must have been compiled after any modules on which it
226 depends (unless you use <Filename>.hi-boot</Filename> files, in which case
227 these <Emphasis>must</Emphasis> be correct with respect to the module
228 source).
229 </Para>
230
231 <Para>
232 For example, if an interface is lying about the type of an imported
233 value then GHC may well generate duff code for the importing module.
234 <Emphasis>This applies to pragmas inside interfaces too!</Emphasis>  If the pragma is
235 lying (e.g., about the &ldquo;arity&rdquo; of a value), then duff code may result.
236 Furthermore, arities may change even if types do not.
237 </Para>
238
239 <Para>
240 In short, if you compile a module and its interface changes, then all
241 the modules that import that interface <Emphasis>must</Emphasis> be re-compiled.
242 </Para>
243
244 <Para>
245 A useful option to alert you when interfaces change is
246 <Option>-hi-diffs</Option><IndexTerm><Primary>-hi-diffs option</Primary></IndexTerm>.  It will run <Command>diff</Command> on the
247 changed interface file, before and after, when applicable.
248 </Para>
249
250 <Para>
251 If you are using <Command>make</Command>, GHC can automatically
252 generate the dependencies required in order to make sure that every
253 module <Emphasis>is</Emphasis> up-to-date with respect to its imported
254 interfaces.  Please see <XRef LinkEnd="sec-makefile-dependencies">.
255 </Para>
256
257 <Para>
258 If you are down to your last-compile-before-a-bug-report, we would
259 recommend that you add a <Option>-dcore-lint</Option> option (for extra checking) to your compilation options.
260 </Para>
261
262 <Para>
263 So, before you report a bug because of a core dump, you should probably:
264
265 <Screen>
266 % rm *.o        # scrub your object files
267 % make my_prog  # re-make your program; use -hi-diffs to highlight changes;
268                 # as mentioned above, use -dcore-lint to be more paranoid
269 % ./my_prog ... # retry...
270 </Screen>
271
272 </Para>
273
274 <Para>
275 Of course, if you have foreign calls in your program then all
276 bets are off, because you can trash the heap, the stack, or whatever.
277 </Para>
278
279 <Para>
280 If you are interested in hard-core debugging of a crashing
281 GHC-compiled program, please see <XRef LinkEnd="hard-core-debug">.
282 </Para>
283 </ListItem>
284 </VarListEntry>
285 <VarListEntry>
286 <Term>&ldquo;My program entered an `absent' argument.&rdquo;</Term>
287 <ListItem>
288 <Para>
289 This is definitely caused by a bug in GHC. Please report it.
290 </Para>
291 </ListItem>
292 </VarListEntry>
293 <VarListEntry>
294 <Term>&ldquo;What's with this `arithmetic (or `floating') exception' &rdquo;?</Term>
295 <ListItem>
296 <Para>
297 <Literal>Int</Literal>, <Literal>Float</Literal>, and <Literal>Double</Literal> arithmetic is <Emphasis>unchecked</Emphasis>.
298 Overflows, underflows and loss of precision are either silent or
299 reported as an exception by the operating system (depending on the
300 architecture).  Divide-by-zero <Emphasis>may</Emphasis> cause an untrapped
301 exception (please report it if it does).
302 </Para>
303 </ListItem>
304 </VarListEntry>
305 </VariableList>
306 </Para>
307
308 </Sect1>
309
310 <Sect1 id="bug-reports">
311 <Title>How to report a bug in the GHC system
312 </Title>
313
314 <Para>
315 <IndexTerm><Primary>bug reports</Primary></IndexTerm>
316 </Para>
317
318 <Para>
319 Glasgow Haskell is a changing system so there are sure to be bugs in
320 it.  Please report them to
321 <Email>glasgow-haskell-bugs@haskell.org</Email>!  (However, please
322 check the earlier part of this section to be sure it's not a known
323 not-really-a problem.)
324 </Para>
325
326 <Para>
327 The name of the bug-reporting game is: facts, facts, facts.
328 Don't omit them because &ldquo;Oh, they won't be interested&hellip;&rdquo;
329 </Para>
330
331 <Para>
332
333 <OrderedList>
334 <ListItem>
335
336 <Para>
337 What kind of machine are you running on, and exactly what version of
338 the operating system are you using? (<Command>uname -a</Command> or
339 <Command>cat /etc/motd</Command> will show the desired information.)
340
341 </Para>
342 </ListItem>
343 <ListItem>
344
345 <Para>
346  What version of GCC are you using? <Command>gcc -v</Command> will tell you.
347
348 </Para>
349 </ListItem>
350 <ListItem>
351
352 <Para>
353  Run the sequence of compiles/runs that caused the offending
354 behaviour, capturing all the input/output in a &ldquo;script&rdquo; (a UNIX
355 command) or in an Emacs shell window.  We'd prefer to see the whole
356 thing.
357
358 </Para>
359 </ListItem>
360 <ListItem>
361
362 <Para>
363  Be sure any Haskell compilations are run with a <Option>-v</Option> (verbose)
364 flag, so we can see exactly what was run, what versions of things you
365 have, etc.
366
367 </Para>
368 </ListItem>
369 <ListItem>
370
371 <Para>
372  What is the program behaviour that is wrong, in your opinion?
373
374 </Para>
375 </ListItem>
376 <ListItem>
377
378 <Para>
379  If practical, please send enough source files for us to duplicate the
380  problem.
381
382 </Para>
383 </ListItem>
384 <ListItem>
385
386 <Para>
387  If you are a Hero and track down the problem in the
388 compilation-system sources, please send us patches relative to a known
389 released version of GHC, or whole files if you prefer.
390
391 </Para>
392 </ListItem>
393
394 </OrderedList>
395
396 </Para>
397
398 </Sect1>
399
400 <Sect1 id="hard-core-debug">
401 <Title>Hard-core debugging of GHC-compiled programs
402 </Title>
403
404 <Para>
405 <IndexTerm><Primary>debugging, hard-core</Primary></IndexTerm>
406 </Para>
407
408 <Para>
409 If your program is crashing, you should almost surely file a bug
410 report, as outlined in previous sections.
411 </Para>
412
413 <Para>
414 This section suggests ways to Make Further Progress Anyway.
415 </Para>
416
417 <Para>
418 The first thing to establish is: Is it a garbage-collection (GC) bug?
419 Try your program with a very large heap and a <Option>-Sstderr</Option> RTS
420 flag.
421
422 <ItemizedList>
423 <ListItem>
424
425 <Para>
426 If it crashes <Emphasis>without</Emphasis> garbage-collecting, then it is
427 definitely <Emphasis>not</Emphasis> a GC bug.
428 </Para>
429 </ListItem>
430 <ListItem>
431
432 <Para>
433 If you can make it crash with one heap size but not with another, then
434 it <Emphasis>probably is</Emphasis> a GC bug.
435 </Para>
436 </ListItem>
437 <ListItem>
438
439 <Para>
440 If it crashes with the normal collector, but not when you force
441 two-space collection (<Option>-G1</Option> runtime flag), then it
442 <Emphasis>probably is</Emphasis> a GC bug.
443 </Para>
444 </ListItem>
445
446 </ItemizedList>
447
448 </Para>
449
450 <Para>
451 If it <Emphasis>is</Emphasis> a GC bug, you may be able to avoid it by
452 using a particular heap size or by using a <Option>-G1</Option>
453 runtime flag.  (But don't forget to report the bug!!!)
454 </Para>
455
456 <Para>
457 ToDo: more here?
458 </Para>
459
460 </Sect1>
461
462 </Chapter>
463
464 <!-- Emacs stuff:
465      ;;; Local Variables: ***
466      ;;; mode: sgml ***
467      ;;; sgml-parent-document: ("users_guide.sgml" "book" "chapter") ***
468      ;;; End: ***
469  -->