[project @ 1996-07-25 20:43:49 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 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                 # as mentioned above, use -dcore-lint to be more paranoid
227 % ./my_prog ... # retry...
228 \end{verbatim}
229
230 Of course, if you have @_ccall_@s/@_casm_@s in your program then all bets
231 are off, because you can trash the heap, the stack, or whatever.
232
233 If you are interested in hard-core debugging of a crashing
234 GHC-compiled program, please see \sectionref{hard-core-debug}.
235
236 % (If you have an ``unregisterised'' arity-checking
237 % (\tr{-O0 -darity-checks}) around [as we sometimes do at Glasgow], then you
238 % might recompile with \tr{-darity-checks}\index{-darity-checks option},
239 % which will definitely detect arity-compatibility errors.)
240
241 %-------------------------------------------------------------------
242 \item[``My program entered an `absent' argument.'']
243 This is definitely caused by a bug in GHC. Please report it.
244
245 %-----------------------------------------------------------------------
246 \item[``What's with this `arithmetic (or `floating') exception' ''?]
247
248 @Int@, @Float@, and @Double@ arithmetic is {\em unchecked}.  Overflows
249 and underflows are {\em silent}.  Divide-by-zero {\em may} cause an
250 untrapped exception (please report it if it does).  I suppose other
251 arithmetic uncheckiness might cause an exception, too...
252 \end{description}
253
254 %************************************************************************
255 %*                                                                      *
256 \subsection[bug-reports]{How to report a bug in the GHC system}
257 \index{bug reports}
258 %*                                                                      *
259 %************************************************************************
260
261 Glasgow Haskell is a changing system so there are sure to be bugs in
262 it.  Please report them to
263 \tr{glasgow-haskell-bugs@dcs.gla.ac.uk}!  (However, please check
264 the earlier part of this section to be sure it's not a known
265 not-really-a problem.)
266
267 The name of the bug-reporting game is: facts, facts, facts.
268 Don't omit them because ``Oh, they won't be interested...''
269 \begin{enumerate}
270 \item
271 What kind of machine are you running on, and exactly what version of the
272 operating system are you using? (\tr{uname -a} or \tr{cat /etc/motd} will show the desired
273 information.)
274
275 \item
276 What version of GCC are you using? \tr{gcc -v} will tell you.
277
278 \item
279 Run the sequence of compiles/runs that caused the offending behaviour,
280 capturing all the input/output in a ``script'' (a UNIX command) or in
281 an Emacs shell window.  We'd prefer to see the whole thing.
282
283 \item
284 Be sure any Haskell compilations are run with a \tr{-v} (verbose)
285 flag, so we can see exactly what was run, what versions of things you
286 have, etc.
287
288 \item
289 What is the program behaviour that is wrong, in your opinion?
290
291 \item
292 If practical, please send enough source files/interface files for us
293 to duplicate the problem.
294
295 \item
296 If you are a Hero and track down the problem in the compilation-system
297 sources, please send us {\em whole files} (by e-mail or FTP) that we
298 can compare against some base release.
299 \end{enumerate}
300
301 %************************************************************************
302 %*                                                                      *
303 \subsection[hard-core-debug]{Hard-core debugging of GHC-compiled programs}
304 \index{debugging, hard-core}
305 %*                                                                      *
306 %************************************************************************
307
308 If your program is crashing, you should almost surely file a bug
309 report, as outlined in previous sections.
310
311 This section suggests ways to Make Further Progress Anyway.
312
313 The first thing to establish is: Is it a garbage-collection (GC) bug?
314 Try your program with a very large heap and a \tr{-Sstderr} RTS
315 flag.
316 \begin{itemize}
317 \item
318 If it crashes {\em without} garbage-collecting, then it is
319 definitely {\em not} a GC bug.
320 \item
321 If you can make it crash with one heap size but not with another, then
322 it {\em probably is} a GC bug.
323 \item
324 If it crashes with the normal
325 collector, but not when you force two-space collection (\tr{-F2s}
326 runtime flag), then it {\em probably is} a GC bug.
327 \end{itemize}
328
329 If it {\em is} a GC bug, you may be able to avoid it by using a
330 particular heap size or by using a \tr{-F2s} runtime flag.  (But don't
331 forget to report the bug!!!)
332
333 ToDo: more here?