Idea: consider implementing a standard selector thunk with variable offset
Idea came up during discussion with @AndreasK.
Currently we have selector thunks in the RTS for selecting offset in range [0 .. 15].
For selecting fields outside of that range we generate code for every selector.
If we implement a selector thunk info table in the RTS that has the offset in the payload, for every selector thunk (even when the offset is larger than 15) we can generate the selector thunk code from the RTS and avoid generating code.
So if call the info table stg_sel_n_info
, a selector that selects 100th field
would look like:
[stg_sel_n_info, 0, selectee, 100]
We could use this info table for selecting range [0..15] too, of course. So that'd be another thing to experiment with.
One motivation comes from GHC's code base: DynFlags
is a huge record, and many
selections in that record will have offset greater than 15, so we generate code
for a lot of the field accesses on DynFlags
. If we had this standard thunk we
wouldn't have to generate code for DynFlags
field accesses.