Specifically, if a function is marked as @transparent or @inlinable, the compiler serializes the SIL generated for the function and the merge modules pass has access to the SIL IR generated for such functions in imported modules. I would like to replicate that behavior by making the SIL IR generated for inlinable functions in one REPL line to be available when parsing subsequent REPL lines.
We also need this in the context of Automatic Differentiation and Graph Program Extraction that we are implementing as part of the Swift for TensorFlow project. Both of these components benefit from having access to the SIL IR generated for certain functions in imported modules.
I have created a proof-of-concept patch to get this working. Basically, it serializes the SIL module for each REPL line into a .swiftmodule in a temporary directory for the session and imports them later. It is admittedly hacky and not robust, but I am looking for feedback on whether this is the right direction to pursue.