Expose a stable subset of `DynFlags` API for TH
Motivation
There are situations where we desire different code generation based on compiler arguments, with TH today, we can already query a lot of information about the environment such as package root, env variables, and consequently a lot more via runIO
. Compiler arguments, specially ones that impact the final code object, should be part of the list.
Where that might be specially useful is FFI
. If we can query what C/C++ compiler GHC will use, and what libraries or included directories it will relay to the respective compiler, we could use that information to generate more specific code. A concrete example is the simple problem of dependency tracking for generators. addDependentFile
allows us to signal files that should trigger recompilation, but we do not currently have a principled way to be able to properly express all the files we need to depend on without having access to some DynFlags
.
Note this is already possible, either via accessing the underlying TcM
that runs Template Haskell's Q
via unsafeCoerce
, or by a level of indirection where some of the information given to the compiler is present on the environment. The latter is imprecise, as the source of truth is what is given to GHC, and a library depending on implicit env information could lead to confusion, were it to not be setup properly.
Inline with that, I am sure more creative applications would arise, and if GHC has stable flags, exposing those should not hamper future changes to the compiler.