Draft: Use a more efficient printer for code generation
This is a work-in-progress implementation of the change described in #21853 (closed). Not everything is totally cleaned up yet, and there are a few things left to be implemented, but enough is in place to accurately represent the nature of the changes. Here is a high level summary of the patch:
-
GHC.Utils.Outputable.HDocprovides a newHDoctype, which is a stripped-down version ofSDocthat writes directly to aBufHandle. -
GHC.Utils.Outputable.Classprovides a shared interface to bothSDocandHDoc, which allows code to be parameterized over the choice of output. -
The
OutputableandOutputablePclasses now include an additional parameter that selects the output implementation.-
Most code that previously used
SDocremains specialized toSDoc. The only required changes for this code are replacements ofOutputablewithOutputable SDoc. -
Printing logic that is used by the code generator is changed to be polymorphic in the choice of output. Usually, this requires little to no changes other than making the types more generic and adding any necessary
SPECIALIZEpragmas.
-
-
The NCG is updated to use
HDocinstead ofSDoc. (Currently, only the x86 printer is updated, but PPC and AArch64 will eventually be updated as well.)
I would appreciate any feedback on the general approach, particularly on the use of the IsLine/IsDoc classes and the reliance on specialization.
NB: This patch currently depends on a fix for #21851 (closed) to achieve maximal performance gains. Since no such fix has materialized, this MR includes a temporary workaround that just runs the simplifier again after specialization. This workaround will be removed before merging and should not be considered part of the patch.