Back-end responsibilities are distributed throughout the compiler
A back end for GHC is described by a value of type GHC.Driver.Backend.Backend
. This type is an enumeration type. The semantics of a particular value constructor is determined by code spread throughout the compiler: while it would be tedious to count exactly how many modules include a case
discrimination on the Backend
type, the GHC.Driver.Backend
module is imported by over 20 other modules. This distributed semantics makes it a bit challenging to add a new value of Backend
type, as is being contemplated for both JavaScript and WebAssembly targets.
One possible remedy would be to keep the existing compiler structure as much as possible, but to make the Backend
type abstract, centralizing all the Backend
-dependent functionality in one module. Because of the potential for recursive imports, such a refactoring is not quite possible, but an approximation would probably be good enough.