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