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