Skip to content

Add Plinth parsed-AST deriving plugin to plutus-tx-plugin#7818

Draft
Icelandjack wants to merge 1 commit into
IntersectMBO:masterfrom
Icelandjack:baldurb/plinth-deriving-plugin
Draft

Add Plinth parsed-AST deriving plugin to plutus-tx-plugin#7818
Icelandjack wants to merge 1 commit into
IntersectMBO:masterfrom
Icelandjack:baldurb/plinth-deriving-plugin

Conversation

@Icelandjack

Copy link
Copy Markdown

What

Ports the PlinthPlugin parsed-result plugin from the ghc-plinth "standalone
Plinth" effort into plutus-tx-plugin. It expands data declarations written
with deriving … via PlinthPlugin into:

  • AsData pattern synonyms (a newtype over BuiltinData plus bidirectional patterns)
  • Optics prisms
  • Match destructor functions

It runs at parsedResultAction, alongside the existing core Plinth.Plugin.
The deriving sentinel lives in PlinthPlugin.Via (data Via = PlinthPlugin).

Notes / open items

  • Builds on GHC 9.6 and 9.12 via CPP shims (9.12 verified locally; 9.6 relies on CI here).
  • No activation/golden test yet: the modules compile, but nothing loads the plugin in plutus (in ghc-plinth it is baked in as a static plugin). A test-frontend-plugin-style golden test is the natural follow-up.
  • Licensing: the code originated as Evoke (MIT); needs an attribution decision relative to plutus's Apache-2.0.

🤖 Generated with Claude Code

@Icelandjack Icelandjack marked this pull request as draft June 16, 2026 12:22
-- This function is responsible for analyzing a deriving strategy to determine
-- if the plugin should fire or not.
parseDerivingStrategy ::
Maybe (Ghc.LDerivStrategy Ghc.GhcPs) -> Maybe [String]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it return a Bool?

Comment thread plutus-tx-plugin/src/PlinthPlugin.hs Outdated
Comment on lines +49 to +59
flags <- Options.parse Flag.options commandLineOptions srcSpan
let config = Config.fromFlags flags

Monad.when (Config.help config)
. Hsc.throwError srcSpan
. Ghc.vcat
. fmap Ghc.text
. lines
$ Console.usageInfo ("PlinthPlugin version " <> version) Flag.options
Monad.when (Config.version config) . Hsc.throwError srcSpan $
Ghc.text version

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this command-line stuff?

It adds quite a lot of complexity (Paths_ module, Flag, Config) and I'm not sure why?

Comment on lines +2 to +4
-- The plugin-generated code uses 'head'/'tail' internally and emits pattern
-- synonyms without top-level signatures; suppress those warnings here (the
-- -Wno-unrecognised-warning-flags keeps -Wno-x-partial harmless pre-GHC 9.8).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we generate explicit pattern matches instead of head/tail?

Could we generate the top-level signatures too?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both done in latest push. No head/tail, Match generator and AsData use an explicit pattern. Top-level signatures are generated.

Comment thread plutus-tx-plugin/src/PlinthPlugin.hs Outdated
Ghc.HsTyVar _ _ x -> Just $ Ghc.unLoc x
_ -> Nothing
case Ghc.occNameString $ Ghc.rdrNameOcc rdrName of
"PlinthPlugin" -> Just []

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"PlinthPlugin" -> Just []
"Plinth" -> Just []

Users don't care that it is a plugin or not.

Comment thread plutus-tx-plugin/plutus-tx-plugin.cabal Outdated
@Icelandjack Icelandjack force-pushed the baldurb/plinth-deriving-plugin branch from f40105d to 3673d06 Compare June 29, 2026 08:02
data declarations written with `deriving … via PlinthPlugin` into
AsData pattern synonyms, Optics prisms, and Match functions at parse
time, alongside the existing core Plinth.Plugin.
@Icelandjack Icelandjack force-pushed the baldurb/plinth-deriving-plugin branch from 3673d06 to 9988b8d Compare June 29, 2026 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants