Skip to content

Commit

Permalink
[Builtins] Remove 'Emitter' and 'MonadEmitter'
Browse files Browse the repository at this point in the history
  • Loading branch information
effectfully committed Jun 20, 2024
1 parent 7dbbd7f commit 2eaae10
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Removed

- Removed `Emitter` and `MonadEmitter` in #6224.

### Changed

- Changed the type of `emit` to `Text -> BuiltinResult ()` in #6224.
1 change: 0 additions & 1 deletion plutus-core/plutus-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion plutus-core/plutus-core/src/PlutusCore/Builtin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 0 additions & 26 deletions plutus-core/plutus-core/src/PlutusCore/Builtin/Emitter.hs

This file was deleted.

15 changes: 0 additions & 15 deletions plutus-core/plutus-core/src/PlutusCore/Builtin/KnownType.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 #-}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
17 changes: 9 additions & 8 deletions plutus-core/plutus-core/src/PlutusCore/Builtin/Result.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ module PlutusCore.Builtin.Result
, _OperationalUnliftingError
, throwNotAConstant
, throwUnderTypeError
, emit
, withLogs
, throwing
, throwing_
) where

import PlutusPrelude

import PlutusCore.Builtin.Emitter
import PlutusCore.Evaluation.Error
import PlutusCore.Evaluation.Result

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 #-}
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions plutus-core/plutus-core/src/PlutusCore/Crypto/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 2eaae10

Please sign in to comment.