[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / includes / SMInfoTables.lh
1 %
2 % (c) The OBFUSCATION-THROUGH-GRATUITOUS-PREPROCESSOR-ABUSE Project,
3 %     Glasgow University, 1990-1994
4 %
5 %************************************************************************
6 %*                                                                      *
7 \section[info-table-macros]{Info-table macros}
8 %*                                                                      *
9 %************************************************************************
10
11 We define {\em info tables} here.  First, all the different pieces of
12 an info table (entry code, evac code, etc.); then all the different
13 kinds of info tables (SPEC, DYN, etc).  NB: some of the parallel-only
14 kinds are defined in \tr{Parallel.lh}, not here.
15
16 An info-table contains several fields. The first field is
17 the label of the closure's {\em standard-entry code}. This is used by
18 the reducer to ``evaluate'' the closure. The remaining fields are used
19 by the garbage collector and other parts of the runtime
20 system. Info-tables are declared using the C macros defined below.
21 The details of the contents are determined by the storage manager and
22 are not of interest outside it.
23
24 Info tables may either be {\em reversed} or not.  Reversed is normal
25 and preferred, but it requires ``assembler mangling'' of the C
26 compiler output.  (The native-code generator does reversed info-tables
27 automagically.) With reversed info tables, (a)~the words are reversed
28 [obviously], (b)~the info-table's C label addresses the word {\em just
29 after} the info table (where its associated entry code ``happens to be''),
30 and (c)~the entry-code word in the info table is omitted (it's
31 vestigial).
32
33 Info-table reversal is hidden behind the @IREL@ macro.
34
35 The following fields are used when defining particular info-tables.
36 Some sorts of info-table (e.g. @FETCHME_ITBL@) don't need all these
37 fields to be specified.
38
39 \begin{description}
40 \item[@infolbl@]
41 The name used to create labels for the info-table, profiling
42 information, etc.
43
44 \item[\tr{entry_code}:]
45 The function which is called when entering the closure.
46
47 \item[\tr{update_code}:]
48 The function which is called when updating the closure (constructors only).
49
50 \item[\tr{tag}:]
51 (So much for the Spineless {\em Tagless} G-Machine...)  Used for
52 semi-tagging checks.
53
54 \item[\tr{type}:]
55 Similar-but-different info to the \tr{tag} stuff; the
56 parallel world needs more elaborate info.
57
58 \item[\tr{size}:]
59 The size of the closure (see \tr{SMClosures.lh} for a precise
60 definition of ``size'').  Used by the garbage-collector, not the
61 Haskell reducer.
62
63 \item[\tr{ptrs}:]
64 The number of pointers in the closure.  Used by the garbage-collector,
65 not the Haskell reducer.
66
67 \item[@localness@]
68 Whether the info-table is local to this module or not.
69 The field is set to @static@ if the info-table is
70 local, and is empty otherwise.
71
72 \item[@entry_localness@]
73 Whether the @entry_code@ routine is local to this module or not.
74 This field can have the following values:
75   \begin{description}
76   \item [@EXTFUN@]
77   The entry code is global.
78   \item [@INTFUN@]
79   The entry code is local.
80   \end{description}
81
82 \item[@kind@]
83 This identifies the general sort of the closure for profiling purposes.
84 It can have the following values (defined in CostCentre.lh):
85
86   \begin{description}
87   \item[@CON_K@]
88   A constructor.
89   \item[@FN_K@]
90   A literal function.
91   \item[@PAP_K@]
92   A partial application.
93   \item[@THK_K@]
94   A thunk, or suspension.
95   \item[@BH_K@]
96   A black hole.
97   \item[@ARR_K@]
98   An array.
99   \item[@MP_K@]
100   A Malloc Pointer.
101   \item[@SPT_K@]
102   The Stable Pointer table.  (There should only be one of these but it
103   represents a form of weak space leak since it can't shrink to meet
104   non-demand so it may be worth watching separately? ADR)
105   \item[@INTERNAL_KIND@]
106   Something internal to the runtime system.
107   \end{description}
108
109 \item[@descr@]
110 This is a string used to identify the closure for profiling purposes.
111 \end{description}
112
113 So, for example:
114 \begin{pseudocode}
115 SPEC_N_ITBL(RBH_Save_0_info,RBH_Save_0_entry,UpdErr,0,INFO_OTHER_TAG,2,0,,IF_,INTERNAL_KIND,"RBH-SAVE","RBH_Save_0");
116 \end{pseudocode}
117
118 %************************************************************************
119 %*                                                                      *
120 \subsection[info-table-common-up]{The commoned-up info-table world}
121 %*                                                                      *
122 %************************************************************************
123
124 Since lots of info-tables share the same information (which doesn't
125 change at run time) needlessly, we gather this common information
126 together into a rep-table.
127
128 Conditionally present data (concerning the parallel world, and also
129 information for the collectors) are gathered into unique rep-tables,
130 which are pointed to from info-tables.  This saves several words for
131 each closure we build, at the cost of making garbage collection and
132 fetching of data from info-tables a little more hairy.
133
134 Size and pointers fields go away altogether, save for @GEN@ closures
135 where they are tacked on to the end of info-tables.
136
137 %************************************************************************
138 %*                                                                      *
139 \subsection[info-table-common]{Bits common to all info-tables}
140 %*                                                                      *
141 %************************************************************************
142
143 The entry code for a closure, its type, its ``size'', and the number
144 of pointer-words it contains are the same in every info table.  For
145 the parallel system, two flush code-entries are also standard.
146
147 Multi-slurp protection:
148 \begin{code}
149 #ifndef SMInfoTables_H
150 #define SMInfoTables_H
151 \end{code}
152
153 \begin{code}
154 #ifdef __STG_REV_TBLS__
155
156 # define IREL(offset)   (-(offset))
157
158 /* NB: the ENT_ macro (StgMacros.lh) must also be changed */
159
160 # define ENTRY_CODE(infoptr)     ((F_)(infoptr))
161
162 #else /* boring non-reversed info tables */
163
164 # define IREL(offset)   (offset)
165
166 # define ENTRY_CODE(infoptr)     (((FP_)(infoptr))[IREL(0)])
167
168 #endif /* non-fixed size info tables */
169 \end{code}
170
171 \begin{code}
172 #define INFO_TAG(infoptr)       ((I_) ((P_)(infoptr))[IREL(1)])
173 #define EVAL_TAG(infoptr)       (INFO_TAG(infoptr) >= 0)
174 \end{code}
175
176 \begin{code}
177
178 #define INFO_INTERNAL           (~0L)   /* Should never see this */
179
180 #define INFO_UNUSED             (~0L)
181 /* We'd like to see this go away in code pointer fields, with specialized code
182    to print out an appropriate error message instead.
183    WDP 94/11: At least make it an Obviously Weird Value?
184  */
185
186 \end{code}
187
188
189 %************************************************************************
190 %*                                                                      *
191 \subsection[info-table-rtbl]{Rep tables in an info table}
192 %*                                                                      *
193 %************************************************************************
194
195 Common information is pointed to by the rep table pointer.  We want to
196 use extern declarations almost everywhere except for the single module
197 (\tr{Rep.lc}) in which the rep tables are declared locally.
198
199 \begin{code}
200 #if defined(COMPILING_REP_LC) || defined(COMPILING_GHC)
201 # define MAYBE_DECLARE_RTBL(l,s,p)
202 #else
203 # define MAYBE_DECLARE_RTBL(l,s,p)      EXTDATA_RO(MK_REP_REF(l,s,p));
204 #endif
205
206 #define INFO_RTBL(infoptr)      (((PP_)(infoptr))[IREL(2)])
207 \end{code}
208   
209 %************************************************************************
210 %*                                                                      *
211 \subsection{Maybe-there-maybe-not fields in an info table}
212 %*                                                                      *
213 %************************************************************************
214
215 That's about it for the fixed stuff...entry code, a tag and an RTBL pointer.
216
217 \begin{code}
218 #define FIXED_INFO_WORDS                3
219 \end{code}
220
221 %************************************************************************
222 %*                                                                      *
223 \subsubsection{Profiling-only fields in an info table}
224 %*                                                                      *
225 %************************************************************************
226
227 These macros result in the profiling kind and description string being
228 included only if required.
229 \begin{code}
230 #define PROFILING_INFO_OFFSET  (FIXED_INFO_WORDS)
231
232 #if !defined(USE_COST_CENTRES)
233 # define PROFILING_INFO_WORDS   0
234 # define INCLUDE_PROFILING_INFO(base_name)
235 # define INREGS_PROFILING_INFO    
236
237 #else
238 # define PROFILING_INFO_WORDS   1
239
240 # define INCLUDE_PROFILING_INFO(base_name) , (W_)REF_CAT_IDENT(base_name)
241 # define INREGS_PROFILING_INFO  ,INFO_UNUSED
242
243 # define INFO_CAT(infoptr)  (((ClCategory *)(infoptr))[IREL(PROFILING_INFO_OFFSET)])
244
245 #endif
246 \end{code}
247
248 %************************************************************************
249 %*                                                                      *
250 \subsubsection{Non-standard fields in an info table: where they'll be}
251 %*                                                                      *
252 %************************************************************************
253
254 The @UPDATE_CODE@ field is a pointer to the update code for a constructor.
255 I believe that constructors are always of the following types:
256
257 \begin{itemize}
258 \item @CHARLIKE@
259 \item @CONST@
260 \item @GEN_N@
261 \item @INTLIKE@
262 \item @SPEC_N@
263 \item @STATIC@
264 \end{itemize}
265
266 Info tables for these types have non-standard update code fields.  In addition,
267 because @GEN@ closures have further non-standard fields (size, ptrs), the
268 info tables for @GEN_U@ closures also have a non-standard update code field 
269 (which is filled in with @StdErrorCode@).
270
271 When we're in the parallel world, we also have to know which registers are
272 live when we're returning a constructor in registers, so we have a second 
273 word for that as well.
274
275 \begin{code}
276
277 #define UPDATE_INFO_OFFSET  (PROFILING_INFO_OFFSET+PROFILING_INFO_WORDS)
278
279 #ifndef PAR
280 # define UPDATE_INFO_WORDS    1
281 # define INCLUDE_UPDATE_INFO(upd,live)  ,(W_)upd
282 #else
283 # define UPDATE_INFO_WORDS    2
284 # define INCLUDE_UPDATE_INFO(upd,live)  ,(W_)upd,(W_)live
285 #endif
286
287 #define UPDATE_CODE(infoptr)    (((FP_)(infoptr))[IREL(UPDATE_INFO_OFFSET)])
288 #define INFO_LIVENESS(infoptr)  (((P_)(infoptr))[IREL(UPDATE_INFO_OFFSET+1)])
289 \end{code}
290
291 @GEN@ closures have the size and number of pointers in the info table
292 rather than the rep table.  These non-standard fields follow the update
293 code field (which is only required for @GEN_N@ closures, but which we
294 include in @GEN_U@ closures just to keep this other stuff at a consistent
295 offset).
296
297 \begin{code}
298 #define GEN_INFO_OFFSET     (UPDATE_INFO_OFFSET+UPDATE_INFO_WORDS)
299 #define GEN_INFO_WORDS    2
300 #define INCLUDE_GEN_INFO(size,ptrs)     ,(W_)size,(W_)ptrs
301
302 #define GEN_INFO_SIZE(infoptr)   ((I_)((P_)(infoptr))[IREL(GEN_INFO_OFFSET)])
303 #define GEN_INFO_NoPTRS(infoptr) ((I_)((P_)(infoptr))[IREL(GEN_INFO_OFFSET+1)])
304 \end{code}
305
306 @CONST@ closures have a pointer to a static version of the closure in their
307 info tables.  This non-standard field follows their update code field.
308
309 \begin{code}
310 #define CONST_INFO_OFFSET           (UPDATE_INFO_OFFSET+UPDATE_INFO_WORDS)
311 #define CONST_INFO_WORDS    1
312 #define INCLUDE_CONST_INFO(closure)     ,(W_)closure
313
314 #define CONST_STATIC_CLOSURE(infoptr)   (((PP_)(infoptr))[IREL(CONST_INFO_OFFSET)])
315 \end{code}
316
317 @STATIC@ closures are like @GEN@ closures in that they also have the
318 size and number of pointers in the info table rather than the rep
319 table.  Again, these non-standard fields follow the update code field
320 (which I believe is not actually needed for STATIC closures).
321
322 \begin{code}
323 #define STATIC_INFO_OFFSET          (UPDATE_INFO_OFFSET+UPDATE_INFO_WORDS)
324 #define STATIC_INFO_WORDS    2
325 #define INCLUDE_STATIC_INFO(size,ptrs)  ,(W_)size,(W_)ptrs
326
327 #define STATIC_INFO_SIZE(infoptr)   ((I_)((P_)(infoptr))[IREL(STATIC_INFO_OFFSET)])
328 #define STATIC_INFO_NoPTRS(infoptr) ((I_)((P_)(infoptr))[IREL(STATIC_INFO_OFFSET+1)])
329 \end{code}
330
331 In the parallel system, all updatable closures have corresponding
332 revertible black holes.  When we are assembly-mangling, we guarantee that
333 the revertible black hole code precedes the normal entry code, so that
334 the RBH info table resides at a fixed offset from the normal info table.
335 Otherwise, we add the RBH info table pointer to the end of the normal
336 info table and vice versa.
337
338 \begin{code}
339 #ifdef PAR
340 # define RBH_INFO_OFFSET            (GEN_INFO_OFFSET+GEN_INFO_WORDS)
341
342 # define INCLUDE_SPEC_PADDING                           \
343         INCLUDE_UPDATE_INFO(INFO_UNUSED,INFO_UNUSED)    \
344         INCLUDE_GEN_INFO(INFO_UNUSED,INFO_UNUSED)
345
346 # ifdef RBH_MAGIC_OFFSET
347
348 #  define RBH_INFO_WORDS    0
349 #  define INCLUDE_RBH_INFO(infoptr)
350
351 #  define RBH_INFOPTR(infoptr)      (((P_)infoptr) - RBH_MAGIC_OFFSET)
352 #  define REVERT_INFOPTR(infoptr)   (((P_)infoptr) + RBH_MAGIC_OFFSET)
353
354 # else
355
356 #  define RBH_INFO_WORDS    1
357 #  define INCLUDE_RBH_INFO(infoptr) ,(W_)infoptr
358
359 #  define RBH_INFOPTR(infoptr)      (((PP_)(infoptr))[IREL(RBH_INFO_OFFSET)])
360 #  define REVERT_INFOPTR(infoptr)   (((PP_)(infoptr))[IREL(RBH_INFO_OFFSET)])
361
362 # endif
363
364 EXTFUN(RBH_entry);
365 P_ convertToRBH PROTO((P_ closure));
366 void convertToFetchMe PROTO((P_ closure, globalAddr *ga));
367 #endif
368 \end{code}
369
370 %************************************************************************
371 %*                                                                      *
372 \subsection{Maybe-there-maybe-not fields in a rep table}
373 %*                                                                      *
374 %************************************************************************
375
376 %************************************************************************
377 %*                                                                      *
378 \subsubsection{Type field in a rep table}
379 %*                                                                      *
380 %************************************************************************
381
382 The @INFO_TYPE@ field in the rep table tells what sort of animal
383 the closure is.  
384
385 \begin{code}
386 #define TYPE_INFO_OFFSET  0
387 #define TYPE_INFO_WORDS    1
388 #define INCLUDE_TYPE_INFO(kind) (W_)CAT3(INFO_,kind,_TYPE)
389
390 #define INFO_TYPE(infoptr)      (((P_)(INFO_RTBL(infoptr)))[TYPE_INFO_OFFSET])
391 \end{code}
392
393 The least significant 9 bits of the info-type are used as follows:
394
395 \begin{tabular}{||l|l||}                                                   \hline
396 Bit & Interpretation                                                    \\ \hline
397 0   & 1 $\Rightarrow$ Head normal form                                  \\
398 1   & 1 $\Rightarrow$ Don't spark me  (Any HNF will have this set to 1) \\
399 2   & 1 $\Rightarrow$ This is a static closure                          \\
400 3   & 1 $\Rightarrow$ Has mutable pointer fields \\ 
401 4   & 1 $\Rightarrow$ May be updated (inconsistent with being a HNF) \\ 
402 5   & 1 $\Rightarrow$ Is a "primitive" array (a BIG structure) \\
403 6   & 1 $\Rightarrow$ Is a black hole                                   \\
404 7   & 1 $\Rightarrow$ Is an indirection                                 \\
405 8   & 1 $\Rightarrow$ Is a thunk                                        \\
406 \hline
407 \end{tabular}
408
409 Updatable structures (@_UP@) are thunks that may be shared.  Primitive
410 arrays (@_BM@ -- Big Mothers) are structures that are always held
411 in-memory (basically extensions of a closure).  Because there may be
412 offsets into these arrays, a primitive array cannot be handled as a
413 FetchMe in the parallel system, but must be shipped in its entirety if
414 its parent closure is shipped.
415
416 \begin{code}
417 #define IP_TAG_BITS             9
418
419 #define _NF                     0x0001  /* Normal form  */
420 #define _NS                     0x0002  /* Don't spark  */
421 #define _ST                     0x0004  /* Is static    */
422 #define _MU                     0x0008  /* Is mutable   */
423 #define _UP                     0x0010  /* Is updatable (but not mutable) */
424 #define _BM                     0x0020  /* Is a "primitive" array */
425 #define _BH                     0x0040  /* Is a black hole */
426 #define _IN                     0x0080  /* Is an indirection */
427 #define _TH                     0x0100  /* Is a thunk */
428
429 #define IS_NF(infoptr)          ((INFO_TYPE(infoptr)&_NF) != 0)
430 #define IS_MUTABLE(infoptr)     ((INFO_TYPE(infoptr)&_MU) != 0)
431 #define IS_STATIC(infoptr)      ((INFO_TYPE(infoptr)&_ST) != 0)
432 #define IS_UPDATABLE(infoptr)   ((INFO_TYPE(infoptr)&_UP) != 0)
433 #define IS_BIG_MOTHER(infoptr)  ((INFO_TYPE(infoptr)&_BM) != 0)
434 #define IS_BLACK_HOLE(infoptr)  ((INFO_TYPE(infoptr)&_BH) != 0)
435 #define IS_INDIRECTION(infoptr) ((INFO_TYPE(infoptr)&_IN) != 0)
436 #define IS_THUNK(infoptr)       ((INFO_TYPE(infoptr)&_TH) != 0)
437
438 #define SHOULD_SPARK(closure)   ((INFO_TYPE(INFO_PTR(closure))&_NS) == 0)
439 \end{code}
440
441 The other bits in the info-type field simply give a unique bit-pattern
442 to identify the closure type.
443
444 \begin{code}
445 #define IP_TAG_BIT_MASK         ((1L<<IP_TAG_BITS)-1)
446
447 #define BASE_INFO_TYPE(infoptr) (INFO_TYPE(infoptr) & (~IP_TAG_BIT_MASK)) /* Strips out the tag bits */
448
449 #define MAKE_BASE_INFO_TYPE(x)  ((x) << IP_TAG_BITS)
450
451 #define INFO_SPEC_TYPE          (MAKE_BASE_INFO_TYPE(1L))
452 #define INFO_GEN_TYPE           (MAKE_BASE_INFO_TYPE(2L))
453 #define INFO_DYN_TYPE           (MAKE_BASE_INFO_TYPE(3L) | _NF | _NS)
454 #define INFO_TUPLE_TYPE         (MAKE_BASE_INFO_TYPE(4L) | _NF | _NS | _BM)
455 #define INFO_DATA_TYPE          (MAKE_BASE_INFO_TYPE(5L) | _NF | _NS | _BM)
456 #define INFO_MUTUPLE_TYPE       (MAKE_BASE_INFO_TYPE(6L) | _NF | _NS | _MU | _BM)
457 #define INFO_IMMUTUPLE_TYPE     (MAKE_BASE_INFO_TYPE(7L) | _NF | _NS | _BM)
458 #define INFO_STATIC_TYPE        (MAKE_BASE_INFO_TYPE(8L) | _NS | _ST)
459 #define INFO_CONST_TYPE         (MAKE_BASE_INFO_TYPE(9L) | _NF | _NS)
460 #define INFO_CHARLIKE_TYPE      (MAKE_BASE_INFO_TYPE(10L) | _NF | _NS)
461 #define INFO_INTLIKE_TYPE       (MAKE_BASE_INFO_TYPE(11L) | _NF | _NS)
462 #define INFO_BH_TYPE            (MAKE_BASE_INFO_TYPE(12L) | _NS | _BH)
463 #define INFO_BQ_TYPE            (MAKE_BASE_INFO_TYPE(13L) | _NS | _MU | _BH)
464 #define INFO_IND_TYPE           (MAKE_BASE_INFO_TYPE(14L) | _NS | _IN)
465 #define INFO_CAF_TYPE           (MAKE_BASE_INFO_TYPE(15L) | _NF | _NS | _ST | _IN)
466 #define INFO_FM_TYPE            (MAKE_BASE_INFO_TYPE(16L))
467 #define INFO_TSO_TYPE           (MAKE_BASE_INFO_TYPE(17L) | _MU)
468 #define INFO_STKO_TYPE          (MAKE_BASE_INFO_TYPE(18L))
469 #define INFO_SPEC_RBH_TYPE      (MAKE_BASE_INFO_TYPE(19L) | _NS | _MU | _BH)
470 #define INFO_GEN_RBH_TYPE       (MAKE_BASE_INFO_TYPE(20L) | _NS | _MU | _BH)
471 #define INFO_BF_TYPE            (MAKE_BASE_INFO_TYPE(21L) | _NS | _MU | _BH)
472 #define INFO_INTERNAL_TYPE      (MAKE_BASE_INFO_TYPE(22L))
473
474 #define INFO_SPEC_N_TYPE        (INFO_SPEC_TYPE | _NF | _NS)
475 #define INFO_SPEC_S_TYPE        (INFO_SPEC_TYPE | _TH)
476 #define INFO_SPEC_U_TYPE        (INFO_SPEC_TYPE | _UP | _TH)
477
478 #define INFO_GEN_N_TYPE         (INFO_GEN_TYPE | _NF | _NS)
479 #define INFO_GEN_S_TYPE         (INFO_GEN_TYPE | _TH)
480 #define INFO_GEN_U_TYPE         (INFO_GEN_TYPE | _UP | _TH)
481
482 #define INFO_BH_N_TYPE          (INFO_BH_TYPE)
483 #define INFO_BH_U_TYPE          (INFO_BH_TYPE | _UP)
484
485 #define INFO_STKO_DYNAMIC_TYPE  (INFO_STKO_TYPE | _MU)
486 #define INFO_STKO_STATIC_TYPE   (INFO_STKO_TYPE | _ST)
487
488 #define INFO_FETCHME_TYPE       (INFO_FM_TYPE | _MU)
489 #define INFO_FMBQ_TYPE          (INFO_FM_TYPE | _MU | _BH)
490
491 #define MIN_INFO_TYPE           0
492 #define MAX_INFO_TYPE           INFO_INTERNAL_TYPE
493
494 \end{code}
495
496 Notes:
497
498 An indirection either points to HNF (post update); or is result of
499 overwriting a FetchMe, in which case the thing fetched is either
500 under evaluation (BH), or by now an HNF.  Thus, indirections get @_NS@.
501
502 %************************************************************************
503 %*                                                                      *
504 \subsubsection{Size/no-of-pointers fields in a rep table}
505 %*                                                                      *
506 %************************************************************************
507
508 \begin{code}
509 #define SIZE_INFO_OFFSET  (TYPE_INFO_OFFSET+TYPE_INFO_WORDS)
510 #define SIZE_INFO_WORDS   2
511 #define INCLUDE_SIZE_INFO(size,ptrs) ,(W_)size, (W_)ptrs
512
513 #define INFO_SIZE(infoptr)   ((I_)((FP_)(INFO_RTBL(infoptr)))[SIZE_INFO_OFFSET])
514 #define INFO_NoPTRS(infoptr) ((I_)((FP_)(INFO_RTBL(infoptr)))[SIZE_INFO_OFFSET+1])
515 \end{code}
516
517 %************************************************************************
518 %*                                                                      *
519 \subsubsection{Parallel-only fields in a rep table}
520 %*                                                                      *
521 %************************************************************************
522
523 There is now nothing that is specific to the parallel world (GUM), but
524 this could change so don't go deleting this little lot!  KH
525
526 \begin{code}
527 # define PAR_INFO_OFFSET                (SIZE_INFO_OFFSET+SIZE_INFO_WORDS)
528
529 /* now the bits that are either on or off: */
530
531 # define PAR_INFO_WORDS         0
532 # define INCLUDE_PAR_INFO
533 \end{code}
534
535 %************************************************************************
536 %*                                                                      *
537 \subsubsection{Copying-only fields in a rep table}
538 %*                                                                      *
539 %************************************************************************
540
541 These macros result in the copying garbage collection code being
542 included only if required.
543 \begin{code}
544 #if defined(_INFO_COPYING)
545 # include "SMcopying.h" /* Copying Code Labels */
546 # define COPY_INFO_OFFSET  (PAR_INFO_OFFSET+PAR_INFO_WORDS)
547 # define COPY_INFO_WORDS 2
548 # define INCLUDE_COPYING_INFO(evac, scav) ,(W_)evac,(W_)scav
549
550 /* 
551  * use these if you have an unquenchable urge to dig around in
552  *  info tables (e.g., runtime/.../StgDebug.lc)
553  */
554
555 # define INFO_EVAC_2S(infoptr)  (((FP_)(INFO_RTBL(infoptr)))[COPY_INFO_OFFSET])
556 # define INFO_SCAV_2S(infoptr)  (((FP_)(INFO_RTBL(infoptr)))[COPY_INFO_OFFSET + 1])
557
558 # if defined(UPDATES_ENTERED_COUNT)
559
560 /* Don't commmon up CONST CHARLIKE and INTLIKE treat as SPEC 1_0 closure */
561 /* This broke it -- turning it off. Use LARGE heap so no GC needed */
562 #  if 0
563 #   define INCLUDE_COPYING_INFO_CONST(evac, scav) \
564         INCLUDE_COPYING_INFO(_Evacuate_1,_Scavenge_1_0)
565 #  endif /* 0 */
566
567 #  define INCLUDE_COPYING_INFO_CONST(evac, scav) \
568         INCLUDE_COPYING_INFO(evac, scav)
569 # else
570 #  define INCLUDE_COPYING_INFO_CONST(evac, scav) \
571         INCLUDE_COPYING_INFO(evac, scav)
572 # endif
573
574 #else  /* ! _INFO_COPYING */
575
576 # define COPY_INFO_WORDS 0
577 # define INCLUDE_COPYING_INFO(evac, scav)
578 # define INCLUDE_COPYING_INFO_CONST(evac, scav)
579
580 #endif /* ! _INFO_COPYING */
581 \end{code}
582
583 %************************************************************************
584 %*                                                                      *
585 \subsubsection{Compacting-only fields in a rep table}
586 %*                                                                      *
587 %************************************************************************
588
589 These macros result in the compacting garbage collection code being
590 included only if required. This includes the variable length
591 specialised marking code.
592
593 \begin{code}
594 #if !defined(_INFO_COMPACTING)
595
596 # define INCLUDE_COMPACTING_INFO(scanlink,prmark,scanmove,marking)
597 # define SPEC_COMPACTING_INFO(scanlink,prmark,scanmove,marking)
598
599 #else /* defined(_INFO_COMPACTING) */
600
601 # include "SMcompact.h"         /* Single Space Compacting Code */
602 # include "SMmark.h"            /* Pointer Reversal Marking Code Labels */
603
604 /* For SPEC closures compacting info is variable length -> must come last */
605
606 # define COMPACTING_INFO_OFFSET  (COPY_INFO_OFFSET+COPY_INFO_WORDS)
607
608 # define INCLUDE_COMPACTING_INFO(scanlink,prmark,scanmove,marking) \
609         ,(W_)scanlink,(W_)prmark \
610         ,(W_)scanmove,(W_)marking
611
612 # define SPEC_COMPACTING_INFO(scanlink,prmark,scanmove,prreturn) \
613         ,(W_)scanlink,(W_)prmark \
614         ,(W_)scanmove, \
615          (W_)prreturn
616
617
618 # define INFO_SCAN_LINK_1S(infoptr)     (((FP_)(INFO_RTBL(infoptr)))[COMPACTING_INFO_OFFSET])
619 # define INFO_MARK_1S(infoptr)          (((FP_)(INFO_RTBL(infoptr)))[COMPACTING_INFO_OFFSET+1])
620 # define INFO_SCAN_MOVE_1S(infoptr)     (((FP_)(INFO_RTBL(infoptr)))[COMPACTING_INFO_OFFSET+2])
621 # define INFO_MARKED_1S(infoptr)        (((FP_)(INFO_RTBL(infoptr)))[COMPACTING_INFO_OFFSET+3])
622 # define INFO_MARKING_1S(infoptr)       (((FP_)(INFO_RTBL(infoptr)))[COMPACTING_INFO_OFFSET+4])
623
624 #ifndef COMPILING_GHC
625 extern F_ _Dummy_Static_entry(STG_NO_ARGS);
626 extern F_ _Dummy_Ind_entry(STG_NO_ARGS);
627 extern F_ _Dummy_Caf_entry(STG_NO_ARGS);
628 extern F_ _Dummy_Const_entry(STG_NO_ARGS);
629 extern F_ _Dummy_CharLike_entry(STG_NO_ARGS);
630 #endif
631
632 #endif /* _INFO_COMPACTING */
633 \end{code}
634
635 %************************************************************************
636 %*                                                                      *
637 \subsection[SPEC_ITBL]{@SPEC_x_ITBL@: @SPEC@ info-tables}
638 %*                                                                      *
639 %************************************************************************
640
641 Normal-form and updatable (non-normal-form) variants.
642
643 \begin{code}
644
645 #define SPEC_N_ITBL(infolbl,entry_code,upd_code,liveness,tag,size,ptrs,localness,entry_localness,kind,descr,type) \
646     CAT_DECLARE(infolbl,kind,descr,type)        \
647     entry_localness(entry_code);                \
648     localness W_ infolbl[] = {                  \
649         (W_) entry_code                         \
650         ,(W_) tag                               \
651         ,(W_) MK_REP_REF(Spec_N,size,ptrs)      \
652         INCLUDE_PROFILING_INFO(infolbl)         \
653         INCLUDE_UPDATE_INFO(upd_code,liveness)  \
654         }
655
656 MAYBE_DECLARE_RTBL(Spec_N,1,0)
657 MAYBE_DECLARE_RTBL(Spec_N,1,1)
658 MAYBE_DECLARE_RTBL(Spec_N,2,0)
659 MAYBE_DECLARE_RTBL(Spec_N,2,1)
660 MAYBE_DECLARE_RTBL(Spec_N,2,2)
661 MAYBE_DECLARE_RTBL(Spec_N,3,0)
662 MAYBE_DECLARE_RTBL(Spec_N,3,1)
663 MAYBE_DECLARE_RTBL(Spec_N,3,2)
664 MAYBE_DECLARE_RTBL(Spec_N,3,3)
665 MAYBE_DECLARE_RTBL(Spec_N,4,0)
666 MAYBE_DECLARE_RTBL(Spec_N,4,4)
667 MAYBE_DECLARE_RTBL(Spec_N,5,0)
668 MAYBE_DECLARE_RTBL(Spec_N,5,5)
669 MAYBE_DECLARE_RTBL(Spec_N,6,6)
670 MAYBE_DECLARE_RTBL(Spec_N,7,7)
671 MAYBE_DECLARE_RTBL(Spec_N,8,8)
672 MAYBE_DECLARE_RTBL(Spec_N,9,9)
673 MAYBE_DECLARE_RTBL(Spec_N,10,10)
674 MAYBE_DECLARE_RTBL(Spec_N,11,11)
675 MAYBE_DECLARE_RTBL(Spec_N,12,12)
676
677 #define SPEC_N_RTBL(size,ptrs)                                                  \
678     const W_ MK_REP_LBL(Spec_N,size,ptrs)[] = {                                 \
679         INCLUDE_TYPE_INFO(SPEC_N)                                               \
680         INCLUDE_SIZE_INFO(size,ptrs)                                            \
681         INCLUDE_PAR_INFO                                                        \
682         INCLUDE_COPYING_INFO(CAT2(_Evacuate_,size),CAT4(_Scavenge_,size,_,ptrs)) \
683         SPEC_COMPACTING_INFO(CAT4(_ScanLink_,size,_,ptrs),                      \
684                              CAT2(_PRStart_,ptrs),                              \
685                              CAT2(_ScanMove_,size),CAT2(_PRIn_,ptrs))           \
686         }
687
688 #define SPEC_S_ITBL(infolbl,entry_code,upd_code,liveness,tag,size,ptrs,localness,entry_localness,kind,descr,type) \
689     CAT_DECLARE(infolbl,kind,descr,type)        \
690     entry_localness(entry_code);                \
691     localness W_ infolbl[] = {                  \
692         (W_) entry_code                         \
693         ,(W_) tag                               \
694         ,(W_) MK_REP_REF(Spec_S,size,ptrs)      \
695         INCLUDE_PROFILING_INFO(infolbl)         \
696         INCLUDE_UPDATE_INFO(upd_code,liveness)  \
697         }
698
699 MAYBE_DECLARE_RTBL(Spec_S,1,0)
700 MAYBE_DECLARE_RTBL(Spec_S,1,1)
701 MAYBE_DECLARE_RTBL(Spec_S,2,0)
702 MAYBE_DECLARE_RTBL(Spec_S,2,1)
703 MAYBE_DECLARE_RTBL(Spec_S,2,2)
704 MAYBE_DECLARE_RTBL(Spec_S,3,0)
705 MAYBE_DECLARE_RTBL(Spec_S,3,1)
706 MAYBE_DECLARE_RTBL(Spec_S,3,2)
707 MAYBE_DECLARE_RTBL(Spec_S,3,3)
708 MAYBE_DECLARE_RTBL(Spec_S,4,0)
709 MAYBE_DECLARE_RTBL(Spec_S,4,4)
710 MAYBE_DECLARE_RTBL(Spec_S,5,0)
711 MAYBE_DECLARE_RTBL(Spec_S,5,5)
712 MAYBE_DECLARE_RTBL(Spec_S,6,6)
713 MAYBE_DECLARE_RTBL(Spec_S,7,7)
714 MAYBE_DECLARE_RTBL(Spec_S,8,8)
715 MAYBE_DECLARE_RTBL(Spec_S,9,9)
716 MAYBE_DECLARE_RTBL(Spec_S,10,10)
717 MAYBE_DECLARE_RTBL(Spec_S,11,11)
718 MAYBE_DECLARE_RTBL(Spec_S,12,12)
719
720 #define SPEC_S_RTBL(size,ptrs)                                                  \
721     const W_ MK_REP_LBL(Spec_S,size,ptrs)[] = {                                 \
722         INCLUDE_TYPE_INFO(SPEC_S)                                               \
723         INCLUDE_SIZE_INFO(size,ptrs)                                            \
724         INCLUDE_PAR_INFO                                                        \
725         INCLUDE_COPYING_INFO(CAT2(_Evacuate_,size),CAT4(_Scavenge_,size,_,ptrs)) \
726         SPEC_COMPACTING_INFO(CAT4(_ScanLink_,size,_,ptrs),                      \
727                              CAT2(_PRStart_,ptrs),                              \
728                              CAT2(_ScanMove_,size),CAT2(_PRIn_,ptrs))           \
729         }
730
731 #ifdef PAR
732 # define SPEC_U_ITBL(infolbl,entry_code,upd_code,liveness,tag,size,ptrs,localness,entry_localness,kind,descr,type) \
733     entry_localness(CAT2(RBH_,entry_code));     \
734     localness W_ infolbl[];                     \
735      localness W_ CAT2(RBH_,infolbl)[] = {      \
736         (W_) CAT2(RBH_,entry_code)              \
737         ,(W_) INFO_OTHER_TAG                    \
738         ,(W_) MK_REP_REF(Spec_RBH,size,ptrs)    \
739         INCLUDE_PROFILING_INFO(RBH)             \
740         INCLUDE_SPEC_PADDING                    \
741         INCLUDE_RBH_INFO(infolbl)               \
742         };                                      \
743     STGFUN(CAT2(RBH_,entry_code)) { JMP_(RBH_entry); }\
744     CAT_DECLARE(infolbl,kind,descr,type)        \
745     entry_localness(entry_code);                \
746     localness W_ infolbl[] = {                  \
747         (W_) entry_code                         \
748         ,(W_) tag                               \
749         ,(W_) MK_REP_REF(Spec_U,size,ptrs)      \
750         INCLUDE_PROFILING_INFO(infolbl)         \
751         INCLUDE_SPEC_PADDING                    \
752         INCLUDE_RBH_INFO(CAT2(RBH_,infolbl))    \
753         }
754
755 MAYBE_DECLARE_RTBL(Spec_RBH,1,0)
756 MAYBE_DECLARE_RTBL(Spec_RBH,1,1)
757 MAYBE_DECLARE_RTBL(Spec_RBH,2,0)
758 MAYBE_DECLARE_RTBL(Spec_RBH,2,1)
759 MAYBE_DECLARE_RTBL(Spec_RBH,2,2)
760 MAYBE_DECLARE_RTBL(Spec_RBH,3,0)
761 MAYBE_DECLARE_RTBL(Spec_RBH,3,1)
762 MAYBE_DECLARE_RTBL(Spec_RBH,3,2)
763 MAYBE_DECLARE_RTBL(Spec_RBH,3,3)
764 MAYBE_DECLARE_RTBL(Spec_RBH,4,0)
765 MAYBE_DECLARE_RTBL(Spec_RBH,4,4)
766 MAYBE_DECLARE_RTBL(Spec_RBH,5,0)
767 MAYBE_DECLARE_RTBL(Spec_RBH,5,5)
768 MAYBE_DECLARE_RTBL(Spec_RBH,6,6)
769 MAYBE_DECLARE_RTBL(Spec_RBH,7,7)
770 MAYBE_DECLARE_RTBL(Spec_RBH,8,8)
771 MAYBE_DECLARE_RTBL(Spec_RBH,9,9)
772 MAYBE_DECLARE_RTBL(Spec_RBH,10,10)
773 MAYBE_DECLARE_RTBL(Spec_RBH,11,11)
774 MAYBE_DECLARE_RTBL(Spec_RBH,12,12)
775
776 #define SPEC_RBH_RTBL(size,ptrs)                                                \
777     const W_ MK_REP_LBL(Spec_RBH,size,ptrs)[] = {                               \
778         INCLUDE_TYPE_INFO(SPEC_RBH)                                             \
779         INCLUDE_SIZE_INFO(size,ptrs)                                            \
780         INCLUDE_PAR_INFO                                                        \
781         INCLUDE_COPYING_INFO(CAT2(_Evacuate_RBH_,size),CAT4(_Scavenge_RBH_,size,_,ptrs)) \
782         SPEC_COMPACTING_INFO(CAT4(_ScanLink_RBH_,size,_,ptrs),                  \
783                              CAT2(_PRStart_RBH_,ptrs),                          \
784                              CAT2(_ScanMove_RBH_,size),CAT2(_PRIn_RBH_,ptrs))   \
785         }
786
787 #define _Scavenge_RBH_2_0   _Scavenge_RBH_2_1
788 #define _Scavenge_RBH_2_2   _Scavenge_RBH_2_1
789
790 #define _Scavenge_RBH_3_0   _Scavenge_RBH_3_1
791 #define _Scavenge_RBH_3_2   _Scavenge_RBH_3_1
792
793 #define _Scavenge_RBH_4_0   _Scavenge_RBH_4_1
794 #define _Scavenge_RBH_5_0   _Scavenge_RBH_5_1
795 #define _Scavenge_RBH_6_0   _Scavenge_RBH_6_1
796 #define _Scavenge_RBH_7_0   _Scavenge_RBH_7_1
797 #define _Scavenge_RBH_8_0   _Scavenge_RBH_8_1
798 #define _Scavenge_RBH_9_0   _Scavenge_RBH_9_1
799 #define _Scavenge_RBH_10_0   _Scavenge_RBH_10_1
800 #define _Scavenge_RBH_11_0   _Scavenge_RBH_11_1
801 #define _Scavenge_RBH_12_0   _Scavenge_RBH_12_1
802
803 #define _ScanLink_RBH_2_0   _ScanLink_RBH_2_1
804 #define _ScanLink_RBH_2_2   _ScanLink_RBH_2_1
805
806 #define _ScanLink_RBH_3_0   _ScanLink_RBH_3_1
807 #define _ScanLink_RBH_3_2   _ScanLink_RBH_3_1
808
809 #define _ScanLink_RBH_4_0   _ScanLink_RBH_4_1
810 #define _ScanLink_RBH_5_0   _ScanLink_RBH_5_1
811 #define _ScanLink_RBH_6_0   _ScanLink_RBH_6_1
812 #define _ScanLink_RBH_7_0   _ScanLink_RBH_7_1
813 #define _ScanLink_RBH_8_0   _ScanLink_RBH_8_1
814 #define _ScanLink_RBH_9_0   _ScanLink_RBH_9_1
815 #define _ScanLink_RBH_10_0   _ScanLink_RBH_10_1
816 #define _ScanLink_RBH_11_0   _ScanLink_RBH_11_1
817 #define _ScanLink_RBH_12_0   _ScanLink_RBH_12_1
818
819 #define _PRStart_RBH_0  _PRStart_RBH_2
820 #define _PRStart_RBH_1  _PRStart_RBH_2
821
822 #define _PRIn_RBH_0     _PRIn_RBH_2
823 #define _PRIn_RBH_1     _PRIn_RBH_2
824
825 #else
826
827 # define SPEC_U_ITBL(infolbl,entry_code,upd_code,liveness,tag,size,ptrs,localness,entry_localness,kind,descr,type) \
828     CAT_DECLARE(infolbl,kind,descr,type)        \
829     entry_localness(entry_code);                \
830     localness W_ infolbl[] = {                  \
831         (W_) entry_code                         \
832         ,(W_) tag                               \
833         ,(W_) MK_REP_REF(Spec_U,size,ptrs)      \
834         INCLUDE_PROFILING_INFO(infolbl)         \
835         }
836 #endif
837
838 MAYBE_DECLARE_RTBL(Spec_U,1,0)
839 MAYBE_DECLARE_RTBL(Spec_U,1,1)
840 MAYBE_DECLARE_RTBL(Spec_U,2,0)
841 MAYBE_DECLARE_RTBL(Spec_U,2,1)
842 MAYBE_DECLARE_RTBL(Spec_U,2,2)
843 MAYBE_DECLARE_RTBL(Spec_U,3,0)
844 MAYBE_DECLARE_RTBL(Spec_U,3,1)
845 MAYBE_DECLARE_RTBL(Spec_U,3,2)
846 MAYBE_DECLARE_RTBL(Spec_U,3,3)
847 MAYBE_DECLARE_RTBL(Spec_U,4,0)
848 MAYBE_DECLARE_RTBL(Spec_U,4,4)
849 MAYBE_DECLARE_RTBL(Spec_U,5,0)
850 MAYBE_DECLARE_RTBL(Spec_U,5,5)
851 MAYBE_DECLARE_RTBL(Spec_U,6,6)
852 MAYBE_DECLARE_RTBL(Spec_U,7,7)
853 MAYBE_DECLARE_RTBL(Spec_U,8,8)
854 MAYBE_DECLARE_RTBL(Spec_U,9,9)
855 MAYBE_DECLARE_RTBL(Spec_U,10,10)
856 MAYBE_DECLARE_RTBL(Spec_U,11,11)
857 MAYBE_DECLARE_RTBL(Spec_U,12,12)
858
859 #define SPEC_U_RTBL(size,ptrs)                                                  \
860     const W_ MK_REP_LBL(Spec_U,size,ptrs)[] = {                                 \
861         INCLUDE_TYPE_INFO(SPEC_U)                                               \
862         INCLUDE_SIZE_INFO(size,ptrs)                                            \
863         INCLUDE_PAR_INFO                                                        \
864         INCLUDE_COPYING_INFO(CAT2(_Evacuate_,size),CAT4(_Scavenge_,size,_,ptrs)) \
865         SPEC_COMPACTING_INFO(CAT4(_ScanLink_,size,_,ptrs),                      \
866                              CAT2(_PRStart_,ptrs),                              \
867                              CAT2(_ScanMove_,size),CAT2(_PRIn_,ptrs))           \
868         }
869
870 \end{code}
871
872 %************************************************************************
873 %*                                                                      *
874 \subsection[SELECT_ITBL]{@SELECT_ITBL@: Special @SPEC_U@ info-table for selectors}
875 %*                                                                      *
876 %************************************************************************
877
878 These are different only in having slightly-magic GC code.  The idea
879 is: it is a @MIN_UPD_SIZE@ (==2) thunk with one pointer, which, when
880 entered, will select word $i$ from its pointee.
881
882 When garbage-collecting such a closure, we ``peek'' at the pointee's
883 tag (in its info table).  If it is evaluated, then we go ahead and do
884 the selection---which is {\em just like an indirection}.  If it is not
885 evaluated, we carry on {\em exactly as if it is a size-2/1-ptr thunk}.
886
887 Copying: only the evacuate routine needs to be special.
888
889 Compacting: only the PRStart (marking) routine needs to be special.
890
891 \begin{code}
892
893 #ifdef PAR
894 # define SELECT_ITBL(infolbl,entry_code,upd_code,liveness,tag,size,ptrs,localness,entry_localness,select_word_i,kind,descr,type) \
895     entry_localness(CAT2(RBH_,entry_code));     \
896     localness W_ infolbl[];                     \
897     localness W_ CAT2(RBH_,infolbl)[] = {       \
898         (W_) CAT2(RBH_,entry_code)              \
899         ,(W_) INFO_OTHER_TAG                    \
900         ,(W_) MK_REP_REF(Spec_RBH,size,ptrs)    \
901         INCLUDE_PROFILING_INFO(RBH)             \
902         INCLUDE_SPEC_PADDING                    \
903         INCLUDE_RBH_INFO(infolbl)               \
904         };                                      \
905     STGFUN(CAT2(RBH_,entry_code)) { JMP_(RBH_entry); }\
906     CAT_DECLARE(infolbl,kind,descr,type)        \
907     entry_localness(entry_code);                \
908     localness W_ infolbl[] = {                  \
909         (W_) entry_code                         \
910         ,(W_) tag                               \
911         ,(W_) MK_REP_REF(Select,,select_word_i) \
912         INCLUDE_PROFILING_INFO(infolbl)         \
913         INCLUDE_SPEC_PADDING                    \
914         INCLUDE_RBH_INFO(CAT2(RBH_,infolbl))    \
915         }                                       \
916
917 #else
918
919 # define SELECT_ITBL(infolbl,entry_code,upd_code,liveness,tag,size,ptrs,localness,entry_localness,select_word_i,kind,descr,type) \
920     CAT_DECLARE(infolbl,kind,descr,type)        \
921     entry_localness(entry_code);                \
922     localness W_ infolbl[] = {                  \
923         (W_) entry_code                         \
924         ,(W_) tag                               \
925         ,(W_) MK_REP_REF(Select,,select_word_i) \
926         INCLUDE_PROFILING_INFO(infolbl)         \
927         }
928
929 #endif
930
931 MAYBE_DECLARE_RTBL(Select,,0)
932 MAYBE_DECLARE_RTBL(Select,,1)
933 MAYBE_DECLARE_RTBL(Select,,2)
934 MAYBE_DECLARE_RTBL(Select,,3)
935 MAYBE_DECLARE_RTBL(Select,,4)
936 MAYBE_DECLARE_RTBL(Select,,5)
937 MAYBE_DECLARE_RTBL(Select,,6)
938 MAYBE_DECLARE_RTBL(Select,,7)
939 MAYBE_DECLARE_RTBL(Select,,8)
940 MAYBE_DECLARE_RTBL(Select,,9)
941 MAYBE_DECLARE_RTBL(Select,,10)
942 MAYBE_DECLARE_RTBL(Select,,11)
943 MAYBE_DECLARE_RTBL(Select,,12)
944
945 #define SELECT_RTBL(size,ptrs,select_word_i)                                    \
946     const W_ MK_REP_LBL(Select,,select_word_i)[] = {                            \
947         INCLUDE_TYPE_INFO(SPEC_U)                                               \
948         INCLUDE_SIZE_INFO(size,ptrs)                                            \
949         INCLUDE_PAR_INFO                                                        \
950         INCLUDE_COPYING_INFO(CAT2(_EvacuateSelector_,select_word_i),            \
951                              CAT4(_Scavenge_,size,_,ptrs))                      \
952         SPEC_COMPACTING_INFO(CAT4(_ScanLink_,size,_,ptrs),                      \
953                              CAT2(_PRStartSelector_,select_word_i),             \
954                              CAT2(_ScanMove_,size),                             \
955                              CAT2(_PRIn_,ptrs))                                 \
956         }
957
958 \end{code}
959
960 %************************************************************************
961 %*                                                                      *
962 \subsection[GEN_ITBL]{@GEN_x_ITBL@: Generic/general? info-tables}
963 %*                                                                      *
964 %************************************************************************
965
966 @GEN@ info-table for non-updatable nodes (normal and non-normal forms).
967
968 Size/no-of-ptrs are known at compile time, but we don't have GC
969 routines wired in for those specific sizes.  Hence the size/no-of-ptrs
970 is stored in the info-table.
971
972 \begin{code}
973
974 #define GEN_N_ITBL(infolbl,entry_code,upd_code,liveness,tag,size,ptrs,localness,entry_localness,kind,descr,type) \
975     CAT_DECLARE(infolbl,kind,descr,type)        \
976     entry_localness(entry_code);                \
977     localness W_ infolbl[] = {                  \
978         (W_) entry_code                         \
979         ,(W_) tag                               \
980         ,(W_) MK_REP_REF(Gen_N,,)               \
981         INCLUDE_PROFILING_INFO(infolbl)         \
982         INCLUDE_UPDATE_INFO(upd_code,liveness)  \
983         INCLUDE_GEN_INFO(size,ptrs)             \
984         }
985
986 MAYBE_DECLARE_RTBL(Gen_N,,)
987
988 #define GEN_N_RTBL()                                                            \
989     const W_ MK_REP_LBL(Gen_N,,)[] = {                                          \
990         INCLUDE_TYPE_INFO(GEN_N)                                                \
991         INCLUDE_SIZE_INFO(INFO_UNUSED,INFO_UNUSED) /* NB: in info table */      \
992         INCLUDE_PAR_INFO                                                        \
993         INCLUDE_COPYING_INFO(_Evacuate_S,_Scavenge_S_N)                         \
994         INCLUDE_COMPACTING_INFO(_ScanLink_S_N,_PRStart_N,_ScanMove_S,_PRIn_I)   \
995         }
996
997 #define GEN_S_ITBL(infolbl,entry_code,upd_code,liveness,tag,size,ptrs,localness,entry_localness,kind,descr,type) \
998     CAT_DECLARE(infolbl,kind,descr,type)        \
999     entry_localness(entry_code);                \
1000     localness W_ infolbl[] = {                  \
1001         (W_) entry_code                         \
1002         ,(W_) tag                               \
1003         ,(W_) MK_REP_REF(Gen_S,,)               \
1004         INCLUDE_PROFILING_INFO(infolbl)         \
1005         INCLUDE_UPDATE_INFO(upd_code,liveness)  \
1006         INCLUDE_GEN_INFO(size,ptrs)             \
1007         }
1008
1009 MAYBE_DECLARE_RTBL(Gen_S,,)
1010
1011 #define GEN_S_RTBL()                                                            \
1012     const W_ MK_REP_LBL(Gen_S,,)[] = {                                          \
1013         INCLUDE_TYPE_INFO(GEN_S)                                                \
1014         INCLUDE_SIZE_INFO(INFO_UNUSED,INFO_UNUSED) /* NB: in info table */      \
1015         INCLUDE_PAR_INFO                                                        \
1016         INCLUDE_COPYING_INFO(_Evacuate_S,_Scavenge_S_N)                         \
1017         INCLUDE_COMPACTING_INFO(_ScanLink_S_N,_PRStart_N,_ScanMove_S,_PRIn_I)   \
1018         }
1019
1020 #ifdef PAR
1021 # define GEN_U_ITBL(infolbl,entry_code,upd_code,liveness,tag,size,ptrs,localness,entry_localness,kind,descr,type) \
1022     entry_localness(CAT2(RBH_,entry_code));     \
1023     localness W_ infolbl[];                     \
1024     localness W_ CAT2(RBH_,infolbl)[] = {       \
1025         (W_) CAT2(RBH_,entry_code)              \
1026         ,(W_) INFO_OTHER_TAG                    \
1027         ,(W_) MK_REP_REF(Gen_RBH,,)             \
1028         INCLUDE_PROFILING_INFO(RBH)             \
1029         INCLUDE_UPDATE_INFO(INFO_UNUSED,INFO_UNUSED)    \
1030         INCLUDE_GEN_INFO(size,ptrs)             \
1031         INCLUDE_RBH_INFO(infolbl)               \
1032         };                                      \
1033     STGFUN(CAT2(RBH_,entry_code)) { JMP_(RBH_entry); }\
1034     CAT_DECLARE(infolbl,kind,descr,type)        \
1035     entry_localness(entry_code);                \
1036     localness W_ infolbl[] = {                  \
1037         (W_) entry_code                         \
1038         ,(W_) tag                               \
1039         ,(W_) MK_REP_REF(Gen_U,,)               \
1040         INCLUDE_PROFILING_INFO(infolbl)         \
1041         INCLUDE_UPDATE_INFO(INFO_UNUSED,INFO_UNUSED)    \
1042         INCLUDE_GEN_INFO(size,ptrs)             \
1043         INCLUDE_RBH_INFO(CAT2(RBH_,infolbl))    \
1044         }
1045
1046 MAYBE_DECLARE_RTBL(Gen_RBH,,)
1047
1048 # define GEN_RBH_RTBL()                                                         \
1049     const W_ MK_REP_LBL(Gen_RBH,,)[] = {                                        \
1050         INCLUDE_TYPE_INFO(GEN_RBH)                                              \
1051         INCLUDE_SIZE_INFO(INFO_UNUSED,INFO_UNUSED) /* NB: no size/no-ptrs! */   \
1052         INCLUDE_PAR_INFO                                                        \
1053         INCLUDE_COPYING_INFO(_Evacuate_RBH_S,_Scavenge_RBH_N)                   \
1054         INCLUDE_COMPACTING_INFO(_ScanLink_RBH_N,_PRStart_RBH_N,_ScanMove_RBH_S,_PRIn_RBH_I)     \
1055         }
1056
1057 #else
1058
1059 # define GEN_U_ITBL(infolbl,entry_code,upd_code,liveness,tag,size,ptrs,localness,entry_localness,kind,descr,type) \
1060     CAT_DECLARE(infolbl,kind,descr,type)        \
1061     entry_localness(entry_code);                \
1062     localness W_ infolbl[] = {                  \
1063         (W_) entry_code                         \
1064         ,(W_) tag                               \
1065         ,(W_) MK_REP_REF(Gen_U,,)               \
1066         INCLUDE_PROFILING_INFO(infolbl)         \
1067         INCLUDE_UPDATE_INFO(INFO_UNUSED,INFO_UNUSED)    \
1068         INCLUDE_GEN_INFO(size,ptrs)             \
1069         }
1070 #endif
1071
1072 MAYBE_DECLARE_RTBL(Gen_U,,)
1073
1074 #define GEN_U_RTBL()                                                            \
1075     const W_ MK_REP_LBL(Gen_U,,)[] = {                                          \
1076         INCLUDE_TYPE_INFO(GEN_U)                                                \
1077         INCLUDE_SIZE_INFO(INFO_UNUSED,INFO_UNUSED) /* NB: no size/no-ptrs! */   \
1078         INCLUDE_PAR_INFO                                                        \
1079         INCLUDE_COPYING_INFO(_Evacuate_S,_Scavenge_S_N)                         \
1080         INCLUDE_COMPACTING_INFO(_ScanLink_S_N,_PRStart_N,_ScanMove_S,_PRIn_I)   \
1081         }
1082
1083 \end{code}
1084
1085 %************************************************************************
1086 %*                                                                      *
1087 \subsection[DYN_ITBL]{Dynamic-object info tables}
1088 %*                                                                      *
1089 %************************************************************************
1090
1091 For these, the size/no-of-pointers is not known until runtime.  E.g.,
1092 arrays.  Those fields are, therefore, in the closure itself, and not
1093 in the info table.
1094
1095 All @DYN@ closures are @PAP@s, so they are not updatable.
1096
1097 \begin{code}
1098
1099 #define DYN_ITBL(infolbl,entry_code,upd_code,liveness,tag,size,ptrs,localness,entry_localness,kind,descr,type) /*size,ptrs unused*/ \
1100     CAT_DECLARE(infolbl,kind,descr,type)        \
1101     entry_localness(entry_code);                \
1102     localness W_ infolbl[] = {                  \
1103         (W_) entry_code                         \
1104         ,(W_) tag                               \
1105         ,(W_) MK_REP_LBL(Dyn,,)                 \
1106         INCLUDE_PROFILING_INFO(infolbl)         \
1107         }
1108
1109 MAYBE_DECLARE_RTBL(Dyn,,)
1110
1111 #define DYN_RTBL()                                                      \
1112     const W_ MK_REP_LBL(Dyn,,)[] = {                                    \
1113         INCLUDE_TYPE_INFO(DYN)                                          \
1114         INCLUDE_SIZE_INFO(INFO_UNUSED,INFO_UNUSED) /* in closure! */    \
1115         INCLUDE_PAR_INFO                                                \
1116         INCLUDE_COPYING_INFO(_Evacuate_Dyn,_Scavenge_Dyn)               \
1117         INCLUDE_COMPACTING_INFO(_ScanLink_Dyn,_PRStart_Dyn,_ScanMove_Dyn,_PRIn_I_Dyn) \
1118         }
1119
1120 \end{code}
1121
1122 %************************************************************************
1123 %*                                                                      *
1124 \subsection[TUPLE_ITBL]{``Tuple'' and ``Data'' info-tables}
1125 %*                                                                      *
1126 %************************************************************************
1127
1128 ``Tuples'' are essentially DYNs with all pointers (no non-pointers).
1129 ``Data things'' are DYNs with all non-pointers.
1130
1131 \begin{code}
1132
1133 #define TUPLE_ITBL(infolbl,entry_code,upd_code,liveness,tag,size,ptrs,localness,entry_localness,kind,descr,type) /*size,ptrs unused*/ \
1134     CAT_DECLARE(infolbl,kind,descr,type)        \
1135     entry_localness(entry_code);                \
1136     localness W_ infolbl[] = {                  \
1137         (W_) entry_code                         \
1138         ,(W_) tag                               \
1139         ,(W_) MK_REP_REF(Tuple,,)               \
1140         INCLUDE_PROFILING_INFO(infolbl)         \
1141         }
1142
1143 MAYBE_DECLARE_RTBL(Tuple,,)
1144
1145 #define TUPLE_RTBL() \
1146     const W_ MK_REP_LBL(Tuple,,)[] = { \
1147         INCLUDE_TYPE_INFO(TUPLE)                                        \
1148         INCLUDE_SIZE_INFO(INFO_UNUSED,INFO_UNUSED) /* NB: in closure */ \
1149         INCLUDE_PAR_INFO                                                \
1150         INCLUDE_COPYING_INFO(_Evacuate_Tuple,_Scavenge_Tuple) \
1151         INCLUDE_COMPACTING_INFO(_ScanLink_Tuple,_PRStart_Tuple,_ScanMove_Tuple,_PRIn_I_Tuple) \
1152         }
1153
1154 #define DATA_ITBL(infolbl,entry_code,upd_code,liveness,tag,size,ptrs,localness,entry_localness,kind,descr,type) /*size,ptrs unused*/ \
1155     CAT_DECLARE(infolbl,kind,descr,type)        \
1156     entry_localness(entry_code);                \
1157     localness W_ infolbl[] = {                  \
1158         (W_) entry_code                         \
1159         ,(W_) tag                               \
1160         ,(W_) MK_REP_REF(Data,,)                \
1161         INCLUDE_PROFILING_INFO(infolbl)         \
1162         }
1163
1164 MAYBE_DECLARE_RTBL(Data,,)
1165
1166 #define DATA_RTBL()                     \
1167     const W_ MK_REP_LBL(Data,,)[] = {   \
1168         INCLUDE_TYPE_INFO(DATA)         \
1169         INCLUDE_SIZE_INFO(INFO_UNUSED,INFO_UNUSED) /* NB: in closure */ \
1170         INCLUDE_PAR_INFO                 \
1171         INCLUDE_COPYING_INFO(_Evacuate_Data,_Scavenge_Data) \
1172         INCLUDE_COMPACTING_INFO(_ScanLink_Data,_PRStart_Data,_ScanMove_Data,_PRIn_Error) \
1173     }
1174
1175 /* Here is the decl for the only DATA info table used! */
1176 #ifndef COMPILING_GHC
1177 EXTDATA_RO(ArrayOfData_info);
1178 #endif
1179 \end{code}
1180
1181 %************************************************************************
1182 %*                                                                      *
1183 \subsection[MUTUPLE_ITBL]{Info-table for (im)mutable [array-ish] objects}
1184 %*                                                                      *
1185 %************************************************************************
1186
1187 ToDo: Integrate with PAR stuff (Kevin) !!
1188 If someone bothers to document this I'll see what I can do! KH
1189
1190 \begin{code}
1191
1192 #if defined(GC_MUT_REQUIRED)
1193
1194 # define MUTUPLE_ITBL(infolbl,entry_code,upd_code,liveness,tag,size,ptrs,localness,entry_localness,kind,descr,type) /*size,ptrs unused*/ \
1195     CAT_DECLARE(infolbl,kind,descr,type)        \
1196     entry_localness(entry_code);                \
1197     localness W_ infolbl[] = {                  \
1198         (W_) entry_code                         \
1199         ,(W_) tag                               \
1200         ,(W_) MK_REP_REF(MuTuple,,)             \
1201         INCLUDE_PROFILING_INFO(infolbl)         \
1202         }
1203
1204 MAYBE_DECLARE_RTBL(MuTuple,,)
1205
1206 # define MUTUPLE_RTBL()                         \
1207     const W_ MK_REP_LBL(MuTuple,,)[] = {        \
1208         INCLUDE_TYPE_INFO(MUTUPLE)              \
1209         INCLUDE_SIZE_INFO(INFO_UNUSED,INFO_UNUSED) /* NB: in closure! */ \
1210         INCLUDE_PAR_INFO                         \
1211         INCLUDE_COPYING_INFO(_Evacuate_MuTuple,_Scavenge_MuTuple) \
1212         INCLUDE_COMPACTING_INFO(_ScanLink_MuTuple,_PRStart_MuTuple,_ScanMove_MuTuple,_PRIn_I_MuTuple) \
1213         }
1214
1215 # define IMMUTUPLE_ITBL(infolbl,entry_code,upd_code,liveness,tag,size,ptrs,localness,entry_localness,kind,descr,type) /*size,ptrs unused*/ \
1216     CAT_DECLARE(infolbl,kind,descr,type)        \
1217     entry_localness(entry_code);                \
1218     localness W_ infolbl[] = {                  \
1219         (W_) entry_code                         \
1220         ,(W_) tag                               \
1221         ,(W_) MK_REP_REF(ImmuTuple,,)           \
1222         INCLUDE_PROFILING_INFO(infolbl)         \
1223         }
1224
1225 MAYBE_DECLARE_RTBL(ImmuTuple,,)
1226
1227 # define IMMUTUPLE_RTBL() \
1228     const W_ MK_REP_LBL(ImmuTuple,,)[] = {  \
1229         INCLUDE_TYPE_INFO(IMMUTUPLE)        \
1230         INCLUDE_SIZE_INFO(INFO_UNUSED,INFO_UNUSED) /* NB: in closure! */ \
1231         INCLUDE_PAR_INFO                         \
1232         INCLUDE_COPYING_INFO(_Evacuate_MuTuple,_Scavenge_MuTuple) \
1233         INCLUDE_COMPACTING_INFO(_ScanLink_MuTuple,_PRStart_MuTuple,_ScanMove_ImmuTuple,_PRIn_I_MuTuple) \
1234     }
1235   
1236 #else   /* ! GC_MUT_REQUIRED --- define as TUPLE closure */
1237
1238 # define MUTUPLE_ITBL(infolbl,entry_code,upd_code,liveness,tag,size,ptrs,localness,entry_localness,kind,descr,type) \
1239         TUPLE_ITBL(infolbl,entry_code,upd_code,liveness,tag,size,ptrs,localness,entry_localness,kind,descr,type)
1240 # define IMMUTUPLE_ITBL(infolbl,entry_code,upd_code,liveness,tag,size,ptrs,localness,entry_localness,kind,descr,type) \
1241         TUPLE_ITBL(infolbl,entry_code,upd_code,liveness,tag,size,ptrs,localness,entry_localness,kind,descr,type)
1242
1243 # define MUTUPLE_RTBL()
1244 # define IMMUTUPLE_RTBL()
1245 #endif
1246
1247 /* Here are the decls for the only MUTUPLE info tables used. */
1248 #ifndef COMPILING_GHC
1249 EXTDATA_RO(ArrayOfPtrs_info);
1250 EXTDATA_RO(ImMutArrayOfPtrs_info);
1251 EXTDATA_RO(EmptySVar_info);
1252 EXTDATA_RO(FullSVar_info);
1253 #endif
1254 \end{code}
1255
1256 %************************************************************************
1257 %*                                                                      *
1258 \subsection[STATIC_ITBL]{Info tables for static objects (outside the heap)}
1259 %*                                                                      *
1260 %************************************************************************
1261
1262 Size and ptrs fields are used by interpretive code, such as @ghci@,
1263 the parallel Pack code (@Pack.lc@) and possibly to-be-written debug
1264 code.
1265
1266 \begin{code}
1267
1268 #define STATIC_ITBL(infolbl,entry_code,upd_code,liveness,tag,size,ptrs,localness,entry_localness,kind,descr,type) \
1269     CAT_DECLARE(infolbl,kind,descr,type)        \
1270     entry_localness(entry_code);                \
1271     localness W_ infolbl[] = {                  \
1272         (W_) entry_code                         \
1273         ,(W_) tag                               \
1274         ,(W_) MK_REP_REF(Static,,)              \
1275         INCLUDE_PROFILING_INFO(infolbl)         \
1276         INCLUDE_UPDATE_INFO(upd_code,liveness)  \
1277         INCLUDE_STATIC_INFO(size,ptrs)          \
1278         }
1279
1280 MAYBE_DECLARE_RTBL(Static,,)
1281
1282 #define STATIC_RTBL() \
1283     const W_ MK_REP_LBL(Static,,)[] = { \
1284         INCLUDE_TYPE_INFO(STATIC)       \
1285         INCLUDE_SIZE_INFO(INFO_UNUSED,INFO_UNUSED) /* NB: in info table! */ \
1286         INCLUDE_PAR_INFO                 \
1287         INCLUDE_COPYING_INFO(_Evacuate_Static,_Scavenge_Static) \
1288         INCLUDE_COMPACTING_INFO(_Dummy_Static_entry,_PRStart_Static, \
1289                                 _Dummy_Static_entry,_Dummy_Static_entry) \
1290         }
1291
1292 \end{code}
1293
1294 %************************************************************************
1295 %*                                                                      *
1296 \subsection[MallocPtr_ITBL]{@MallocPtr_TBL@: @MallocPtr@ info-table}
1297 %*                                                                      *
1298 %************************************************************************
1299
1300 The following table is a bit like that for @SPEC@ with 0 pointers and
1301 a small number of non-ptrs.  However, the garbage collection routines
1302 are a bit special.
1303
1304 I'm assuming @SPEC_N@, so that we don't need to pad out the info table. (JSM)
1305
1306 \begin{code}
1307 #if !defined(PAR)
1308
1309 # define MallocPtr_ITBL(infolbl,entry_code,upd_code,liveness,tag,size,ptrs,localness,entry_localness,kind,descr,type) /*size,ptrs unused*/ \
1310     CAT_DECLARE(infolbl,kind,descr,type)        \
1311     entry_localness(entry_code);                \
1312     localness W_ infolbl[] = {                  \
1313         (W_) entry_code                         \
1314         ,(W_) tag                               \
1315         ,(W_) MK_REP_REF(MallocPtr,,)           \
1316         INCLUDE_PROFILING_INFO(infolbl)         \
1317     }
1318
1319 MAYBE_DECLARE_RTBL(MallocPtr,,)
1320
1321 # define MallocPtr_RTBL() \
1322     const W_ MK_REP_LBL(MallocPtr,,)[] = { \
1323         INCLUDE_TYPE_INFO(INTERNAL)                             \
1324         INCLUDE_SIZE_INFO(MallocPtr_SIZE, 0L)                   \
1325         INCLUDE_PAR_INFO                                        \
1326         INCLUDE_COPYING_INFO(_Evacuate_MallocPtr,_Scavenge_MallocPtr)   \
1327         SPEC_COMPACTING_INFO(_ScanLink_MallocPtr,_PRStart_MallocPtr,_ScanMove_MallocPtr,_PRIn_0) \
1328         }
1329
1330 #endif /* !PAR */
1331 \end{code}
1332
1333 %************************************************************************
1334 %*                                                                      *
1335 \subsection[BH_ITBL]{Info tables for ``black holes''}
1336 %*                                                                      *
1337 %************************************************************************
1338
1339 Special info-table for black holes. It is possible to describe these
1340 using @SPEC@ closures but this requires explicit use of the value of
1341 @MIN_UPD_SIZE@. For now we have a special macro and code.
1342
1343 \begin{code}
1344
1345 #define BH_ITBL(infolbl,bh_code,kind,localness,entry_localness) \
1346     entry_localness(bh_code);                   \
1347     localness W_ infolbl[] = {                  \
1348         (W_) bh_code                            \
1349         ,(W_) INFO_OTHER_TAG                    \
1350         ,(W_) MK_REP_REF(BH,kind,)              \
1351         INCLUDE_PROFILING_INFO(BH)              \
1352     }
1353
1354 MAYBE_DECLARE_RTBL(BH,U,)
1355 MAYBE_DECLARE_RTBL(BH,N,)
1356
1357 #define BH_U_SIZE   MIN_UPD_SIZE
1358 #define BH_N_SIZE   MIN_NONUPD_SIZE
1359 #define BH_RTBL(kind)                                                           \
1360     const W_ MK_REP_LBL(BH,kind,)[] = {                                         \
1361         INCLUDE_TYPE_INFO(BH)                                                   \
1362         INCLUDE_SIZE_INFO(CAT3(BH_,kind,_SIZE),0L)                              \
1363         INCLUDE_PAR_INFO                                                        \
1364         INCLUDE_COPYING_INFO(CAT2(_Evacuate_BH_,kind),CAT2(_Scavenge_BH_,kind)) \
1365         INCLUDE_COMPACTING_INFO(CAT2(_ScanLink_BH_,kind),_PRStart_BH,           \
1366                                 CAT2(_ScanMove_BH_,kind),_PRIn_Error)           \
1367     }
1368
1369 \end{code}
1370
1371 %************************************************************************
1372 %*                                                                      *
1373 \subsection[IND_ITBL]{Info table for indirections}
1374 %*                                                                      *
1375 %************************************************************************
1376
1377 An indirection simply extracts the pointer from the
1378 @IND_CLOSURE_PTR(closure)@ field. The garbage collection routines will
1379 short out the indirection.
1380 \begin{code}
1381
1382 #define IND_ITBL(infolbl,ind_code,localness,entry_localness) \
1383     CAT_DECLARE(infolbl,INTERNAL_KIND,"IND","IND")      \
1384     entry_localness(ind_code);                          \
1385     localness W_ infolbl[] = {                          \
1386         (W_) ind_code                                   \
1387         ,(W_) INFO_IND_TAG                              \
1388         ,(W_) MK_REP_REF(Ind,,)                         \
1389         INCLUDE_PROFILING_INFO(infolbl)                 \
1390         }
1391
1392 MAYBE_DECLARE_RTBL(Ind,,)
1393
1394 #define IND_RTBL()                                                              \
1395     const W_ MK_REP_LBL(Ind,,)[] = {                                            \
1396         INCLUDE_TYPE_INFO(IND)                                                  \
1397         INCLUDE_SIZE_INFO(MIN_UPD_SIZE,INFO_UNUSED) /* #ptrs not here! */       \
1398         INCLUDE_PAR_INFO                                                        \
1399         INCLUDE_COPYING_INFO(_Evacuate_Ind,_Scavenge_Ind)                       \
1400         INCLUDE_COMPACTING_INFO(_Dummy_Ind_entry,_PRStart_Ind,                  \
1401                                 _Dummy_Ind_entry,_Dummy_Ind_entry)              \
1402     }
1403
1404 \end{code}
1405
1406 Lexical-scoped profiling (now more-or-less the default... 94/06)
1407 requires a special permanent indirection for PAP closures.  These 
1408 look exactly like regular indirections, but they are not short-circuited
1409 on garbage collection.
1410
1411 \begin{code}
1412 #if defined(USE_COST_CENTRES)
1413
1414 # define PERM_IND_ITBL(infolbl,ind_code,localness,entry_localness) \
1415     entry_localness(ind_code);                          \
1416     CAT_DECLARE(infolbl,INTERNAL_KIND,"IND","IND")      \
1417     localness W_ infolbl[] = {                          \
1418         (W_) ind_code                                   \
1419         ,(W_) INFO_IND_TAG                              \
1420         ,(W_) MK_REP_REF(Perm_Ind,,)                    \
1421         INCLUDE_PROFILING_INFO(infolbl)                 \
1422     }
1423
1424 MAYBE_DECLARE_RTBL(Perm_Ind,,)
1425
1426 # define PERM_IND_RTBL()                                                        \
1427     const W_ MK_REP_LBL(Perm_Ind,,)[] = {                                       \
1428         INCLUDE_TYPE_INFO(IND)                                                  \
1429         INCLUDE_SIZE_INFO(MIN_UPD_SIZE,INFO_UNUSED) /* #ptrs not here! */       \
1430         INCLUDE_PAR_INFO                                                        \
1431         INCLUDE_COPYING_INFO(_Evacuate_PI,_Scavenge_PI)                         \
1432         SPEC_COMPACTING_INFO(_ScanLink_PI,_PRStart_PI,                          \
1433                              _ScanMove_PI,_PRIn_PI)                             \
1434         }
1435
1436 #else
1437 # define PERM_IND_RTBL()
1438 #endif
1439 \end{code}
1440
1441 %************************************************************************
1442 %*                                                                      *
1443 \subsection[CAF_ITBL]{Info table for updated @CAF@s}
1444 %*                                                                      *
1445 %************************************************************************
1446
1447 Garbage collection of @CAF@s is tricky.  We have to cope with explicit
1448 collection from the @CAFlist@ as well as potential references from the
1449 stack and heap which will cause the @CAF@ evacuation code to be
1450 called.  They are treated like indirections which are shorted out.
1451 However they must also be updated to point to the new location of the
1452 new closure as the @CAF@ may still be used by references which
1453 reside in the code.
1454
1455 \subsubsection{Copying Collection}
1456
1457 A first scheme might use evacuation code which evacuates the reference
1458 and updates the indirection. This is no good as subsequent evacuations
1459 will result in an already evacuated closure being evacuated. This will
1460 leave a forward reference in to-space!
1461
1462 An alternative scheme evacuates the @CAFlist@ first. The closures
1463 referenced are evacuated and the @CAF@ indirection updated to point to
1464 the evacuated closure. The @CAF@ evacuation code simply returns the
1465 updated indirection pointer --- the pointer to the evacuated closure.
1466 Unfortunately the closure the @CAF@ references may be a static
1467 closure, in fact, it may be another @CAF@. This will cause the second
1468 @CAF@'s evacuation code to be called before the @CAF@ has been
1469 evacuated, returning an unevacuated pointer.
1470
1471 Another scheme leaves updating the @CAF@ indirections to the end
1472 of the garbage collection.
1473 All the references are evacuated and scavenged as usual (including the
1474 @CAFlist@). Once collection is complete the @CAFlist@ is traversed
1475 updating the @CAF@ references with the result of evacuating the
1476 referenced closure again. This will immediately return as it must be a
1477 forward reference, a static closure, or a @CAF@ which will indirect by
1478 evacuating its reference.
1479
1480 The crux of the problem is that the @CAF@ evacuation code needs to
1481 know if its reference has already been evacuated and updated. If not, then
1482 the reference can be evacuated, updated and returned safely (possibly
1483 evacuating another @CAF@). If it has, then the updated reference can be
1484 returned. This can be done using two @CAF@ info-tables. At the start
1485 of a collection the @CAFlist@ is traversed and set to an internal {\em
1486 evacuate and update} info-table. During collection, evacution of such a
1487 @CAF@ also results in the info-table being reset back to the standard
1488 @CAF@ {\em return reference} info-table. Thus subsequent evacuations
1489 will simply return the updated reference. On completion of the
1490 collection all @CAF@s will have {\em return reference} info-tables
1491 again.
1492
1493 This is the scheme we adopt. A @CAF@ indirection has evacuation code
1494 which returns the evacuated and updated reference. During garbage
1495 collection all the @CAF@s are overwritten with an internal @CAF@ info
1496 table which has evacuation code which performs this evacuate and
1497 update and restores the original @CAF@ code. At some point during the
1498 collection we must ensure that all the @CAF@s are indeed
1499 evacuated.
1500
1501 The only potential problem with this scheme is a cyclic list of @CAF@s
1502 all directly referencing (possibly via indirections) another @CAF@!
1503 Evacuation of the first @CAF@ will fail in an infinite loop of @CAF@
1504 evacuations. This is solved by ensuring that the @CAF@ info-table is
1505 updated to a {\em return reference} info-table before performing the
1506 evacuate and update. If this {\em return reference} evacuation code is
1507 called before the actual evacuation is complete it must be because
1508 such a cycle of references exists. Returning the still unevacuated
1509 reference is OK --- all the @CAF@s will now reference the same
1510 @CAF@ which will reference itself! Construction of such a structure
1511 indicates the program must be in an infinite loop.
1512
1513
1514 \subsubsection{Compacting Collector}
1515
1516 When shorting out a @CAF@, its reference must be marked. A first attempt
1517 might explicitly mark the @CAF@s, updating the reference with the
1518 marked reference (possibly short circuting indirections). The actual
1519 @CAF@ marking code can indicate that they have already been marked
1520 (though this might not have actually been done yet) and return the
1521 indirection pointer so it is shorted out. Unfortunately the @CAF@
1522 reference might point to an indirection which will be subsequently
1523 shorted out. Rather than returning the @CAF@ reference we treat the
1524 @CAF@ as an indirection, calling the mark code of the reference, which
1525 will return the appropriately shorted reference.
1526
1527 Problem: Cyclic list of @CAF@s all directly referencing (possibly via
1528 indirections) another @CAF@!
1529
1530 Before compacting, the locations of the @CAF@ references are
1531 explicitly linked to the closures they reference (if they reference
1532 heap allocated closures) so that the compacting process will update
1533 them to the closure's new location. Unfortunately these locations'
1534 @CAF@ indirections are static.  This causes premature termination
1535 since the test to find the info pointer at the end of the location
1536 list will match more than one value.  This can be solved by using an
1537 auxiliary dynamic array (on the top of the A stack).  One location for
1538 each @CAF@ indirection is linked to the closure that the @CAF@
1539 references. Once collection is complete this array is traversed and
1540 the corresponding @CAF@ is then updated with the updated pointer from
1541 the auxiliary array.
1542
1543 \begin{code}
1544
1545 #define CAF_ITBL(infolbl,ind_code,localness,entry_localness) \
1546     CAT_DECLARE(infolbl,INTERNAL_KIND,"CAF","CAF")      \
1547     entry_localness(ind_code);                          \
1548     localness W_ infolbl[] = {                          \
1549         (W_) ind_code                                   \
1550         ,(W_) INFO_IND_TAG                              \
1551         ,(W_) MK_REP_REF(Caf,,)                         \
1552         INCLUDE_PROFILING_INFO(infolbl)                 \
1553     }
1554
1555 MAYBE_DECLARE_RTBL(Caf,,)
1556
1557 #define CAF_RTBL()                                                              \
1558     const W_ MK_REP_LBL(Caf,,)[] = {                                            \
1559         INCLUDE_TYPE_INFO(CAF)                                                  \
1560         INCLUDE_SIZE_INFO(MIN_UPD_SIZE,INFO_UNUSED) /* #ptrs not here! */       \
1561         INCLUDE_PAR_INFO                                                        \
1562         INCLUDE_COPYING_INFO(_Evacuate_Caf,_Scavenge_Caf)                       \
1563         INCLUDE_COMPACTING_INFO(_Dummy_Caf_entry,_PRStart_Caf,                  \
1564                                 _Dummy_Caf_entry,_Dummy_Caf_entry)              \
1565         }
1566 \end{code}
1567
1568
1569 It is possible to use an alternative marking scheme, using a similar
1570 idea to the copying solution. This scheme avoids the need to update
1571 the @CAF@ references explicitly. We introduce an auxillary {\em mark
1572 and update} @CAF@ info-table which is used to update all @CAF@s at the
1573 start of a collection. The new code marks the @CAF@ reference,
1574 updating it with the returned reference.  The returned reference is
1575 itself returned so the @CAF@ is shorted out.  The code also modifies the
1576 @CAF@ info-table to be a {\em return reference}.  Subsequent attempts to
1577 mark the @CAF@ simply return the updated reference.
1578
1579 A cyclic @CAF@ reference will result in an attempt to mark the @CAF@
1580 before the marking has been completed and the reference updated. We
1581 cannot start marking the @CAF@ as it is already being marked. Nor can
1582 we return the reference as it has not yet been updated. Neither can we
1583 treat the CAF as an indirection since the @CAF@ reference has been
1584 obscured by the pointer reversal stack. All we can do is return the
1585 @CAF@ itself. This will result in some @CAF@ references not being
1586 shorted out.
1587
1588 This scheme has not been adopted but has been implemented. The code is
1589 commented out with @#if 0@.
1590
1591 %************************************************************************
1592 %*                                                                      *
1593 \subsection[CONST_ITBL]{@CONST_ITBL@}
1594 %*                                                                      *
1595 %************************************************************************
1596
1597 This declares an info table for @CONST@ closures (size 0). 
1598 It is the info table for a dynamicaly-allocated closure which
1599 will redirect references to the corresponding
1600 static closure @<infolbl>_closure@ during garbage collection. 
1601 A pointer to the static closure is kept in the info table.  (It is
1602 assumed that this closure is declared elsewhere.)
1603
1604 Why do such @CONST@ objects ever exist?  Why don't we just use the static
1605 object in the first place?  @CONST@ objects are used only for updating
1606 existing objects.  We could use an indirection, but that risks costing
1607 extra run-time indirections until the next gc shorts it out.  So
1608 we update with a @CONST@, and the next gc gets rid of it.
1609
1610 \begin{code}
1611
1612 #define CONST_ITBL(infolbl,closurelbl,entry_code,upd_code,liveness,tag,size,ptrs,localness,entry_localness,kind,descr,type) /*size,ptrs unused*/ \
1613     CAT_DECLARE(infolbl,kind,descr,type)        \
1614     entry_localness(entry_code);                \
1615     EXTDATA(closurelbl);                        \
1616     localness W_ infolbl[] = {                  \
1617         (W_) entry_code                         \
1618         ,(W_) tag                               \
1619         ,(W_) MK_REP_REF(Const,,)               \
1620         INCLUDE_PROFILING_INFO(infolbl)         \
1621         INCLUDE_UPDATE_INFO(upd_code,liveness)  \
1622         INCLUDE_CONST_INFO(closurelbl)          \
1623         }
1624
1625 MAYBE_DECLARE_RTBL(Const,,)
1626
1627 #define CONST_RTBL()                                                    \
1628     const W_ MK_REP_LBL(Const,,)[] = {                                  \
1629         INCLUDE_TYPE_INFO(CONST)                                        \
1630         INCLUDE_SIZE_INFO(INFO_UNUSED,INFO_UNUSED)                      \
1631         INCLUDE_PAR_INFO                                                \
1632         INCLUDE_COPYING_INFO_CONST(_Evacuate_Const,_Scavenge_Const)     \
1633         INCLUDE_COMPACTING_INFO(_Dummy_Const_entry,_PRStart_Const,      \
1634                                 _Dummy_Const_entry,_Dummy_Const_entry)  \
1635     }
1636
1637 \end{code}
1638
1639 This builds an info-table which will have pointers to the closure
1640 replaced with @closure_lbl@ during garbage collection. @closure_lbl@
1641 must be the label of a static closure, whose entry code has identical
1642 behaviour to that in the corresponding @CONST_ITBL@.  Usually
1643 the info pointer of this closure will be the very one defined by this
1644 macro!
1645
1646 These closures always consist only of an info pointer; that is, its
1647 size is zero.
1648
1649 A copying collection implements this with evacuation code which
1650 returns @closure_lbl@, without actually evacuating the object at all.
1651 A compacting collector uses marking code which returns
1652 @closure_lbl@, without marking the closure.
1653
1654 %************************************************************************
1655 %*                                                                      *
1656 \subsection[FOOLIKE_ITBL]{``Char-like'' and ``Int-like'' info-tables}
1657 %*                                                                      *
1658 %************************************************************************
1659
1660 Char-like: This builds an info-table which, when GC happens, will have
1661 pointers to the closure replaced with the appropriate element of the
1662 @CHARLIKE_closures@ array.
1663
1664 \begin{code}
1665
1666 #define CHARLIKE_ITBL(infolbl,entry_code,upd_code,liveness,tag,size,ptrs,localness,entry_localness,kind,descr,type) /*tag,size,ptrs unused*/ \
1667     CAT_DECLARE(infolbl,kind,descr,type)        \
1668     entry_localness(entry_code);                \
1669     localness W_ infolbl[] = {                  \
1670         (W_) entry_code                         \
1671         ,(W_) INFO_FIRST_TAG                    \
1672         ,(W_) MK_REP_REF(CharLike,,)            \
1673         INCLUDE_PROFILING_INFO(infolbl)         \
1674         INCLUDE_UPDATE_INFO(upd_code,liveness)  \
1675         }
1676
1677 MAYBE_DECLARE_RTBL(CharLike,,)
1678
1679 #define CHARLIKE_RTBL()                                                         \
1680     const W_ MK_REP_LBL(CharLike,,)[] = {                                       \
1681         INCLUDE_TYPE_INFO(CHARLIKE)                                             \
1682         INCLUDE_SIZE_INFO(INFO_UNUSED,INFO_UNUSED)                              \
1683         INCLUDE_PAR_INFO                                                        \
1684         INCLUDE_COPYING_INFO_CONST(_Evacuate_CharLike,_Scavenge_CharLike)       \
1685         INCLUDE_COMPACTING_INFO(_Dummy_CharLike_entry,_PRStart_CharLike,        \
1686                                 _Dummy_CharLike_entry,_Dummy_CharLike_entry)    \
1687         }
1688
1689 \end{code}
1690
1691
1692 Int-like: this builds the info-table required for intlike closures.
1693 The normal heap-allocated info-table for fixed-size integers (size
1694 @1@); it is used for updates too. 
1695 At GC, this is redirected to a static intlike closure if one is
1696 available.
1697
1698 Note again the sneaky hiding of a reference to the real info-table in
1699 the part of the info-table that normally holds the size of the
1700 closure.
1701 THIS CHANGES IN THE COMMONED INFO-TABLE WORLD.
1702
1703 \begin{code}
1704
1705 #define INTLIKE_ITBL(infolbl,entry_code,upd_code,liveness,tag,size,ptrs,localness,entry_localness,kind,descr,type) /*tag,size,ptrs unused*/ \
1706     CAT_DECLARE(infolbl,kind,descr,type)        \
1707     entry_localness(entry_code);                \
1708     localness W_ infolbl[] = {                  \
1709         (W_) entry_code                         \
1710         ,(W_) INFO_FIRST_TAG                    \
1711         ,(W_) MK_REP_REF(IntLike,,)             \
1712         INCLUDE_PROFILING_INFO(infolbl)         \
1713         INCLUDE_UPDATE_INFO(upd_code,liveness)  \
1714     }
1715
1716 MAYBE_DECLARE_RTBL(IntLike,,)
1717
1718 #define INTLIKE_RTBL()                                                  \
1719     const W_ MK_REP_LBL(IntLike,,)[] = {                                \
1720         INCLUDE_TYPE_INFO(INTLIKE)                                      \
1721         INCLUDE_SIZE_INFO(INFO_UNUSED,INFO_UNUSED)                      \
1722         INCLUDE_PAR_INFO                                                \
1723         INCLUDE_COPYING_INFO_CONST(_Evacuate_IntLike,_Scavenge_1_0)     \
1724         INCLUDE_COMPACTING_INFO(_ScanLink_1_0,_PRStart_IntLike,         \
1725                                 _ScanMove_1,_PRIn_Error)                \
1726     }
1727
1728 \end{code}
1729
1730 %************************************************************************
1731 %*                                                                      *
1732 \subsection[INREGS_ITBL]{@INREGS_ITBL@s}
1733 %*                                                                      *
1734 %************************************************************************
1735
1736 The emaciated info table for a phantom closure that lives only in regs.
1737 We don't need any GC information, because these closures never make it into
1738 the heap (not with this info table, anyway).  Similarly, we don't need an
1739 entry address, because these closures are never entered...they only exist
1740 during a return.
1741
1742 \begin{code}
1743
1744 #define INREGS_ITBL(infolbl,entry_code,upd_code,liveness,tag,size,ptrs,localness,entry_localness,kind,descr,type) /*mostly unused*/ \
1745     localness W_ infolbl[] = {                  \
1746         (W_) INFO_UNUSED                        \
1747         ,(W_) tag                               \
1748         ,(W_) INFO_UNUSED                       \
1749         INREGS_PROFILING_INFO                   \
1750         INCLUDE_UPDATE_INFO(upd_code,liveness)  \
1751     }
1752
1753 /* Declare the phantom info table vectors (just Bool at the moment) */
1754 #ifndef COMPILING_GHC
1755 EXTDATA_RO(Bool_itblvtbl);
1756 #endif
1757
1758 \end{code}
1759
1760 End multi-slurp protection:
1761 \begin{code}
1762 #endif /* SMInfoTables_H */
1763 \end{code}