| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Plutarch.Internal.Term
Synopsis
- newtype ((a :: S -> Type) :--> (b :: S -> Type)) (s :: S) = PLam (Term s a -> Term s b)
- data PDelayed (a :: S -> Type) (s :: S)
- newtype Term (s :: S) (a :: S -> Type) = Term {
- asRawTerm :: Word64 -> TermMonad TermResult
- asClosedRawTerm :: forall (a :: S -> Type). (forall (s :: S). Term s a) -> TermMonad TermResult
- newtype Script = Script (Program DeBruijn DefaultUni DefaultFun ())
- mapTerm :: (RawTerm -> RawTerm) -> TermResult -> TermResult
- plam' :: forall (s :: S) (a :: S -> Type) (b :: S -> Type). (Term s a -> Term s b) -> Term s (a :--> b)
- plet :: forall (s :: S) (a :: S -> Type) (b :: S -> Type). Term s a -> (Term s a -> Term s b) -> Term s b
- papp :: forall (s :: S) (a :: S -> Type) (b :: S -> Type). Term s (a :--> b) -> Term s a -> Term s b
- pdelay :: forall (s :: S) (a :: S -> Type). Term s a -> Term s (PDelayed a)
- pforce :: forall (s :: S) (a :: S -> Type). Term s (PDelayed a) -> Term s a
- phoistAcyclic :: forall (a :: S -> Type) (s :: S). HasCallStack => (forall (s' :: S). Term s' a) -> Term s a
- perror :: forall (s :: S) (a :: S -> Type). Term s a
- pplaceholder :: forall (s :: S) (a :: S -> Type). Integer -> Term s a
- punsafeCoerce :: forall (b :: S -> Type) (a :: S -> Type) (s :: S). Term s a -> Term s b
- punsafeBuiltin :: forall (s :: S) (a :: S -> Type). DefaultFun -> Term s a
- punsafeConstantInternal :: forall (s :: S) (a :: S -> Type). Some (ValueOf DefaultUni) -> Term s a
- compile :: forall (a :: S -> Type). Config -> (forall (s :: S). Term s a) -> Either Text Script
- compileWithInternalConfig :: forall (a :: S -> Type). InternalConfig -> Config -> (forall (s :: S). Term s a) -> Either Text Script
- compileOptimized :: forall (a :: S -> Type). (forall (s :: S). Term s a) -> Either Text Script
- compileOptimizedWithInternalConfig :: forall (a :: S -> Type). InternalConfig -> (forall (s :: S). Term s a) -> Either Text Script
- compile' :: TermResult -> Term DeBruijn DefaultUni DefaultFun ()
- optimizeTerm :: forall (a :: S -> Type). (forall (s :: S). Term s a) -> forall (s :: S). Term s a
- data RawTerm
- = RVar Word64
- | RLamAbs Word64 RawTerm
- | RApply RawTerm [RawTerm]
- | RForce RawTerm
- | RDelay RawTerm
- | RConstant (Some (ValueOf DefaultUni))
- | RBuiltin DefaultFun
- | RCompiled (Term DeBruijn DefaultUni DefaultFun ())
- | RError
- | RHoisted HoistedTerm
- | RPlaceHolder Integer
- | RConstr Word64 [RawTerm]
- | RCase RawTerm [RawTerm]
- data HoistedTerm = HoistedTerm {}
- data TermResult = TermResult {
- getTerm :: RawTerm
- getDeps :: [HoistedTerm]
- data S = SI
- pthrow :: forall (s :: S) (a :: S -> Type). HasCallStack => Text -> Term s a
- data Config where
- data InternalConfig = InternalConfig {}
- data TracingMode
- data LogLevel
- tracingMode :: Config -> Maybe TracingMode
- logLevel :: Config -> Maybe LogLevel
- pgetConfig :: forall (s :: S) (a :: S -> Type). (Config -> Term s a) -> Term s a
- pgetInternalConfig :: forall (s :: S) (a :: S -> Type). (InternalConfig -> Term s a) -> Term s a
- pwithInternalConfig :: forall (s :: S) (a :: S -> Type). InternalConfig -> Term s a -> Term s a
- newtype TermMonad m = TermMonad {
- runTermMonad :: ReaderT (InternalConfig, Config) (Either Text) m
- (#) :: forall (s :: S) (a :: S -> Type) (b :: S -> Type). Term s (a :--> b) -> Term s a -> Term s b
- (#$) :: forall (s :: S) (a :: S -> Type) (b :: S -> Type). Term s (a :--> b) -> Term s a -> Term s b
Documentation
$hoisted
newtype ((a :: S -> Type) :--> (b :: S -> Type)) (s :: S) infixr 0 Source #
Instances
| PlutusType (a :--> b) Source # | |||||
Defined in Plutarch.Internal.PlutusType Associated Types
| |||||
| (a' ~ Term s a, PLamN b' b s) => PLamN (a' -> b') (a :--> b) s Source # | |||||
| type PInner (a :--> b) Source # | |||||
Defined in Plutarch.Internal.PlutusType | |||||
$term
newtype Term (s :: S) (a :: S -> Type) Source #
Constructors
| Term | |
Fields
| |
Instances
asClosedRawTerm :: forall (a :: S -> Type). (forall (s :: S). Term s a) -> TermMonad TermResult Source #
Constructors
| Script (Program DeBruijn DefaultUni DefaultFun ()) |
mapTerm :: (RawTerm -> RawTerm) -> TermResult -> TermResult Source #
plam' :: forall (s :: S) (a :: S -> Type) (b :: S -> Type). (Term s a -> Term s b) -> Term s (a :--> b) Source #
Lambda abstraction.
Only works with a single argument.
Use plam instead, to support currying.
plet :: forall (s :: S) (a :: S -> Type) (b :: S -> Type). Term s a -> (Term s a -> Term s b) -> Term s b Source #
Let bindings.
This is approximately a shorthand for a lambda and application:
plet v f == papp (plam f) v
But sufficiently small terms in WHNF may be inlined for efficiency.
papp :: forall (s :: S) (a :: S -> Type) (b :: S -> Type). Term s (a :--> b) -> Term s a -> Term s b Source #
Lambda Application.
pdelay :: forall (s :: S) (a :: S -> Type). Term s a -> Term s (PDelayed a) Source #
Plutus 'delay', used for laziness.
pforce :: forall (s :: S) (a :: S -> Type). Term s (PDelayed a) -> Term s a Source #
Plutus 'force',
used to force evaluation of PDelayed terms.
phoistAcyclic :: forall (a :: S -> Type) (s :: S). HasCallStack => (forall (s' :: S). Term s' a) -> Term s a Source #
perror :: forall (s :: S) (a :: S -> Type). Term s a Source #
Plutus 'error'.
When using this explicitly, it should be ensured that the containing term is delayed, avoiding premature evaluation.
pplaceholder :: forall (s :: S) (a :: S -> Type). Integer -> Term s a Source #
Same as perror except this holds integer id for AST look-ahead.
This can be used to "tag" branch and generate AST first to see if that branch is actually used or not,
allowing optimization cutting unused branches. For more detailed uscases, check pmatchDataRec.
punsafeCoerce :: forall (b :: S -> Type) (a :: S -> Type) (s :: S). Term s a -> Term s b Source #
Unsafely coerce the type-tag of a Term.
This should mostly be avoided, though it can be safely used to assert known types of Datums, Redeemers or ScriptContext.
punsafeConstantInternal :: forall (s :: S) (a :: S -> Type). Some (ValueOf DefaultUni) -> Term s a Source #
compile :: forall (a :: S -> Type). Config -> (forall (s :: S). Term s a) -> Either Text Script Source #
Compile a (closed) Plutus Term to a usable script
compileWithInternalConfig :: forall (a :: S -> Type). InternalConfig -> Config -> (forall (s :: S). Term s a) -> Either Text Script Source #
As compile but exposes InternalConfig options.
Since: 1.12.0
compileOptimized :: forall (a :: S -> Type). (forall (s :: S). Term s a) -> Either Text Script Source #
compileOptimizedWithInternalConfig :: forall (a :: S -> Type). InternalConfig -> (forall (s :: S). Term s a) -> Either Text Script Source #
As compileOptimized but exposes InternalConfig options.
Since: 1.12.0
compile' :: TermResult -> Term DeBruijn DefaultUni DefaultFun () Source #
optimizeTerm :: forall (a :: S -> Type). (forall (s :: S). Term s a) -> forall (s :: S). Term s a Source #
Given a closed Term, run the UPLC optimizer on it.
Important note
If the input term has any hoisted dependencies, these are completely erased
by this process. Thus, if the resulting Term is used as part of a larger
computation with the same dependencies, the Plutarch compiler will not be
aware of them, and will not be able to optimize them properly. More
concretely, in a case like this:
@
padd # optimizeTerm (f # pexpensive) # optimizeTerm (g # pexpensive)
@
pexpensive will end up being duplicated entirely into each 'arm' of the
padd, even though under normal circumstances it could be shared.
Thus, if you plan to use this, ensure that it is done 'as late as
possible'; embedding Terms produced by optimizeTerm into larger
computations can lead to size blowout if not done carefully.
Constructors
| RVar Word64 | |
| RLamAbs Word64 RawTerm | |
| RApply RawTerm [RawTerm] | |
| RForce RawTerm | |
| RDelay RawTerm | |
| RConstant (Some (ValueOf DefaultUni)) | |
| RBuiltin DefaultFun | |
| RCompiled (Term DeBruijn DefaultUni DefaultFun ()) | |
| RError | |
| RHoisted HoistedTerm | |
| RPlaceHolder Integer | |
| RConstr Word64 [RawTerm] | |
| RCase RawTerm [RawTerm] |
data HoistedTerm Source #
Constructors
| HoistedTerm | |
Instances
| Show HoistedTerm Source # | |
Defined in Plutarch.Internal.Term | |
| Eq HoistedTerm Source # | Equality of hoisted terms is first checked via their non-cryptographic hash, then via term equality. Inequality, which should happen much more often is thus cheap. Note that we could just as well derive this instance... |
Defined in Plutarch.Internal.Term Methods (==) :: HoistedTerm -> HoistedTerm -> Bool Source # (/=) :: HoistedTerm -> HoistedTerm -> Bool Source # | |
| Hashable HoistedTerm Source # | Hoisted term carry their own non-cryptographic hash, making it incredibly cheap to hold these in hashmaps. |
Defined in Plutarch.Internal.Term | |
data TermResult Source #
Constructors
| TermResult | |
Fields
| |
Constructors
| SI |
Instances
| UnsafeConstrNP ('[] :: [S -> Type]) Source # | |
| UnsafeConstrNP xs => UnsafeConstrNP (x ': xs) Source # | |
Configuration for Plutarch scripts at compile time. This indicates whether we want to trace, and if so, under what log level and mode.
Since: 1.6.0
Bundled Patterns
| pattern NoTracing :: Config | Pattern for the config that does no tracing (also the default). Since: 1.6.0 |
| pattern Tracing :: LogLevel -> TracingMode -> Config | Pattern for a tracing config, with both its log level and mode. Since: 1.6.0 |
Instances
| FromJSON Config Source # | Since: 1.6.0 |
Defined in Plutarch.Internal.Term | |
| ToJSON Config Source # | Since: 1.6.0 |
Defined in Plutarch.Internal.Term Methods toEncoding :: Config -> Encoding toJSONList :: [Config] -> Value toEncodingList :: [Config] -> Encoding | |
| Monoid Config Source # | Since: 1.6.0 |
| Semigroup Config Source # | Since: 1.6.0 |
| Show Config Source # | Since: 1.6.0 |
| Eq Config Source # | Since: 1.6.0 |
| Pretty Config Source # | Since: 1.6.0 |
Defined in Plutarch.Internal.Term | |
data InternalConfig Source #
Constructors
| InternalConfig | |
Instances
| Show InternalConfig Source # | |
Defined in Plutarch.Internal.Term | |
| Eq InternalConfig Source # | |
Defined in Plutarch.Internal.Term Methods (==) :: InternalConfig -> InternalConfig -> Bool Source # (/=) :: InternalConfig -> InternalConfig -> Bool Source # | |
data TracingMode Source #
How to trace.
Since: 1.6.0
Constructors
| DetTracing | |
| DoTracing | |
| DoTracingAndBinds |
Instances
What logging level we want to use.
Since: 1.6.0
Instances
| FromJSON LogLevel Source # | Since: 1.6.0 |
Defined in Plutarch.Internal.Term | |
| ToJSON LogLevel Source # | Since: 1.6.0 |
Defined in Plutarch.Internal.Term Methods toEncoding :: LogLevel -> Encoding toJSONList :: [LogLevel] -> Value toEncodingList :: [LogLevel] -> Encoding | |
| Semigroup LogLevel Source # | More general logging supersedes less general. Since: 1.6.0 |
| Show LogLevel Source # | Since: 1.6.0 |
| Eq LogLevel Source # | Since: 1.6.0 |
| Ord LogLevel Source # | We have a linear order of generality, so this instance reflects it:
Since: 1.6.0 |
Defined in Plutarch.Internal.Term | |
| Pretty LogLevel Source # | Since: 1.6.0 |
Defined in Plutarch.Internal.Term | |
tracingMode :: Config -> Maybe TracingMode Source #
If the config indicates that we want to trace, get its mode.
Since: 1.6.0
logLevel :: Config -> Maybe LogLevel Source #
If the config indicates that we want to trace, get its log level.
Since: 1.6.0
pgetInternalConfig :: forall (s :: S) (a :: S -> Type). (InternalConfig -> Term s a) -> Term s a Source #
pwithInternalConfig :: forall (s :: S) (a :: S -> Type). InternalConfig -> Term s a -> Term s a Source #
Constructors
| TermMonad | |
Fields
| |