[project @ 2000-06-08 14:36:13 by rrt]
[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>, a useful tool to make sure that every module
252 <Emphasis>is</Emphasis> up-to-date with respect to its imported interfaces is
253 <Command>mkdependHS</Command> (which comes with GHC).  Please see <XRef LinkEnd="mkdependHS">.
254 </Para>
255
256 <Para>
257 If you are down to your last-compile-before-a-bug-report, we would
258 recommend that you add a <Option>-dcore-lint</Option> option (for extra checking) to your compilation options.
259 </Para>
260
261 <Para>
262 So, before you report a bug because of a core dump, you should probably:
263
264 <Screen>
265 % rm *.o        # scrub your object files
266 % make my_prog  # re-make your program; use -hi-diffs to highlight changes;
267                 # as mentioned above, use -dcore-lint to be more paranoid
268 % ./my_prog ... # retry...
269 </Screen>
270
271 </Para>
272
273 <Para>
274 Of course, if you have foreign calls in your program then all
275 bets are off, because you can trash the heap, the stack, or whatever.
276 </Para>
277
278 <Para>
279 If you are interested in hard-core debugging of a crashing
280 GHC-compiled program, please see <XRef LinkEnd="hard-core-debug">.
281 </Para>
282 </ListItem>
283 </VarListEntry>
284 <VarListEntry>
285 <Term>&ldquo;My program entered an `absent' argument.&rdquo;</Term>
286 <ListItem>
287 <Para>
288 This is definitely caused by a bug in GHC. Please report it.
289 </Para>
290 </ListItem>
291 </VarListEntry>
292 <VarListEntry>
293 <Term>&ldquo;What's with this `arithmetic (or `floating') exception' &rdquo;?</Term>
294 <ListItem>
295 <Para>
296 <Literal>Int</Literal>, <Literal>Float</Literal>, and <Literal>Double</Literal> arithmetic is <Emphasis>unchecked</Emphasis>.
297 Overflows, underflows and loss of precision are either silent or
298 reported as an exception by the operating system (depending on the
299 architecture).  Divide-by-zero <Emphasis>may</Emphasis> cause an untrapped
300 exception (please report it if it does).
301 </Para>
302 </ListItem>
303 </VarListEntry>
304 </VariableList>
305 </Para>
306
307 </Sect1>
308
309 <Sect1 id="bug-reports">
310 <Title>How to report a bug in the GHC system
311 </Title>
312
313 <Para>
314 <IndexTerm><Primary>bug reports</Primary></IndexTerm>
315 </Para>
316
317 <Para>
318 Glasgow Haskell is a changing system so there are sure to be bugs in
319 it.  Please report them to
320 <Email>glasgow-haskell-bugs@haskell.org</Email>!  (However, please
321 check the earlier part of this section to be sure it's not a known
322 not-really-a problem.)
323 </Para>
324
325 <Para>
326 The name of the bug-reporting game is: facts, facts, facts.
327 Don't omit them because &ldquo;Oh, they won't be interested&hellip;&rdquo;
328 </Para>
329
330 <Para>
331
332 <OrderedList>
333 <ListItem>
334
335 <Para>
336 What kind of machine are you running on, and exactly what version of
337 the operating system are you using? (<Command>uname -a</Command> or
338 <Command>cat /etc/motd</Command> will show the desired information.)
339
340 </Para>
341 </ListItem>
342 <ListItem>
343
344 <Para>
345  What version of GCC are you using? <Command>gcc -v</Command> will tell you.
346
347 </Para>
348 </ListItem>
349 <ListItem>
350
351 <Para>
352  Run the sequence of compiles/runs that caused the offending
353 behaviour, capturing all the input/output in a &ldquo;script&rdquo; (a UNIX
354 command) or in an Emacs shell window.  We'd prefer to see the whole
355 thing.
356
357 </Para>
358 </ListItem>
359 <ListItem>
360
361 <Para>
362  Be sure any Haskell compilations are run with a <Option>-v</Option> (verbose)
363 flag, so we can see exactly what was run, what versions of things you
364 have, etc.
365
366 </Para>
367 </ListItem>
368 <ListItem>
369
370 <Para>
371  What is the program behaviour that is wrong, in your opinion?
372
373 </Para>
374 </ListItem>
375 <ListItem>
376
377 <Para>
378  If practical, please send enough source files for us to duplicate the
379  problem.
380
381 </Para>
382 </ListItem>
383 <ListItem>
384
385 <Para>
386  If you are a Hero and track down the problem in the
387 compilation-system sources, please send us patches relative to a known
388 released version of GHC, or whole files if you prefer.
389
390 </Para>
391 </ListItem>
392
393 </OrderedList>
394
395 </Para>
396
397 </Sect1>
398
399 <Sect1 id="hard-core-debug">
400 <Title>Hard-core debugging of GHC-compiled programs
401 </Title>
402
403 <Para>
404 <IndexTerm><Primary>debugging, hard-core</Primary></IndexTerm>
405 </Para>
406
407 <Para>
408 If your program is crashing, you should almost surely file a bug
409 report, as outlined in previous sections.
410 </Para>
411
412 <Para>
413 This section suggests ways to Make Further Progress Anyway.
414 </Para>
415
416 <Para>
417 The first thing to establish is: Is it a garbage-collection (GC) bug?
418 Try your program with a very large heap and a <Option>-Sstderr</Option> RTS
419 flag.
420
421 <ItemizedList>
422 <ListItem>
423
424 <Para>
425 If it crashes <Emphasis>without</Emphasis> garbage-collecting, then it is
426 definitely <Emphasis>not</Emphasis> a GC bug.
427 </Para>
428 </ListItem>
429 <ListItem>
430
431 <Para>
432 If you can make it crash with one heap size but not with another, then
433 it <Emphasis>probably is</Emphasis> a GC bug.
434 </Para>
435 </ListItem>
436 <ListItem>
437
438 <Para>
439 If it crashes with the normal collector, but not when you force
440 two-space collection (<Option>-G1</Option> runtime flag), then it
441 <Emphasis>probably is</Emphasis> a GC bug.
442 </Para>
443 </ListItem>
444
445 </ItemizedList>
446
447 </Para>
448
449 <Para>
450 If it <Emphasis>is</Emphasis> a GC bug, you may be able to avoid it by
451 using a particular heap size or by using a <Option>-G1</Option>
452 runtime flag.  (But don't forget to report the bug!!!)
453 </Para>
454
455 <Para>
456 ToDo: more here?
457 </Para>
458
459 </Sect1>
460
461 </Chapter>
462
463 <!-- Emacs stuff:
464      ;;; Local Variables: ***
465      ;;; mode: sgml ***
466      ;;; sgml-parent-document: ("users_guide.sgml" "book" "chapter") ***
467      ;;; End: ***
468  -->