Adding flags to a PointerIntPair that has run out of space?

i was experimenting with something that involved trying to add a new flag to the CapturedValue type. i was not previously familiar with 'PointerIntPair', but it seems that this type in particular stores its flags within its pointer, and it appears to only have room for 2 bits. does anyone have any refactoring tips for this sort of situation? what's the most straightforward way to add storage for more flags?

It's generally portable to store up to 3 bits of flags in PointerIntPair. However, in the case of CapturedValue's storage, one of those 3 bits is already being consumed by the PointerUnion payload since that's also designed to take advantage of uninhabited bits in order to discriminate which union value is stored. So all 3 extra bits in that pointer sized field are already used.

If you need to add more flags you may just have to widen this struct by adding dedicated flags field. I'm not super familiar with CapturedValue but I suspect expanding its stride from 2 words to 3 words won't really noticeably change compiler memory usage.

1 Like