Skip to content

Run fourmolu against plutus-tx-plugin files #7105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions plutus-tx-plugin/app/GeneratePluginOptionsDoc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,32 @@ import Options.Applicative qualified as OA
import Prettyprinter
import PyF (fmt)


newtype Params = Params
{paramOutputFile :: Text}
{paramOutputFile :: Text}

parseParams :: OA.Parser Params
parseParams = do
paramOutputFile <-
OA.argument OA.str $
mconcat
[ OA.metavar "OUTPUT_FILE"
, OA.help "Output file path"
]
pure Params{..}
paramOutputFile <-
OA.argument OA.str $
mconcat
[ OA.metavar "OUTPUT_FILE"
, OA.help "Output file path"
]
pure Params{..}

main :: IO ()
main = do
params <-
OA.execParser $
OA.info
(parseParams OA.<**> OA.helper)
(OA.fullDesc <> OA.header "Generate plugin option documentation")
Text.writeFile (Text.unpack $ paramOutputFile params) optionsTable
params <-
OA.execParser $
OA.info
(parseParams OA.<**> OA.helper)
(OA.fullDesc <> OA.header "Generate plugin option documentation")
Text.writeFile (Text.unpack $ paramOutputFile params) optionsTable

optionsTable :: Text
optionsTable = Text.stripStart $ [fmt|
optionsTable =
Text.stripStart $
[fmt|
---
sidebar_position: 5
---
Expand Down Expand Up @@ -70,5 +71,5 @@ For each boolean option, you can add a `no-` prefix to switch it off, such as `n
genRow :: O.OptionKey -> O.PluginOption -> Text
genRow k (O.PluginOption tr _ field desc _) =
[fmt||`{k}`|{show tr}|{show (pretty defaultValue)}|{desc}||]
where
defaultValue = O.defaultPluginOptions ^. field
where
defaultValue = O.defaultPluginOptions ^. field
162 changes: 84 additions & 78 deletions plutus-tx-plugin/src/PlutusTx/Compiler/Binders.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,99 +31,105 @@ first.
variable *last* (so it is on the outside, so will be first when applying).
-}

withVarScoped ::
CompilingDefault uni fun m ann =>
GHC.Var ->
Ann ->
Maybe (PIRTerm uni fun) ->
(PIR.VarDecl PIR.TyName PIR.Name uni Ann -> m a) ->
m a
withVarScoped
:: (CompilingDefault uni fun m ann)
=> GHC.Var
-> Ann
-> Maybe (PIRTerm uni fun)
-> (PIR.VarDecl PIR.TyName PIR.Name uni Ann -> m a)
-> m a
withVarScoped v ann def k = do
let ghcName = GHC.getName v
var <- compileVarFresh ann v
local (\c -> c {ccScope=pushName ghcName var def (ccScope c)}) (k var)

-- | Like `withVarScoped`, but takes a `PIRType`, and uses it for the type
-- of the compiled `GHC.Var`.
withVarTyScoped ::
CompilingDefault uni fun m ann =>
GHC.Var ->
PIRType uni ->
(PIR.VarDecl PIR.TyName PIR.Name uni Ann -> m a) ->
m a
let ghcName = GHC.getName v
var <- compileVarFresh ann v
local (\c -> c{ccScope = pushName ghcName var def (ccScope c)}) (k var)

{-| Like `withVarScoped`, but takes a `PIRType`, and uses it for the type
of the compiled `GHC.Var`.
-}
withVarTyScoped
:: (CompilingDefault uni fun m ann)
=> GHC.Var
-> PIRType uni
-> (PIR.VarDecl PIR.TyName PIR.Name uni Ann -> m a)
-> m a
withVarTyScoped v t k = do
let ghcName = GHC.getName v
var <- compileVarWithTyFresh annMayInline v t
local (\c -> c {ccScope=pushName ghcName var Nothing (ccScope c)}) (k var)

withVarsScoped ::
CompilingDefault uni fun m ann =>
[(GHC.Var, Maybe (PIRTerm uni fun))] ->
([PIR.VarDecl PIR.TyName PIR.Name uni Ann] -> m a) ->
m a
let ghcName = GHC.getName v
var <- compileVarWithTyFresh annMayInline v t
local (\c -> c{ccScope = pushName ghcName var Nothing (ccScope c)}) (k var)

withVarsScoped
:: (CompilingDefault uni fun m ann)
=> [(GHC.Var, Maybe (PIRTerm uni fun))]
-> ([PIR.VarDecl PIR.TyName PIR.Name uni Ann] -> m a)
-> m a
withVarsScoped vs k = do
vars <- for vs $ \(v, def) -> do
let name = GHC.getName v
var' <- compileVarFresh annMayInline v
pure (name, var', def)
local (\c -> c {ccScope=pushNames vars (ccScope c)}) (k (fmap snd3 vars))

withTyVarScoped ::
Compiling uni fun m ann =>
GHC.Var ->
(PIR.TyVarDecl PIR.TyName Ann -> m a) ->
m a
vars <- for vs $ \(v, def) -> do
let name = GHC.getName v
var' <- compileVarFresh annMayInline v
pure (name, var', def)
local (\c -> c{ccScope = pushNames vars (ccScope c)}) (k (fmap snd3 vars))

withTyVarScoped
:: (Compiling uni fun m ann)
=> GHC.Var
-> (PIR.TyVarDecl PIR.TyName Ann -> m a)
-> m a
withTyVarScoped v k = do
let ghcName = GHC.getName v
var <- compileTyVarFresh v
local (\c -> c {ccScope=pushTyName ghcName var (ccScope c)}) (k var)

withTyVarsScoped ::
Compiling uni fun m ann =>
[GHC.Var] ->
([PIR.TyVarDecl PIR.TyName Ann] -> m a) ->
m a
let ghcName = GHC.getName v
var <- compileTyVarFresh v
local (\c -> c{ccScope = pushTyName ghcName var (ccScope c)}) (k var)

withTyVarsScoped
:: (Compiling uni fun m ann)
=> [GHC.Var]
-> ([PIR.TyVarDecl PIR.TyName Ann] -> m a)
-> m a
withTyVarsScoped vs k = do
vars <- for vs $ \v -> do
let name = GHC.getName v
var' <- compileTyVarFresh v
pure (name, var')
local (\c -> c {ccScope=pushTyNames vars (ccScope c)}) (k (fmap snd vars))

-- | Builds a lambda, binding the given variable to a name that
-- will be in scope when running the second argument.
mkLamAbsScoped ::
CompilingDefault uni fun m ann =>
Ann ->
GHC.Var ->
m (PIRTerm uni fun) ->
m (PIRTerm uni fun)
vars <- for vs $ \v -> do
let name = GHC.getName v
var' <- compileTyVarFresh v
pure (name, var')
local (\c -> c{ccScope = pushTyNames vars (ccScope c)}) (k (fmap snd vars))

{-| Builds a lambda, binding the given variable to a name that
will be in scope when running the second argument.
-}
mkLamAbsScoped
:: (CompilingDefault uni fun m ann)
=> Ann
-> GHC.Var
-> m (PIRTerm uni fun)
-> m (PIRTerm uni fun)
mkLamAbsScoped ann v body =
withVarScoped v ann Nothing $ \(PIR.VarDecl _ n t) ->
PIR.LamAbs ann n t <$> body
withVarScoped v ann Nothing $ \(PIR.VarDecl _ n t) ->
PIR.LamAbs ann n t <$> body

-- | Builds a type abstraction, binding the given variable to a name that
-- will be in scope when running the second argument.
mkTyAbsScoped :: Compiling uni fun m ann => GHC.Var -> m (PIRTerm uni fun) -> m (PIRTerm uni fun)
{-| Builds a type abstraction, binding the given variable to a name that
will be in scope when running the second argument.
-}
mkTyAbsScoped :: (Compiling uni fun m ann) => GHC.Var -> m (PIRTerm uni fun) -> m (PIRTerm uni fun)
mkTyAbsScoped v body = withTyVarScoped v $ \(PIR.TyVarDecl _ t k) -> PIR.TyAbs annMayInline t k <$> body

mkIterTyAbsScoped :: Compiling uni fun m ann => [GHC.Var] -> m (PIRTerm uni fun) -> m (PIRTerm uni fun)
mkIterTyAbsScoped
:: (Compiling uni fun m ann) => [GHC.Var] -> m (PIRTerm uni fun) -> m (PIRTerm uni fun)
mkIterTyAbsScoped vars body = foldr (\v acc -> mkTyAbsScoped v acc) body vars

-- | Builds a forall, binding the given variable to a name that
-- will be in scope when running the second argument.
mkTyForallScoped :: Compiling uni fun m ann => GHC.Var -> m (PIRType uni) -> m (PIRType uni)
{-| Builds a forall, binding the given variable to a name that
will be in scope when running the second argument.
-}
mkTyForallScoped :: (Compiling uni fun m ann) => GHC.Var -> m (PIRType uni) -> m (PIRType uni)
mkTyForallScoped v body =
withTyVarScoped v $ \(PIR.TyVarDecl _ t k) -> PIR.TyForall annMayInline t k <$> body
withTyVarScoped v $ \(PIR.TyVarDecl _ t k) -> PIR.TyForall annMayInline t k <$> body

mkIterTyForallScoped :: Compiling uni fun m ann => [GHC.Var] -> m (PIRType uni) -> m (PIRType uni)
mkIterTyForallScoped :: (Compiling uni fun m ann) => [GHC.Var] -> m (PIRType uni) -> m (PIRType uni)
mkIterTyForallScoped vars body = foldr (\v acc -> mkTyForallScoped v acc) body vars

-- | Builds a type lambda, binding the given variable to a name that
-- will be in scope when running the second argument.
mkTyLamScoped :: Compiling uni fun m ann => GHC.Var -> m (PIRType uni) -> m (PIRType uni)
{-| Builds a type lambda, binding the given variable to a name that
will be in scope when running the second argument.
-}
mkTyLamScoped :: (Compiling uni fun m ann) => GHC.Var -> m (PIRType uni) -> m (PIRType uni)
mkTyLamScoped v body =
withTyVarScoped v $ \(PIR.TyVarDecl _ t k) -> PIR.TyLam annMayInline t k <$> body
withTyVarScoped v $ \(PIR.TyVarDecl _ t k) -> PIR.TyLam annMayInline t k <$> body

mkIterTyLamScoped :: Compiling uni fun m ann => [GHC.Var] -> m (PIRType uni) -> m (PIRType uni)
mkIterTyLamScoped :: (Compiling uni fun m ann) => [GHC.Var] -> m (PIRType uni) -> m (PIRType uni)
mkIterTyLamScoped vars body = foldr (\v acc -> mkTyLamScoped v acc) body vars
Loading