Follow up: Modifying the "StgHeader" struct

Sylvain Henry sylvain at haskus.fr
Mon Mar 18 10:31:42 UTC 2024


Hi,

Adding a new way that changes heap closure representation won't be 
trivial. Handling of the profiling way is very ad-hoc.

Did you update the `deriveConstants` utils and 
`ghc:GHC.Runtime.Heap.Layout.*HdrSize` to take into account your new 
optional field?

Sylvain


On 18/03/2024 08:47, Adithya Kumar wrote:
> Hey folks,
>
> I'm adding a field to "StgHeader" under a flag.
>
> ```
> typedef struct {
>     const StgInfoTable* info;
> #if defined(NEW_WAY)
>     StgWord             new_field;
> #endif
> #if defined(PROFILING)
>     StgProfHeader         prof;
> #endif
> } StgHeader;
>
> typedef struct {
>     const StgInfoTable* info;
> #if defined(NEW_WAY)
>     StgWord             new_field;
> #endif
> #if defined(PROFILING)
>     StgProfHeader         prof;
> #endif
>     StgSMPThunkHeader     smp;
> } StgThunkHeader;
> ```
>
> Follow-up changes:
> ==================
>
> The following are the additional changes I've made following the 
> `PROFILING`
> flag:
>
> Similar to `PROF_HDR_FIELDS` macro, I've added `NEW_HDR_FIELDS` macro:
>
> ```
> #if defined(NEW_WAY)
> #define NEW_HDR_FIELDS(w_,hdr) w_ hdr,
> #else
> #define NEW_HDR_FIELDS(w_,hdr) /* Nothing */
> #endif
> ```
> and updated the required stg code accordingly following the changes from
> `PROF_HDR_FIELDS`.
>
> I've also updated `GHC.Exts.Heap.ClosureTypes.closureTypeHeaderSize`
> accordingly.
>
> Error:
> ======
>
> I'm greeted with the following error,
> ```
> ASSERTION FAILED: file rts/StgStartup.cmm, line 100
> ```
>
> Basically, the following assert fails
> ```
> #define CHECK_SENSIBLE_REGS()                           \
>     ASSERT(Hp != 0);                                    \
>     ASSERT(HpAlloc == 0);                               \
>     ASSERT(Sp != 0);                                    \
>     ASSERT(SpLim != 0);                                 \
>     ASSERT(SpLim - WDS(RESERVED_STACK_WORDS) <= Sp);
> ```
>
> More context for the error:
> ===========================
>
> Values for the correct version:
> ```
> Hp      283468906488
> HpAlloc 0
> Sp      283468911440
> SpLim   283468910784
> SpLim - WDS(RESERVED_STACK_WORDS) 1069080
> ```
>
> Values with the changes:
> ```
> Hp      283468906488
> HpAlloc 0
> Sp      7532120
> SpLim   9301536
> SpLim - WDS(RESERVED_STACK_WORDS) 9301368
> ```
>
> I recorded these values by calling a C print from the Cmm code.
>
> Clearly, my changes messed up a lot of things. How do I go about this 
> now? The
> past 2 weeks I've only been looking at a lot of ghc code. If any more 
> additional
> context is required I can provide it.
>
> Best,
> Adithya
>
> _______________________________________________
> ghc-devs mailing list
> ghc-devs at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs


More information about the ghc-devs mailing list