Confused about PAP object layout

Ömer Sinan Ağacan omeragacan at
Fri Feb 14 11:49:21 UTC 2020

Hi Simon,

In this code: (slightly simplified)

    scavenge_PAP (StgPAP *pap)
        return scavenge_PAP_payload (pap->fun, pap->payload, pap->n_args);

    scavenge_PAP_payload (StgClosure *fun, StgClosure **payload, StgWord size)
        const StgFunInfoTable *fun_info =
        StgPtr p = (StgPtr)payload;

        switch (fun_info->f.fun_type) {
        case ARG_GEN_BIG:
            scavenge_large_bitmap(p, GET_FUN_LARGE_BITMAP(fun_info), size);
            p += size;
        return p;

Here the `size` argument in `scavenge_PAP_payload` is the number of arguments
applied to the function in `pap->fun`. But when scavenging the function's bitmap
we're using this number as the size of the bitmap which doesn't make sense to
me, because I think size of the function's bitmap and size of the PAP's payload
may be different.

Or in other words I may have the same function used in many PAPs with different
n_args, but that'd be buggy if this code is correct.

I haven't checked every single place where we build a PAP but for example the
`NEW_PAP` macro uses the argument's (another PAP) function directly, without
making any bitmap-related changes, but bumps n_args by one. If the code above is
right, then this new PAP will be scavenged incorrectly.

Am I missing anything?



More information about the ghc-devs mailing list