Bytecode generator: Allocate constructor closures immediately when possible for let bound constructors.
Currently the byte code generator always creates a BCO which will eventually allocate the constructor once executed instead of allocating a constructor immediately.
I became acutely aware of this while looking into #22840 (closed)
At least for top level constructors when using the internal interpreter we should be able to immediately allocate constructors on the heap instead of generating a BCO which then allocates the constructor on the heap.
E.g currently for foo = Just True
we get:
[1 of 1] Compiling M ( test.hs, interpreted )
==================== CodeGenInput STG: ====================
M.foo :: GHC.Maybe.Maybe GHC.Types.Bool
[GblId] =
{} \u [] GHC.Maybe.Just [GHC.Types.True];
==================== Proto-BCOs ====================
ProtoBCO M.foo#0 []:
\u [] break<0>() GHC.Maybe.Just [GHC.Types.True]
bitmap: 0 []
BRK_FUN 0 ESg45 <cc>
PACK GHC.Types.True 0
PACK GHC.Maybe.Just 1
RETURN
But when using the internal interpreter at least we could allocate the closure for the Just value right away and just use a pointer to that instead of a pointer to the BCO.
Without having looked at this issue deeply however I don't see a good way to make this happen for the external interpreter, nor for local binds which might capture arguments whos address we do not yet know. Without being able to tackle these it might not be worth making this change. But it's possible that there are good solutions for this which I have not thought off.