GHC issueshttps://gitlab.haskell.org/ghc/ghc/-/issues2019-07-07T18:02:49Zhttps://gitlab.haskell.org/ghc/ghc/-/issues/15826Allow registering (Source)Plugins through the GHC API2019-07-07T18:02:49ZDanielGAllow registering (Source)Plugins through the GHC APIOne might expect to be able to load plugins through the GHC API by doing something like:
```
runGHC $ do
dflags <- getSessionDynFlags
setSessionDynFlags dflags { plugins = [LoadedPlugin some_plugin _conjure_up_modiface []] }
```
bu...One might expect to be able to load plugins through the GHC API by doing something like:
```
runGHC $ do
dflags <- getSessionDynFlags
setSessionDynFlags dflags { plugins = [LoadedPlugin some_plugin _conjure_up_modiface []] }
```
but this doesn't actually work because the `plugins` field in `DynFlags` is used as a cache and overwritten by `initializePlugins` whenever plugins loaded through the command-line need reloading. Not to mention that there isn't a meaningful way to fill the `_conjure_up_modiface` hole AFAIK.
While in principle it might be possible to use source plugins via the API right now by messing with the exposed cmdline flags the right way it feels much cleaner to just have a new type of plugin that can be added to GHC right through the API.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | -------------- |
| Version | 8.7 |
| Type | FeatureRequest |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Allow using (Source)Plugins through the GHC API","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.7","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"FeatureRequest","description":"One might expect to be able to load plugins through the GHC API by doing something like:\r\n\r\n{{{\r\nrunGHC $ do\r\n dflags <- getSessionDynFlags\r\n setSessionDynFlags dflags { plugins = [LoadedPlugin some_plugin _conjure_up_modiface []] }\r\n}}}\r\n\r\nbut this doesn't actually work because the `plugins` field in `DynFlags` is used as a cache and overwritten by `initializePlugins` whenever plugins loaded through the command-line need reloading. Not to mention that there isn't a meaningful way to fill the `_conjure_up_modiface` hole AFAIK.\r\n\r\nWhile in principle it might be possible to use source plugins via the API right now by messing with the exposed cmdline flags the right way it feels much cleaner to just have a new type of plugin that can be added to GHC right through the API.","type_of_failure":"OtherFailure","blocking":[]} -->8.8.1DanielGDanielG