diff --git a/plutus-core/changelog.d/20240620_025344_effectfully_remove_Emitter_and_MonadEmitter.md b/plutus-core/changelog.d/20240620_025344_effectfully_remove_Emitter_and_MonadEmitter.md new file mode 100644 index 00000000000..50b699210d9 --- /dev/null +++ b/plutus-core/changelog.d/20240620_025344_effectfully_remove_Emitter_and_MonadEmitter.md @@ -0,0 +1,7 @@ +### Removed + +- Removed `Emitter` and `MonadEmitter` in #6224. + +### Changed + +- Changed the type of `emit` to `Text -> BuiltinResult ()` in #6224. diff --git a/plutus-core/plutus-core.cabal b/plutus-core/plutus-core.cabal index 70944d10bbe..ec4def5ff28 100644 --- a/plutus-core/plutus-core.cabal +++ b/plutus-core/plutus-core.cabal @@ -96,7 +96,6 @@ library PlutusCore.Builtin PlutusCore.Builtin.Debug PlutusCore.Builtin.Elaborate - PlutusCore.Builtin.Emitter PlutusCore.Check.Normal PlutusCore.Check.Scoping PlutusCore.Check.Uniques diff --git a/plutus-core/plutus-core/src/PlutusCore/Builtin.hs b/plutus-core/plutus-core/src/PlutusCore/Builtin.hs index ba73d2d989d..fc34b3d4d70 100644 --- a/plutus-core/plutus-core/src/PlutusCore/Builtin.hs +++ b/plutus-core/plutus-core/src/PlutusCore/Builtin.hs @@ -4,7 +4,6 @@ module PlutusCore.Builtin ( module Export ) where -import PlutusCore.Builtin.Emitter as Export import PlutusCore.Builtin.HasConstant as Export import PlutusCore.Builtin.KnownKind as Export import PlutusCore.Builtin.KnownType as Export diff --git a/plutus-core/plutus-core/src/PlutusCore/Builtin/Emitter.hs b/plutus-core/plutus-core/src/PlutusCore/Builtin/Emitter.hs deleted file mode 100644 index 84d813d0f0f..00000000000 --- a/plutus-core/plutus-core/src/PlutusCore/Builtin/Emitter.hs +++ /dev/null @@ -1,26 +0,0 @@ -module PlutusCore.Builtin.Emitter - ( Emitter (..) - , runEmitter - , MonadEmitter (..) - ) where - -import Control.Monad.Trans.Writer.Strict (Writer, runWriter, tell) -import Data.DList as DList -import Data.Text (Text) - --- | A monad for logging. -newtype Emitter a = Emitter - { unEmitter :: Writer (DList Text) a - } deriving newtype (Functor, Applicative, Monad) - -runEmitter :: Emitter a -> (a, DList Text) -runEmitter = runWriter . unEmitter -{-# INLINE runEmitter #-} - --- | A type class for \"this monad supports logging\". -class MonadEmitter m where - emit :: Text -> m () - -instance MonadEmitter Emitter where - emit = Emitter . tell . pure - {-# INLINE emit #-} diff --git a/plutus-core/plutus-core/src/PlutusCore/Builtin/KnownType.hs b/plutus-core/plutus-core/src/PlutusCore/Builtin/KnownType.hs index 3c4b7a79cf9..46b3c46a430 100644 --- a/plutus-core/plutus-core/src/PlutusCore/Builtin/KnownType.hs +++ b/plutus-core/plutus-core/src/PlutusCore/Builtin/KnownType.hs @@ -33,7 +33,6 @@ module PlutusCore.Builtin.KnownType import PlutusPrelude -import PlutusCore.Builtin.Emitter import PlutusCore.Builtin.HasConstant import PlutusCore.Builtin.Polymorphism import PlutusCore.Builtin.Result @@ -352,20 +351,6 @@ instance readKnown _ = throwUnderTypeError {-# INLINE readKnown #-} -instance - ( TypeError ('Text "Use ‘BuiltinResult’ instead of ‘Emitter’") - , uni ~ UniOf val - ) => MakeKnownIn uni val (Emitter a) where - makeKnown _ = throwUnderTypeError - {-# INLINE makeKnown #-} - -instance - ( TypeError ('Text "Use ‘BuiltinResult’ instead of ‘Emitter’") - , uni ~ UniOf val - ) => ReadKnownIn uni val (Emitter a) where - readKnown _ = throwUnderTypeError - {-# INLINE readKnown #-} - instance HasConstantIn uni val => MakeKnownIn uni val (SomeConstant uni rep) where makeKnown = coerceArg $ pure . fromConstant {-# INLINE makeKnown #-} diff --git a/plutus-core/plutus-core/src/PlutusCore/Builtin/KnownTypeAst.hs b/plutus-core/plutus-core/src/PlutusCore/Builtin/KnownTypeAst.hs index 19196231858..aa04be0a09f 100644 --- a/plutus-core/plutus-core/src/PlutusCore/Builtin/KnownTypeAst.hs +++ b/plutus-core/plutus-core/src/PlutusCore/Builtin/KnownTypeAst.hs @@ -31,7 +31,6 @@ module PlutusCore.Builtin.KnownTypeAst , Delete ) where -import PlutusCore.Builtin.Emitter import PlutusCore.Builtin.KnownKind import PlutusCore.Builtin.Polymorphism import PlutusCore.Builtin.Result @@ -232,13 +231,6 @@ instance KnownTypeAst tyname uni a => KnownTypeAst tyname uni (BuiltinResult a) typeAst = toTypeAst $ Proxy @a {-# INLINE typeAst #-} -instance KnownTypeAst tyname uni a => KnownTypeAst tyname uni (Emitter a) where - type IsBuiltin _ (Emitter a) = 'False - type ToHoles _ (Emitter a) = '[TypeHole a] - type ToBinds uni acc (Emitter a) = ToBinds uni acc a - typeAst = toTypeAst $ Proxy @a - {-# INLINE typeAst #-} - instance KnownTypeAst tyname uni rep => KnownTypeAst tyname uni (SomeConstant uni rep) where type IsBuiltin _ (SomeConstant uni rep) = 'False type ToHoles _ (SomeConstant _ rep) = '[RepHole rep] diff --git a/plutus-core/plutus-core/src/PlutusCore/Builtin/Result.hs b/plutus-core/plutus-core/src/PlutusCore/Builtin/Result.hs index b1685d6b5fb..f16449a7b74 100644 --- a/plutus-core/plutus-core/src/PlutusCore/Builtin/Result.hs +++ b/plutus-core/plutus-core/src/PlutusCore/Builtin/Result.hs @@ -24,6 +24,7 @@ module PlutusCore.Builtin.Result , _OperationalUnliftingError , throwNotAConstant , throwUnderTypeError + , emit , withLogs , throwing , throwing_ @@ -31,7 +32,6 @@ module PlutusCore.Builtin.Result import PlutusPrelude -import PlutusCore.Builtin.Emitter import PlutusCore.Evaluation.Error import PlutusCore.Evaluation.Result @@ -64,15 +64,15 @@ data BuiltinError deriving stock (Show, Eq) -- | The monad that 'makeKnown' runs in. --- Equivalent to @ExceptT BuiltinError Emitter@, except optimized in two ways: +-- Equivalent to @ExceptT BuiltinError (Writer (DList Text))@, except optimized in two ways: -- -- 1. everything is strict -- 2. has the 'BuiltinSuccess' constructor that is used for returning a value with no logs -- attached, which is the most common case for us, so it helps a lot not to construct and -- deconstruct a redundant tuple -- --- Moving from @ExceptT BuiltinError Emitter@ to this data type gave us a speedup of 8% of total --- evaluation time. +-- Moving from @ExceptT BuiltinError (Writer (DList Text))@ to this data type gave us a speedup of +-- 8% of total evaluation time. -- -- Logs are represented as a 'DList', because we don't particularly care about the efficiency of -- logging, since there's no logging on the chain and builtins don't emit much anyway. Otherwise @@ -143,10 +143,6 @@ instance AsEvaluationFailure (BuiltinResult a) where _EvaluationFailure = _BuiltinFailure . iso (\_ -> ()) (\_ -> pure evaluationFailure) {-# INLINE _EvaluationFailure #-} -instance MonadEmitter BuiltinResult where - emit txt = BuiltinSuccessWithLogs (pure txt) () - {-# INLINE emit #-} - instance MonadFail BuiltinResult where fail err = BuiltinFailure (pure $ Text.pack err) BuiltinEvaluationFailure {-# INLINE fail #-} @@ -208,6 +204,11 @@ throwUnderTypeError :: MonadError BuiltinError m => m void throwUnderTypeError = throwing _StructuralUnliftingError "Panic: 'TypeError' was bypassed" {-# INLINE throwUnderTypeError #-} +-- | Add a log line to the logs. +emit :: Text -> BuiltinResult () +emit txt = BuiltinSuccessWithLogs (pure txt) () +{-# INLINE emit #-} + -- | Prepend logs to a 'BuiltinResult' computation. withLogs :: DList Text -> BuiltinResult a -> BuiltinResult a withLogs logs1 = \case diff --git a/plutus-core/plutus-core/src/PlutusCore/Crypto/Utils.hs b/plutus-core/plutus-core/src/PlutusCore/Crypto/Utils.hs index bb80ce83dcb..35cb885cffe 100644 --- a/plutus-core/plutus-core/src/PlutusCore/Crypto/Utils.hs +++ b/plutus-core/plutus-core/src/PlutusCore/Crypto/Utils.hs @@ -3,8 +3,7 @@ module PlutusCore.Crypto.Utils (failWithMessage, byteStringAsHex) where -import PlutusCore.Builtin.Emitter (emit) -import PlutusCore.Builtin.Result (BuiltinResult) +import PlutusCore.Builtin.Result (BuiltinResult, emit) import PlutusCore.Evaluation.Result (evaluationFailure) import Data.ByteString (ByteString, foldr')