A record containing all the stages necessary for the operation of a type-checking plugin, as defined in this API.
Note: this is not the same record as GHC's built-in TcPlugin record. Use mkTcPlugin for the conversion.
To create a type-checking plugin, define something of this type
and then call mkTcPlugin on the result.
This will return something that can be passed to GHC.Plugins.Plugin:
plugin :: GHC.Plugins.Plugin
plugin =
GHC.Plugins.defaultPlugin
{ GHC.Plugins.tcPlugin =
\ args -> Just $
GHC.TcPlugin.API.mkTcPlugin ( myTcPlugin args )
}
myTcPlugin :: [String] -> GHC.TcPlugin.API.TcPlugin
myTcPlugin args = ...Constructors
forall s. TcPlugintcPluginInit :: TcPluginM 'Init sInitialize plugin (once per module), when starting the type-checker.
tcPluginSolve :: s -> TcPluginSolverSolve some constraints.
This function will be invoked at two points in the constraint solving process: once to simplify Given constraints, and once to solve Wanted constraints. In the first case (and only in the first case), no Wanted constraints will be passed to the plugin.
The plugin can either return a contradiction, or specify that it has solved some constraints (with evidence), and possibly emit additional constraints. These returned constraints must be Givens in the first case, and Wanteds in the second.
Use
\ _ _ _ _ -> pure $ TcPluginOk [] []if your plugintcPluginRewrite :: s -> UniqFM TyCon TcPluginRewriterRewrite saturated type family applications.
The plugin is expected to supply a mapping from type family names to rewriting functions. For each type family TyCon, the plugin should provide a function which takes in the given constraints and arguments of a saturated type family application, and return a possible rewriting. See TcPluginRewriter for the expected shape of such a function.
Use
const emptyUFMif your plugin does not provide this functionality.tcPluginPostTc :: s -> TcPluginM 'PostTc ()Action to run at the end of typechecking a module, e.g. to intercept the final
TcGblEnv/TcLclEnvat the end of typechecking, possibly modifying mutable fields.Should not terminate the plugin, as the plugin may continue to be invoked when desugaring the module (as the pattern-match checker may invoke the constraint solver).
tcPluginShutdown :: s -> IO ()Clean up after the plugin, when GHC is done processing the given module (e.g. after desugaring).