<div dir="ltr"><div>Dear devs,<div><br></div><div>I upgraded inline-java [1] to use GHC 9.10.2 recently. inline-java has a GHC plugin responsible for embedding JVM bytecode in Haskell modules. This message is to consult on the most appropriate way to do it.</div><div><br></div><div>The byte code is placed in a C literal array of bytes, and the C code is added in mg_foreign together with C constructor functions that run when loading the module to add the bytecode to a global bytecode table [2]. The global bytecode table is then fed to the JVM when initializing inline-java.</div><div><br></div><div>The GHC API in 9.10.2 requires creating a CStub which does have a field to indicate constructor functions [3], but I wouldn't know how to create the CLabels it needs. So instead, I just put the constructor functions in the getCStub field, and set getInitializers to an empty list. The constructor functions seem to run at initialization just the same.</div><div><br></div><div>Should inline-java do this differently?</div><div><br></div><div>Thanks in advance!</div><div>Facundo</div><div><br></div><div>[1] <a href="https://github.com/tweag/inline-java" target="_blank">https://github.com/tweag/inline-java</a></div><div>[2] <a href="https://github.com/tweag/inline-java/blob/c6b590c29ef9190164dec3a235b8e386c537bd29/src/Language/Java/Inline/Plugin.hs#L87" target="_blank">https://github.com/tweag/inline-java/blob/c6b590c29ef9190164dec3a235b8e386c537bd29/src/Language/Java/Inline/Plugin.hs#L87</a><br>[3] <a href="https://gitlab.haskell.org/ghc/ghc/-/blob/3c37d30b07fc85fe09452f4ce250aec42cb1d2e4/compiler/GHC/Types/ForeignStubs.hs#L23" target="_blank">https://gitlab.haskell.org/ghc/ghc/-/blob/3c37d30b07fc85fe09452f4ce250aec42cb1d2e4/compiler/GHC/Types/ForeignStubs.hs#L23</a></div><div><br><div>data CStub = CStub { getCStub :: SDoc<br>                   , getInitializers :: [CLabel]<br>                     -- ^ Initializers to be run at startup<br>                     -- See Note [Initializers and finalizers in Cmm] in<br>                     -- "GHC.Cmm.InitFini".<br>                   , getFinalizers :: [CLabel]<br>                     -- ^ Finalizers to be run at shutdown<br>                   }</div></div></div><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><span style="font-family:Mulish,sans-serif;margin-bottom:inherit;line-height:inherit"><font color="#000000">All views and opinions expressed in this email message are the personal opinions of the author and do not represent those of the </font></span>organization or its customers.<br></div></div></div></div>