| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
PlutusCore.Builtin
Description
Reexports from modules from the Builtin folder.
Synopsis
- class Typeable (a :: k)
- data TypeScheme val (args :: [Type]) res where
- TypeSchemeResult :: (Typeable res, KnownTypeAst TyName (UniOf val) res, MakeKnown val res) => TypeScheme val '[] res
- TypeSchemeArrow :: (Typeable arg, KnownTypeAst TyName (UniOf val) arg, MakeKnown val arg, ReadKnown val arg) => TypeScheme val args res -> TypeScheme val (arg ': args) res
- TypeSchemeAll :: (KnownSymbol text, KnownNat uniq, KnownKind kind) => Proxy '(text, uniq, kind) -> TypeScheme val args res -> TypeScheme val args res
- argProxy :: TypeScheme val (arg ': args) res -> Proxy arg
- typeSchemeToType :: TypeScheme val args res -> Type TyName (UniOf val) ()
- class (uni `Everywhere` ImplementedKnownTypeAst uni, uni `Everywhere` ImplementedReadKnownIn uni, uni `Everywhere` ImplementedMakeKnownIn uni) => TestTypesFromTheUniverseAreAllKnown uni
- data BuiltinRuntime val
- = BuiltinCostedResult ExBudgetStream ~(BuiltinResult val)
- | BuiltinExpectArgument (val -> BuiltinRuntime val)
- | BuiltinExpectForce (BuiltinRuntime val)
- data BuiltinsRuntime fun val = BuiltinsRuntime {
- unBuiltinsRuntime :: fun -> BuiltinRuntime val
- builtinRuntimeFailure :: BuiltinError -> BuiltinRuntime val
- lookupBuiltin :: fun -> BuiltinsRuntime fun val -> BuiltinRuntime val
- data EvaluationError structural operational
- = StructuralError !structural
- | OperationalError !operational
- newtype UnliftingError = MkUnliftingError {}
- newtype UnliftingEvaluationError = MkUnliftingEvaluationError {}
- data BuiltinError
- data BuiltinResult a
- = BuiltinSuccess a
- | BuiltinSuccessWithLogs (DList Text) a
- | BuiltinFailure (DList Text) BuiltinError
- notAConstant :: BuiltinError
- underTypeError :: BuiltinError
- operationalUnliftingError :: Text -> BuiltinError
- structuralUnliftingError :: Text -> BuiltinError
- emit :: Text -> BuiltinResult ()
- withLogs :: DList Text -> BuiltinResult a -> BuiltinResult a
- throwing :: MonadError e m => AReview e t -> t -> m x
- throwing_ :: MonadError e m => AReview e () -> m x
- builtinResultFailure :: BuiltinResult a
- newtype Opaque val (rep :: Type) = Opaque {
- unOpaque :: val
- newtype SomeConstant uni (rep :: Type) = SomeConstant {
- unSomeConstant :: Some (ValueOf uni)
- data TyNameRep (kind :: Type) = TyNameRep Symbol Nat
- data family TyVarRep (name :: TyNameRep kind) :: kind
- data family TyAppRep (fun :: dom -> cod) (arg :: dom) :: cod
- data family TyForallRep (name :: TyNameRep kind) (a :: Type) :: Type
- data family BuiltinHead x
- data family LastArg x y
- type family ElaborateBuiltin uni x
- type family AllElaboratedArgs constr x where ...
- class AllElaboratedArgs constr (ElaborateBuiltin uni x) => AllBuiltinArgs uni constr x
- type family FoldArgs args res where ...
- data BuiltinMeaning val cost = forall args res. BuiltinMeaning (TypeScheme val args res) ~(FoldArgs args res) (cost -> BuiltinRuntime val)
- type HasMeaningIn uni val = (Typeable val, ExMemoryUsage val, HasConstantIn uni val)
- class (Typeable uni, Typeable fun, Bounded fun, Enum fun, Ix fun, Default (BuiltinSemanticsVariant fun)) => ToBuiltinMeaning uni fun where
- type CostingPart uni fun
- data BuiltinSemanticsVariant fun
- toBuiltinMeaning :: HasMeaningIn uni val => BuiltinSemanticsVariant fun -> fun -> BuiltinMeaning val (CostingPart uni fun)
- withTypeSchemeOfBuiltinFunction :: forall val fun r. (ToBuiltinMeaning (UniOf val) fun, ExMemoryUsage val, Typeable val, HasConstant val) => BuiltinSemanticsVariant fun -> fun -> (forall args res. TypeScheme val args res -> r) -> r
- typeOfBuiltinFunction :: forall uni fun. ToBuiltinMeaning uni fun => BuiltinSemanticsVariant fun -> fun -> Type TyName uni ()
- type family GetArgs a where ...
- class KnownMonotype val args res where
- knownMonotype :: TypeScheme val args res
- toMonoF :: ReadKnownM (FoldArgs args res, FoldArgs args ExBudgetStream) -> BuiltinRuntime val
- class KnownMonotype val args res => KnownPolytype (binds :: [Some TyNameRep]) val args res where
- knownPolytype :: TypeScheme val args res
- toPolyF :: ReadKnownM (FoldArgs args res, FoldArgs args ExBudgetStream) -> BuiltinRuntime val
- type family ThrowOnBothEmpty binds args isBuiltin a where ...
- class MakeBuiltinMeaning a val where
- makeBuiltinMeaning :: a -> (cost -> FoldArgs (GetArgs a) ExBudgetStream) -> BuiltinMeaning val cost
- toBuiltinRuntime :: cost -> BuiltinMeaning val cost -> BuiltinRuntime val
- toBuiltinsRuntime :: (cost ~ CostingPart uni fun, ToBuiltinMeaning uni fun, HasMeaningIn uni val) => BuiltinSemanticsVariant fun -> cost -> BuiltinsRuntime fun val
- data TyNameRep (kind :: Type) = TyNameRep Symbol Nat
- data family TyVarRep (name :: TyNameRep kind) :: kind
- data family TyAppRep (fun :: dom -> cod) (arg :: dom) :: cod
- data family TyForallRep (name :: TyNameRep kind) (a :: Type) :: Type
- data Hole
- data family RepHole x
- data family TypeHole a
- type family RunHole hole where ...
- type HasTermLevel uni = Includes uni
- type HasTypeLevel uni x = KnownTypeAst Void uni (ElaborateBuiltin uni x)
- type HasTypeAndTermLevel uni x = (uni `HasTypeLevel` x, uni `HasTermLevel` x)
- mkTyBuiltin :: forall a (x :: a) uni ann tyname. uni `HasTypeLevel` x => ann -> Type tyname uni ann
- type KnownBuiltinTypeAst tyname uni x = AllBuiltinArgs uni (KnownTypeAst tyname uni) x
- class KnownTypeAst tyname uni x where
- toTypeAst :: forall a tyname uni (x :: a) proxy. KnownTypeAst tyname uni x => proxy x -> Type tyname uni ()
- type family Insert x xs where ...
- type family Delete x xs where ...
- data BuiltinError
- class GEqL f a where
- geqL :: f (Esc a) -> f (Esc b) -> EvaluationResult (a :~: b)
- newtype LoopBreaker uni a = LoopBreaker (uni a)
- type KnownBuiltinTypeIn uni val a = (HasConstantIn uni val, PrettyParens (SomeTypeIn uni), GEqL uni a, uni `HasTermLevel` a)
- type KnownBuiltinType val a = KnownBuiltinTypeIn (UniOf val) val a
- data BuiltinResult a
- = BuiltinSuccess a
- | BuiltinSuccessWithLogs (DList Text) a
- | BuiltinFailure (DList Text) BuiltinError
- type ReadKnownM = Either BuiltinError
- data Spine a
- data HeadSpine err a b
- headSpine :: a -> [b] -> HeadSpine err a b
- type MonoHeadSpine err a = HeadSpine err a a
- class uni ~ UniOf val => MakeKnownIn uni val a where
- makeKnown :: a -> BuiltinResult val
- readKnownConstant :: forall val a. KnownBuiltinType val a => val -> ReadKnownM a
- type MakeKnown val = MakeKnownIn (UniOf val) val
- class uni ~ UniOf val => ReadKnownIn uni val a where
- readKnown :: val -> ReadKnownM a
- type ReadKnown val = ReadKnownIn (UniOf val) val
- makeKnownOrFail :: MakeKnownIn uni val a => a -> EvaluationResult val
- readKnownSelf :: (ReadKnown val a, BuiltinErrorToEvaluationError structural operational) => val -> Either (ErrorWithCause (EvaluationError structural operational) val) a
- data SingKind k where
- withSingKind :: Kind ann -> (forall k. SingKind k -> r) -> r
- class KnownKind k where
- bringKnownKind :: SingKind k -> (KnownKind k => r) -> r
- withKnownKind :: Kind ann -> (forall k. KnownKind k => Proxy k -> r) -> r
- class ToKind (uni :: Type -> Type) where
- toSingKind :: uni (Esc (a :: k)) -> SingKind k
- demoteKind :: SingKind k -> Kind ()
- kindOfBuiltinType :: ToKind uni => uni (Esc a) -> Kind ()
- data BuiltinError
- notAConstant :: BuiltinError
- class HasConstant term where
- asConstant :: term -> Either BuiltinError (Some (ValueOf (UniOf term)))
- fromConstant :: Some (ValueOf (UniOf term)) -> term
- type HasConstantIn uni term = (UniOf term ~ uni, HasConstant term)
- fromValueOf :: forall a term. HasConstant term => UniOf term (Esc a) -> a -> term
- fromValue :: forall a term. (HasConstant term, UniOf term `HasTermLevel` a) => a -> term
- class AnnotateCaseBuiltin uni where
- class CaseBuiltin uni where
- data CaserBuiltin uni = CaserBuiltin {}
- unavailableCaserBuiltin :: Int -> CaserBuiltin uni
Documentation
class Typeable (a :: k) Source #
The class Typeable allows a concrete representation of a type to
be calculated.
Minimal complete definition
typeRep#
data TypeScheme val (args :: [Type]) res where Source #
The type of type schemes of built-in functions.
args is a list of types of arguments, res is the resulting type.
E.g. Text -> Bool -> Integer is encoded as TypeScheme val [Text, Bool] Integer.
Constructors
| TypeSchemeResult :: (Typeable res, KnownTypeAst TyName (UniOf val) res, MakeKnown val res) => TypeScheme val '[] res | |
| TypeSchemeArrow :: (Typeable arg, KnownTypeAst TyName (UniOf val) arg, MakeKnown val arg, ReadKnown val arg) => TypeScheme val args res -> TypeScheme val (arg ': args) res infixr 9 | |
| TypeSchemeAll :: (KnownSymbol text, KnownNat uniq, KnownKind kind) => Proxy '(text, uniq, kind) -> TypeScheme val args res -> TypeScheme val args res |
Instances
| Show (TypeScheme val args res) Source # | |
Defined in PlutusCore.Builtin.TypeScheme | |
argProxy :: TypeScheme val (arg ': args) res -> Proxy arg Source #
typeSchemeToType :: TypeScheme val args res -> Type TyName (UniOf val) () Source #
Convert a TypeScheme to the corresponding Kind.
class (uni `Everywhere` ImplementedKnownTypeAst uni, uni `Everywhere` ImplementedReadKnownIn uni, uni `Everywhere` ImplementedMakeKnownIn uni) => TestTypesFromTheUniverseAreAllKnown uni Source #
An instance of this class not having any constraints ensures that every type (according to
Everywhere) from the universe has 'KnownTypeAst, ReadKnownIn and MakeKnownIn instances.
Instances
data BuiltinRuntime val Source #
A BuiltinRuntime represents a possibly partial builtin application, including an empty
builtin application (i.e. just the builtin with no arguments).
Applying or type-instantiating a builtin peels off the corresponding constructor from its
BuiltinRuntime.
BuiltinCostedResult contains the cost (an ExBudgetStream) and the result (a
BuiltinResult (HeadSpine val)) of the builtin application. The cost is stored strictly, since
the evaluator is going to look at it and the result is stored lazily, since it's not supposed to
be forced before accounting for the cost of the application. If the cost exceeds the available
budget, the evaluator discards the result of the builtin application without ever forcing it and
terminates with evaluation failure. Allowing the user to compute something that they don't have
the budget for would be a major bug.
Evaluators that ignore the entire concept of costing (e.g. the CK machine) may of course force the result of the builtin application unconditionally.
Constructors
| BuiltinCostedResult ExBudgetStream ~(BuiltinResult val) | |
| BuiltinExpectArgument (val -> BuiltinRuntime val) | |
| BuiltinExpectForce (BuiltinRuntime val) |
Instances
| Show (BuiltinRuntime (CkValue uni fun)) Source # | |
Defined in PlutusCore.Evaluation.Machine.Ck | |
| Show (BuiltinRuntime (CekValue uni fun ann)) Source # | |
| NFData (BuiltinRuntime val) Source # | |
Defined in PlutusCore.Builtin.Runtime Methods rnf :: BuiltinRuntime val -> () Source # | |
| NoThunks (BuiltinRuntime val) Source # | |
Defined in PlutusCore.Builtin.Runtime Methods noThunks :: Context -> BuiltinRuntime val -> IO (Maybe ThunkInfo) wNoThunks :: Context -> BuiltinRuntime val -> IO (Maybe ThunkInfo) showTypeOf :: Proxy (BuiltinRuntime val) -> String | |
data BuiltinsRuntime fun val Source #
A data wrapper around a function returning the BuiltinRuntime of a built-in function.
In order for lookups to be efficient the BuiltinRuntimes need to be cached, i.e. pulled out
of the function statically. See makeBuiltinMeaning for how we achieve that.
Constructors
| BuiltinsRuntime | |
Fields
| |
Instances
| (Bounded fun, Enum fun) => NFData (BuiltinsRuntime fun val) Source # | |
Defined in PlutusCore.Builtin.Runtime Methods rnf :: BuiltinsRuntime fun val -> () Source # | |
| (Bounded fun, Enum fun) => NoThunks (BuiltinsRuntime fun val) Source # | |
Defined in PlutusCore.Builtin.Runtime Methods noThunks :: Context -> BuiltinsRuntime fun val -> IO (Maybe ThunkInfo) wNoThunks :: Context -> BuiltinsRuntime fun val -> IO (Maybe ThunkInfo) showTypeOf :: Proxy (BuiltinsRuntime fun val) -> String | |
builtinRuntimeFailure :: BuiltinError -> BuiltinRuntime val Source #
lookupBuiltin :: fun -> BuiltinsRuntime fun val -> BuiltinRuntime val Source #
Look up the runtime info of a built-in function during evaluation.
data EvaluationError structural operational Source #
The type of errors that can occur during evaluation. There are two kinds of errors:
- Structural ones -- these are errors that are indicative of the _structure_ of the program being
wrong. For example, a free variable was encountered during evaluation, a non-function was
applied to an argument or
tailListwas applied to a non-list. - Operational ones -- these are errors that are indicative of the _logic_ of the program being
wrong. For example,
errorwas executed,tailListwas applied to an empty list or evaluation ran out of gas.
On the chain both of these are just regular failures and we don't distinguish between them there: if a script fails, it fails, it doesn't matter what the reason was. However in the tests it does matter why the failure occurred: a structural error may indicate that the test was written incorrectly while an operational error may be entirely expected.
In other words, structural errors are "runtime type errors" and operational errors are regular runtime errors. Which means that evaluating an (erased) well-typed program should never produce a structural error, only an operational one. This creates a sort of "runtime type system" for UPLC and it would be great to stick to it and enforce in tests etc, but we currently don't.
Constructors
| StructuralError !structural | |
| OperationalError !operational |
Instances
| Bifoldable EvaluationError Source # | |
Defined in PlutusCore.Evaluation.Error Methods bifold :: Monoid m => EvaluationError m m -> m Source # bifoldMap :: Monoid m => (a -> m) -> (b -> m) -> EvaluationError a b -> m Source # bifoldr :: (a -> c -> c) -> (b -> c -> c) -> c -> EvaluationError a b -> c Source # bifoldl :: (c -> a -> c) -> (c -> b -> c) -> c -> EvaluationError a b -> c Source # | |
| Bifunctor EvaluationError Source # | |
Defined in PlutusCore.Evaluation.Error Methods bimap :: (a -> b) -> (c -> d) -> EvaluationError a c -> EvaluationError b d Source # first :: (a -> b) -> EvaluationError a c -> EvaluationError b c Source # second :: (b -> c) -> EvaluationError a b -> EvaluationError a c Source # | |
| Bitraversable EvaluationError Source # | |
Defined in PlutusCore.Evaluation.Error Methods bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> EvaluationError a b -> f (EvaluationError c d) Source # | |
| (HasPrettyDefaults config ~ 'True, PrettyBy config structural, Pretty operational) => PrettyBy config (EvaluationError structural operational) Source # | |
Defined in PlutusCore.Evaluation.Error Methods prettyBy :: config -> EvaluationError structural operational -> Doc ann # prettyListBy :: config -> [EvaluationError structural operational] -> Doc ann # | |
| Functor (EvaluationError structural) Source # | |
Defined in PlutusCore.Evaluation.Error Methods fmap :: (a -> b) -> EvaluationError structural a -> EvaluationError structural b Source # (<$) :: a -> EvaluationError structural b -> EvaluationError structural a Source # | |
| Generic (EvaluationError structural operational) Source # | |
Defined in PlutusCore.Evaluation.Error Methods from :: EvaluationError structural operational -> Rep (EvaluationError structural operational) x Source # to :: Rep (EvaluationError structural operational) x -> EvaluationError structural operational Source # | |
| (Show structural, Show operational) => Show (EvaluationError structural operational) Source # | |
Defined in PlutusCore.Evaluation.Error | |
| (NFData structural, NFData operational) => NFData (EvaluationError structural operational) Source # | |
Defined in PlutusCore.Evaluation.Error Methods rnf :: EvaluationError structural operational -> () Source # | |
| (Eq structural, Eq operational) => Eq (EvaluationError structural operational) Source # | |
Defined in PlutusCore.Evaluation.Error Methods (==) :: EvaluationError structural operational -> EvaluationError structural operational -> Bool Source # (/=) :: EvaluationError structural operational -> EvaluationError structural operational -> Bool Source # | |
| (Pretty structural, Pretty operational) => Pretty (EvaluationError structural operational) Source # | |
Defined in PlutusCore.Evaluation.Error Methods pretty :: EvaluationError structural operational -> Doc ann # prettyList :: [EvaluationError structural operational] -> Doc ann # | |
| ThrowableBuiltins uni fun => MonadError (CekEvaluationException NamedDeBruijn uni fun) (CekM uni fun s) Source # | |
Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal Methods throwError :: CekEvaluationException NamedDeBruijn uni fun -> CekM uni fun s a Source # catchError :: CekM uni fun s a -> (CekEvaluationException NamedDeBruijn uni fun -> CekM uni fun s a) -> CekM uni fun s a Source # | |
| type Rep (EvaluationError structural operational) Source # | |
Defined in PlutusCore.Evaluation.Error type Rep (EvaluationError structural operational) = D1 ('MetaData "EvaluationError" "PlutusCore.Evaluation.Error" "plutus-core-1.65.0.0-3gtmUmff0YR8c8vnU0QX4N" 'False) (C1 ('MetaCons "StructuralError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 structural)) :+: C1 ('MetaCons "OperationalError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 operational))) | |
newtype UnliftingError Source #
The error message part of an UnliftingEvaluationError.
Constructors
| MkUnliftingError | |
Fields | |
Instances
newtype UnliftingEvaluationError Source #
When unlifting of a PLC term into a Haskell value fails, this error is thrown.
Constructors
| MkUnliftingEvaluationError | |
Instances
| Show UnliftingEvaluationError Source # | |
Defined in PlutusCore.Builtin.Result | |
| NFData UnliftingEvaluationError Source # | |
Defined in PlutusCore.Builtin.Result Methods rnf :: UnliftingEvaluationError -> () Source # | |
| Eq UnliftingEvaluationError Source # | |
Defined in PlutusCore.Builtin.Result Methods (==) :: UnliftingEvaluationError -> UnliftingEvaluationError -> Bool Source # (/=) :: UnliftingEvaluationError -> UnliftingEvaluationError -> Bool Source # | |
| Pretty UnliftingEvaluationError Source # | |
Defined in PlutusCore.Builtin.Result Methods pretty :: UnliftingEvaluationError -> Doc ann # prettyList :: [UnliftingEvaluationError] -> Doc ann # | |
data BuiltinError Source #
The type of errors that readKnown and makeKnown can return.
Instances
| Show BuiltinError Source # | |
Defined in PlutusCore.Builtin.Result | |
| Eq BuiltinError Source # | |
Defined in PlutusCore.Builtin.Result Methods (==) :: BuiltinError -> BuiltinError -> Bool Source # (/=) :: BuiltinError -> BuiltinError -> Bool Source # | |
| Pretty BuiltinError Source # | |
Defined in PlutusCore.Builtin.Result | |
| MonadError BuiltinError BuiltinResult Source # |
|
Defined in PlutusCore.Builtin.Result Methods throwError :: BuiltinError -> BuiltinResult a Source # catchError :: BuiltinResult a -> (BuiltinError -> BuiltinResult a) -> BuiltinResult a Source # | |
data BuiltinResult a Source #
The monad that makeKnown runs in.
Equivalent to ExceptT BuiltinError (Writer (DList Text)), except optimized in two ways:
- everything is strict
- has the
BuiltinSuccessconstructor 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 (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
we'd have to use text-builder or text-builder-linear or something of this sort.
Constructors
| BuiltinSuccess a | |
| BuiltinSuccessWithLogs (DList Text) a | |
| BuiltinFailure (DList Text) BuiltinError |
Instances
operationalUnliftingError :: Text -> BuiltinError Source #
Construct a prism focusing on the *EvaluationFailure part of err by taking
that *EvaluationFailure and
- pretty-printing and embedding it into an
UnliftingErrorfor the setter part of the prism - returning it directly for the opposite direction (there's no other way to convert an
UnliftingErrorto an evaluation failure, since the latter doesn't carry any content)
This is useful for providing AsUnliftingError instances for types such as CkUserError and
CekUserError.
emit :: Text -> BuiltinResult () Source #
Add a log line to the logs.
withLogs :: DList Text -> BuiltinResult a -> BuiltinResult a Source #
Prepend logs to a BuiltinResult computation.
throwing :: MonadError e m => AReview e t -> t -> m x #
throwing_ :: MonadError e m => AReview e () -> m x #
newtype Opaque val (rep :: Type) Source #
The AST of a value with a Plutus type attached to it. The type is for the Plutus type checker
to look at. Opaque can appear in the type of the denotation of a builtin.
Instances
| KnownTypeAst tyname uni rep => KnownTypeAst tyname uni (Opaque val rep :: Type) Source # | |
| uni ~ UniOf val => MakeKnownIn uni val (Opaque val rep) Source # | |
Defined in PlutusCore.Builtin.KnownType Methods makeKnown :: Opaque val rep -> BuiltinResult val Source # | |
| uni ~ UniOf val => ReadKnownIn uni val (Opaque val rep) Source # | |
Defined in PlutusCore.Builtin.KnownType Methods readKnown :: val -> ReadKnownM (Opaque val rep) Source # | |
| (TypeError NoConstraintsErrMsg :: Constraint) => Monoid (Opaque val rep) Source # | |
| (TypeError NoConstraintsErrMsg :: Constraint) => Semigroup (Opaque val rep) Source # | |
| (TypeError NoConstraintsErrMsg :: Constraint) => Bounded (Opaque val rep) Source # | |
| (TypeError NoConstraintsErrMsg :: Constraint) => Enum (Opaque val rep) Source # | |
Defined in PlutusCore.Builtin.Polymorphism Methods succ :: Opaque val rep -> Opaque val rep Source # pred :: Opaque val rep -> Opaque val rep Source # toEnum :: Int -> Opaque val rep Source # fromEnum :: Opaque val rep -> Int Source # enumFrom :: Opaque val rep -> [Opaque val rep] Source # enumFromThen :: Opaque val rep -> Opaque val rep -> [Opaque val rep] Source # enumFromTo :: Opaque val rep -> Opaque val rep -> [Opaque val rep] Source # enumFromThenTo :: Opaque val rep -> Opaque val rep -> Opaque val rep -> [Opaque val rep] Source # | |
| (TypeError NoConstraintsErrMsg :: Constraint) => Ix (Opaque val rep) Source # | |
Defined in PlutusCore.Builtin.Polymorphism Methods range :: (Opaque val rep, Opaque val rep) -> [Opaque val rep] Source # index :: (Opaque val rep, Opaque val rep) -> Opaque val rep -> Int Source # unsafeIndex :: (Opaque val rep, Opaque val rep) -> Opaque val rep -> Int Source # inRange :: (Opaque val rep, Opaque val rep) -> Opaque val rep -> Bool Source # rangeSize :: (Opaque val rep, Opaque val rep) -> Int Source # unsafeRangeSize :: (Opaque val rep, Opaque val rep) -> Int Source # | |
| (TypeError NoConstraintsErrMsg :: Constraint) => Num (Opaque val rep) Source # | |
Defined in PlutusCore.Builtin.Polymorphism Methods (+) :: Opaque val rep -> Opaque val rep -> Opaque val rep Source # (-) :: Opaque val rep -> Opaque val rep -> Opaque val rep Source # (*) :: Opaque val rep -> Opaque val rep -> Opaque val rep Source # negate :: Opaque val rep -> Opaque val rep Source # abs :: Opaque val rep -> Opaque val rep Source # signum :: Opaque val rep -> Opaque val rep Source # fromInteger :: Integer -> Opaque val rep Source # | |
| (TypeError NoConstraintsErrMsg :: Constraint) => Integral (Opaque val rep) Source # | |
Defined in PlutusCore.Builtin.Polymorphism Methods quot :: Opaque val rep -> Opaque val rep -> Opaque val rep Source # rem :: Opaque val rep -> Opaque val rep -> Opaque val rep Source # div :: Opaque val rep -> Opaque val rep -> Opaque val rep Source # mod :: Opaque val rep -> Opaque val rep -> Opaque val rep Source # quotRem :: Opaque val rep -> Opaque val rep -> (Opaque val rep, Opaque val rep) Source # divMod :: Opaque val rep -> Opaque val rep -> (Opaque val rep, Opaque val rep) Source # | |
| (TypeError NoConstraintsErrMsg :: Constraint) => Real (Opaque val rep) Source # | |
Defined in PlutusCore.Builtin.Polymorphism Methods toRational :: Opaque val rep -> Rational Source # | |
| (TypeError NoConstraintsErrMsg :: Constraint) => Eq (Opaque val rep) Source # | |
| (TypeError NoConstraintsErrMsg :: Constraint) => Ord (Opaque val rep) Source # | |
Defined in PlutusCore.Builtin.Polymorphism Methods compare :: Opaque val rep -> Opaque val rep -> Ordering Source # (<) :: Opaque val rep -> Opaque val rep -> Bool Source # (<=) :: Opaque val rep -> Opaque val rep -> Bool Source # (>) :: Opaque val rep -> Opaque val rep -> Bool Source # (>=) :: Opaque val rep -> Opaque val rep -> Bool Source # max :: Opaque val rep -> Opaque val rep -> Opaque val rep Source # min :: Opaque val rep -> Opaque val rep -> Opaque val rep Source # | |
| HasConstant val => HasConstant (Opaque val rep) Source # | |
Defined in PlutusCore.Builtin.Polymorphism | |
| ExMemoryUsage val => ExMemoryUsage (Opaque val rep) Source # | |
Defined in PlutusCore.Builtin.Polymorphism Methods memoryUsage :: Opaque val rep -> CostRose Source # | |
| type ToBinds uni acc (Opaque val rep :: Type) Source # | |
Defined in PlutusCore.Builtin.KnownTypeAst | |
| type ToHoles uni _1 (Opaque val rep :: Type) Source # | |
| type IsBuiltin uni (Opaque val rep :: Type) Source # | |
Defined in PlutusCore.Builtin.KnownTypeAst | |
| type UniOf (Opaque val rep) Source # | |
Defined in PlutusCore.Builtin.Polymorphism | |
newtype SomeConstant uni (rep :: Type) Source #
For unlifting from the Constant constructor when the stored value is of a monomorphic
built-in type
The rep parameter specifies how the type looks on the PLC side (i.e. just like with
Opaque val rep).
Constructors
| SomeConstant | |
Fields
| |
Instances
data TyNameRep (kind :: Type) Source #
Representation of a type variable: its name and unique and an implicit kind.
Instances
| (name ~ ('TyNameRep text uniq :: TyNameRep kind), KnownSymbol text, KnownNat uniq, KnownKind kind, KnownTypeAst tyname uni a) => KnownTypeAst tyname uni (MetaForall name a :: Type) Source # | |
Defined in PlutusCore.Examples.Builtins Associated Types type IsBuiltin uni (MetaForall name a) :: Bool Source # type ToHoles uni hole (MetaForall name a) :: [Hole] Source # type ToBinds uni acc (MetaForall name a) :: [Some TyNameRep] Source # | |
| KnownMonotype val args res => KnownPolytype ('[] :: [Some TyNameRep]) val args res Source # | Once we've run out of type-level arguments, we start handling term-level ones. |
Defined in PlutusCore.Builtin.Meaning Methods knownPolytype :: TypeScheme val args res Source # toPolyF :: ReadKnownM (FoldArgs args res, FoldArgs args ExBudgetStream) -> BuiltinRuntime val Source # | |
| (TypeError NoStandalonePolymorphicDataErrMsg :: Constraint) => Contains uni (TyVarRep :: TyNameRep kind -> kind) Source # | |
| (KnownSymbol name, KnownNat uniq, KnownKind kind, KnownPolytype binds val args res) => KnownPolytype ('Some ('TyNameRep name uniq :: TyNameRep kind) ': binds) val args res Source # | Every type-level argument becomes a |
Defined in PlutusCore.Builtin.Meaning Methods knownPolytype :: TypeScheme val args res Source # toPolyF :: ReadKnownM (FoldArgs args res, FoldArgs args ExBudgetStream) -> BuiltinRuntime val Source # | |
| type ToBinds uni acc (MetaForall name a :: Type) Source # | |
Defined in PlutusCore.Examples.Builtins | |
| type ToHoles uni _1 (MetaForall name a :: Type) Source # | |
Defined in PlutusCore.Examples.Builtins | |
| type IsBuiltin uni (MetaForall name a :: Type) Source # | |
Defined in PlutusCore.Examples.Builtins | |
data family TyVarRep (name :: TyNameRep kind) :: kind Source #
Representation of an intrinsically-kinded type variable: a name.
Instances
| (tyname ~ TyName, name ~ ('TyNameRep text uniq :: TyNameRep a), KnownSymbol text, KnownNat uniq) => KnownTypeAst tyname uni (TyVarRep name :: a) Source # | |
| (TypeError NoStandalonePolymorphicDataErrMsg :: Constraint) => Contains uni (TyVarRep :: TyNameRep kind -> kind) Source # | |
| type ToBinds uni acc (TyVarRep name :: a) Source # | |
Defined in PlutusCore.Builtin.KnownTypeAst | |
| type ToHoles uni _1 (TyVarRep name :: a) Source # | |
Defined in PlutusCore.Builtin.KnownTypeAst | |
| type IsBuiltin uni (TyVarRep name :: a) Source # | |
Defined in PlutusCore.Builtin.KnownTypeAst | |
data family TyAppRep (fun :: dom -> cod) (arg :: dom) :: cod Source #
Representation of an intrinsically-kinded type application: a function and an argument.
Instances
| (KnownTypeAst tyname uni fun, KnownTypeAst tyname uni arg) => KnownTypeAst tyname uni (TyAppRep fun arg :: a) Source # | |
| type ToBinds uni acc (TyAppRep fun arg :: a) Source # | |
Defined in PlutusCore.Builtin.KnownTypeAst | |
| type ToHoles uni _1 (TyAppRep fun arg :: a) Source # | |
| type IsBuiltin uni (TyAppRep fun arg :: a) Source # | |
data family TyForallRep (name :: TyNameRep kind) (a :: Type) :: Type Source #
Representation of of an intrinsically-kinded universal quantifier: a bound name and a body.
Instances
| (tyname ~ TyName, name ~ ('TyNameRep text uniq :: TyNameRep kind), KnownSymbol text, KnownNat uniq, KnownKind kind, KnownTypeAst tyname uni a) => KnownTypeAst tyname uni (TyForallRep name a :: Type) Source # | |
Defined in PlutusCore.Builtin.KnownTypeAst Associated Types type IsBuiltin uni (TyForallRep name a) :: Bool Source # type ToHoles uni hole (TyForallRep name a) :: [Hole] Source # type ToBinds uni acc (TyForallRep name a) :: [Some TyNameRep] Source # | |
| type ToBinds uni acc (TyForallRep name a :: Type) Source # | |
Defined in PlutusCore.Builtin.KnownTypeAst | |
| type ToHoles uni _1 (TyForallRep name a :: Type) Source # | |
Defined in PlutusCore.Builtin.KnownTypeAst | |
| type IsBuiltin uni (TyForallRep name a :: Type) Source # | |
Defined in PlutusCore.Builtin.KnownTypeAst | |
data family BuiltinHead x Source #
For annotating an uninstantiated built-in type, so that it gets handled by the right instance or type family.
Instances
| Contains uni f => KnownTypeAst tyname uni (BuiltinHead f :: a) Source # | |
Defined in PlutusCore.Builtin.KnownTypeAst Associated Types type IsBuiltin uni (BuiltinHead f) :: Bool Source # type ToHoles uni hole (BuiltinHead f) :: [Hole] Source # type ToBinds uni acc (BuiltinHead f) :: [Some TyNameRep] Source # | |
| type ToBinds uni acc (BuiltinHead f :: a) Source # | |
Defined in PlutusCore.Builtin.KnownTypeAst | |
| type ToHoles uni _1 (BuiltinHead f :: a) Source # | |
Defined in PlutusCore.Builtin.KnownTypeAst | |
| type IsBuiltin uni (BuiltinHead f :: a) Source # | |
Defined in PlutusCore.Builtin.KnownTypeAst | |
data family LastArg x y Source #
LastArg x y is the same thing as y in the signature of the denotation of a built-in
functions and this type is only used for referencing x before y, so that the elaboration
machinery generates x before y in the all part of the Plutus signature of the builtin.
This is a very hacky and indirect way of specifying the ordering of type variables in a Plutus
signature, in future we'll do it explicitly by introducing a Forall binder for use in type
signatures of denotations of builtins.
type family ElaborateBuiltin uni x Source #
Take an iterated application of a built-in type and elaborate every function application
inside of it to TyAppRep and annotate the head with BuiltinHead.
The idea is that we don't need to process built-in types manually if we simply add some
annotations for instance resolution to look for. Think what we'd have to do manually for, say,
ToHoles: traverse the spine of the application and collect all the holes into a list, which is
troubling, because type applications are left-nested and lists are right-nested, so we'd have to
use accumulators or an explicit Reverse type family. And then we also have KnownTypeAst and
ToBinds, so handling built-in types in a special way for each of those would be a hassle,
especially given the fact that type-level Haskell is not exactly good at computing things.
With the ElaborateBuiltin approach we get KnownTypeAst, ToHoles and ToBinds for free.
We make this an open type family, so that elaboration is customizable for each universe.
Instances
| type ElaborateBuiltin DefaultUni (x :: a) Source # | |
Defined in PlutusCore.Default.Universe | |
type family AllElaboratedArgs constr x where ... Source #
Take a constraint and use it to constrain every argument of a possibly 0-ary elaborated application of a built-in type.
Equations
| AllElaboratedArgs constr (f `TyAppRep` x) = (constr x, AllElaboratedArgs constr f) | |
| AllElaboratedArgs _ (BuiltinHead _) = () |
class AllElaboratedArgs constr (ElaborateBuiltin uni x) => AllBuiltinArgs uni constr x Source #
Take a constraint and use it to constrain every argument of a possibly 0-ary application of a built-in type.
Instances
| AllElaboratedArgs constr (ElaborateBuiltin uni x) => AllBuiltinArgs uni constr (x :: a) Source # | |
Defined in PlutusCore.Builtin.Polymorphism | |
type family FoldArgs args res where ... Source #
Turn a list of Haskell types args into a functional type ending in res.
>>>:set -XDataKinds>>>:kind! FoldArgs [(), Bool] IntegerFoldArgs [(), Bool] Integer :: * = () -> Bool -> Integer
data BuiltinMeaning val cost Source #
The meaning of a built-in function consists of its type represented as a TypeScheme,
its Haskell denotation and its uninstantiated runtime denotation.
The TypeScheme of a built-in function is used for example for
- computing the PLC type of the function to be used during type checking
- getting arity information
- generating arbitrary values to apply the function to in tests
The denotation is lazy, so that we don't need to worry about a builtin being bottom (happens in tests). The production path is not affected by that, since only runtime denotations are used for evaluation.
Constructors
| forall args res. BuiltinMeaning (TypeScheme val args res) ~(FoldArgs args res) (cost -> BuiltinRuntime val) |
type HasMeaningIn uni val = (Typeable val, ExMemoryUsage val, HasConstantIn uni val) Source #
Constraints available when defining a built-in function.
class (Typeable uni, Typeable fun, Bounded fun, Enum fun, Ix fun, Default (BuiltinSemanticsVariant fun)) => ToBuiltinMeaning uni fun where Source #
A type class for "each function from a set of built-in functions has a BuiltinMeaning".
Associated Types
type CostingPart uni fun Source #
The cost part of BuiltinMeaning.
data BuiltinSemanticsVariant fun Source #
See Note [Builtin semantics variants]
Methods
toBuiltinMeaning :: HasMeaningIn uni val => BuiltinSemanticsVariant fun -> fun -> BuiltinMeaning val (CostingPart uni fun) Source #
Get the BuiltinMeaning of a built-in function.
Instances
withTypeSchemeOfBuiltinFunction :: forall val fun r. (ToBuiltinMeaning (UniOf val) fun, ExMemoryUsage val, Typeable val, HasConstant val) => BuiltinSemanticsVariant fun -> fun -> (forall args res. TypeScheme val args res -> r) -> r Source #
Feed the TypeScheme of the given built-in function to the continuation.
typeOfBuiltinFunction :: forall uni fun. ToBuiltinMeaning uni fun => BuiltinSemanticsVariant fun -> fun -> Type TyName uni () Source #
Get the type of a built-in function.
class KnownMonotype val args res where Source #
A class that allows us to derive a monotype for a builtin.
We could've computed the runtime denotation from the
TypeScheme and the denotation of the builtin, but not statically (due to unfolding not working
for recursive functions and TypeScheme being recursive, i.e. requiring the conversion function
to be recursive), and so it would cause us to retain a lot of evaluation-irrelevant stuff in the
constructors of BuiltinRuntime, which has to make evaluation slower (we didn't check) and
certainly makes the generated Core much harder to read. Technically speaking, we could get
a RuntimeScheme from the TypeScheme and the denotation statically if we changed the
definition of TypeScheme and made it a singleton, but then the conversion function would have
to become a class anyway and we'd just replicate what we have here, except in a much more
complicated way.
Methods
knownMonotype :: TypeScheme val args res Source #
toMonoF :: ReadKnownM (FoldArgs args res, FoldArgs args ExBudgetStream) -> BuiltinRuntime val Source #
Convert the denotation of a builtin to its runtime counterpart.
The argument is in ReadKnownM, because that's what deferred unlifting amounts to:
passing the action returning the builtin application around until full saturation, which is
when the action actually gets run.
Instances
| (Typeable res, KnownTypeAst TyName (UniOf val) res, MakeKnown val res) => KnownMonotype val ('[] :: [Type]) res Source # | Once we've run out of term-level arguments, we return a
|
Defined in PlutusCore.Builtin.Meaning Methods knownMonotype :: TypeScheme val '[] res Source # toMonoF :: ReadKnownM (FoldArgs '[] res, FoldArgs '[] ExBudgetStream) -> BuiltinRuntime val Source # | |
| (Typeable arg, KnownTypeAst TyName (UniOf val) arg, MakeKnown val arg, ReadKnown val arg, KnownMonotype val args res) => KnownMonotype val (arg ': args) res Source # | Every term-level argument becomes a |
Defined in PlutusCore.Builtin.Meaning Methods knownMonotype :: TypeScheme val (arg ': args) res Source # toMonoF :: ReadKnownM (FoldArgs (arg ': args) res, FoldArgs (arg ': args) ExBudgetStream) -> BuiltinRuntime val Source # | |
class KnownMonotype val args res => KnownPolytype (binds :: [Some TyNameRep]) val args res where Source #
A class that allows us to derive a polytype for a builtin.
Methods
knownPolytype :: TypeScheme val args res Source #
toPolyF :: ReadKnownM (FoldArgs args res, FoldArgs args ExBudgetStream) -> BuiltinRuntime val Source #
Convert the denotation of a builtin to its runtime counterpart.
The argument is in ReadKnownM, because that's what we need to do:
passing the action returning the builtin application around until full saturation, which is
when the action actually gets run.
Instances
| KnownMonotype val args res => KnownPolytype ('[] :: [Some TyNameRep]) val args res Source # | Once we've run out of type-level arguments, we start handling term-level ones. |
Defined in PlutusCore.Builtin.Meaning Methods knownPolytype :: TypeScheme val args res Source # toPolyF :: ReadKnownM (FoldArgs args res, FoldArgs args ExBudgetStream) -> BuiltinRuntime val Source # | |
| (KnownSymbol name, KnownNat uniq, KnownKind kind, KnownPolytype binds val args res) => KnownPolytype ('Some ('TyNameRep name uniq :: TyNameRep kind) ': binds) val args res Source # | Every type-level argument becomes a |
Defined in PlutusCore.Builtin.Meaning Methods knownPolytype :: TypeScheme val args res Source # toPolyF :: ReadKnownM (FoldArgs args res, FoldArgs args ExBudgetStream) -> BuiltinRuntime val Source # | |
type family ThrowOnBothEmpty binds args isBuiltin a where ... Source #
Ensure a built-in function is not nullary and throw a nice error otherwise.
Equations
| ThrowOnBothEmpty '[] '[] 'True a = TypeError (('Text "A built-in function must take at least one type or term argument" ':$$: ((('Text "\8216" ':<>: 'ShowType a) ':<>: 'Text "\8217 is a built-in type") ':<>: 'Text " so you can embed any of its values as a constant")) ':$$: 'Text "If you still want a built-in function, add a dummy \8216()\8217 argument") | |
| ThrowOnBothEmpty '[] '[] 'False a = TypeError ('Text "A built-in function must take at least one type or term argument" ':$$: 'Text "To fix this error add a dummy \8216()\8217 argument") | |
| ThrowOnBothEmpty _ _ _ _ = () |
class MakeBuiltinMeaning a val where Source #
A function turned into a type class with exactly one fully general instance.
We can't package up the constraints of makeBuiltinMeaning (see the instance) into a type or
class synonym, because they contain a bunch of variables defined by ~ or determined via
functional dependencies and neither class nor type definitions can handle that
(see https://gitlab.haskell.org/ghc/ghc/-/issues/7100). Inlining three lines of constraints
whenever we need to call makeBuiltinMeaning over a non-concrete type is a bad option and this
abstraction is free anyway, hence its existence.
The a type variable goes first, because makeBuiltinMeaning @A is a common pattern.
Methods
makeBuiltinMeaning :: a -> (cost -> FoldArgs (GetArgs a) ExBudgetStream) -> BuiltinMeaning val cost Source #
Construct the meaning for a built-in function by automatically deriving its
TypeScheme, given
- the denotation of the builtin
- an uninstantiated costing function
Instances
| (uni ~ UniOf val, binds ~ ToBinds uni ('[] :: [Some TyNameRep]) a, args ~ GetArgs a, a ~ FoldArgs args res, ThrowOnBothEmpty binds args (IsBuiltin uni a) a, ElaborateFromTo uni 0 j val a, KnownPolytype binds val args res) => MakeBuiltinMeaning a val Source # | |
Defined in PlutusCore.Builtin.Meaning Methods makeBuiltinMeaning :: a -> (cost -> FoldArgs (GetArgs a) ExBudgetStream) -> BuiltinMeaning val cost Source # | |
toBuiltinRuntime :: cost -> BuiltinMeaning val cost -> BuiltinRuntime val Source #
Convert a BuiltinMeaning to a BuiltinRuntime given a cost model.
toBuiltinsRuntime :: (cost ~ CostingPart uni fun, ToBuiltinMeaning uni fun, HasMeaningIn uni val) => BuiltinSemanticsVariant fun -> cost -> BuiltinsRuntime fun val Source #
Calculate runtime info for all built-in functions given meanings of builtins (as a constraint), the semantics variant of the set of builtins and a cost model.
data TyNameRep (kind :: Type) Source #
Representation of a type variable: its name and unique and an implicit kind.
Instances
| (name ~ ('TyNameRep text uniq :: TyNameRep kind), KnownSymbol text, KnownNat uniq, KnownKind kind, KnownTypeAst tyname uni a) => KnownTypeAst tyname uni (MetaForall name a :: Type) Source # | |
Defined in PlutusCore.Examples.Builtins Associated Types type IsBuiltin uni (MetaForall name a) :: Bool Source # type ToHoles uni hole (MetaForall name a) :: [Hole] Source # type ToBinds uni acc (MetaForall name a) :: [Some TyNameRep] Source # | |
| KnownMonotype val args res => KnownPolytype ('[] :: [Some TyNameRep]) val args res Source # | Once we've run out of type-level arguments, we start handling term-level ones. |
Defined in PlutusCore.Builtin.Meaning Methods knownPolytype :: TypeScheme val args res Source # toPolyF :: ReadKnownM (FoldArgs args res, FoldArgs args ExBudgetStream) -> BuiltinRuntime val Source # | |
| (TypeError NoStandalonePolymorphicDataErrMsg :: Constraint) => Contains uni (TyVarRep :: TyNameRep kind -> kind) Source # | |
| (KnownSymbol name, KnownNat uniq, KnownKind kind, KnownPolytype binds val args res) => KnownPolytype ('Some ('TyNameRep name uniq :: TyNameRep kind) ': binds) val args res Source # | Every type-level argument becomes a |
Defined in PlutusCore.Builtin.Meaning Methods knownPolytype :: TypeScheme val args res Source # toPolyF :: ReadKnownM (FoldArgs args res, FoldArgs args ExBudgetStream) -> BuiltinRuntime val Source # | |
| type ToBinds uni acc (MetaForall name a :: Type) Source # | |
Defined in PlutusCore.Examples.Builtins | |
| type ToHoles uni _1 (MetaForall name a :: Type) Source # | |
Defined in PlutusCore.Examples.Builtins | |
| type IsBuiltin uni (MetaForall name a :: Type) Source # | |
Defined in PlutusCore.Examples.Builtins | |
data family TyVarRep (name :: TyNameRep kind) :: kind Source #
Representation of an intrinsically-kinded type variable: a name.
Instances
| (tyname ~ TyName, name ~ ('TyNameRep text uniq :: TyNameRep a), KnownSymbol text, KnownNat uniq) => KnownTypeAst tyname uni (TyVarRep name :: a) Source # | |
| (TypeError NoStandalonePolymorphicDataErrMsg :: Constraint) => Contains uni (TyVarRep :: TyNameRep kind -> kind) Source # | |
| type ToBinds uni acc (TyVarRep name :: a) Source # | |
Defined in PlutusCore.Builtin.KnownTypeAst | |
| type ToHoles uni _1 (TyVarRep name :: a) Source # | |
Defined in PlutusCore.Builtin.KnownTypeAst | |
| type IsBuiltin uni (TyVarRep name :: a) Source # | |
Defined in PlutusCore.Builtin.KnownTypeAst | |
data family TyAppRep (fun :: dom -> cod) (arg :: dom) :: cod Source #
Representation of an intrinsically-kinded type application: a function and an argument.
Instances
| (KnownTypeAst tyname uni fun, KnownTypeAst tyname uni arg) => KnownTypeAst tyname uni (TyAppRep fun arg :: a) Source # | |
| type ToBinds uni acc (TyAppRep fun arg :: a) Source # | |
Defined in PlutusCore.Builtin.KnownTypeAst | |
| type ToHoles uni _1 (TyAppRep fun arg :: a) Source # | |
| type IsBuiltin uni (TyAppRep fun arg :: a) Source # | |
data family TyForallRep (name :: TyNameRep kind) (a :: Type) :: Type Source #
Representation of of an intrinsically-kinded universal quantifier: a bound name and a body.
Instances
| (tyname ~ TyName, name ~ ('TyNameRep text uniq :: TyNameRep kind), KnownSymbol text, KnownNat uniq, KnownKind kind, KnownTypeAst tyname uni a) => KnownTypeAst tyname uni (TyForallRep name a :: Type) Source # | |
Defined in PlutusCore.Builtin.KnownTypeAst Associated Types type IsBuiltin uni (TyForallRep name a) :: Bool Source # type ToHoles uni hole (TyForallRep name a) :: [Hole] Source # type ToBinds uni acc (TyForallRep name a) :: [Some TyNameRep] Source # | |
| type ToBinds uni acc (TyForallRep name a :: Type) Source # | |
Defined in PlutusCore.Builtin.KnownTypeAst | |
| type ToHoles uni _1 (TyForallRep name a :: Type) Source # | |
Defined in PlutusCore.Builtin.KnownTypeAst | |
| type IsBuiltin uni (TyForallRep name a :: Type) Source # | |
Defined in PlutusCore.Builtin.KnownTypeAst | |
type family RunHole hole where ... Source #
Turn a hole in the GHC.Type -> GHC.Type form into one of the Hole form. This only changes
the kind of the given argument. This is a way of encoding forall a. a -> Hole at the kind
level, which we don't attempt to use, because GHC apparently hates polymorphism at the kind
level and chokes upon encountering it.
type HasTermLevel uni = Includes uni Source #
Specifies that the given type is a built-in one and its values can be embedded into a Term.
type HasTypeLevel uni x = KnownTypeAst Void uni (ElaborateBuiltin uni x) Source #
Specifies that the given type is a built-in one and can be embedded into a Kind.
type HasTypeAndTermLevel uni x = (uni `HasTypeLevel` x, uni `HasTermLevel` x) Source #
The product of HasTypeLevel and HasTermLevel.
mkTyBuiltin :: forall a (x :: a) uni ann tyname. uni `HasTypeLevel` x => ann -> Type tyname uni ann Source #
Convert a Haskell representation of a possibly 0-ary application of a built-in type to
arbitrary types implementing KnownTypeAst.
type KnownBuiltinTypeAst tyname uni x = AllBuiltinArgs uni (KnownTypeAst tyname uni) x Source #
A constraint for "a is a KnownTypeAst by means of being included in uni".
class KnownTypeAst tyname uni x where Source #
This class allows one to convert the type-level Haskell representation of a Plutus type into the corresponding Plutus type. Associated type families are needed to help elaboration.
Depending on the universe converting a Haskell type to a Plutus team can give different results
(e.g. Int can be a built-in type instead of being encoded via built-in Integer), hence this
class takes a uni argument. Plus, elaboration is universe-specific too.
Minimal complete definition
Nothing
Associated Types
type IsBuiltin uni x :: Bool Source #
Whether x is a built-in type.
type IsBuiltin uni x = IsBuiltin uni (ElaborateBuiltin uni x)
type ToHoles uni (hole :: Type -> Type) x :: [Hole] Source #
Return every part of the type that can be a to-be-instantiated type variable.
For example, in Integer there's no such types and in (a, b) it's the two arguments
(a and b) and the same applies to a -> b (to mention a type that is not built-in).
Takes a hole in the GHC.Type -> GHC.Type form (a convention originally adopted in the
elaborator, perhaps not a very helpful one), which can be turned into an actual Hole via
RunHole.
type ToHoles uni hole x = ToHoles uni hole (ElaborateBuiltin uni x)
type ToBinds uni (acc :: [Some TyNameRep]) x :: [Some TyNameRep] Source #
Collect all unique variables (a variable consists of a textual name, a unique and a kind) in an accumulator and return the accumulator once a leaf is reached.
type ToBinds uni acc x = ToBinds uni acc (ElaborateBuiltin uni x)
Methods
typeAst :: Type tyname uni () Source #
The Plutus counterpart of the x type.
default typeAst :: KnownTypeAst tyname uni (ElaborateBuiltin uni x) => Type tyname uni () Source #
Instances
toTypeAst :: forall a tyname uni (x :: a) proxy. KnownTypeAst tyname uni x => proxy x -> Type tyname uni () Source #
Return the Plutus counterpart of the x type.
type family Delete x xs where ... Source #
Delete the first x from a list. Which is okay since we only ever put things in once.
data BuiltinError Source #
The type of errors that readKnown and makeKnown can return.
Instances
| Show BuiltinError Source # | |
Defined in PlutusCore.Builtin.Result | |
| Eq BuiltinError Source # | |
Defined in PlutusCore.Builtin.Result Methods (==) :: BuiltinError -> BuiltinError -> Bool Source # (/=) :: BuiltinError -> BuiltinError -> Bool Source # | |
| Pretty BuiltinError Source # | |
Defined in PlutusCore.Builtin.Result | |
| MonadError BuiltinError BuiltinResult Source # |
|
Defined in PlutusCore.Builtin.Result Methods throwError :: BuiltinError -> BuiltinResult a Source # catchError :: BuiltinResult a -> (BuiltinError -> BuiltinResult a) -> BuiltinResult a Source # | |
A version of GEq that fixes a in place, which allows us to create an inlinable recursive
implementation of geqL.
The way it works is that whenever there's recursion, we look up the recursive case in the current
context (i.e. the dictionary) instead of actually calling geqL recursively (even though it's
gonna look like we do exactly that, because there's no way to distinguish between a recursive
call and a dictionary lookup as the two share the same name, although to help GHC choose a lookup
we sprinkle the perhaps unreliable LoopBreaker in the DefaultUni instance of this class).
Alligning things this way allows us to inline arbitrarily deep recursion for as long as types keep being monomorphic.
For example, the MapData builtin accepts a [(Data, Data)] and with geqL matching on all of
DefaultUniProtoList, DefaultUniProtoPair and DefaultUniData gets inlined in the denotation
of the builtin. For the Constr builtin that resulted in a 4.3% speedup at the time this comment
was written.
Instances
| AllBuiltinArgs DefaultUni (GEqL DefaultUni) a => GEqL DefaultUni a Source # | |
Defined in PlutusCore.Default.Universe Methods geqL :: DefaultUni (Esc a) -> DefaultUni (Esc b) -> EvaluationResult (a :~: b) Source # | |
| GEqL uni a => GEqL (LoopBreaker uni) a Source # | |
Defined in PlutusCore.Builtin.KnownType Methods geqL :: LoopBreaker uni (Esc a) -> LoopBreaker uni (Esc b) -> EvaluationResult (a :~: b) Source # | |
newtype LoopBreaker uni a Source #
In f = ... f ... where f is a class method, how do you know if f is going to be a
recursive call or a type class method call? If both type check, then you don't really know how
GHC is going to play it. So we add this data type to make sure that the RHS f will have to
become a type class method call.
Can GHC turn that method call into a recursive one once type classes are resolved? Dunno, but at least we've introduced an obstacle preventing GHC from immediately creating a non-inlinable recursive definition.
Constructors
| LoopBreaker (uni a) |
Instances
| GEqL uni a => GEqL (LoopBreaker uni) a Source # | |
Defined in PlutusCore.Builtin.KnownType Methods geqL :: LoopBreaker uni (Esc a) -> LoopBreaker uni (Esc b) -> EvaluationResult (a :~: b) Source # | |
type KnownBuiltinTypeIn uni val a = (HasConstantIn uni val, PrettyParens (SomeTypeIn uni), GEqL uni a, uni `HasTermLevel` a) Source #
A constraint for "a is a ReadKnownIn and MakeKnownIn by means of being included
in uni".
type KnownBuiltinType val a = KnownBuiltinTypeIn (UniOf val) val a Source #
A constraint for "a is a ReadKnownIn and MakeKnownIn by means of being included
in UniOf term".
data BuiltinResult a Source #
The monad that makeKnown runs in.
Equivalent to ExceptT BuiltinError (Writer (DList Text)), except optimized in two ways:
- everything is strict
- has the
BuiltinSuccessconstructor 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 (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
we'd have to use text-builder or text-builder-linear or something of this sort.
Constructors
| BuiltinSuccess a | |
| BuiltinSuccessWithLogs (DList Text) a | |
| BuiltinFailure (DList Text) BuiltinError |
Instances
type ReadKnownM = Either BuiltinError Source #
The monad that readKnown runs in.
A non-empty spine. Isomorphic to NonEmpty, except is strict and is defined as a single
recursive data type.
Instances
| Foldable Spine Source # | |
Defined in PlutusCore.Builtin.KnownType Methods fold :: Monoid m => Spine m -> m Source # foldMap :: Monoid m => (a -> m) -> Spine a -> m Source # foldMap' :: Monoid m => (a -> m) -> Spine a -> m Source # foldr :: (a -> b -> b) -> b -> Spine a -> b Source # foldr' :: (a -> b -> b) -> b -> Spine a -> b Source # foldl :: (b -> a -> b) -> b -> Spine a -> b Source # foldl' :: (b -> a -> b) -> b -> Spine a -> b Source # foldr1 :: (a -> a -> a) -> Spine a -> a Source # foldl1 :: (a -> a -> a) -> Spine a -> a Source # toList :: Spine a -> [a] Source # null :: Spine a -> Bool Source # length :: Spine a -> Int Source # elem :: Eq a => a -> Spine a -> Bool Source # maximum :: Ord a => Spine a -> a Source # minimum :: Ord a => Spine a -> a Source # | |
| Functor Spine Source # | |
| PrettyBy config a => DefaultPrettyBy config (Spine a) Source # | |
Defined in PlutusCore.Builtin.KnownType Methods defaultPrettyBy :: config -> Spine a -> Doc ann defaultPrettyListBy :: config -> [Spine a] -> Doc ann | |
| PrettyDefaultBy config (Spine a) => PrettyBy config (Spine a) Source # | |
Defined in PlutusCore.Builtin.KnownType | |
| Show a => Show (Spine a) Source # | |
| Eq a => Eq (Spine a) Source # | |
| Pretty a => Pretty (Spine a) Source # |
|
Defined in PlutusCore.Builtin.KnownType | |
data HeadSpine err a b Source #
The head-spine form of an iterated application. Provides O(1) access to the head of the
application. NonEmpty a ~ HeadSpine a a, except is strict and the no-spine case is made a separate
constructor for performance reasons (it only takes a single pattern match to access the head when
there's no spine this way, while otherwise we'd also need to match on the spine to ensure that
it's empty -- and the no-spine case is by far the most common one, hence we want to optimize it).
Used in built-in functions returning function applications such as CaseList.
Instances
| (PrettyBy config err, PrettyBy config a, PrettyBy config (Spine b)) => DefaultPrettyBy config (HeadSpine err a b) Source # | |
Defined in PlutusCore.Builtin.KnownType Methods defaultPrettyBy :: config -> HeadSpine err a b -> Doc ann defaultPrettyListBy :: config -> [HeadSpine err a b] -> Doc ann | |
| PrettyDefaultBy config (HeadSpine err a b) => PrettyBy config (HeadSpine err a b) Source # | |
Defined in PlutusCore.Builtin.KnownType | |
| Bifunctor (HeadSpine err) Source # | |
| Functor (HeadSpine err a) Source # | |
| (Show a, Show b, Show err) => Show (HeadSpine err a b) Source # | |
| (Eq a, Eq b, Eq err) => Eq (HeadSpine err a b) Source # | |
| (Pretty err, Pretty a, Pretty b) => Pretty (HeadSpine err a b) Source # |
|
Defined in PlutusCore.Builtin.KnownType | |
type MonoHeadSpine err a = HeadSpine err a a Source #
HeadSpine but the type of head and spine is same
class uni ~ UniOf val => MakeKnownIn uni val a where Source #
Minimal complete definition
Nothing
Methods
makeKnown :: a -> BuiltinResult val Source #
Convert a Haskell value to the corresponding PLC value.
The inverse of readKnown.
default makeKnown :: KnownBuiltinType val a => a -> BuiltinResult val Source #
Instances
readKnownConstant :: forall val a. KnownBuiltinType val a => val -> ReadKnownM a Source #
Convert a constant embedded into a PLC term to the corresponding Haskell value.
type MakeKnown val = MakeKnownIn (UniOf val) val Source #
class uni ~ UniOf val => ReadKnownIn uni val a where Source #
Minimal complete definition
Nothing
Methods
readKnown :: val -> ReadKnownM a Source #
Convert a PLC value to the corresponding Haskell value.
The inverse of makeKnown.
default readKnown :: KnownBuiltinType val a => val -> ReadKnownM a Source #
Instances
type ReadKnown val = ReadKnownIn (UniOf val) val Source #
makeKnownOrFail :: MakeKnownIn uni val a => a -> EvaluationResult val Source #
Same as makeKnown, but allows for neither emitting nor storing the cause of a failure.
readKnownSelf :: (ReadKnown val a, BuiltinErrorToEvaluationError structural operational) => val -> Either (ErrorWithCause (EvaluationError structural operational) val) a Source #
Same as readKnown, but the cause of a potential failure is the provided term itself.
withSingKind :: Kind ann -> (forall k. SingKind k -> r) -> r Source #
class KnownKind k where Source #
For reifying Haskell kinds representing Plutus kinds at the term level.
bringKnownKind :: SingKind k -> (KnownKind k => r) -> r Source #
class ToKind (uni :: Type -> Type) where Source #
For computing the Plutus kind of a built-in type. See kindOfBuiltinType.
Methods
toSingKind :: uni (Esc (a :: k)) -> SingKind k Source #
Reify the kind of a type from the universe at the term level.
Instances
| ToKind DefaultUni Source # | |
Defined in PlutusCore.Default.Universe Methods toSingKind :: forall k (a :: k). DefaultUni (Esc a) -> SingKind k Source # | |
demoteKind :: SingKind k -> Kind () Source #
Convert a reified Haskell kind to a Plutus kind.
kindOfBuiltinType :: ToKind uni => uni (Esc a) -> Kind () Source #
Compute the kind of a type from a universe.
data BuiltinError Source #
The type of errors that readKnown and makeKnown can return.
Instances
| Show BuiltinError Source # | |
Defined in PlutusCore.Builtin.Result | |
| Eq BuiltinError Source # | |
Defined in PlutusCore.Builtin.Result Methods (==) :: BuiltinError -> BuiltinError -> Bool Source # (/=) :: BuiltinError -> BuiltinError -> Bool Source # | |
| Pretty BuiltinError Source # | |
Defined in PlutusCore.Builtin.Result | |
| MonadError BuiltinError BuiltinResult Source # |
|
Defined in PlutusCore.Builtin.Result Methods throwError :: BuiltinError -> BuiltinResult a Source # catchError :: BuiltinResult a -> (BuiltinError -> BuiltinResult a) -> BuiltinResult a Source # | |
class HasConstant term where Source #
Ensures that term has a Constant-like constructor to lift values to and unlift values from.
Methods
asConstant :: term -> Either BuiltinError (Some (ValueOf (UniOf term))) Source #
Unwrap from a Constant-like constructor throwing an UnliftingError if the provided
term is not a wrapped Haskell value.
fromConstant :: Some (ValueOf (UniOf term)) -> term Source #
Wrap a Haskell value as a term.
Instances
| HasConstant val => HasConstant (Opaque val rep) Source # | |
Defined in PlutusCore.Builtin.Polymorphism | |
| HasConstant (SomeConstant uni rep) Source # | |
Defined in PlutusCore.Builtin.Polymorphism Methods asConstant :: SomeConstant uni rep -> Either BuiltinError (Some (ValueOf (UniOf (SomeConstant uni rep)))) Source # fromConstant :: Some (ValueOf (UniOf (SomeConstant uni rep))) -> SomeConstant uni rep Source # | |
| HasConstant (CkValue uni fun) Source # | |
Defined in PlutusCore.Evaluation.Machine.Ck | |
| HasConstant (CekValue uni fun ann) Source # | |
| HasConstant (Term name uni fun ()) Source # | |
Defined in UntypedPlutusCore.Core.Type | |
| HasConstant (Term TyName Name uni fun ()) Source # | |
type HasConstantIn uni term = (UniOf term ~ uni, HasConstant term) Source #
Ensures that term has a Constant-like constructor to lift values to and unlift values from
and connects term and its uni.
fromValueOf :: forall a term. HasConstant term => UniOf term (Esc a) -> a -> term Source #
Wrap a Haskell value (given its explicit type tag) as a term.
fromValue :: forall a term. (HasConstant term, UniOf term `HasTermLevel` a) => a -> term Source #
Wrap a Haskell value (provided its type is in the universe) as a term.
class AnnotateCaseBuiltin uni where Source #
Methods
annotateCaseBuiltin :: UniOf term ~ uni => Type TyName uni ann -> [term] -> Either Text [(term, [Type TyName uni ann])] Source #
Given a tag for a built-in type and a list of branches, annotate each of the branches with its expected argument types or fail if casing on values of the built-in type isn't supported. Note: you don't need to include the resulting type of the whole case matching in the returning list here.
Instances
| AnnotateCaseBuiltin DefaultUni Source # | |
Defined in PlutusCore.Default.Universe Methods annotateCaseBuiltin :: UniOf term ~ DefaultUni => Type TyName DefaultUni ann -> [term] -> Either Text [(term, [Type TyName DefaultUni ann])] Source # | |
class CaseBuiltin uni where Source #
Methods
caseBuiltin :: UniOf term ~ uni => Some (ValueOf uni) -> Vector term -> HeadSpine Text term (Some (ValueOf uni)) Source #
Given a constant with its type tag and a vector of branches, choose the appropriate branch or fail if the constant doesn't correspond to any of the branches (or casing on constants of this type isn't supported at all).
Instances
| CaseBuiltin DefaultUni Source # | |
Defined in PlutusCore.Default.Universe Methods caseBuiltin :: UniOf term ~ DefaultUni => Some (ValueOf DefaultUni) -> Vector term -> HeadSpine Text term (Some (ValueOf DefaultUni)) Source # | |
data CaserBuiltin uni Source #
A data version of CaseBuiltin. we parameterize the evaluator by a CaserBuiltin so that
the caller can choose whether to use the caseBuiltin method or the always failing caser (the
latter is required for earlier protocol versions when we didn't support casing on builtins).
Constructors
| CaserBuiltin | |
Instances
| CaseBuiltin uni => Default (CaserBuiltin uni) Source # | |
Defined in PlutusCore.Builtin.Case Methods def :: CaserBuiltin uni # | |
| NFData (CaserBuiltin uni) Source # | |
Defined in PlutusCore.Builtin.Case Methods rnf :: CaserBuiltin uni -> () Source # | |
| NoThunks (CaserBuiltin uni) Source # | |
Defined in PlutusCore.Builtin.Case Methods noThunks :: Context -> CaserBuiltin uni -> IO (Maybe ThunkInfo) wNoThunks :: Context -> CaserBuiltin uni -> IO (Maybe ThunkInfo) showTypeOf :: Proxy (CaserBuiltin uni) -> String | |
unavailableCaserBuiltin :: Int -> CaserBuiltin uni Source #