[project @ 1996-07-19 18:36:04 by partain]
[ghc-hetmet.git] / ghc / includes / SMClosures.lh
1 %************************************************************************
2 %*                                                                      *
3 \section[closure-layout]{Closure Layout}
4 %*                                                                      *
5 %************************************************************************
6
7 We first describes the data structures that are shared by
8 both the reducer and storage manager and then go on to describe
9 the interface and its implementation.
10
11 The heap consists of a contiguous sequence of closures. Each standard
12 closure occupies a contiguous sequence of machine words, which is laid
13 out as follows:
14
15 \begin{rawlatex}
16 \begin{center}
17 \mbox{\epsffile{closure.ps}}
18 \end{center}
19 \end{rawlatex}
20
21 \begin{onlyinfo}
22 \begin{verbatim}
23 < fixed-hdr-size> < var-hdr-size  >
24 -----------------+-----------------+---------+-------------+
25 |info|     |     |     |     |     | ptrs... | nonptrs ... |
26 -----------------+-----------------+---------+-------------+
27 <------------- header ------------>
28 \end{verbatim}
29 \end{onlyinfo}
30
31 The closure starts with a header. Typically, the first word in the
32 header is the {\em info pointer}, and points to its {\em info-table}.
33 The rest of the header is used for bookkeeping and depends on the
34 compiler options used. The fixed header is the same for all closures
35 while the variable header may depend on the closure type.
36
37 Following the header is a block of words each of which contains a
38 pointer to another closure, followed by a block of words containing
39 non-pointers. The non-pointers may include an unused portion of
40 ``slop'' needed to pad the closure.  This is to satisfy any minimum
41 closure size requirements, primarily for updates in place.  The
42 distinction between the pointers and non-pointers is that the garbage
43 collector must follow the former but not the latter.  The pointers are
44 placed first to mimimize the number of distinct closure shapes that
45 have to be managed by the garbage collector.
46
47 There are a few non-standard closures which do not follow the convention
48 of placing all pointers first, but they are all administrative closures
49 which require their own unique garbage collection code anyway (such as
50 @TSO@'s and @STKO@'s in the threaded world).
51
52 The heap grows upwards (towards higher addresses), and closures are
53 laid out with the info pointer at the lowest address.
54
55 During reduction, the heap pointer (@Hp@) points to the last word of
56 allocated space (and not to the first word of free space) and the heap
57 limit (@HpLim@) points to the last word of available space.
58
59 %************************************************************************
60 %*                                                                      *
61 \subsection[closure-size]{The ``Size'' of Closures}
62 %*                                                                      *
63 %************************************************************************
64
65 When we speak of the ``size'' of a closure, we mean {\em the number of
66 words in the closure, excluding the fixed header, but including the
67 variable header, the pointers, non-pointers and slop, if any}.
68
69 All closures which may be updated must have a size of at least
70 @MIN_UPD_SIZE@---currently, this is two, so that they may be directly
71 overwritten with a small constructor closure, such as a @(:)@ cell or
72 an indirection on the ``mutables'' list.
73
74 %************************************************************************
75 %*                                                                      *
76 \subsection[closure-kinds]{Types of Closure}
77 %*                                                                      *
78 %************************************************************************
79
80 {\em This section is now hopelessly out-of-date}.  This stuff is {\em
81 important} if you want newcomers to understand GHC.  Am I the only
82 person who bothers with documentation?! KH
83
84 Yes, Kevin, you are.  I've taken a stab at this section.  I think {\em
85 hopelessly out-of-date} is a bit overboard, especially compared to
86 some of the other documentation in this system.  If you still don't
87 like it, you're welcome to update it.
88
89 (Umm... Before we update it, would anyone like to go for a pizza?
90 [WDP 95/03])
91
92 We identify several kinds of heap closures. Each type of closure
93 is treated differently by the storage manager. Different
94 info-table macros are used to declare the appropriate info-tables used
95 by the storage manager (see section \ref{info-table-macros}).
96
97 Note: it is vitally important that every closure has an appropriate
98 info-table attached---otherwise chaos results!
99
100 \begin{description}
101
102 \item[@SPEC@ closures:] These are standard closures which contain
103 specialized garbage collection code that ``knows'' the @size@/@ptrs@
104 of the closure. It is only possible to use a specialized info-table if
105 appropriately specialized garbage collection code is present in the
106 runtime system. This implies that the compiler needs to know which
107 @size@/@ptr@ combinations have specialized info-tables. A link-time
108 error results if the compiler attempts to build a @SPEC@ closure for
109 an inappropriate @size@/@ptr@ combination.
110
111 \item[@GEN@ closures:] These are normal closures which use generic
112 code for garbage collection. This interprets the @size@/@ptrs@
113 information stored in the info table. @GEN@ closures can be built for
114 any @size@/@ptrs@ combination.
115
116 \item[@DYN@ closures:] Dynamic closures have the layout information
117 (@size@/@ptrs@) stored within the variable header of the closure
118 itself. They are currently only used for partial applications (@PAP@s)
119 and the ``stable pointer table.''
120 %partain:\begin{center}
121 \begin{tabular}{|c|c|c|c|c|c|}
122 \hline
123 {\em Fixed Hdr} & {\em Size} & {\em No of ptrs} & {\em Pointers\ldots} & {\em Non-pointers\ldots}       \\ \hline
124 \end{tabular}
125 %partain:\end{center}
126
127 \item[@TUPLE@ closure:] These are similar to @DYN@ closures but for
128 closures which contain only pointers.  They are currently used for
129 primitive arrays of pointers when mutuples and immutuples do not have
130 to be distinguished during garbage collection.
131 %partain:\begin{center}
132 \begin{tabular}{|c|c|c|c|}
133 \hline
134 {\em Fixed Hdr} & {\em Size (= No of ptrs + TUPLE\_VHS)} & {\em Pointers\ldots} \\ \hline
135 \end{tabular}
136 %partain:\end{center}
137
138 \item[@DATA@ closures:] These are also similar to @DYN@ closures but
139 for closures containing only non-pointers. They are currently used for
140 primitive arrays of bytes (arbitrary precision integers and arrays of
141 unboxed values, for example).
142 %partain:\begin{center}
143 \begin{tabular}{|c|c|c|}
144 \hline
145 {\em Fixed Hdr} & {\em Size (= No of non-ptr words + DATA\_VHS)} & {\em Non-pointers\ldots} \\ \hline
146 \end{tabular}
147 %partain:\end{center}
148
149 \item[@MUTUPLE@ closures:] These are a variant of the @TUPLE@
150 closure. They are used when the garbage collection strategy requires a
151 distinction between mutable and immutable tuples (i.e. when there is a
152 ``mutables'' list.)  Such an array may be frozen, becoming an @IMMUTUPLE@,
153 with a different info-table.
154 %partain:\begin{center}
155 \begin{tabular}{|c|c|c|c|}
156 \hline
157 {\em Fixed Hdr} & {\em Size (= No of ptrs + MUTUPLE\_VHS)} & {\em Pointers\ldots} \\ \hline
158 \end{tabular}
159 %partain:\end{center}
160
161 \item[@IMMUTUPLE@ closures:] These are frozen @MUTUPLE@ closures.
162 %mattson:\begin{center}
163 \begin{tabular}{|c|c|c|c|}
164 \hline
165 {\em Fixed Hdr} & {\em Size (= No of ptrs + MUTUPLE\_VHS)} & {\em Pointers\ldots} \\ \hline
166 \end{tabular}
167 %mattson:\end{center}
168
169 \end{description}
170
171 %************************************************************************
172 %*                                                                      *
173 \subsection[special-closure-types]{Special types}
174 %*                                                                      *
175 %************************************************************************
176
177 Special kinds of closures are required for static closures, ``black
178 holes'', indirections, and in-place updates.
179
180 When a ``black hole'' is updated it must be updated with a closure of
181 size @MIN_UPD_SIZE@ or less.  Updates to some specific closure types
182 are handled specially, as follows:
183
184 \begin{itemize}
185 \item
186 if the new closure is of zero arity, then the black hole is replaced by
187 the corresponding static closure (@CONST@);
188 \item
189 if the data type of the new closure is isomorphic to Char (one
190 constructor, with argument type @Char#@), then the black hole is
191 replaced by the corresponding member of the static character table
192 (@CHARLIKE@);
193 \item
194 if the data type of the new closure is isomorphic to Int (one
195 constructor, with argument type @Int#@), and the argument is in the
196 range of the static small-int table then the black hole is replaced by
197 the corresponding member of the integer table (@INTLIKE@).
198 \end{itemize}   
199
200 The special kinds of closure are:
201
202 \begin{description}
203
204 \item[@STATIC@ closures:] These are closures which are declared
205 statically and hence do not reside in the heap. Such closures must not
206 contain any heap pointers and must not be updated.  @CAF@ closures are
207 an exception; see below.
208
209 \item[@CONST@ closures:] There need be only one (static) closure for a
210 nullary constructor. These are declared static at compile time and all
211 references use the static closure (avoiding heap allocation). However,
212 dynamic heap-allocated ones will nevertheless arise through updates.
213
214 \item[@CHARLIKE@ and @INTLIKE@ closures] There is a similar story for
215 constructors which have a single primitive data field such as @Int#@
216 or @Char#@. During garbage collection, pointers to these closures can
217 be replaced with a known @STATIC@ closure if an appropriate one exists.
218
219 \item[@BH@ closures:] Black hole closures are used to overwrite
220 closures currently being evaluated. They inform the garbage collector
221 that there are no live roots in the closure, thus removing a potential
222 space leak.  They also become synchronization points in the threaded
223 world.
224
225 \item[@BQ@ closures:] Blocking queue closures are black holes with a
226 list of blocked threads to be awakened when the black hole is updated.
227
228 \item[@IND@ closures:] Indirection closures just point to other
229 closures. They are introduced when a closure is updated with a closure
230 that has to be allocated in the heap. The closure to be updated is
231 {\em indirected} to the new closure.  Indirections are normally
232 removed during garbage collection.  However, when profiling, it may be
233 necessary to maintain cost center information in an indirection, so
234 there are also ``permanent indirections'' which are retained forever.
235
236 \item[@CAF@ indirections:] These are statically defined closures which have
237 been updated with a heap-allocated result.
238 Initially these are exactly the same as a @STATIC@ closure but with
239 special entry code. On entering the closure the entry code must:
240 \begin{itemize}
241 \item Allocate a black hole in the heap which will be updated with
242       the result.
243 \item Overwrite the static closure with a special @CAF@ indirection.
244
245 \item Link the static indirection onto the list of updated @CAF@s.
246 \end{itemize}
247 The indirection and the link field require the initial @STATIC@
248 closure to be of at least size @MIN_UPD_SIZE@ (excluding the fixed
249 header).
250
251 @CAF@s are treated as special garbage collection roots.  These roots
252 are explicitly collected by the garbage collector, since they may
253 appear in code even if they are not linked with the main heap.  They
254 consequently represent potentially enormous space-leaks.  A @CAF@
255 closure retains a fixed location in statically allocated data space.
256 When updated, the contents of the @CAF@ indirection are changed to
257 reflect the new closure. @CAF@ indirections require special garbage
258 collection code.
259
260 \item[@FETCHME@ closures:] These are simply references to remote
261 objects in the parallel system.
262
263 \item[@TSO@ closures:] These are ``thread state objects,'' which are
264 used in the threaded world to maintain the context (STG registers,
265 PC location when asleep, etc.) for individual threads of computation.
266
267 \item[@STKO@ closures:] These are ``stack objects,'' which are
268 used in the threaded world as the stack for each thread is allocated
269 from the heap in smallish chunks.  (The stack in the sequential world
270 is allocated outside of the heap.)
271
272 \item[@SPEC_RBH@ and @GEN_RBH@ closures:] These are ``revertible black
273 holes'' for updatable @SPEC@ (respectively @GEN@) closures.  They are
274 currently used in the parallel system, but they could also be used for
275 speculation.  They act like a black hole for thread synchronization,
276 but they can also be reverted back to the original @SPEC@
277 (respectively @GEN@) form (so they do introduce a space leak).
278
279 \end{description}
280
281 %************************************************************************
282 %*                                                                      *
283 \subsection[closure-layout-macros]{Closure layout macros}
284 %*                                                                      *
285 %************************************************************************
286
287 \begin{description}
288 \item[@FIXED_HS@:]
289 This is the number of fixed-header words present in every closures.
290 This includes the info pointer---always the first word---and any
291 other fixed info.  Because this name occurs so often, @_FHS@ is used as
292 a shorthand form.
293
294 \item[@SET_FIXED_HDR(closure, infolbl, costcentre)@:] Initialize the
295 fixed-header part of @closure@, putting @infolbl@ into the first word
296 (where the info-table pointer normally lives). Note that @infolbl@
297 should be the name of the appropriate info-table. If we are profiling
298 on a sequential machine, then the cost centre will be placed in the
299 second word of the fixed header.
300
301 \item[@<closure-kind>_VHS@:]
302 This is the number of words in the variable part of the header.  This
303 includes the @size@ and/or @ptr@ fields if required for this closure
304 type, and any words which are reserved for garbage collection.
305
306 @SPEC@, @CONST@, @CHARLIKE@, @INTLIKE@, @BH@ and @IND@ do
307 not have variable header parts, hence no @<closure-kind>_VHS@ macro is
308 defined for any of these closure types.
309
310 \item[@SET_<closure-kind>_HDR(closure,infolbl,costcentre,size,no-of-ptrs)@:]
311 This is used to initialize the header of a \tr{<closure-kind>} closure.
312 The fixed header is set by using @SET_FIXED_HDR(closure,infolbl,costcentre)@
313 macro.
314
315 The variable part of the header, if present, uses the
316 @size@/@ptrs@ fields.  The @size@ should {\em include} any slop
317 words in the closure.  Any field that is not used may be junk.
318
319 The fields actually used depend on the type of the closure (other
320 fields are ignored):
321
322 %partain:\begin{center}
323 \begin{tabular}{|l|l|} \hline
324 Closure     & Fields Used                              \\ \hline
325             &                                          \\
326 \tr{SPEC}   & size/nonptrs fields ignored              \\
327 \tr{GEN}    & both fields also ignored                 \\
328 \tr{DYN}    & both fields used                         \\
329 \tr{TUPLE}  & size used (ptrs = size - \tr{TUPLE_VHS}) \\
330 \tr{DATA}   & size used (ptrs = 0)                      \\\hline
331 \end{tabular}
332 %partain:\end{center}
333
334 \item[@<closure-kind>_HS@:]
335 Total number of words in the header:
336
337 \pl{TOT_HDR = FIXED_HDR + VAR_HDR}.
338
339 \item[@<closure-kind>_CLOSURE_SIZE(closure)@:]
340 Returns the size of a closure of this kind.  This includes any @VAR_HDR@
341 words and slop---but excludes the @FIXED_HDR@ words.
342
343 \item[@<closure-kind>_CLOSURE_NoPTRS(closure)@:]
344 Returns the number of closure pointer words in a closure of this kind.
345
346 \item[@<closure-kind>_CLOSURE_NoNONPTRS(closure)@:]
347 Returns the number of useful non-pointer words (including slop) in a
348 closure of this kind.  These follow the pointer words in the closure;
349 \pl{NoNONPTRS = SIZE - NoPTRS - VAR_HDR}.
350
351 \item[@<closure-kind>_CLOSURE_PTR(closure,nth)@:]
352 Returns the $n$th closure pointer in the closure (starting at 1).
353
354 If a loop needs to process all the pointers and non-pointers in a closure then
355 this macro should be avoided. Instead, have a pointer run over the closure;
356 for example (from @StgUpdate.lhc@):
357 \begin{pseudocode}
358 { P_ p = PapClosure + FIXED_HS + DYN_VHS;
359   I_ NPtrWords = DYN_CLOSURE_NoPTRS(Node);
360   I_ NNonPtrWords = DYN_CLOSURE_NoNONPTRS(Node);
361   for (i=0; i<NPtrWords;    i++) SpA[AREL(i)] = *(p++);
362   for (i=0; i<NNonPtrWords; i++) SpB[BREL(i)] = *(p++);
363 }
364 \end{pseudocode}
365
366 \end{description}
367
368
369 %************************************************************************
370 %*                                                                      *
371 \subsection[SMinterface.h-implementation]{Interface implementation}
372 %*                                                                      *
373 %************************************************************************
374
375 This section details the implementation of the storage manager
376 interface.
377
378 NB: Heap objects specific to parallel implementations are not defined
379 here, but in \tr{Parallel.lh} instead.
380
381 %************************************************************************
382 %*                                                                      *
383 \subsubsection[common-to-all-closures]{Bits common to all closures (esp. @FIXED_HS@)}
384 %*                                                                      *
385 %************************************************************************
386
387 The maximum number of pointers in a generic closure (@GEN@, @DYN@,
388 @TUPLE@, @DATA@) is defined here.
389
390 Multi-slurp protection:
391 \begin{code}
392 #ifndef SMClosures_H
393 #define SMClosures_H
394 \end{code}
395
396 Macros to make rep-table names:
397 If you change either of these, change .../nativeGen/StixInfo.lhs
398 too---or else!
399 \begin{code}
400
401 #define MK_REP_LBL(n,s,p)       CAT6(n,_,s,_,p,_rtbl)
402 #define MK_REP_REF(n,s,p)       CAT6(n,_,s,_,p,_rtbl)
403
404 \end{code}
405
406 At the start of a closure is a fixed header. The info-pointer is
407 normally the first word of a closure, in the fixed header.  Following
408 this we may have any of (but occuring in this order): parallel words
409 (currently a global address); profiling words (currently a cost
410 centre).  It is possible to change the ordering of fixed header
411 components by changing the @_HDR_POSN@ macros in the appropriate
412 files, and the @SET_FIXED_HDR@/@SET_STATIC_FIXED_HDR@ macros below.
413
414 The @FIXED_HS@, @SET_FIXED_HDR@ macros and the components
415 which are used to define them must all be defined consistently.
416
417 \begin{code}
418
419 #define FIXED_HS (INFO_FIXED_HDR + PAR_FIXED_HDR + PROF_FIXED_HDR + TICKY_FIXED_HDR)
420
421 /* NB: this *defines* the intended order for the pieces of 
422    the fixed header.  Care should be taken to ensure that this
423    is followed below and in the component headers.
424 */
425
426 #define _FHS                    FIXED_HS /* shorthand */
427
428 #define SET_FIXED_HDR(closure,infolbl,costcentre)       \
429         SET_INFO_PTR(closure,infolbl);                  \
430         SET_GRAN_HDR(closure,ThisPE);                   \
431         SET_PAR_HDR(closure,LOCAL_GA);                  \
432         SET_PROF_HDR(closure,costcentre);               \
433         SET_TICKY_HDR(closure,0)
434
435 #define UPD_FIXED_HDR(closure,infolbl,costcentre)       \
436         SET_INFO_PTR(closure,infolbl);                  \
437         SET_PROF_HDR(closure,costcentre);               \
438         SET_TICKY_HDR(closure,1)
439         /* fiddling SET_PAR_HDR would be a bug (says Patrick) */
440         /* We set ticky-hdr to 1 because the only place we
441            use this macro is when we have just done an update
442            (WDP 96/01)
443         */
444
445 /* These items are comma-separated */
446
447 #define SET_STATIC_FIXED_HDR(closure,infolbl,cc_ident)  \
448         SET_STATIC_INFO_PTR(infolbl)                    \
449         SET_STATIC_PROCS(closure)                       \
450         SET_STATIC_PAR_HDR(closure)                     \
451         SET_STATIC_PROF_HDR(cc_ident)                   \
452         SET_STATIC_TICKY_HDR()
453
454 \end{code}
455
456 We define @MIN_UPD_SIZE@ to be the minimum size for updatable
457 closures. This must be at least 2, to allow for @(:)@ cells and
458 indirections on the ``mutables'' list. This is defined in
459 \tr{GhcConstants.lh}.
460
461 All updates are performed on closures of this size so @BH@ and @IND@
462 closures all have this size.
463
464 Finally we define the number of words that the storage-manager needs
465 to reserve in the variable header for mutable closures:
466
467 \begin{code}
468 #if defined(GCap) || defined(GCgn)
469 # define GC_MUT_REQUIRED
470 # define GC_MUT_RESERVED_WORDS          1
471 # define MUT_NOT_LINKED                 1 /* Assuming 1 is not a valid pointer */
472 # define MUT_LINK(closure)              (((P_)(closure))[FIXED_HS])
473 # define SET_MUT_RESERVED_WORDS(closure) MUT_LINK(closure) = MUT_NOT_LINKED
474 # define SET_STATIC_MUT_RESERVED_WORDS  , (W_) MUT_NOT_LINKED
475 #else
476 # define GC_MUT_RESERVED_WORDS          0
477 # define SET_STATIC_MUT_RESERVED_WORDS
478 #endif
479 \end{code}
480
481
482 %************************************************************************
483 %*                                                                      *
484 \subsubsection[SPEC-closures]{@SPEC@ (specialized) closure macros}
485 %*                                                                      *
486 %************************************************************************
487
488 @SPEC@ closures have no variable header size---it is always 0.
489 @SPEC_VHS@ is left undefined, so that if anyone tries to use it,
490 they will hear about it soon enough (WDP 95/05).
491
492 \begin{code}
493 #define SPEC_HS         (FIXED_HS)
494
495 #define SPEC_SIZE(fields) (FIXED_HS + (fields))
496                         /*notational convenience; in SMscan.lc + elsewhere */
497
498 #define SPEC_CLOSURE_PTR(closure, no)   (((P_)(closure))[SPEC_HS + (no) - 1])
499 #define SPEC_CLOSURE_SIZE(closure)      ((W_)INFO_SIZE(INFO_PTR(closure)))
500 #define SPEC_CLOSURE_NoPTRS(closure)    ((W_)INFO_NoPTRS(INFO_PTR(closure)))
501 #define SPEC_CLOSURE_NoNONPTRS(closure) (SPEC_CLOSURE_SIZE(closure)-SPEC_CLOSURE_NoPTRS(closure)/*-SPEC_VHS*/)
502
503 #define SET_SPEC_HDR(closure,infolbl,cc,size,ptrs) \
504                                         SET_FIXED_HDR(closure,infolbl,cc)
505 \end{code}
506
507 %************************************************************************
508 %*                                                                      *
509 \subsubsection[ForeignObj-closures]{@ForeignObj@ closure macros}
510 %*                                                                      *
511 %************************************************************************
512
513 Here's what a ForeignObj looks like:
514
515 \begin{verbatim}
516             <Var  Hdr> 
517 +----------+----------+------+-------------+------+
518 | Info Ptr | Forward  | Data | FreeRoutine | List |
519 +----------+----------+------+-------------+------+
520 \end{verbatim}
521
522 @List@ is a pointer to the next ForeignObj in the list of all
523 ForeignObjs.  Note that it is essential that the garbage collector {\em
524 not\/} follow this link but that the link must get updated with the
525 new address.
526
527 The optional @Forward@ field is used by copying collectors to insert
528 the forwarding pointer into.  (If we overwrite the @Data@ part, we
529 don't know which ForeignObj has just died; if we overwrite the @List@ part,
530 we can't traverse the list of all ForeignObjs.)
531
532 The @FreeRoutine@ is a reference to the finalisation routine to call
533 when the @ForeignObj@ becomes garbage -- SOF 4/96
534
535 \begin{code}
536 #if !defined(PAR)
537
538 # if defined(_INFO_COPYING)
539 #  define ForeignObj_VHS                        1
540 # else
541 #  define ForeignObj_VHS                        0
542 # endif
543
544 # define ForeignObj_HS                  (FIXED_HS + ForeignObj_VHS)
545 # define ForeignObj_SIZE                (ForeignObj_VHS + 3)
546
547 # define ForeignObj_CLOSURE_NoPTRS(closure)     0
548 # define ForeignObj_CLOSURE_DATA(closure)       (((StgForeignObj *)(closure))[ForeignObj_HS + 0])
549 # define ForeignObj_CLOSURE_FINALISER(closure)  (((StgForeignObj *)(closure))[ForeignObj_HS + 1])
550 # define ForeignObj_CLOSURE_LINK(closure)       (((StgPtrPtr) (closure))[ForeignObj_HS + 2])
551
552 # define SET_ForeignObj_HDR(closure,infolbl,cc,size,ptrs) \
553                                         SET_FIXED_HDR(closure,infolbl,cc)
554 \end{code}
555
556 And to check that a Foreign ptr closure is valid
557
558 \begin{code}
559 EXTDATA_RO(ForeignObj_info);
560
561 # if defined(DEBUG)
562
563 #  define CHECK_ForeignObj_CLOSURE( closure ) \
564 do {                                       \
565   CHECK_ForeignObj_InfoTable( closure );    \
566 } while (0)
567
568 #  define CHECK_ForeignObj_InfoTable( closure ) \
569   ASSERT( (*((PP_)(closure))) == ForeignObj_info )
570
571 extern void Validate_ForeignObjList( P_ MPlist );
572 #  define VALIDATE_ForeignObjList( mplist ) Validate_ForeignObjList( mplist )
573
574 # else /* !DEBUG */
575
576 #  define CHECK_ForeignObj_CLOSURE( closure ) /* nothing */
577 #  define VALIDATE_ForeignObjList( mplist ) /* nothing */
578
579 # endif /* !DEBUG */
580 #endif /* !PAR */
581 \end{code}
582
583 %************************************************************************
584 %*                                                                      *
585 \subsubsection[SP-table-closures]{@SPTable@ Stable Pointer Table closure macros}
586 %*                                                                      *
587 %************************************************************************
588
589
590 A stable pointer is a name for a Haskell object which can be passed to
591 the external world.  It is ``stable'' in the sense that the name does
592 not change when the Haskell garbage collector runs---in contrast to
593 the address of the object which may well change.
594
595 The stable pointer type is parameterized by the type of the thing
596 which is named.
597
598 \begin{verbatim}
599 type StablePtr# a
600 \end{verbatim}
601
602 A stable pointer is represented by an index into the (unique,
603 heap-allocated) @StablePointerTable@.  The Haskell garbage collector
604 treats the @StablePointerTable@ as a source of roots for GC.
605
606 In order to provide efficient access to stable pointers and to be able
607 to cope with any number of stable pointers ($0 \ldots 100000$), the
608 table of stable pointers is an array stored on the heap and can grow
609 when it overflows.  (Since we cannot compact the table by moving
610 stable pointers about, it seems unlikely that a half-empty table can
611 be reduced in size---this could be fixed if neccessary by using a
612 hash table of some sort.)
613
614 In general a stable pointer table closure looks like this:
615
616 \begin{verbatim}
617 <------------header--------------->
618 +------+------------+------+-------+---+---+---+-----+-----+--+--+--+----+
619 | Info | GCReserved | Size | NPtrs |SP0|SP1|...|SPn-1| Top |s0|s1|..|sn-1|
620 +------+------------+------+-------+---+---+---+-----+-----+--+--+--+----+
621 \end{verbatim}
622
623 The fields are:
624 \begin{description}
625
626 \item[@Size@:] number of words excluding fixed header ($= @DYN_VHS@ + @NPtrs@ + 1 + @NPtrs@$)
627
628 \item[@NPtrs@:] number of (stable) pointers.
629
630 \item[@SPi@:] ``unstable'' pointer to a closure.  This is the pointer
631 that gets updated when the garbage collector moves an object we have a
632 stable pointer to.  If the pointer is not in use, it points to a
633 static closure.
634
635 \item[@si@:] entry in a stack of unused pointers.  Entries in
636 use will contain a number in the range $0\ldots n-1$.
637
638 \item[@Top@] is the index of the first element above the top of the stack.
639
640 \end{description}
641
642 For example, with $n = 4$ and pointers @0@ and @3@ in use (pointing to
643 @p1@ and @p2@ respectively), the table might look like this:
644
645 \begin{verbatim}
646 +------+----+---+----+---+---+----+---+---+---+---+---+
647 | Info | 11 | 4 | p1 | x | x | p2 | 2 | 2 | 1 | ? | ? |
648 +------+----+---+----+---+---+----+---+---+---+---+---+
649                                    +-----------^
650 \end{verbatim}
651
652 From the above description, it should be clear that this is just a
653 special case of a @DYN@ closure.  However, a few macros to access the
654 various fields would be jolly useful.
655
656 Nota Bene: one might think that since the table is mutable, we'd need
657 to treat it a bit more like a @MUTUPLE@.  This isn't necessary because
658 we treat the stable pointer table as a root.
659
660 \begin{code}
661 #if !defined(PAR)
662 \end{code}
663
664 \begin{code}
665 # define SPT_SIZE(closure)         DYN_CLOSURE_SIZE(closure)
666 # define SPT_NoPTRS(closure)       DYN_CLOSURE_NoPTRS(closure)
667 # define SPT_TOP(closure)          (((I_ *) closure)[DYN_HS + SPT_NoPTRS(closure)])
668 # define SPT_SPTR(closure,index)   (((PP_) closure)[DYN_HS + index])
669 # define SPT_FREE(closure,index)   (((I_ *) closure)[DYN_HS + SPT_NoPTRS(closure) + 1 + index])
670 \end{code}
671
672 And to implement the stack:
673
674 \begin{code}
675 # define SPT_FULL(closure)         (SPT_TOP(closure) == SPT_NoPTRS(closure))
676 # define SPT_EMPTY(closure)        (SPT_TOP(closure) == 0)
677
678 # define SPT_PUSH(closure,free)    SPT_FREE(closure,SPT_TOP(closure)++) = free
679 # define SPT_POP(closure)          SPT_FREE(closure,--SPT_TOP(closure))
680 \end{code}
681
682 And to check that an SPT_Closure is what it's supposed to be, we check
683 that the size and number of pointers match up and we check that the
684 free list and sptr areas are consistent.  
685
686 Note that we cannot always check the info table since we might be
687 halfway through garbage collection when we call these (eg in
688 @freeStablePointer@.
689
690 \begin{code}
691 # if defined(DEBUG)
692
693 #  define CHECK_SPT_CLOSURE( closure ) \
694 do {                                 \
695   CHECK_SPT_InfoTable( closure );    \
696   CHECK_SPT_Size( closure );         \
697   CHECK_SPT_Contents( closure );     \
698 } while (0)
699
700 EXTDATA_RO(StablePointerTable_info);
701 EXTDATA_RO(EmptyStablePointerTable_info);
702 EXTDATA(EmptySPTable_closure);
703 int ValidateSPTable PROTO(( P_ SPTable ));
704
705 #  define CHECK_SPT_InfoTable( closure ) \
706   ASSERT( (*((PP_) (closure)) == EmptyStablePointerTable_info && (closure == EmptySPTable_closure) ) || \
707           (*((PP_) (closure)) == StablePointerTable_info) )
708
709 #  define CHECK_SPT_Size( closure ) \
710   ASSERT( SPT_SIZE( closure ) == DYN_VHS + 2 * SPT_NoPTRS( closure ) + 1 )
711
712 #  define CHECK_SPT_Contents( closure ) \
713   ASSERT( ValidateSPTable( closure ) == 0 )
714
715 # else
716
717 #  define CHECK_SPT_InfoTable( closure ) /* nothing */
718 #  define CHECK_SPT_Contents( closure ) /* nothing */
719 #  define CHECK_SPT_Size( closure ) /* nothing */
720 #  define CHECK_SPT_CLOSURE( closure ) /* nothing */
721
722 # endif /* DEBUG */
723 #endif  /* !PAR */
724 \end{code}
725
726 %************************************************************************
727 %*                                                                      *
728 \subsubsection[GEN-closures]{@GEN@ (generic) closure macros}
729 %*                                                                      *
730 %************************************************************************
731
732 \begin{code}
733 #define GEN_VHS         0
734 #define GEN_HS          (FIXED_HS + GEN_VHS)
735
736 #define GEN_N_VHS       GEN_VHS
737 #define GEN_N_HS        GEN_HS
738
739 #define GEN_S_VHS       GEN_VHS
740 #define GEN_S_HS        GEN_HS
741
742 #define GEN_U_VHS       GEN_VHS
743 #define GEN_U_HS        GEN_HS
744
745 #define GEN_CLOSURE_SIZE(closure)       GEN_INFO_SIZE(INFO_PTR(closure))
746 #define GEN_CLOSURE_NoPTRS(closure)     GEN_INFO_NoPTRS(INFO_PTR(closure))
747
748 #define GEN_CLOSURE_NoNONPTRS(closure)  (GEN_CLOSURE_SIZE(closure) - GEN_CLOSURE_NoPTRS(closure) - GEN_VHS) 
749 #define GEN_CLOSURE_PTR(closure, no)    (((P_)(closure))[GEN_HS + (no) - 1])
750
751 #define SET_GEN_HDR(closure,infolbl,cc,size,ptrs) SET_FIXED_HDR(closure,infolbl,cc)
752 \end{code}
753
754 %************************************************************************
755 %*                                                                      *
756 \subsubsection[DYN-closures]{@DYN@ (dynamic) closure macros}
757 %*                                                                      *
758 %************************************************************************
759
760 For dynamic closures (with both pointers and data stored within the closure).
761
762 \begin{code}
763 #define DYN_VHS                 2
764 #define DYN_HS                  (FIXED_HS + DYN_VHS)
765
766 #define DYN_CLOSURE_SIZE(closure)       (((P_)(closure))[FIXED_HS])
767 #define DYN_CLOSURE_NoPTRS(closure)     (((P_)(closure))[FIXED_HS + 1])
768
769 #define DYN_CLOSURE_NoNONPTRS(closure)  (DYN_CLOSURE_SIZE(closure) - DYN_CLOSURE_NoPTRS(closure) - DYN_VHS)
770 #define DYN_CLOSURE_PTR(closure, no)    (((P_)(closure))[DYN_HS + (no) - 1])
771
772 #define SET_DYN_HDR(closure,infolbl,cc,size,ptrs) \
773         { SET_FIXED_HDR(closure,infolbl,cc);    \
774           DYN_CLOSURE_NoPTRS(closure) = (W_)(ptrs); \
775           DYN_CLOSURE_SIZE(closure) = (W_)(size); }
776 \end{code}
777
778 %************************************************************************
779 %*                                                                      *
780 \subsubsection[TUPLE-closures]{@TUPLE@ (big purely-pointer) closure macros}
781 %*                                                                      *
782 %************************************************************************
783
784 For tuple closures (which contain only pointers after the variable header).
785
786 \begin{code}
787 #define TUPLE_VHS               1
788 #define TUPLE_HS                (FIXED_HS + TUPLE_VHS)
789
790 #define TUPLE_CLOSURE_SIZE(closure)     (((P_)(closure))[FIXED_HS])
791
792 #define TUPLE_CLOSURE_NoPTRS(closure)   (TUPLE_CLOSURE_SIZE(closure) - TUPLE_VHS)
793 #define TUPLE_CLOSURE_NoNONPTRS(closure) 0L
794 #define TUPLE_CLOSURE_PTR(closure, no)  (((P_)(closure))[TUPLE_HS + (no) - 1])
795
796 #define SET_TUPLE_HDR(closure,infolbl,cc,size,ptrs) \
797         { SET_FIXED_HDR(closure,infolbl,cc);    \
798           TUPLE_CLOSURE_SIZE(closure) = (W_)(size); }
799 \end{code}
800
801 %************************************************************************
802 %*                                                                      *
803 \subsubsection[DATA-closures]{@DATA@ (big purely non-pointer) closure macros}
804 %*                                                                      *
805 %************************************************************************
806
807 For data closures (which contain only raw data (no pointers) after the
808 variable header):
809
810 \begin{code}
811 #define DATA_VHS        1
812 #define DATA_HS         (FIXED_HS + DATA_VHS)
813
814 #define DATA_CLOSURE_SIZE(closure)      (((P_)(closure))[FIXED_HS])
815
816 #define DATA_CLOSURE_NoPTRS(closure)    ((I_)0)
817 #define DATA_CLOSURE_NoNONPTRS(closure) (DATA_CLOSURE_SIZE(closure) - DATA_VHS)
818
819 #define SET_DATA_HDR(closure,infolbl,cc,size,ptrs)      \
820         { SET_FIXED_HDR(closure,infolbl,cc);            \
821           DATA_CLOSURE_SIZE(closure) = (W_)(size); }
822 \end{code}
823
824
825 %************************************************************************
826 %*                                                                      *
827 \subsubsection[MUTUPLE-closures]{@MUTUPLE@ (mutable pointer) closure macros}
828 %*                                                                      *
829 %************************************************************************
830
831 Mutable closures of pointers have to be treated specially for the
832 benefit of generational garbage collection schemes. If the garbage
833 collection scheme does not need to treat them specially
834 @GC_MUT_REQUIRED@ is undefined and the closures are defined
835 identical to @TUPLE@ closures.
836
837 \begin{code}
838
839 #if defined(GC_MUT_REQUIRED)
840
841 # define MUTUPLE_VHS            (1 + GC_MUT_RESERVED_WORDS)
842 # define MUTUPLE_HS             (FIXED_HS + MUTUPLE_VHS)
843
844 # define MUTUPLE_CLOSURE_SIZE(closure)    (((P_)(closure))[FIXED_HS + GC_MUT_RESERVED_WORDS])
845
846 # define MUTUPLE_CLOSURE_NoPTRS(closure)    (MUTUPLE_CLOSURE_SIZE(closure) - MUTUPLE_VHS)
847 # define MUTUPLE_CLOSURE_NoNONPTRS(closure) 0L
848 # define MUTUPLE_CLOSURE_PTR(closure, no)   (((P_)(closure))[MUTUPLE_HS + (no) - 1])
849
850 # define SET_MUTUPLE_HDR(closure,infolbl,cc,size,ptrs) \
851         { SET_FIXED_HDR(closure,infolbl,cc);    \
852           SET_MUT_RESERVED_WORDS(closure);      \
853           MUTUPLE_CLOSURE_SIZE(closure) = (W_)(size); }
854
855 #else   /* ! GC_MUT_REQUIRED---define as TUPLE closure */
856
857 # define MUTUPLE_VHS TUPLE_VHS
858 # define MUTUPLE_HS  TUPLE_HS   
859 # define MUTUPLE_CLOSURE_SIZE(closure)      TUPLE_CLOSURE_SIZE(closure)
860 # define MUTUPLE_CLOSURE_NoPTRS(closure)    TUPLE_CLOSURE_NoPTRS(closure)
861 # define MUTUPLE_CLOSURE_NoNONPTRS(closure) TUPLE_CLOSURE_NoNONPTRS(closure)
862 # define MUTUPLE_CLOSURE_PTR(closure, no)   TUPLE_CLOSURE_PTR(closure, no)
863 # define SET_MUTUPLE_HDR(closure,infolbl,cc,size,ptrs) \
864          SET_TUPLE_HDR(closure,infolbl,cc,size,ptrs)
865 #endif
866
867 \end{code}
868
869 %************************************************************************
870 %*                                                                      *
871 \subsubsection[STATIC-closures]{@STATIC@ closure macros}
872 %*                                                                      *
873 %************************************************************************
874
875 Static closures are those that are allocated in text/data space at
876 compile time (i.e., not in dynamic heap).  The odd-looking macro
877 @SET_STATIC_HDR@ depends on the compiler to cooperate---it must drop
878 in the closure free-variable words and the concluding @};@!  Also note
879 that the info-table label is a ``base'' label.
880
881 @SET_STATIC_HDR@ is for SPEC-layout closures.
882
883 \begin{code}
884 #define STATIC_VHS              0
885 #define STATIC_HS               (FIXED_HS)
886
887 #define STATIC_CLOSURE_SIZE(closure)            (STATIC_INFO_SIZE(INFO_PTR(closure)))
888 #define STATIC_CLOSURE_NoPTRS(closure)          (STATIC_INFO_NoPTRS(INFO_PTR(closure)))
889 #define STATIC_CLOSURE_NoNONPTRS(closure)       (STATIC_CLOSURE_SIZE(closure)-STATIC_CLOSURE_NoPTRS(closure)-STATIC_VHS)
890
891 #define SET_STATIC_HDR(closure,infolbl,cc,closure_localness,info_localness_macro) \
892         info_localness_macro(infolbl); \
893         closure_localness \
894         W_ closure[] = {SET_STATIC_FIXED_HDR(&closure[0],infolbl,cc)
895 \end{code}
896
897 %************************************************************************
898 %*                                                                      *
899 \subsubsection[IND-closures]{@IND@ (indirection) closure macros}
900 %*                                                                      *
901 %************************************************************************
902
903 Indirections are introduced when closures are updated. They are only
904 built by the update macros and the special @CAF@ entry macro in
905 @SMupdate.lh@.
906
907 Indirections also have a fixed size of @IND_CLOSURE_SIZE(closure)@.
908
909 Both for @CAF@s and for normal nodes in Appel's collector we have to
910 be able to identify and link together lists of indirections which are
911 treated specially by the garbage collector. For this purpose we use
912 the @MUT_LINK@ field.
913
914 @CAF@s (which look like indirections) need to be linked regardless of
915 whether or not we're doing generational collection, so we don't rely
916 on @MUT_LINK@ being defined.
917
918 \begin{code}
919 #define IND_VHS                 (1)
920 #define IND_HS                  (FIXED_HS + IND_VHS)
921
922 #define IND_CLOSURE_SIZE(closure) (MIN_UPD_SIZE)
923 #define IND_CLOSURE_NoPTRS(closure) 1
924 #define IND_CLOSURE_NoNONPTRS(closure) \
925             (IND_CLOSURE_SIZE(closure)-IND_CLOSURE_NoPTRS(closure)-IND_VHS)
926 \end{code}
927
928 Indirections must store a pointer to the closure which is the target
929 of the indirection:
930 \begin{code}
931 #define IND_CLOSURE_PTR(closure)  (((P_)(closure))[IND_HS])
932 #define IND_CLOSURE_LINK(closure) (((P_)(closure))[FIXED_HS])
933 \end{code}
934
935 When we are profiling, we occasionally use ``permanent indirections''
936 to store cost centres associated in some way with PAPs.  Don't ask me
937 why.  For now, a permanent indirection must have the same shape as a
938 regular indirection.  The only difference is that it is, well,
939 permanent.  That is to say, it is never short-circuited.  (What is the
940 point, anyway?)
941
942 Presumably, such objects could shrink as they moved into the old
943 generation, but then their header size would change as well (the word
944 that they get to lose is the VHS word of a standard indirection), and
945 I just don't feel up to it today.  --JSM.
946
947 \begin{code}
948 #if defined(PROFILING) || defined(TICKY_TICKY)
949
950 #define PERM_IND_CLOSURE_PTR(closure,dummy) IND_CLOSURE_PTR(closure)
951     /* really *must* be the same as IND_CLOSURE_PTR; it is
952        merely a "two-argument" variant, to fit in with the
953        bizarre goings-on in SMmark.lhc and friends. WDP 95/12
954     */
955 #endif
956 \end{code}
957
958 %************************************************************************
959 %*                                                                      *
960 \subsubsection[BH-closures]{@BH@ (black hole) closure macros}
961 %*                                                                      *
962 %************************************************************************
963
964 There are two flavours of black holes; one for updatable closures
965 (size @MIN_UPD_SIZE@) and one for single entry closures (size
966 @MIN_NONUPD_SIZE@).  Note that single-entry black holes can never
967 become blocking queues, because that would imply multiple entries
968 to the closure.
969
970 Black holes are introduced either on entering a closure or when
971 performing garbage collection (see section
972 \ref{black-hole-overwrite}). They indicate that the pointers within
973 the closure are no longer needed.
974
975 The compiler will also allocate an updatable black hole on entering a
976 @CAF@.
977
978 \begin{code}
979 #define BH_HS           (FIXED_HS)
980 #define BH_VHS          0L
981
982 #define BH_U_SIZE       MIN_UPD_SIZE
983 #define BH_N_SIZE       MIN_NONUPD_SIZE
984
985 #define BH_CLOSURE_SIZE(closure)        ((W_)INFO_SIZE(INFO_PTR(closure)))
986 #define BH_CLOSURE_NoPTRS(closure)      0L
987 #define BH_CLOSURE_NoNONPTRS(closure)   (BH_CLOSURE_SIZE(closure)-BH_CLOSURE_NoPTRS(closure)-BH_VHS)
988
989 #define SET_BH_HDR(closure,infolbl,cc,size,ptrs) \
990         SET_FIXED_HDR(closure,infolbl,cc)
991         /* most args aren't used, but are required for SET_*_HDR uniformity */
992 \end{code}
993
994 %************************************************************************
995 %*                                                                      *
996 \subsubsection[RBH-closures]{@RBH@ (revertible black hole) closure macros}
997 %*                                                                      *
998 %************************************************************************
999
1000 There are two kinds of revertible black holes, produced from GEN or
1001 SPEC closures, respectively.  There's no @SET_RBH_HDR@ macro -- use
1002 @convertToRBH@ instead!!
1003
1004 Note that the NoPTRS and NoNONPTRS macros refer to the *original* closure.
1005
1006 \begin{code}
1007 #define SPEC_RBH_VHS                            (1L)
1008 #define SPEC_RBH_HS                             (FIXED_HS + SPEC_RBH_VHS)
1009
1010 #define SPEC_RBH_CLOSURE_PTR(closure, no)       (((P_)(closure))[SPEC_RBH_HS + (no) - 1])
1011 #define SPEC_RBH_CLOSURE_SIZE(closure)          ((W_)INFO_SIZE(REVERT_INFOPTR(INFO_PTR(closure))))
1012 #define SPEC_RBH_CLOSURE_NoPTRS(closure)        ((W_)INFO_NoPTRS(REVERT_INFOPTR(INFO_PTR(closure))))
1013 #define SPEC_RBH_CLOSURE_NoNONPTRS(closure)     (SPEC_RBH_CLOSURE_SIZE(closure)-SPEC_RBH_CLOSURE_NoPTRS(closure))
1014
1015 #define SPEC_RBH_BQ_LOCN                        (SPEC_RBH_HS)
1016 #define SPEC_RBH_BQ(closure)                    (((P_)(closure))[SPEC_RBH_BQ_LOCN])
1017
1018 #define GEN_RBH_VHS                             (1L)
1019 #define GEN_RBH_HS                              (FIXED_HS + GEN_RBH_VHS)
1020
1021 #define GEN_RBH_CLOSURE_PTR(closure, no)        (((P_)(closure))[GEN_RBH_HS + (no) - 1])
1022 #define GEN_RBH_CLOSURE_SIZE(closure)           (GEN_INFO_SIZE(REVERT_INFOPTR(INFO_PTR(closure))))
1023 #define GEN_RBH_CLOSURE_NoPTRS(closure)         (GEN_INFO_NoPTRS(REVERT_INFOPTR(INFO_PTR(closure))))
1024 #define GEN_RBH_CLOSURE_NoNONPTRS(closure)      (GEN_RBH_CLOSURE_SIZE(closure)-GEN_RBH_CLOSURE_NoPTRS(closure)-GEN_VHS)
1025
1026 #define GEN_RBH_BQ_LOCN                         (GEN_RBH_HS)
1027 #define GEN_RBH_BQ(closure)                     (((P_)(closure))[GEN_RBH_BQ_LOCN])
1028
1029 \end{code}
1030
1031
1032 %************************************************************************
1033 %*                                                                      *
1034 \subsubsection[CONST-closures]{@CONST@ (nullary data-constructor) closure macros}
1035 %*                                                                      *
1036 %************************************************************************
1037
1038 These are never allocated normally---static closures are used
1039 instead.  They arise only as a result of in-place updates which use
1040 @INPLACE_UPD_HDR@.
1041
1042 \begin{code}
1043 #define CONST_HS                                (FIXED_HS)
1044 #define CONST_VHS                               (0L)
1045
1046 #define CONST_CLOSURE_SIZE(closure)             (0L)
1047 #define CONST_CLOSURE_NoPTRS(closure)           (0L)
1048 #define CONST_CLOSURE_NoNONPTRS(closure)        (0L)
1049 \end{code}
1050
1051 %************************************************************************
1052 %*                                                                      *
1053 \subsubsection[CHARLIKE-closures]{@CHARLIKE@ closure macros}
1054 %*                                                                      *
1055 %************************************************************************
1056
1057 These are never allocated normally.  They are a static array of
1058 closures indexed by literal characters.  As with @CONST@ closures,
1059 @CHARLIKE@ closures only arise from in-place updates using
1060 @INPLACE_UPD_HDR@.
1061 \begin{code}
1062 #define CHARLIKE_HS             (FIXED_HS)
1063 #define CHARLIKE_VHS                            (0L)
1064
1065 #define CHARLIKE_CLOSURE_SIZE(closure)          (1L)
1066 #define CHARLIKE_CLOSURE_NoPTRS(closure)        (0L)
1067 #define CHARLIKE_CLOSURE_NoNONPTRS(closure)     (1L)
1068
1069 /* Array of static charlike closures */
1070 extern const W_ CHARLIKE_closures[];
1071
1072 /* Macro to retrieve static charlike closure */
1073 #define CHARLIKE_CLOSURE(the_char) \
1074         (& CHARLIKE_closures[(CHARLIKE_HS+1) * ((W_)(the_char))])
1075
1076 #define CHARLIKE_VALUE(closure) \
1077         (((P_)(closure))[CHARLIKE_HS])
1078
1079 /* INPLACE_UPD_HDR used for inplace updates */
1080 \end{code}
1081
1082
1083 %************************************************************************
1084 %*                                                                      *
1085 \subsubsection[INTLIKE-closures]{@INTLIKE@ closure macros}
1086 %*                                                                      *
1087 %************************************************************************
1088
1089 These may be allocated normally (@SET_INTLIKE_HDR@) or result from
1090 inplace updates (@INPLACE_UPD_HDR@). They may be converted to a static
1091 closure during garbage collection.
1092
1093 Note: the garbage collector (@EVAC_FN(IntLike)@) assumes that this has
1094 the same structure as a @SPEC_1_0@ closure.
1095
1096 \begin{code}
1097 #define INTLIKE_HS              (FIXED_HS)
1098 #define INTLIKE_VHS                             (0L)
1099
1100 #define INTLIKE_CLOSURE_SIZE(closure)           (1L)
1101 #define INTLIKE_CLOSURE_NoPTRS(closure)         (0L)
1102 #define INTLIKE_CLOSURE_NoNONPTRS(closure)      (1L)
1103
1104 /* Array of static intlike closures */
1105 extern P_ INTLIKE_closures;
1106
1107 /* Range of static intlike closures MAX_INTLIKE, MIN_INTLIKE is in GhcConstants.lh */
1108
1109 /* Macro to retrieve static intlike closure */
1110 #define INTLIKE_CLOSURE(the_int) \
1111         (INTLIKE_closures + ((INTLIKE_HS+1) * ((I_)(the_int))))
1112
1113 #define INTLIKE_VALUE(closure) \
1114         ((I_) ((P_)(closure))[INTLIKE_HS])
1115
1116 #define SET_INTLIKE_HDR(closure,infolbl,cc,size,ptrs) \
1117         SET_FIXED_HDR(closure,infolbl,cc)
1118
1119 /* INPLACE_UPD_HDR used for inplace updates */
1120 \end{code}
1121
1122
1123 End multi-slurp protection:
1124 \begin{code}
1125 #endif /* SMClosures_H */
1126 \end{code}