[GHC] #15826: Allow using (Source)Plugins through the GHC API

#15826: Allow using (Source)Plugins through the GHC API -------------------------------------+------------------------------------- Reporter: DanielG | Owner: (none) Type: feature | Status: new request | Priority: normal | Milestone: Component: Compiler | Version: 8.7 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- 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. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15826 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15826: Allow registering (Source)Plugins through the GHC API -------------------------------------+------------------------------------- Reporter: DanielG | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15826#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15826: Allow registering (Source)Plugins through the GHC API -------------------------------------+------------------------------------- Reporter: DanielG | Owner: DanielG Type: feature request | Status: new Priority: normal | Milestone: Component: GHC API | Version: 8.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by DanielG): * owner: (none) => DanielG * component: Compiler => GHC API -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15826#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15826: Allow registering (Source)Plugins through the GHC API -------------------------------------+------------------------------------- Reporter: DanielG | Owner: DanielG Type: feature request | Status: new Priority: normal | Milestone: Component: GHC API | Version: 8.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): D5278 Wiki Page: | -------------------------------------+------------------------------------- Changes (by DanielG): * differential: => D5278 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15826#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15826: Allow registering (Source)Plugins through the GHC API -------------------------------------+------------------------------------- Reporter: DanielG | Owner: DanielG Type: feature request | Status: new Priority: normal | Milestone: Component: GHC API | Version: 8.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): D5278 Wiki Page: | -------------------------------------+------------------------------------- Comment (by mpickering): The reason for the existence of the `ModIface` is for recompilation checking. How do you imagine recompilation checking working for functions added using the API? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15826#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15826: Allow registering (Source)Plugins through the GHC API -------------------------------------+------------------------------------- Reporter: DanielG | Owner: DanielG Type: feature request | Status: new Priority: normal | Milestone: Component: GHC API | Version: 8.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): D5278 Wiki Page: | -------------------------------------+------------------------------------- Comment (by DanielG): I guess "plugin" is the wrong term here, so that might be causing some confusion. The whole point of this endeavor is to be able to use plugins already compiled into the programm calling the GHC API, without loading anything dynamically, so recompilation checking simply isn't needed here. The idea is that since GHC now has plugin support lots of people will build interresintg plugins and I'd like to be able to use these in tooling projects without mucking about with having to `cabal install` them at runtime. So instead I figure since plugins are just regular packages/modules why not just link against them at build time? If I just wanted to just load some (dynamically) loaded plugins through the GHC API you are right, what I'm doing wouldn't make much sense. That just not the use-case though. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15826#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15826: Allow registering (Source)Plugins through the GHC API -------------------------------------+------------------------------------- Reporter: DanielG | Owner: DanielG Type: feature request | Status: new Priority: normal | Milestone: Component: GHC API | Version: 8.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): D5278 Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj):
The reason for the existence of the ModIface is for recompilation checking.
Recomopilation checking is a ''contributory'' reason. But the `Iface` data type is incredibly useful as an intermediate between the serialised bytestring form of a `.hi` file and a fully type-checked form of the module `ModDetails`. `TcIface` goes from `ModIface` to `ModDetails`. But yes, `ModIface` is a great intermediate form on which to base fingerprint generation. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15826#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15826: Allow registering (Source)Plugins through the GHC API -------------------------------------+------------------------------------- Reporter: DanielG | Owner: DanielG Type: feature request | Status: new Priority: normal | Milestone: Component: GHC API | Version: 8.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): D5278 Wiki Page: | -------------------------------------+------------------------------------- Comment (by mpickering): That's a fair point. I should have clarified I was talking specifically about the `ModIface` field in the `LoadedPlugin` datatype. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15826#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15826: Allow registering (Source)Plugins through the GHC API -------------------------------------+------------------------------------- Reporter: DanielG | Owner: DanielG Type: feature request | Status: new Priority: normal | Milestone: Component: GHC API | Version: 8.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): D5278 Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): Alright, I see the use-case here and it sounds reasonable. However, I agree that we need to make sure that recompilation checking works in a safe and predictable manner. Let's first try to specify what semantics we are looking for. Here is my guess: a. within a GHC session with a `LoadedPlugin` the plugin-module hash check should never trigger a recompilation but the plugin's `PluginRecompile` strategy should, of course, be able to trigger a rebuild b. build artifacts produced by a GHC session with a `LoadedPlugin` should never be used by another session Does this sound right, DanielG? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15826#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15826: Allow registering (Source)Plugins through the GHC API -------------------------------------+------------------------------------- Reporter: DanielG | Owner: DanielG Type: feature request | Status: new Priority: normal | Milestone: Component: GHC API | Version: 8.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): D5278 Wiki Page: | -------------------------------------+------------------------------------- Comment (by DanielG): I assume you mean `s/LoadedPlugin/StaticPlugin/` above? My patch doesn't change anything about how `LoadedPlugin`s are handled. Indeed since `StaticPlugin` doesn't have an associated `ModIface` only the `PluginRecompile` field can influence recompilation and that's intended. As for build products: right now I only intend to use plugins that extract information while GHC is compiling and not change anything. If someone decides to use a plugin that changes the build output I don't see how the situation is any different for `StaticPlugin` compared to `LoadedPlugin`. If the plugin changes the build output it must sutably declare `pluginRecompile`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15826#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15826: Allow registering (Source)Plugins through the GHC API -------------------------------------+------------------------------------- Reporter: DanielG | Owner: DanielG Type: feature request | Status: patch Priority: normal | Milestone: Component: GHC API | Version: 8.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D5278 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => patch * differential: D5278 => Phab:D5278 Comment: Sigh, yes. `s/LoadedPlugin/StaticPlugin/` indeed.
If someone decides to use a plugin that changes the build output I don't see how the situation is any different for `StaticPlugin` compared to `LoadedPlugin`. If the plugin changes the build output it must suitably declare `pluginRecompile`.
The difference I was thinking of is that a compiler session using a `LoadedPlugin` will recompile if a different version of the plugin in used (see #15492). This is accounted for in `DsUsage.mkPluginUsage`. Looking more closely at this, I actually suspect this logic will ensure that the right thing happens. However, we would need a test to know for certain. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15826#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15826: Allow registering (Source)Plugins through the GHC API -------------------------------------+------------------------------------- Reporter: DanielG | Owner: DanielG Type: feature request | Status: patch Priority: normal | Milestone: Component: GHC API | Version: 8.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D5278 Wiki Page: | -------------------------------------+------------------------------------- Comment (by DanielG): Yeah I just had another look and I think I forgot to hook up some of the recompilation logic, I'll fix it and add some tests. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15826#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15826: Allow registering (Source)Plugins through the GHC API
-------------------------------------+-------------------------------------
Reporter: DanielG | Owner: DanielG
Type: feature request | Status: patch
Priority: normal | Milestone:
Component: GHC API | Version: 8.7
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D5278
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#15826: Allow registering (Source)Plugins through the GHC API -------------------------------------+------------------------------------- Reporter: DanielG | Owner: DanielG Type: feature request | Status: closed Priority: normal | Milestone: 8.8.1 Component: GHC API | Version: 8.7 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D5278 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => closed * resolution: => fixed * milestone: => 8.8.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15826#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC