Skip to content

Introduce OutputableP

Sylvain Henry requested to merge hsyl20/ghc:hsyl20/dynflags/outputablep into master

Some types need a Platform value to be pretty-printed: CLabel, Cmm types, instructions, etc.

Before this patch they had an Outputable instance and the Platform value was obtained via sdocWithDynFlags. It meant that the renderer of the SDoc was responsible of passing the appropriate Platform value (e.g. via the DynFlags given to showSDoc). It put the burden of passing the Platform value on the renderer while the generator of the SDoc knows the Platform it is generating the SDoc for and there is no point passing a different Platform at rendering time.

With this patch, we introduce a new OutputableP class:

class OutputableP a where
    pdoc :: Platform -> a -> SDoc

With this class we still have some polymorphism as we have with ppr (i.e. we can use pdoc on a variety of types instead of having a dedicated pprXXX function for each XXX type).

One step closer removing sdocWithDynFlags (#10143 (closed)) and supporting several platforms (#14335).

Edited by Sylvain Henry

Merge request reports